summaryrefslogtreecommitdiff
path: root/lib/js
diff options
context:
space:
mode:
authorGravatar fab <fabrice.leal.ch@gmail.com>2018-12-06 21:24:04 +0000
committerGravatar fab <fabrice.leal.ch@gmail.com>2018-12-06 21:24:04 +0000
commitdf191c8374991f65c5f5a552cfa5f4fb08fe29e8 (patch)
tree42f8c1d6bae638bf47e2e012dff8feba30e74463 /lib/js
parentbc1547efbbad30da255b7c29973c94c8d37edabc (diff)
chars with more than 2 bytes are awkwardly handled by the "normal" string of javascript. the best way to get consistent results seems to be to convert to array by Array.from(...) and back to strings with .join("")
Diffstat (limited to 'lib/js')
-rw-r--r--lib/js/urweb.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index c7725e28..e28446e3 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -1462,9 +1462,9 @@ function s2b(s) { return s == "True" ? true : s == "False" ? false : null; }
function s2be(s) { return s == "True" ? true : s == "False" ? false : er("Illegal Boolean " ^ s); }
function id(x) { return x; }
-function sub(s, i) { return s.charAt(i); }
-function suf(s, i) { return s.substring(i); }
-function slen(s) { return s.length; }
+function sub(s, i) { return Array.from(s)[i].codePointAt(0); }
+function suf(s, i) { return Array.from(s).slice(i).join(""); }
+function slen(s) { return Array.from(s).length; }
function sidx(s, ch) {
var r = s.indexOf(ch);
if (r == -1)
@@ -1494,10 +1494,10 @@ function schr(s, ch) {
return s.substring(r);
}
function ssub(s, start, len) {
- return s.substring(start, start+len);
+ return Array.from(s).slice(start, start+len).join("");
}
function strlenGe(s, len) {
- return s.length >= len;
+ return slen(s) >= len;
}
function trimZeroes(s) {
@@ -1596,11 +1596,11 @@ function strcmp(str1, str2) {
}
function chr(n) {
- return String.fromCharCode(n);
+ return String.fromCodePoint(n);
}
function htmlifySpecialChar(ch) {
- return "&#" + ch.charCodeAt(0) + ";";
+ return "&#" + ch.codePointAt(0) + ";";
}