summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/urweb.h1
-rw-r--r--lib/ur/basis.urs1
-rw-r--r--lib/ur/string.ur7
-rw-r--r--lib/ur/string.urs3
-rw-r--r--src/c/urweb.c11
5 files changed, 23 insertions, 0 deletions
diff --git a/include/urweb.h b/include/urweb.h
index 6fceeb50..646aa64d 100644
--- a/include/urweb.h
+++ b/include/urweb.h
@@ -140,6 +140,7 @@ uw_Basis_string uw_Basis_strsuffix(uw_context, const char *, uw_Basis_int);
uw_Basis_string uw_Basis_strcat(uw_context, const char *, const char *);
uw_Basis_string uw_Basis_mstrcat(uw_context ctx, ...);
uw_Basis_int *uw_Basis_strindex(uw_context, const char *, uw_Basis_char);
+uw_Basis_int *uw_Basis_strsindex(uw_context, const char *, const char *needle);
uw_Basis_string uw_Basis_strchr(uw_context, const char *, uw_Basis_char);
uw_Basis_int uw_Basis_strcspn(uw_context, const char *, const char *);
uw_Basis_string uw_Basis_substring(uw_context, const char *, uw_Basis_int, uw_Basis_int);
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
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 7e62d571..015bb5f9 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -2194,6 +2194,17 @@ uw_Basis_int *uw_Basis_strindex(uw_context ctx, uw_Basis_string s, uw_Basis_char
}
}
+uw_Basis_int *uw_Basis_strsindex(uw_context ctx, const char *haystack, const char *needle) {
+ uw_Basis_string r = strstr(haystack, needle);
+ if (r == NULL)
+ return NULL;
+ else {
+ uw_Basis_int *nr = uw_malloc(ctx, sizeof(uw_Basis_int));
+ *nr = r - haystack;
+ return nr;
+ }
+}
+
uw_Basis_string uw_Basis_strcat(uw_context ctx, uw_Basis_string s1, uw_Basis_string s2) {
int len = uw_Basis_strlen(ctx, s1) + uw_Basis_strlen(ctx, s2) + 1;
char *s;