Commits

camlspotter committed 5f5ca25

added String.split

Comments (0)

Files changed (3)

 2.1.2 (Not yet)
 ------------
 
+- Added String.split
+
 2.1.1
 ------------
 
   in
   aux [] 0 0
 
+(* split a string according to char_sep predicate *)
+let split char_sep str =
+  let len = String.length str in
+  if len = 0 then [] else
+    let rec skip_sep cur =
+      if cur >= len then cur
+      else if char_sep str.[cur] then skip_sep (succ cur)
+      else cur  in
+    let rec split beg cur =
+      if cur >= len then 
+	if beg = cur then []
+	else [String.sub str beg (len - beg)]
+      else if char_sep str.[cur] 
+	   then 
+	     let nextw = skip_sep cur in
+	      (String.sub str beg (cur - beg))
+		::(split nextw nextw)
+	   else split beg (succ cur) in
+    let wstart = skip_sep 0 in
+    split wstart wstart
+
 let make1 = String.make 1
 
 module Set = Xset.Make(struct type t = string let compare (x:string) y = compare x y end)
 let split_at len str = String.sub str 0 len, String.sub str len (String.length str - len)
 let take len str = String.sub str 0 len
 let drop len str = String.sub str len (String.length str - len)
+
 (** [make1 = String.make 1] *) 
 
 val split_by_newline : string -> string list
+val split : (char -> bool) -> string -> string list
 
 module Set : Xset.S with type elt = String.t
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.