aboutsummaryrefslogtreecommitdiff
path: root/lib/cString.ml
diff options
context:
space:
mode:
authorppedrot2012-12-13 15:59:59 +0000
committerppedrot2012-12-13 15:59:59 +0000
commit0a7347b567d6ea5d71907b570c81ea6dc61a626d (patch)
tree4dd25cc9d1d53f9bb539c6d7c9eebcd36ed59b63 /lib/cString.ml
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/cString.ml')
-rw-r--r--lib/cString.ml20
1 files changed, 19 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 =