Files
kotlin/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realStringEscape.kt
2019-11-19 11:00:09 +03:00

20 lines
480 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
// KJS_WITH_FULL_RUNTIME
// DONT_RUN_GENERATED_CODE: JS
fun escapeChar(c : Char) : String? = when (c) {
'\\' -> "\\\\"
'\n' -> "\\n"
'"' -> "\\\""
else -> "" + c
}
tailrec fun String.escape(i : Int = 0, result : StringBuilder = StringBuilder()) : String =
if (i == length) result.toString()
else escape(i + 1, result.append(escapeChar(get(i))))
fun box() : String {
"test me not \\".escape()
return "OK"
}