Mercurial > urweb
diff lib/ur/string.ur @ 831:5e1a4b12c83a
strcspn and friends
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 31 May 2009 12:41:34 -0400 |
parents | 20fe00fd81da |
children | e46227efcbba |
line wrap: on
line diff
--- a/lib/ur/string.ur Sat May 30 14:44:29 2009 -0400 +++ b/lib/ur/string.ur Sun May 31 12:41:34 2009 -0400 @@ -9,6 +9,8 @@ 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 @@ 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})