mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 19:25:28 -05:00
add CCString.rev
This commit is contained in:
parent
d6487a02a0
commit
9c338f193e
2 changed files with 19 additions and 0 deletions
|
|
@ -50,6 +50,10 @@ let init n f =
|
||||||
|
|
||||||
let length = String.length
|
let length = String.length
|
||||||
|
|
||||||
|
let rev s =
|
||||||
|
let n = length s in
|
||||||
|
init n (fun i -> s.[n-i-1])
|
||||||
|
|
||||||
let rec _to_list s acc i len =
|
let rec _to_list s acc i len =
|
||||||
if len=0 then List.rev acc
|
if len=0 then List.rev acc
|
||||||
else _to_list s (s.[i]::acc) (i+1) (len-1)
|
else _to_list s (s.[i]::acc) (i+1) (len-1)
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,21 @@ val init : int -> (int -> char) -> string
|
||||||
init 0 (fun _ -> assert false) = ""
|
init 0 (fun _ -> assert false) = ""
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
val rev : string -> string
|
||||||
|
(** [rev s] returns the reverse of [s]
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
(*$Q
|
||||||
|
Q.printable_string (fun s -> s = rev (rev s))
|
||||||
|
Q.printable_string (fun s -> length s = length (rev s))
|
||||||
|
*)
|
||||||
|
|
||||||
|
(*$=
|
||||||
|
"abc" (rev "cba")
|
||||||
|
"" (rev "")
|
||||||
|
" " (rev " ")
|
||||||
|
*)
|
||||||
|
|
||||||
val of_gen : char gen -> string
|
val of_gen : char gen -> string
|
||||||
val of_seq : char sequence -> string
|
val of_seq : char sequence -> string
|
||||||
val of_klist : char klist -> string
|
val of_klist : char klist -> string
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue