<commit_before>package com.ephox.argonaut

object JsonPrinter extends Application{
  def compact(json: Json): String = prettyPrint(json, "", "", "")

  def pretty(json: Json): String = prettyPrint(json, "    ", "\n",  "")

  // FIX Naive test to get some testing happening... delete. Clean up.  
  def prettyPrint(json: Json, tab:String, delimbreak: String, currentindent: String): String = {

    def join(s: List[String]) = s.mkString("," + delimbreak + currentindent + tab)

    def recurse(json: Json) = prettyPrint(json, tab, delimbreak, currentindent + tab)

    json.fold (
      "null",
      _.toString,
      _.toString,
      printString,
      xs => "[" + delimbreak + currentindent + tab +
          join(xs.map(recurse(_))) +
       delimbreak + currentindent + "]",
      xs => "{" + delimbreak + currentindent + tab +
          join(xs.map({case (k, v) => printString(k) + ": " + recurse(v)})) +
       delimbreak + currentindent + "}"
    )
  }

  def printString(s: String) =  '"' + escape(s) + '"'



  def escape(s: String) =
    s.replace("\\", "\\\\").
      replace("\"", "\\\"").
      replace("\b", "\\b").
      replace("\f", "\\f").
      replace("\n", "\\n").
      replace("\r", "\\r").
      replace("\t", "\\t")
}<commit_msg>Attempt at cleaning up pretty printer.<commit_after>package com.ephox.argonaut

object JsonPrinter extends Application{
  def compact(json: Json): String = prettyPrint(json, "", "", "")

  def pretty(json: Json): String = prettyPrint(json, "    ", "\n",  "")

  // FIX simplify this fugly duckling
  def prettyPrint(json: Json, tab:String, delimbreak: String, currentindent: String): String = {

    def join(s: List[String]) = s.mkString("," + delimbreak + currentindent + tab)

    def recurse(json: Json) = prettyPrint(json, tab, delimbreak, currentindent + tab)

    def bracket(s: String, open: String, close: String) =
        open + delimbreak + currentindent + tab + s +  delimbreak + currentindent + close

    def entries[A](entries: List[A], open: String, close: String, f: A => String) =
        bracket(join(entries map f), open, close)

    def printString(s: String) =  '"' + escape(s) + '"'

    def escape(s: String) =
      s.replace("\\", "\\\\").
        replace("\"", "\\\"").
        replace("\b", "\\b").
        replace("\f", "\\f").
        replace("\n", "\\n").
        replace("\r", "\\r").
        replace("\t", "\\t")

    json.fold (
      "null",
      _.toString,
      _.toString,
      printString,
      xs =>
        entries(xs, "[", "]", recurse(_:Json)),
      xs =>
        // FIX why does the inferencer fail here, but not for `map`.
        entries(xs, "{", "}", {case (k, v) => printString(k) + ": " + recurse(v)}:Function[(String, Json), String])
    )
  }





}
{'fraction_non_alphanumeric': 0.19732078204199854, 'fraction_numerical': 0.0, 'mean_word_length': 2.5929778933680105, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 10, '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': '6641609', 'n_tokens_mistral': 915, 'n_tokens_neox': 857, 'n_words': 222}