summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/js/urweb.js32
1 files changed, 25 insertions, 7 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index e28446e3..2b34f8dd 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -1462,23 +1462,41 @@ 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 Array.from(s)[i].codePointAt(0); }
+function sub(s, i) { return Array.from(s)[i]; }
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);
+ var r = Array.from(s).indexOf(ch);
if (r == -1)
return null;
else
return r;
}
function ssidx(h, n) {
- var r = h.indexOf(n);
- if (r == -1)
- return null;
- else
- return r;
+ if (n == "") return 0;
+ var ah = Array.from(h);
+ var an = Array.from(n);
+ var i = 0, y = 0;
+ var top = ah.length - an.length + 1;
+ if (top < 0) top = 0;
+ var found = true;
+
+ for(i = 0; i < top; ++i) {
+ found = true;
+
+ for (y = 0; y < an.length; ++y) {
+ if (ah[i + y] != an[y]) {
+ found = false;
+ break;
+ }
+ }
+
+ if (found)
+ return i;
+ }
+ return null;
}
+
function sspn(s, chs) {
for (var i = 0; i < s.length; ++i)
if (chs.indexOf(s.charAt(i)) != -1)