comparison 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
comparison
equal deleted inserted replaced
830:d07980bf1444 831:5e1a4b12c83a
7 val suffix = Basis.strsuffix 7 val suffix = Basis.strsuffix
8 8
9 val index = Basis.strindex 9 val index = Basis.strindex
10 val atFirst = Basis.strchr 10 val atFirst = Basis.strchr
11 11
12 fun mindex {Haystack = s, Needle = chs} = Basis.strcspn s chs
13
12 fun substring s {Start = start, Len = len} = Basis.substring s start len 14 fun substring s {Start = start, Len = len} = Basis.substring s start len
13 15
14 fun split s ch = 16 fun split s ch =
15 case index s ch of 17 case index s ch of
16 None => None 18 None => None
17 | Some i => Some (substring s {Start = 0, Len = i}, 19 | Some i => Some (substring s {Start = 0, Len = i},
18 substring s {Start = i + 1, Len = length s - i - 1}) 20 substring s {Start = i + 1, Len = length s - i - 1})
21 fun msplit {Haystack = s, Needle = chs} =
22 case mindex {Haystack = s, Needle = chs} of
23 None => None
24 | Some i => Some (substring s {Start = 0, Len = i},
25 sub s i,
26 substring s {Start = i + 1, Len = length s - i - 1})