summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-01-13 10:02:50 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2011-01-13 10:02:50 -0500
commit24c29015ba668b044be7428f69058687a56d6a06 (patch)
treead413eedbc7c3eed30a276f339d9adf87ff01e49 /lib
parent4eb2a196fa24d52462f3f325d73952fe2d1c12cd (diff)
More string processing
Diffstat (limited to 'lib')
-rw-r--r--lib/ur/basis.urs1
-rw-r--r--lib/ur/string.ur7
-rw-r--r--lib/ur/string.urs3
3 files changed, 11 insertions, 0 deletions
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index 0b22544f..a91fd498 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -87,6 +87,7 @@ val strsub : string -> int -> char
val strsuffix : string -> int -> string
val strchr : string -> char -> option string
val strindex : string -> char -> option int
+val strsindex : string -> string -> option int
val strcspn : string -> string -> int
val substring : string -> int -> int -> string
val str1 : char -> string
diff --git a/lib/ur/string.ur b/lib/ur/string.ur
index a93f7a57..59a8e5c5 100644
--- a/lib/ur/string.ur
+++ b/lib/ur/string.ur
@@ -10,6 +10,7 @@ val sub = Basis.strsub
val suffix = Basis.strsuffix
val index = Basis.strindex
+fun sindex r = Basis.strsindex r.Haystack r.Needle
val atFirst = Basis.strchr
fun mindex {Haystack = s, Needle = chs} =
@@ -50,6 +51,12 @@ fun msplit {Haystack = s, Needle = chs} =
sub s i,
suffix s (i + 1))
+fun ssplit r =
+ case sindex r of
+ None => None
+ | Some i => Some (substring r.Haystack {Start = 0, Len = i},
+ suffix r.Haystack (i + length r.Needle))
+
fun all f s =
let
val len = length s
diff --git a/lib/ur/string.urs b/lib/ur/string.urs
index 55133578..0861279d 100644
--- a/lib/ur/string.urs
+++ b/lib/ur/string.urs
@@ -11,6 +11,7 @@ val sub : t -> int -> char
val suffix : t -> int -> string
val index : t -> char -> option int
+val sindex : {Haystack : t, Needle : t} -> option int
val atFirst : t -> char -> option string
val mindex : {Haystack : t, Needle : t} -> option int
@@ -24,6 +25,8 @@ val split : t -> char -> option (string * string)
val split' : t -> char -> option (string * string) (* The matched character is kept at the beginning of the suffix. *)
val msplit : {Haystack : t, Needle : t} -> option (string * char * string)
+val ssplit : {Haystack : t, Needle : t} -> option (string * string)
+
val all : (char -> bool) -> string -> bool
val mp : (char -> char) -> string -> string