<commit_before>package s_mach.string

import scala.collection.mutable
import scala.util.matching.Regex
import scala.util.matching.Regex.Match

object StringOps {

  /** @return string with suffix appended if string does not end with suffix */
  def ensureSuffix(s: String, suffix: String) : String = {
    if(s.endsWith(suffix)) s else s + suffix
  }

  /** @return string with all occurrences of regex replaced with the paired string returned by supplying the match generated by the regex. Ensures recursive replacements cannot occur. */
  def findRegexReplaceMatch(
    s: String,
    zomRegex: Seq[(Regex, Match => String)]
  ) : String = ???

  /** @return string with all occurrences of regex replaced with the paired string. Ensures recursive replacements cannot occur. */
  def findRegexReplace(
    s: String,
    zomRegex: Seq[(Regex, String)]
  ) : String = ???

  /** @return string with all replacements. For each (find,replace) pair, all occurrences of find are substituted with replace. Ensures recursive replacements cannot occur. */
  def findReplace(
    s: String,
    caseSensitive: Boolean,
    fr: Seq[(String, String)]
  ) : String = ???

  /** @return string with all replacements. For each (find,replace) pair, all occurrences of find as a word are substituted with replace. Ensures recursive replacements cannot occur. */
  def findReplaceWords(
    s: String,
    caseSensitive: Boolean,
    fr: Seq[(String, String)]
  )(implicit splitter:WordSplitter) : String = ???

  /** @return string with all replacements. For each (find*,replace) pair, all occurrences of find are substituted with replace. Ensures recursive replacements cannot occur. */
  def findAllReplace(
    s: String,
    caseSensitive: Boolean,
    fr: Seq[(Seq[String], String)]
  ) : String = ???

  /** @return string with all replacements. For each (find*,replace) pair, all occurrences of find as a word are substituted with replace. Ensures recursive replacements cannot occur. */
  def findAllReplaceWords(
    s: String,
    caseSensitive: Boolean,
    fr: Seq[(Seq[String], String)]
  )(implicit splitter:WordSplitter) : String = ???

  /** @return string with all whitespace collapsed to a single space and all leading and trailing whitespace trimmed */
  def collapseWhitespace(s: String) : String = ???

  /** @return the first character to uppercase and the remaining characters to lowercase */
  def toProperCase(s: String) : String = s.capitalize

  /** @return all whitespace collapsed, each word in proper case */
  def toTitleCase(s: String)(implicit words:WordSplitter) : String = ???

  /** @return all words camel-cased i.e. camelCase */
  def toCamelCase(s: String)(implicit words:WordSplitter) : String = ???

  /** @return all words camel-cased i.e. CamelCase */
  def toPascalCase(s: String)(implicit words:WordSplitter) : String = ???

  /** @return all words camel-cased i.e. camel_case */
  def toSnakeCase(s: String)(implicit words:WordSplitter) : String = ???

  /** @return string with all lines indented by n occurrences of s */
  def indent(s: String, n: Int, spacer: String = " ") : String = {
    // TODO: use a StringBuilder here - didn't know about linesWithSeparators - nice find!
    val builder : StringBuilder = mutable.StringBuilder.newBuilder
    s.linesWithSeparators.map {
      case line => builder.append(spacer * n + line)
    }.mkString
  }

  /** @return None if string length is 0 OR Some(String) if length > 0 */
  def toOption(s: String) : Option[String] = {
    if(s.length == 0) None else Some(s)
  }

  /** @return None if String fails to convert to Double OR Some(Double) if string can be converted to a valid Double value */
  def toDoubleOpt(s: String) : Option[Double] = convert[Double](s, java.lang.Double.parseDouble)

  /** @return None if String fails to convert to Long OR Some(Long) if string can be converted to a valid Long value */
  def toLongOpt(s: String) : Option[Long] = convert[Long](s, java.lang.Long.parseLong)

  /** @return None if String fails to convert to Int OR Some(Int) if string can be converted to a valid Int value */
  def toIntOpt(s: String) : Option[Int] = convert[Int](s, java.lang.Integer.parseInt)

  /** @return None if String fails to convert to A OR Some(A) if string can be converted to a valid A value */
  def convert[A](s: String, f: String => A) : Option[A] = {
    try {
      Some(f(s))
    }
    catch {
      case e : Exception  => None
    }
  }

  /** @return all words contained in string */
  def toWords(s: String)(implicit splitter:WordSplitter) : Iterator[String] = splitter.split(s)
}
<commit_msg>Fixed indent()<commit_after>package s_mach.string

import scala.collection.mutable
import scala.util.matching.Regex
import scala.util.matching.Regex.Match

