diff 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
line wrap: on
line diff
--- a/lib/ur/string.ur	Tue Jan 11 14:03:54 2011 -0500
+++ b/lib/ur/string.ur	Tue Jan 11 18:04:52 2011 -0500
@@ -24,17 +24,31 @@
 
 fun substring s {Start = start, Len = len} = Basis.substring s start len
 
+fun seek s ch =
+    case index s ch of
+        None => None
+      | Some i => Some (suffix s (i + 1))
+fun mseek {Haystack = s, Needle = chs} =
+    case mindex {Haystack = s, Needle = chs} of
+        None => None
+      | Some i => Some (sub s i, suffix s (i + 1))
+
 fun split s ch =
     case index s ch of
         None => None
       | Some i => Some (substring s {Start = 0, Len = i},
-                        substring s {Start = i + 1, Len = length s - i - 1})
+                        suffix s (i + 1))
+fun split' s ch =
+    case index s ch of
+        None => None
+      | Some i => Some (substring s {Start = 0, Len = i},
+                        suffix s i)
 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})
+                        suffix s (i + 1))
 
 fun all f s =
     let