add CCString.rev

This commit is contained in:
Simon Cruanes 2016-03-09 19:45:38 +01:00
parent d6487a02a0
commit 9c338f193e
2 changed files with 19 additions and 0 deletions

View file

@ -50,6 +50,10 @@ let init n f =
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 =
if len=0 then List.rev acc
else _to_list s (s.[i]::acc) (i+1) (len-1)

View file

@ -63,6 +63,21 @@ val init : int -> (int -> char) -> string
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_seq : char sequence -> string
val of_klist : char klist -> string