summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-05-30 13:29:00 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-05-30 13:29:00 -0400
commit54276f5a38163eb7997c574810faed0cc6dea35c (patch)
treeff01535ec8b49034e5cb39f0be1e36261bea9d8b /lib
parent581a2290590268039cacfbe0762b343f710c3116 (diff)
Substring functions; fix a nasty MonoReduce pattern match substitution bug
Diffstat (limited to 'lib')
-rw-r--r--lib/js/urweb.js17
-rw-r--r--lib/ur/basis.urs3
-rw-r--r--lib/ur/string.ur11
-rw-r--r--lib/ur/string.urs7
4 files changed, 38 insertions, 0 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index db3c934c..be3d652a 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -353,6 +353,23 @@ function bs(b) { return (b ? "True" : "False") }
function sub(s, i) { return s[i]; }
function suf(s, i) { return s.substring(i); }
function slen(s) { return s.length; }
+function sidx(s, ch) {
+ var r = s.indexOf(ch);
+ if (r == -1)
+ return null;
+ else
+ return r;
+}
+function schr(s, ch) {
+ var r = s.indexOf(ch);
+ if (r == -1)
+ return null;
+ else
+ return s.substring(r);
+}
+function ssub(s, start, len) {
+ return s.substring(start, start+len);
+}
function pi(s) {
var r = parseInt(s);
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index c63c5ed4..d70ccc24 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -57,6 +57,9 @@ val strlen : string -> int
val strcat : string -> string -> string
val strsub : string -> int -> char
val strsuffix : string -> int -> string
+val strchr : string -> char -> option string
+val strindex : string -> char -> option int
+val substring : string -> int -> int -> string
class show
val show : t ::: Type -> show t -> t -> string
diff --git a/lib/ur/string.ur b/lib/ur/string.ur
index 23670966..e6d5903e 100644
--- a/lib/ur/string.ur
+++ b/lib/ur/string.ur
@@ -5,3 +5,14 @@ val append = Basis.strcat
val sub = Basis.strsub
val suffix = Basis.strsuffix
+
+val index = Basis.strindex
+val atFirst = Basis.strchr
+
+fun substring s {Start = start, Len = len} = Basis.substring s start len
+
+fun split s ch =
+ case index s ch of
+ None => None
+ | Some i => Some (substring s {Start = 0, Len = i},
+ substring s {Start = i + 1, Len = length s - i - 1})
diff --git a/lib/ur/string.urs b/lib/ur/string.urs
index ef522387..097a423f 100644
--- a/lib/ur/string.urs
+++ b/lib/ur/string.urs
@@ -6,3 +6,10 @@ val append : t -> t -> t
val sub : t -> int -> char
val suffix : t -> int -> string
+
+val index : t -> char -> option int
+val atFirst : t -> char -> option string
+
+val substring : t -> {Start : int, Len : int} -> string
+
+val split : t -> char -> option (string * string)