Commit 01c1e52a authored by David Hauzar's avatar David Hauzar

Bugfix: bounded_split.

The concatenation of strings in the list of strings returned by
bounded_split must be equal to the string being split.
parent 89a12307
......@@ -28,11 +28,12 @@ let split c s = List.rev (rev_split c s)
let rev_bounded_split c s n =
let rec aux acc i n =
if n = 1 then acc else
let get_rest_of_s = (String.sub s i (String.length s - i)) in
if n = 1 then get_rest_of_s::acc else
try
let j = String.index_from s i c in
aux ((String.sub s i (j-i))::acc) (j+1) (n-1)
with Not_found -> (String.sub s i (String.length s - i))::acc
with Not_found -> get_rest_of_s::acc
| Invalid_argument _ -> ""::acc in
aux [] 0 n
......
......@@ -29,7 +29,8 @@ val split : char -> string -> string list
val bounded_split : char -> string -> int -> string list
(** [bounded_split c s n] do the same as [split c s] but splits into
[n] substring at most *)
[n] substring at most.
The concatenation of returned substrings is equal to the string s.*)
val ends_with : string -> string -> bool
(** test if a string ends with another *)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment