1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Tue Apr 26 08:35:46 2016 +0200
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Wed Apr 27 18:14:25 2016 +0200
1.3 @@ -272,13 +272,13 @@
1.4 throw new IOException("Can't find " + resource);
1.5 }
1.6 append("\n// resource from ").append(resource).append("\n");
1.7 + append("\neval(\"");
1.8 readResource(emul, this);
1.9 - append("\n");
1.10 + append("\");\n");
1.11 }
1.12
1.13 private static void readResource(InputStream emul, Appendable out) throws IOException {
1.14 try {
1.15 - int state = 0;
1.16 for (;;) {
1.17 int ch = emul.read();
1.18 if (ch == -1) {
1.19 @@ -287,7 +287,25 @@
1.20 if (ch < 0 || ch > 255) {
1.21 throw new IOException("Invalid char in emulation " + ch);
1.22 }
1.23 - out.append((char)ch);
1.24 + switch (ch) {
1.25 + case '"':
1.26 + out.append("\\\"");
1.27 + break;
1.28 + case '\\':
1.29 + out.append("\\\\");
1.30 + break;
1.31 + case '\n':
1.32 + out.append("\\n\"\n + \"");
1.33 + break;
1.34 + case '\t':
1.35 + out.append("\\t");
1.36 + break;
1.37 + case '\r':
1.38 + out.append("\\r");
1.39 + break;
1.40 + default:
1.41 + out.append((char)ch);
1.42 + }
1.43 }
1.44 } finally {
1.45 emul.close();