<commit_before>package com.beust.klaxon

private fun <A: Appendable> A.renderString(s: String): A {
    append("\"")

    for (idx in 0..s.length - 1) {
        val ch = s[idx]
        when (ch) {
            '"' -> append("\\").append(ch)
            '\\' -> append(ch).append(ch)
            '\n' -> append("\\n")
            '\r' -> append("\\r")
            '\t' -> append("\\t")
            '\b' -> append("\\b")
            '\u000c' -> append("\\f")
            else -> {
                if(isPrintableUnicode(ch)){
                    append("\\u")
                    append(Integer.toHexString(ch.toInt()).padStart(4, '0'))
                } else {
                    append(ch)
                }
            }
        }
    }

    append("\"")
    return this
}

private fun isPrintableUnicode(c: Char) : Boolean = ((c >= '\u0000' && c <= '\u001F')
        || (c >= '\u007F' && c <= '\u009F') || (c >= '\u2000' && c <= '\u20FF'))

fun renderValue(v: Any?, result: Appendable, prettyPrint: Boolean, level: Int) {
    when (v) {
        is JsonBase -> v.appendJsonStringImpl(result, prettyPrint, level)
        is String -> result.renderString(v)
        is Map<*, *> -> renderValue(
                JsonObject(v.mapKeys { it.key.toString() }.mapValues { it.value?.toString() }),
                result,
                prettyPrint,
                level)
        is List<*> -> renderValue(JsonArray(v.map { it?.toString() }), result, prettyPrint, level)
        else -> result.append(v.toString())
    }
}

fun Appendable.indent(level: Int) {
    for (i in 1..level) {
        append("  ")
    }
}
<commit_msg>fixes map rendering, issue #24<commit_after>package com.beust.klaxon

private fun <A: Appendable> A.renderString(s: String): A {
    append("\"")

    for (idx in 0..s.length - 1) {
        val ch = s[idx]
        when (ch) {
            '"' -> append("\\").append(ch)
            '\\' -> append(ch).append(ch)
            '\n' -> append("\\n")
            '\r' -> append("\\r")
            '\t' -> append("\\t")
            '\b' -> append("\\b")
            '\u000c' -> append("\\f")
            else -> {
                if(isPrintableUnicode(ch)){
                    append("\\u")
                    append(Integer.toHexString(ch.toInt()).padStart(4, '0'))
                } else {
                    append(ch)
                }
            }
        }
    }

    append("\"")
    return this
}

private fun isPrintableUnicode(c: Char) : Boolean = ((c >= '\u0000' && c <= '\u001F')
        || (c >= '\u007F' && c <= '\u009F') || (c >= '\u2000' && c <= '\u20FF'))

tailrec fun renderValue(v: Any?, result: Appendable, prettyPrint: Boolean, level: Int) {
    when (v) {
        is JsonBase -> v.appendJsonStringImpl(result, prettyPrint, level)
        is String -> result.renderString(v)
        is Map<*, *> -> renderValue(
                JsonObject(v.mapKeys { it.key.toString() }.mapValues { it.value?.toString() }),
                result,
                prettyPrint,
                level)
        is List<*> -> renderValue(JsonArray(v.map { it?.toString() }), result, prettyPrint, level)
        is Pair<*, *> -> renderValue(v.second, result.renderString(v.first.toString()).append(": "), prettyPrint, level)
        else -> result.append(v.toString())
    }
}

fun Appendable.indent(level: Int) {
    for (i in 1..level) {
        append("  ")
    }
}

{'fraction_non_alphanumeric': 0.19078558771411694, 'fraction_numerical': 0.016538688718251624, 'mean_word_length': 1.6154440154440155, 'pattern_counts': {'":': 1, '<': 16, '<?xml version=': 0, '>': 43, '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': '4881072', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1068, 'n_words': 221}