diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-07-15 13:50:05 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-07-15 13:50:05 -0700 |
commit | f1d11329a4d309682f0deb5c4cb2671fea8c9c00 (patch) | |
tree | 284fa99a0b58264c7870b7ed7a0aaf545d42a854 /src/runtime.js | |
parent | 83b96fcd9d9c060f3ea063cec04e603af4442de0 (diff) |
utf parsing in writeStringToMemory as well
Diffstat (limited to 'src/runtime.js')
-rw-r--r-- | src/runtime.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/runtime.js b/src/runtime.js index e39fa61e..6defbb35 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -334,10 +334,13 @@ var Runtime = { return Runtime.funcWrappers[func]; }, + // Returns a processor of UTF. + // processCChar() receives characters from a C-like UTF representation and returns JS string fragments. + // processJSString() receives a JS string and returns a C-like UTF representation in an array UTF8Processor: function() { var buffer = []; var needed = 0; - this.feed = function (code) { + this.processCChar = function (code) { code = code & 0xff; if (needed) { buffer.push(code); @@ -366,6 +369,14 @@ var Runtime = { buffer.length = 0; return ret; } + this.processJSString = function(string) { + string = unescape(encodeURIComponent(string)); + var ret = []; + for (var i = 0; i < string.length; i++) { + ret.push(string.charCodeAt(i)); + } + return ret; + } }, #if RUNTIME_DEBUG |