commit
7131d6231d
1 changed files with 5 additions and 2 deletions
|
|
@ -178,15 +178,18 @@ proc toJSStr(s: string): cstring {.asmNoStackFrame, compilerproc.} =
|
||||||
var asciiPart = new Array(len);
|
var asciiPart = new Array(len);
|
||||||
var fcc = String.fromCharCode;
|
var fcc = String.fromCharCode;
|
||||||
var nonAsciiPart = null;
|
var nonAsciiPart = null;
|
||||||
|
var nonAsciiOffset = 0;
|
||||||
for (var i = 0; i < len; ++i) {
|
for (var i = 0; i < len; ++i) {
|
||||||
if (nonAsciiPart !== null) {
|
if (nonAsciiPart !== null) {
|
||||||
nonAsciiPart[i * 2] = "%";
|
var offset = (i - nonAsciiOffset) * 2;
|
||||||
nonAsciiPart[i * 2 + 1] = `s`[i].toString(16);
|
nonAsciiPart[offset] = "%";
|
||||||
|
nonAsciiPart[offset + 1] = `s`[i].toString(16);
|
||||||
}
|
}
|
||||||
else if (`s`[i] < 128)
|
else if (`s`[i] < 128)
|
||||||
asciiPart[i] = fcc(`s`[i]);
|
asciiPart[i] = fcc(`s`[i]);
|
||||||
else {
|
else {
|
||||||
asciiPart.length = i;
|
asciiPart.length = i;
|
||||||
|
nonAsciiOffset = i;
|
||||||
nonAsciiPart = new Array((len - i) * 2);
|
nonAsciiPart = new Array((len - i) * 2);
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue