diff options
author | fab <fabrice.leal.ch@gmail.com> | 2018-12-06 21:53:26 +0000 |
---|---|---|
committer | fab <fabrice.leal.ch@gmail.com> | 2018-12-06 21:53:26 +0000 |
commit | 0d28aca9aebaf8aab32c96f8477d7121ac16b4e9 (patch) | |
tree | 75dc0f49bcccc4ad41ca0abc7b645cdc764bac56 /lib/js | |
parent | df191c8374991f65c5f5a552cfa5f4fb08fe29e8 (diff) |
strsindex
Diffstat (limited to 'lib/js')
-rw-r--r-- | lib/js/urweb.js | 32 |
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) |