summaryrefslogtreecommitdiff
path: root/stdlib/stringLabels.mli
diff options
context:
space:
mode:
authorAlain Frisch <alain@frisch.fr>2016-11-07 17:11:35 +0100
committerDavid Allsopp <david.allsopp@metastack.com>2016-11-07 16:11:35 +0000
commit69263a989313ab334f85f68e7c53ba2ff0f049f3 (patch)
tree77e4f22f3a356da8f3ef71c391e8680325182305 /stdlib/stringLabels.mli
parenta02958960640cba8f8058a7c7ca04af99a988097 (diff)
downloadocaml-69263a989313ab334f85f68e7c53ba2ff0f049f3.tar.gz
Option-returning variants of stdlib functions (#885)
Provide an xxx_opt alternative for functions raising Not_found and many instances of Failure/Invalid_arg. The only exception is the rarely used Buffer.add_substitute, where the [Not_found] can really be interpreted as an error condition. Most new functions are implemented directly (instead of wrapping the raising version). This is for performance reasons and also to avoid destroying the stacktrace (if the function is used in an exception handler). One could instead implement the raising versions on top of the new functions, but there might be a small penalty.
Diffstat (limited to 'stdlib/stringLabels.mli')
-rw-r--r--stdlib/stringLabels.mli36
1 files changed, 36 insertions, 0 deletions
diff --git a/stdlib/stringLabels.mli b/stdlib/stringLabels.mli
index a11e2ead1e..9844901152 100644
--- a/stdlib/stringLabels.mli
+++ b/stdlib/stringLabels.mli
@@ -135,12 +135,24 @@ val index : string -> char -> int
Raise [Not_found] if [c] does not occur in [s]. *)
+val index_opt: string -> char -> int option
+(** [String.index_opt s c] returns the index of the first
+ occurrence of character [c] in string [s], or
+ [None] if [c] does not occur in [s].
+ @since 4.05 *)
+
val rindex : string -> char -> int
(** [String.rindex s c] returns the index of the last
occurrence of character [c] in string [s].
Raise [Not_found] if [c] does not occur in [s]. *)
+val rindex_opt: string -> char -> int option
+(** [String.rindex_opt s c] returns the index of the last occurrence
+ of character [c] in string [s], or [None] if [c] does not occur in
+ [s].
+ @since 4.05 *)
+
val index_from : string -> int -> char -> int
(** [String.index_from s i c] returns the index of the
first occurrence of character [c] in string [s] after position [i].
@@ -149,6 +161,17 @@ val index_from : string -> int -> char -> int
Raise [Invalid_argument] if [i] is not a valid position in [s].
Raise [Not_found] if [c] does not occur in [s] after position [i]. *)
+val index_from_opt: string -> int -> char -> int option
+(** [String.index_from_opt s i c] returns the index of the
+ first occurrence of character [c] in string [s] after position [i]
+ or [None] if [c] does not occur in [s] after position [i].
+
+ [String.index_opt s c] is equivalent to [String.index_from_opt s 0 c].
+ Raise [Invalid_argument] if [i] is not a valid position in [s].
+
+ @since 4.05
+*)
+
val rindex_from : string -> int -> char -> int
(** [String.rindex_from s i c] returns the index of the
last occurrence of character [c] in string [s] before position [i+1].
@@ -158,6 +181,19 @@ val rindex_from : string -> int -> char -> int
Raise [Invalid_argument] if [i+1] is not a valid position in [s].
Raise [Not_found] if [c] does not occur in [s] before position [i+1]. *)
+val rindex_from_opt: string -> int -> char -> int option
+(** [String.rindex_from_opt s i c] returns the index of the
+ last occurrence of character [c] in string [s] before position [i+1]
+ or [None] if [c] does not occur in [s] before position [i+1].
+
+ [String.rindex_opt s c] is equivalent to
+ [String.rindex_from_opt s (String.length s - 1) c].
+
+ Raise [Invalid_argument] if [i+1] is not a valid position in [s].
+
+ @since 4.05
+*)
+
val contains : string -> char -> bool
(** [String.contains s c] tests if character [c]
appears in the string [s]. *)