19 lines
478 B
Plaintext
19 lines
478 B
Plaintext
(* [try .. with] structures break tail-recursion,
|
|
so we externalise it in a sub-function *)
|
|
let string_index str c =
|
|
try Some(String.index str c)
|
|
with Not_found -> None
|
|
|
|
let split_char sep str =
|
|
let rec aux acc str =
|
|
match string_index str sep with
|
|
| Some i ->
|
|
let this = String.sub str 0 i
|
|
and next = String.sub str (i+1) (String.length str - i - 1) in
|
|
aux (this::acc) next
|
|
| None ->
|
|
List.rev(str::acc)
|
|
in
|
|
aux [] str
|
|
;;
|