mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add CCString.set for updating immutable strings
This commit is contained in:
parent
8f33484dff
commit
0c624461d5
2 changed files with 16 additions and 0 deletions
|
|
@ -281,6 +281,16 @@ let unlines l = String.concat "\n" l
|
||||||
|
|
||||||
let unlines_gen g = concat_gen ~sep:"\n" g
|
let unlines_gen g = concat_gen ~sep:"\n" g
|
||||||
|
|
||||||
|
let set s i c =
|
||||||
|
if i<0 || i>= String.length s then invalid_arg "CCString.set";
|
||||||
|
init (String.length s) (fun j -> if i=j then c else s.[j])
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
set "abcd" 1 '_' = "a_cd"
|
||||||
|
set "abcd" 0 '-' = "-bcd"
|
||||||
|
(try set "abc" 5 '_'; false with Invalid_argument _ -> true)
|
||||||
|
*)
|
||||||
|
|
||||||
let pp buf s =
|
let pp buf s =
|
||||||
Buffer.add_char buf '"';
|
Buffer.add_char buf '"';
|
||||||
Buffer.add_string buf s;
|
Buffer.add_string buf s;
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,12 @@ val unlines_gen : string gen -> string
|
||||||
Q.printable_string (fun s -> unlines (lines s) = s)
|
Q.printable_string (fun s -> unlines (lines s) = s)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
val set : string -> int -> char -> string
|
||||||
|
(** [set s i c] creates a new string which is a copy of [s], except
|
||||||
|
for index [i], which becomes [c].
|
||||||
|
@raise Invalid_argument if [i] is an invalid index
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
include S with type t := string
|
include S with type t := string
|
||||||
|
|
||||||
(** {2 Splitting} *)
|
(** {2 Splitting} *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue