mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add CCString.{lines,unlines,concat_gen}
This commit is contained in:
parent
1da809c596
commit
e3b4c5eaf9
2 changed files with 30 additions and 0 deletions
|
|
@ -263,6 +263,20 @@ 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 concat_gen ~sep g =
|
||||
let b = Buffer.create 256 in
|
||||
let rec aux ~first () = match g () with
|
||||
| None -> Buffer.contents b
|
||||
| Some s ->
|
||||
if not first then Buffer.add_string b sep;
|
||||
Buffer.add_string b s;
|
||||
aux ~first:false ()
|
||||
in aux ~first:true ()
|
||||
|
||||
let unlines g = concat_gen ~sep:"\n" g
|
||||
|
||||
let pp buf s =
|
||||
Buffer.add_char buf '"';
|
||||
Buffer.add_string buf s;
|
||||
|
|
|
|||
|
|
@ -113,6 +113,22 @@ 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')
|
||||
@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'
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
(*$Q
|
||||
Q.printable_string (fun s -> unlines (lines s) = s)
|
||||
*)
|
||||
|
||||
include S with type t := string
|
||||
|
||||
(** {2 Splitting} *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue