[ocaml-extlib] r412 committed - String.find_from (Closes issue 15)

3 views
Skip to first unread message

codesite...@google.com

unread,
May 8, 2013, 1:28:07 PM5/8/13
to ocaml-extl...@googlegroups.com
Revision: 412
Author: ygrekheretix
Date: Wed May 8 10:27:54 2013
Log: String.find_from (Closes issue 15)

http://code.google.com/p/ocaml-extlib/source/detail?r=412

Modified:
/trunk/extlib/extString.ml
/trunk/extlib/extString.mli

=======================================
--- /trunk/extlib/extString.ml Sat Aug 6 07:48:50 2011
+++ /trunk/extlib/extString.ml Wed May 8 10:27:54 2013
@@ -53,7 +53,7 @@
in
loop s e 0

-let find str sub =
+let find_from str pos sub =
let sublen = length sub in
if sublen = 0 then
0
@@ -61,7 +61,7 @@
let found = ref 0 in
let len = length str in
try
- for i = 0 to len - sublen do
+ for i = pos to len - sublen do
let j = ref 0 in
while unsafe_get str (i + !j) = unsafe_get sub !j do
incr j;
@@ -72,6 +72,8 @@
with
Exit -> !found

+let find str sub = find_from str 0 sub
+
let exists str sub =
try
ignore(find str sub);
=======================================
--- /trunk/extlib/extString.mli Sun Mar 6 06:09:12 2011
+++ /trunk/extlib/extString.mli Wed May 8 10:27:54 2013
@@ -29,16 +29,22 @@

val init : int -> (int -> char) -> string
(** [init l f] returns the string of length [l] with the chars
- f 0 , f 1 , f 2 ... f (l-1). *)
+ f 0 , f 1 , f 2 ... f (l-1). *)

val find : string -> string -> int
(** [find s x] returns the starting index of the string [x]
within the string [s] or raises [Invalid_string] if [x]
is not a substring of [s]. *)

+ val find_from : string -> int -> string -> int
+ (** [find s i x] returns the starting index of the string [x]
+ within the string [s] (starting search from position [i]) or
+ raises [Invalid_string] if no such substring exists.
+ [find s x] is equivalent to [find_from s 0 x]. *)
+
val split : string -> string -> string * string
(** [split s sep] splits the string [s] between the first
- occurrence of [sep].
+ occurrence of [sep].
raises [Invalid_string] if the separator is not found. *)

val nsplit : string -> string -> string list
Reply all
Reply to author
Forward
0 new messages