瀏覽代碼

Merge pull request #2113 from TopHattedCoder/printer-fixes

haxe.macro.Printer escapes String with printString (closes #2001)
Simon Krajewski 12 年之前
父節點
當前提交
fc5cee4ec0
共有 2 個文件被更改,包括 4 次插入3 次删除
  1. 0 1
      std/StringTools.hx
  2. 4 2
      std/haxe/macro/Printer.hx

+ 0 - 1
std/StringTools.hx

@@ -30,7 +30,6 @@
 @:keep
 #end
 class StringTools {
-
 	/**
 		Encode an URL by using the standard format.
 	**/

+ 4 - 2
std/haxe/macro/Printer.hx

@@ -69,9 +69,11 @@ class Printer {
 			printBinop(op)
 			+ "=";
 	}
-
+	public function printString(s:String) {
+		return '"' + s.split("\n").join("\\n").split("\t").join("\\t").split("'").join("\\'").split('"').join("\\\"") #if sys .split("\x00").join("\\x00") #end + '"';
+	}
 	public function printConstant(c:Constant) return switch(c) {
-		case CString(s): '"$s"';
+		case CString(s): printString(s);
 		case CIdent(s),
 			CInt(s),
 			CFloat(s):