summaryrefslogtreecommitdiff
path: root/lib/ur
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-05-31 12:41:34 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-05-31 12:41:34 -0400
commita6424094365f7d63b6c9dade8f8f72ef26e92b45 (patch)
tree4eac927486b596ee7118f84c2dc468489840e98d /lib/ur
parentbd0d3db78996b00e153252f03b02551ac3fde4cf (diff)
strcspn and friends
Diffstat (limited to 'lib/ur')
-rw-r--r--lib/ur/basis.urs1
-rw-r--r--lib/ur/string.ur8
-rw-r--r--lib/ur/string.urs3
3 files changed, 12 insertions, 0 deletions
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index d70ccc24..d3fbe037 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -59,6 +59,7 @@ val strsub : string -> int -> char
val strsuffix : string -> int -> string
val strchr : string -> char -> option string
val strindex : string -> char -> option int
+val strcspn : string -> string -> option int
val substring : string -> int -> int -> string
class show
diff --git a/lib/ur/string.ur b/lib/ur/string.ur
index e6d5903e..e31bbc27 100644
--- a/lib/ur/string.ur
+++ b/lib/ur/string.ur
@@ -9,6 +9,8 @@ val suffix = Basis.strsuffix
val index = Basis.strindex
val atFirst = Basis.strchr
+fun mindex {Haystack = s, Needle = chs} = Basis.strcspn s chs
+
fun substring s {Start = start, Len = len} = Basis.substring s start len
fun split s ch =
@@ -16,3 +18,9 @@ fun split s ch =
None => None
| Some i => Some (substring s {Start = 0, Len = i},
substring s {Start = i + 1, Len = length s - i - 1})
+fun msplit {Haystack = s, Needle = chs} =
+ case mindex {Haystack = s, Needle = chs} of
+ None => None
+ | Some i => Some (substring s {Start = 0, Len = i},
+ sub s i,
+ substring s {Start = i + 1, Len = length s - i - 1})
diff --git a/lib/ur/string.urs b/lib/ur/string.urs
index 097a423f..8fd434b4 100644
--- a/lib/ur/string.urs
+++ b/lib/ur/string.urs
@@ -10,6 +10,9 @@ val suffix : t -> int -> string
val index : t -> char -> option int
val atFirst : t -> char -> option string
+val mindex : {Haystack : t, Needle : t} -> option int
+
val substring : t -> {Start : int, Len : int} -> string
val split : t -> char -> option (string * string)
+val msplit : {Haystack : t, Needle : t} -> option (string * char * string)