Skip to content

Commit fa68ad8

Browse files
committed
Fix escaped characters not generating properly.
1 parent c697a4e commit fa68ad8

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/gdcompiler/GDCompiler.hx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ ${exitTreeLines.length > 0 ? exitTreeLines.join("\n").tab() : "\tpass"}
10771077
switch(constant) {
10781078
case TInt(i): return Std.string(i);
10791079
case TFloat(s): return s.indexOf(".") == -1 ? '$s.0' : s;
1080-
case TString(s): return "\"" + StringTools.replace(StringTools.replace(s, "\\", "\\\\"), "\"", "\\\"") + "\"";
1080+
case TString(s): return stringToGDScript(s);
10811081
case TBool(b): return b ? "true" : "false";
10821082
case TNull: return "null";
10831083
case TThis: {
@@ -1092,6 +1092,15 @@ ${exitTreeLines.length > 0 ? exitTreeLines.join("\n").tab() : "\tpass"}
10921092
return "";
10931093
}
10941094

1095+
function stringToGDScript(s: String): String {
1096+
var result = StringTools.replace(s, "\\", "\\\\");
1097+
result = StringTools.replace(result, "\"", "\\\"");
1098+
result = StringTools.replace(result, "\t", "\\t");
1099+
result = StringTools.replace(result, "\n", "\\n");
1100+
result = StringTools.replace(result, "\r", "\\r");
1101+
return "\"" + result + "\"";
1102+
}
1103+
10951104
function binopToGDScript(op: Binop, e1: TypedExpr, e2: TypedExpr): String {
10961105
var gdExpr1 = compileExpression(e1);
10971106
var gdExpr2 = compileExpression(e2);

0 commit comments

Comments
 (0)