add CCString.{lines,unlines} that work on lines

This commit is contained in:
Simon Cruanes 2015-03-31 15:24:10 +02:00
parent 0b38c9e272
commit ef92ef19fd
2 changed files with 18 additions and 6 deletions

View file

@ -263,7 +263,9 @@ let of_array a =
let to_array s =
Array.init (String.length s) (fun i -> s.[i])
let lines s = Split.gen_cpy ~by:"\n" s
let lines_gen s = Split.gen_cpy ~by:"\n" s
let lines s = Split.list_cpy ~by:"\n" s
let concat_gen ~sep g =
let b = Buffer.create 256 in
@ -275,7 +277,9 @@ let concat_gen ~sep g =
aux ~first:false ()
in aux ~first:true ()
let unlines g = concat_gen ~sep:"\n" g
let unlines l = String.concat "\n" l
let unlines_gen g = concat_gen ~sep:"\n" g
let pp buf s =
Buffer.add_char buf '"';

View file

@ -113,16 +113,24 @@ val suffix : suf:string -> string -> bool
not (suffix ~suf:"abcd" "cd")
*)
val lines : string -> string gen
(** [lines s] returns a generator of the lines of [s] (splits along '\n')
val lines : string -> string list
(** [lines s] returns a list of the lines of [s] (splits along '\n')
@since NEXT_RELEASE *)
val lines_gen : string -> string gen
(** [lines_gen s] returns a generator of the lines of [s] (splits along '\n')
@since NEXT_RELEASE *)
val concat_gen : sep:string -> string gen -> string
(** [concat_gen ~sep g] concatenates all strings of [g], separated with [sep].
@since NEXT_RELEASE *)
val unlines : string gen -> string
(** [unlines g] concatenates all strings of [g], separated with '\n'
val unlines : string list -> string
(** [unlines l] concatenates all strings of [l], separated with '\n'
@since NEXT_RELEASE *)
val unlines_gen : string gen -> string
(** [unlines_gen g] concatenates all strings of [g], separated with '\n'
@since NEXT_RELEASE *)
(*$Q