object StringOps {

  /** @return string with suffix appended if string does not end with suffix */
  def ensureSuffix(s: String, suffix: String) : String = {
    if(s.endsWith(suffix)) s else s + suffix
  }

  /** @return string with all occurrences of regex replaced with the paired string returned by supplying the match generated by the regex. Ensures recursive replacements cannot occur. */
  def findRegexReplaceMatch(
    s: String,
    zomRegex: Seq[(Regex, Match => String)]
  ) : String = ???

  /** @return string with all occurrences of regex replaced with the paired string. Ensures recursive replacements cannot occur. */
  def findRegexReplace(
    s: String,
    zomRegex: Seq[(Regex, String)]
  ) : String = ???

  /** @return string with all replacements. For each (find,replace) pair, all occurrences of find are substituted with replace. Ensures recursive replacements cannot occur. */
  def findReplace(
    s: String,
    caseSensitive: Boolean,
    fr: Seq[(String, String)]
  ) : String = ???

  /** @return string with all replacements. For each (find,replace) pair, all occurrences of find as a word are substituted with replace. Ensures recursive replacements cannot occur. */
  def findReplaceWords(
    s: String,
    caseSensitive: Boolean,
    fr: Seq[(String, String)]
  )(implicit splitter:WordSplitter) : String = ???

  /** @return string with all replacements. For each (find*,replace) pair, all occurrences of find are substituted with replace. Ensures recursive replacements cannot occur. */
  def findAllReplace(
    s: String,
    caseSensitive: Boolean,
    fr: Seq[(Seq[String], String)]
  ) : String = ???

  /** @return string with all replacements. For each (find*,replace) pair, all occurrences of find as a word are substituted with replace. Ensures recursive replacements cannot occur. */
  def findAllReplaceWords(
    s: String,
    caseSensitive: Boolean,
    fr: Seq[(Seq[String], String)]
  )(implicit splitter:WordSplitter) : String = ???

  /** @return string with all whitespace collapsed to a single space and all leading and trailing whitespace trimmed */
  def collapseWhitespace(s: String) : String = ???

  /** @return the first character to uppercase and the remaining characters to lowercase */
  def toProperCase(s: String) : String = s.capitalize

  /** @return all whitespace collapsed, each word in proper case */
  def toTitleCase(s: String)(implicit words:WordSplitter) : String = ???

  /** @return all words camel-cased i.e. camelCase */
  def toCamelCase(s: String)(implicit words:WordSplitter) : String = ???

  /** @return all words camel-cased i.e. CamelCase */
  def toPascalCase(s: String)(implicit words:WordSplitter) : String = ???

  /** @return all words camel-cased i.e. camel_case */
  def toSnakeCase(s: String)(implicit words:WordSplitter) : String = ???

  /** @return string with all lines indented by n occurrences of s */
  def indent(s: String, n: Int, spacer: String = " ") : String = {
    // TODO: use a StringBuilder here - didn't know about linesWithSeparators - nice find!
    val builder : StringBuilder = mutable.StringBuilder.newBuilder
    s.linesWithSeparators.map {
      case line => builder.append(spacer * n + line)
    }
    builder.toString()
  }

  /** @return None if string length is 0 OR Some(String) if length > 0 */
  def toOption(s: String) : Option[String] = {
    if(s.length == 0) None else Some(s)
  }

  /** @return None if String fails to convert to Double OR Some(Double) if string can be converted to a valid Double value */
  def toDoubleOpt(s: String) : Option[Double] = convert[Double](s, java.lang.Double.parseDouble)

  /** @return None if String fails to convert to Long OR Some(Long) if string can be converted to a valid Long value */
  def toLongOpt(s: String) : Option[Long] = convert[Long](s, java.lang.Long.parseLong)

  /** @return None if String fails to convert to Int OR Some(Int) if string can be converted to a valid Int value */
  def toIntOpt(s: String) : Option[Int] = convert[Int](s, java.lang.Integer.parseInt)

  /** @return None if String fails to convert to A OR Some(A) if string can be converted to a valid A value */
  def convert[A](s: String, f: String => A) : Option[A] = {
    try {
      Some(f(s))
    }
    catch {
      case e : Exception  => None
    }
  }

  /** @return all words contained in string */
  def toWords(s: String)(implicit splitter:WordSplitter) : Iterator[String] = splitter.split(s)
}

{'fraction_non_alphanumeric': 0.1110267808739022, 'fraction_numerical': 0.0006505475441830207, 'mean_word_length': 3.7037225905150435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4032957', 'n_tokens_mistral': 2810, 'n_tokens_neox': 2618, 'n_words': 1025}