+(* Split a string at a separator.
+ * Functions copied from extlib Copyright (C) 2003 Nicolas Cannasse et al.
+ * to avoid the explicit dependency on extlib.
+ *)
+let str_find str sub =
+ let sublen = String.length sub in
+ if sublen = 0 then
+ 0
+ else
+ let found = ref 0 in
+ let len = String.length str in
+ try
+ for i = 0 to len - sublen do
+ let j = ref 0 in
+ while String.unsafe_get str (i + !j) = String.unsafe_get sub !j do
+ incr j;
+ if !j = sublen then begin found := i; raise Exit; end;
+ done;
+ done;
+ raise Not_found
+ with
+ Exit -> !found
+
+let str_split str sep =
+ let p = str_find str sep in
+ let len = String.length sep in
+ let slen = String.length str in
+ String.sub str 0 p, String.sub str (p + len) (slen - p - len)
+
+let str_nsplit str sep =
+ if str = "" then []
+ else (
+ let rec nsplit str sep =
+ try
+ let s1 , s2 = str_split str sep in
+ s1 :: nsplit s2 sep
+ with
+ Not_found -> [str]
+ in
+ nsplit str sep
+ )
+