<commit_before>package com.intellij.openapi.vcs.impl;

import com.intellij.openapi.editor.Document;
import com.intellij.openapi.localVcs.UpToDateLineNumberProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ex.LineStatusTracker;
import com.intellij.openapi.vcs.ex.Range;

import java.util.List;

/**
 * author: lesya
 */
public class UpToDateLineNumberProviderImpl implements UpToDateLineNumberProvider {
  private final Document myDocument;
  private final Project myProject;
  private final String myUpToDateContent;

  public UpToDateLineNumberProviderImpl(Document document, Project project, String upToDateContent) {
    myDocument = document;
    myProject = project;
    myUpToDateContent = upToDateContent;
  }

  public int getLineNumber(int currentNumber) {
    LineStatusTracker tracker = LineStatusTrackerManager.getInstance(myProject).getLineStatusTracker(myDocument);
    if (tracker == null) {
      tracker = LineStatusTrackerManager.getInstance(myProject).setUpToDateContent(myDocument,
                                                                                   fixLatestLineSeparator(myDocument, myUpToDateContent));
    }
    return calcLineNumber(tracker, currentNumber);
  }

  private boolean endsWithSeparator(final CharSequence string) {
    if ((string == null) || (string.length() == 0)) {
      return false;
    }
    final char latest = string.charAt(string.length() - 1);
    return ('\n' == latest) || ('\r' == latest);
  }

  // annotated content is not aware about latest line ends with end-line separator or not. ignore latest separator difference then
  private String fixLatestLineSeparator(final Document document, final String content) {
    final CharSequence documentSequence = document.getCharsSequence();
    if (endsWithSeparator(documentSequence) && (! endsWithSeparator(content))) {
      int numCharsToCopy = 1;
      final int docLen = documentSequence.length();
      if (docLen > 1) {
        final char beforeLatest = documentSequence.charAt(docLen - 2);
        if (('\r' == beforeLatest) || ('\n' == beforeLatest)) {
          numCharsToCopy = 2;
        }
      }
      return content + documentSequence.subSequence(docLen - numCharsToCopy, docLen);
    }
    return content;<commit_msg>IDEA-20854 (SVN: Annotate command show wrong 'changed' marks on strings with 'ÿ' character)<commit_after>package com.intellij.openapi.vcs.impl;

import com.intellij.openapi.editor.Document;
import com.intellij.openapi.localVcs.UpToDateLineNumberProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ex.LineStatusTracker;
import com.intellij.openapi.vcs.ex.Range;

import java.util.List;

/**
 * author: lesya
 */
public class UpToDateLineNumberProviderImpl implements UpToDateLineNumberProvider {
  private final Document myDocument;
  private final Project myProject;
  private final String myUpToDateContent;

  public UpToDateLineNumberProviderImpl(Document document, Project project, String upToDateContent) {
    myDocument = document;
    myProject = project;
    myUpToDateContent = upToDateContent;
  }

  public int getLineNumber(int currentNumber) {
    LineStatusTracker tracker = LineStatusTrackerManager.getInstance(myProject).getLineStatusTracker(myDocument);
    if (tracker == null) {
      tracker = LineStatusTrackerManager.getInstance(myProject).setUpToDateContent(myDocument, myUpToDateContent);
    }
    return calcLineNumber(tracker, currentNumber);
  }

  private boolean endsWithSeparator(final CharSequence string) {
    if ((string == null) || (string.length() == 0)) {
      return false;
    }
    final char latest = string.charAt(string.length() - 1);
    return ('\n' == latest) || ('\r' == latest);
  }

  // annotated content is not aware about latest line ends with end-line separator or not. ignore latest separator difference then
  private String fixLatestLineSeparator(final Document document, final String content) {
    final CharSequence documentSequence = document.getCharsSequence();
    if (endsWithSeparator(documentSequence) && (! endsWithSeparator(content))) {
      int numCharsToCopy = 1;
      final int docLen = documentSequence.length();
      if (docLen > 1) {
        final char beforeLatest = documentSequence.charAt(docLen - 2);
        if (('\r' == beforeLatest) || ('\n' == beforeLatest)) {
          numCharsToCopy = 2;
        }
      }
      return content + documentSequence.subSequence(docLen - numCharsToCopy, docLen);
    }
    return content;
{'fraction_non_alphanumeric': 0.09701657458563535, 'fraction_numerical': 0.0037569060773480663, 'mean_word_length': 3.877155172413793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5046910', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1258, 'n_words': 306}