From ef92ef19fd7a068ef1b8cad293eb589a56e1399e Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 31 Mar 2015 15:24:10 +0200 Subject: [PATCH] add `CCString.{lines,unlines}` that work on lines --- src/core/CCString.cppo.ml | 8 ++++++-- src/core/CCString.mli | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/CCString.cppo.ml b/src/core/CCString.cppo.ml index 6f64b4e1..36ed8936 100644 --- a/src/core/CCString.cppo.ml +++ b/src/core/CCString.cppo.ml @@ -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 '"'; diff --git a/src/core/CCString.mli b/src/core/CCString.mli index ad0e0317..b18df249 100644 --- a/src/core/CCString.mli +++ b/src/core/CCString.mli @@ -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