<commit_before>package com.softwaremill.clippy

import com.softwaremill.clippy.StringDiff.{DeltaEnd, DeltaStart}

object StringDiff {
  val AnsiReset = "\u001B[0m"
  val AnsiRed = "\u001B[31m"
  val DeltaEnd = AnsiReset
  val DeltaStart = AnsiRed
}

class StringDiff(expected: String, actual: String) {

  def diff(message: String): String = {
    if (this.expected == this.actual) format(message, this.expected, this.actual)
    else format(message, markDiff(expected), markDiff(actual))
  }

  private def format(msg: String, expected: String, actual: String) = msg.format(expected, actual)

  private def markDiff(source: String) = {
    val prefix = findCommonPrefix()
    val suffix = findCommonSuffix()
    val diff = DeltaStart + source.substring(prefix.length, source.length - suffix.length) + DeltaEnd
    prefix + diff + suffix
  }

  private def findCommonPrefix(expectedStr: String = expected, actualStr: String = actual): String = {<commit_msg>Use predefined constants for ANSI colors<commit_after>package com.softwaremill.clippy

import com.softwaremill.clippy.StringDiff.{DeltaEnd, DeltaStart}

object StringDiff {
  val DeltaEnd = Console.RESET
  val DeltaStart = Console.RED
}

class StringDiff(expected: String, actual: String) {

  def diff(message: String): String = {
    if (this.expected == this.actual) format(message, this.expected, this.actual)
    else format(message, markDiff(expected), markDiff(actual))
  }

  private def format(msg: String, expected: String, actual: String) = msg.format(expected, actual)

  private def markDiff(source: String) = {
    val prefix = findCommonPrefix()
    val suffix = findCommonSuffix()
    val diff = DeltaStart + source.substring(prefix.length, source.length - suffix.length) + DeltaEnd
    prefix + diff + suffix
  }

  private def findCommonPrefix(expectedStr: String = expected, actualStr: String = actual): String = {
{'fraction_non_alphanumeric': 0.10793650793650794, 'fraction_numerical': 0.004761904761904762, 'mean_word_length': 4.594674556213017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6959423', 'n_tokens_mistral': 565, 'n_tokens_neox': 546, 'n_words': 153}