comparison lib/ur/string.ur @ 1389:9a721f0722d3

Some more string parsing functions; naughtyDebug
author Adam Chlipala <adam@chlipala.net>
date Tue, 11 Jan 2011 18:04:52 -0500
parents 3913cbfd72e9
children 65fbb250b875
comparison
equal deleted inserted replaced
1388:3913cbfd72e9 1389:9a721f0722d3
22 Some n 22 Some n
23 end 23 end
24 24
25 fun substring s {Start = start, Len = len} = Basis.substring s start len 25 fun substring s {Start = start, Len = len} = Basis.substring s start len
26 26
27 fun seek s ch =
28 case index s ch of
29 None => None
30 | Some i => Some (suffix s (i + 1))
31 fun mseek {Haystack = s, Needle = chs} =
32 case mindex {Haystack = s, Needle = chs} of
33 None => None
34 | Some i => Some (sub s i, suffix s (i + 1))
35
27 fun split s ch = 36 fun split s ch =
28 case index s ch of 37 case index s ch of
29 None => None 38 None => None
30 | Some i => Some (substring s {Start = 0, Len = i}, 39 | Some i => Some (substring s {Start = 0, Len = i},
31 substring s {Start = i + 1, Len = length s - i - 1}) 40 suffix s (i + 1))
41 fun split' s ch =
42 case index s ch of
43 None => None
44 | Some i => Some (substring s {Start = 0, Len = i},
45 suffix s i)
32 fun msplit {Haystack = s, Needle = chs} = 46 fun msplit {Haystack = s, Needle = chs} =
33 case mindex {Haystack = s, Needle = chs} of 47 case mindex {Haystack = s, Needle = chs} of
34 None => None 48 None => None
35 | Some i => Some (substring s {Start = 0, Len = i}, 49 | Some i => Some (substring s {Start = 0, Len = i},
36 sub s i, 50 sub s i,
37 substring s {Start = i + 1, Len = length s - i - 1}) 51 suffix s (i + 1))
38 52
39 fun all f s = 53 fun all f s =
40 let 54 let
41 val len = length s 55 val len = length s
42 56