Files
kotlin-fork/compiler/testData/codegen/regressions/kt684.jet
T
Stepan Koltsov 8f889c0cfd fix one test
2012-03-21 19:35:14 +04:00

30 lines
1.8 KiB
Plaintext

fun escapeChar(c : Char) : String? = when (c) {
'\\' -> "\\\\"
'\n' -> "\\n"
'"' -> "\\\""
else -> "" + c
}
fun String.escape(i : Int = 0, result : String = "") : String =
if (i == length) result
else escape(i + 1, result + escapeChar(get(i)))
fun box() : String {
val s = " System.out?.println(\"fun escapeChar(c : Char) : String? = when (c) {\");\n System.out?.println(\" '\\\\\\\\' => \\\"\\\\\\\\\\\\\\\\\\\"\");\n System.out?.println(\" '\\\\n' => \\\"\\\\\\\\n\\\"\");\n System.out?.println(\" '\\\"' => \\\"\\\\\\\\\\\\\\\"\\\"\");\n System.out?.println(\" else => String.valueOf(c)\");\n System.out?.println(\"}\");\n System.out?.println();\n System.out?.println(\"fun String.escape(i : Int = 0, result : String = \\\"\\\") : String =\");\n System.out?.println(\" if (i == length) result\");\n System.out?.println(\" else escape(i + 1, result + escapeChar(this.get(i)))\");\n System.out?.println();\n System.out?.println(\"fun main(args : Array<String>) {\");\n System.out?.println(\" val s = \\\"\" + s.escape() + \"\\\";\");\n System.out?.println(s);\n}\n";
System.out?.println("fun escapeChar(c : Char) : String? = when (c) {");
System.out?.println(" '\\\\' => \"\\\\\\\\\"");
System.out?.println(" '\\n' => \"\\\\n\"");
System.out?.println(" '\"' => \"\\\\\\\"\"");
System.out?.println(" else => String.valueOf(c)");
System.out?.println("}");
System.out?.println();
System.out?.println("fun String.escape(i : Int = 0, result : String = \"\") : String =");
System.out?.println(" if (i == length) result");
System.out?.println(" else escape(i + 1, result + escapeChar(this.get(i)))");
System.out?.println();
System.out?.println("fun main(args : Array<String>) {");
System.out?.println(" val s = \"" + s.escape() + "\";");
System.out?.println(s);
return "OK"
}