diff options
Diffstat (limited to 'lib/ur/string.ur')
-rw-r--r-- | lib/ur/string.ur | 8 |
1 files changed, 8 insertions, 0 deletions
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}) |