summaryrefslogtreecommitdiff
path: root/src/lutf8lib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-14 08:30:45 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-14 09:09:52 +0100
commit0d51854b27836c485d0bac7a1a28c19fc61496f1 (patch)
tree0e5fc99d7b205b79ed10eab1f4ce49aa39f7ae59 /src/lutf8lib.js
parentf72e2999b92084a8e2d0cef8bfb3b52607bc8dd5 (diff)
downloadfengari-0d51854b27836c485d0bac7a1a28c19fc61496f1.tar.gz
fengari-0d51854b27836c485d0bac7a1a28c19fc61496f1.tar.bz2
fengari-0d51854b27836c485d0bac7a1a28c19fc61496f1.zip
Use emscripten's utf8tojs string function
Diffstat (limited to 'src/lutf8lib.js')
-rw-r--r--src/lutf8lib.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lutf8lib.js b/src/lutf8lib.js
index bc43d54..db5f7ad 100644
--- a/src/lutf8lib.js
+++ b/src/lutf8lib.js
@@ -8,7 +8,8 @@ const lauxlib = require('./lauxlib.js');
const iscont = function(p) {
- return p & 0xC0 === 0x80;
+ let c = p & 0xC0;
+ return c === 0x80;
};
/* translate a relative string position: negative means back from end */
@@ -24,6 +25,7 @@ const u_posrelat = function(pos, len) {
*/
const byteoffset = function(L) {
let s = lauxlib.luaL_checkstring(L, 1);
+ s = L.stack[lapi.index2addr_(L, 1)].value;
let n = lauxlib.luaL_checkinteger(L, 2);
let posi = n >= 0 ? 1 : s.length + 1;
posi = u_posrelat(lauxlib.luaL_optinteger(L, 3, posi), s.length);
@@ -31,16 +33,16 @@ const byteoffset = function(L) {
if (n === 0) {
/* find beginning of current byte sequence */
- while (posi > 0 && iscont(s.slice(posi))) posi--;
+ while (posi > 0 && iscont(s[posi])) posi--;
} else {
- if (iscont(s.slice(posi)))
+ if (iscont(s[posi]))
lauxlib.luaL_error(L, "initial position is a continuation byte");
if (n < 0) {
while (n < 0 && posi > 0) { /* move back */
do { /* find beginning of previous character */
posi--;
- } while (posi > 0 && iscont(s.slice(posi)));
+ } while (posi > 0 && iscont(s[posi]));
n++;
}
} else {
@@ -48,7 +50,7 @@ const byteoffset = function(L) {
while (n > 0 && posi < s.length) {
do { /* find beginning of next character */
posi++;
- } while (iscont(s.slice(posi))); /* (cannot pass final '\0') */
+ } while (iscont(s[posi])); /* (cannot pass final '\0') */
n--;
}
}