diff options
author | Alain Frisch <alain@frisch.fr> | 2010-11-05 08:15:36 +0000 |
---|---|---|
committer | Alain Frisch <alain@frisch.fr> | 2010-11-05 08:15:36 +0000 |
commit | f537ba28b044ee7c4ea9d05e3934c9146e079cc1 (patch) | |
tree | d9c06dc96b017ad80ebb38929b88f91ced9b0a9a /stdlib | |
parent | a5628ad72587ecef6e117b7436d49935638beab9 (diff) |
Adding String.iteri.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10762 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/string.ml | 3 | ||||
-rw-r--r-- | stdlib/string.mli | 7 | ||||
-rw-r--r-- | stdlib/stringLabels.mli | 7 |
3 files changed, 17 insertions, 0 deletions
diff --git a/stdlib/string.ml b/stdlib/string.ml index 0cb67d289..e61e9efe9 100644 --- a/stdlib/string.ml +++ b/stdlib/string.ml @@ -60,6 +60,9 @@ let blit s1 ofs1 s2 ofs2 len = let iter f a = for i = 0 to length a - 1 do f(unsafe_get a i) done +let iteri f a = + for i = 0 to length a - 1 do f i (unsafe_get a i) done + let concat sep l = match l with [] -> "" diff --git a/stdlib/string.mli b/stdlib/string.mli index 21bfb7c0e..a2d995df2 100644 --- a/stdlib/string.mli +++ b/stdlib/string.mli @@ -94,6 +94,13 @@ val iter : (char -> unit) -> string -> unit the characters of [s]. It is equivalent to [f s.[0]; f s.[1]; ...; f s.[String.length s - 1]; ()]. *) +val iteri : (int -> char -> unit) -> string -> unit +(** Same as {!String.iter}, but the + function is applied to the index of the element as first argument (counting from 0), + and the character itself as second argument. + @since 3.13.0 +*) + val escaped : string -> string (** Return a copy of the argument, with special characters represented by escape sequences, following the lexical diff --git a/stdlib/stringLabels.mli b/stdlib/stringLabels.mli index 9cbee708b..d1a3966f5 100644 --- a/stdlib/stringLabels.mli +++ b/stdlib/stringLabels.mli @@ -84,6 +84,13 @@ val iter : f:(char -> unit) -> string -> unit the characters of [s]. It is equivalent to [f s.[0]; f s.[1]; ...; f s.[String.length s - 1]; ()]. *) +val iteri : f:(int -> char -> unit) -> string -> unit +(** Same as {!String.iter}, but the + function is applied to the index of the element as first argument (counting from 0), + and the character itself as second argument. + @since 3.13.0 +*) + val escaped : string -> string (** Return a copy of the argument, with special characters represented by escape sequences, following the lexical |