Commits

camlspotter  committed 4dc86a0

index_opt and sub_from_to

  • Participants
  • Parent commits 6acfc80

Comments (0)

Files changed (3)

File lib/OMakefile

    overload
 #   graph
    at
+   channel
    spot
 
 LIB = spotlib

File lib/xstring.ml

+open String
+
+let index_opt s c = try Some (index s c) with Not_found -> None
+
 let is_prefix ?from:(pos=0) ~prefix:sub str =
   let str_len = String.length str in
   let sub_len = String.length sub in
     else String.sub s 0 (len-1)
   else s
 
+let sub_from_to s from to_ = 
+  if from > to_ then invalid_arg "sub_from_to";
+  String.sub s from (to_ - from + 1)
+
 let split_by_newline s =
   let length = String.length s in
   let rec aux st start_pos pos = 

File lib/xstring.mli

 val index_from_to : string -> int -> int -> char -> int option
 val index_string_from : string -> int -> string -> int (* may raise Not_found *)
 
+val sub_from_to : string -> int -> int -> string
+
 val chop_newline : string -> string
 (** [chop_newline s] returns the string [s] w/o the newline chars at the end.
     [chop_newline "hello\r\n" = "hello"]
 val split_at : int -> string -> string * string
 val take : int -> string -> string
 val drop : int -> string -> string
+
+(** Optionalized *)
+val index_opt : string -> char -> int option