Merge pull request #3756 from yglukhov/revert-3733-js-unicode

Revert "Fixed unicode handling in JS. Fixes #3714."
This commit is contained in:
Andreas Rumpf 2016-01-21 21:50:30 +01:00
commit 71e4e39295
2 changed files with 8 additions and 45 deletions

View file

@ -163,26 +163,8 @@ proc mangleName(s: PSym): Rope =
add(result, rope(s.id)) add(result, rope(s.id))
s.loc.r = result s.loc.r = result
proc escapeJSString(s: string): string =
result = newStringOfCap(s.len + s.len shr 2)
result.add("\"")
for c in items(s):
case c
of '\l': result.add("\\n")
of '\r': result.add("\\r")
of '\t': result.add("\\t")
of '\b': result.add("\\b")
of '\a': result.add("\\a")
of '\e': result.add("\\e")
of '\v': result.add("\\v")
of '\\': result.add("\\\\")
of '\'': result.add("\\'")
of '\"': result.add("\\\"")
else: add(result, c)
result.add("\"")
proc makeJSString(s: string): Rope = proc makeJSString(s: string): Rope =
(if s.isNil: "null".rope else: escapeJSString(s).rope) (if s.isNil: "null".rope else: strutils.escape(s).rope)
include jstypes include jstypes

View file

@ -166,33 +166,14 @@ proc SetConstr() {.varargs, asmNoStackFrame, compilerproc.} =
""" """
proc cstrToNimstr(c: cstring): string {.asmNoStackFrame, compilerproc.} = proc cstrToNimstr(c: cstring): string {.asmNoStackFrame, compilerproc.} =
{.emit: """ asm """
var ln = `c`.length; var result = [];
var result = new Array(ln); for (var i = 0; i < `c`.length; ++i) {
var r = 0; result[i] = `c`.charCodeAt(i);
for (var i = 0; i < ln; ++i) {
var ch = `c`.charCodeAt(i);
if (ch < 128) {
result[r] = ch;
} }
else if((ch > 127) && (ch < 2048)) { result[result.length] = 0; // terminating zero
result[r] = (ch >> 6) | 192; return result;
++r; """
result[r] = (ch & 63) | 128;
}
else {
result[r] = (ch >> 12) | 224;
++r;
result[r] = ((ch >> 6) & 63) | 128;
++r;
result[r] = (ch & 63) | 128;
}
++r;
}
result[r] = 0; // terminating zero
return result;
""".}
proc toJSStr(s: string): cstring {.asmNoStackFrame, compilerproc.} = proc toJSStr(s: string): cstring {.asmNoStackFrame, compilerproc.} =
asm """ asm """