aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorppedrot2012-12-13 15:59:59 +0000
committerppedrot2012-12-13 15:59:59 +0000
commit0a7347b567d6ea5d71907b570c81ea6dc61a626d (patch)
tree4dd25cc9d1d53f9bb539c6d7c9eebcd36ed59b63 /lib
parent989d7d5f4d3d023704935f2db49090b9ac4b2e13 (diff)
Documented CString.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@16064 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'lib')
-rw-r--r--lib/cString.ml20
-rw-r--r--lib/cString.mli29
2 files changed, 48 insertions, 1 deletions
diff --git a/lib/cString.ml b/lib/cString.ml
index b54c23c5b2..fd375c5c34 100644
--- a/lib/cString.ml
+++ b/lib/cString.ml
@@ -46,6 +46,7 @@ module type ExtS =
sig
include S
external equal : string -> string -> bool = "caml_string_equal" "noalloc"
+ val is_empty : string -> bool
val explode : string -> string list
val implode : string list -> string
val strip : string -> string
@@ -56,6 +57,7 @@ sig
val plural : int -> string -> string
val ordinal : int -> string
val split : char -> string -> string list
+ val is_sub : string -> string -> int -> bool
end
include String
@@ -77,6 +79,8 @@ let is_blank = function
| ' ' | '\r' | '\t' | '\n' -> true
| _ -> false
+let is_empty s = String.length s = 0
+
let strip s =
let n = String.length s in
let rec lstrip_rec i =
@@ -100,7 +104,7 @@ let map f s =
let drop_simple_quotes s =
let n = String.length s in
- if n > 2 & s.[0] = '\'' & s.[n-1] = '\'' then String.sub s 1 (n-2) else s
+ if n > 2 && s.[0] = '\'' & s.[n-1] = '\'' then String.sub s 1 (n-2) else s
(* substring searching... *)
@@ -130,6 +134,20 @@ let string_contains ~where ~what =
with
Not_found -> false
+let is_sub p s off =
+ let lp = String.length p in
+ let ls = String.length s in
+ if ls < off + lp then false
+ else
+ let rec aux i =
+ if lp <= i then true
+ else
+ let cp = String.unsafe_get p i in
+ let cs = String.unsafe_get s (off + i) in
+ if cp = cs then aux (succ i) else false
+ in
+ aux 0
+
let plural n s = if n<>1 then s^"s" else s
let ordinal n =
diff --git a/lib/cString.mli b/lib/cString.mli
index 1d33cef39b..9f4a47f19d 100644
--- a/lib/cString.mli
+++ b/lib/cString.mli
@@ -47,17 +47,46 @@ end
module type ExtS =
sig
include S
+ (** We include the standard library *)
+
external equal : string -> string -> bool = "caml_string_equal" "noalloc"
+ (** Equality on strings *)
+
+ val is_empty : string -> bool
+ (** Test whether a string is empty. *)
+
val explode : string -> string list
+ (** [explode "x1...xn"] returns [["x1"; ...; "xn"]] *)
+
val implode : string list -> string
+ (** [implode [s1; ...; sn]] returns [s1 ^ ... ^ sn] *)
+
val strip : string -> string
+ (** Remove the surrounding blank characters from a string *)
+
val map : (char -> char) -> string -> string
+ (** Apply a function on a string character-wise. *)
+
val drop_simple_quotes : string -> string
+ (** Remove the eventual first surrounding simple quotes of a string. *)
+
val string_index_from : string -> int -> string -> int
+ (** As [index_from], but takes a string instead of a char as pattern argument *)
+
val string_contains : where:string -> what:string -> bool
+ (** As [contains], but takes a string instead of a char as pattern argument *)
+
val plural : int -> string -> string
+ (** [plural n s] adds a optional 's' to the [s] when [2 <= n]. *)
+
val ordinal : int -> string
+ (** Generate the ordinal number in English. *)
+
val split : char -> string -> string list
+ (** [split c s] splits [s] into sequences separated by [c], excluded. *)
+
+ val is_sub : string -> string -> int -> bool
+ (** [is_sub p s off] tests whether [s] contains [p] at offset [off]. *)
end
include ExtS