aboutsummaryrefslogtreecommitdiff
path: root/clib
diff options
context:
space:
mode:
Diffstat (limited to 'clib')
-rw-r--r--clib/cList.ml20
-rw-r--r--clib/cString.ml4
-rw-r--r--clib/cString.mli3
3 files changed, 13 insertions, 14 deletions
diff --git a/clib/cList.ml b/clib/cList.ml
index 057200f83e..6b13fac48c 100644
--- a/clib/cList.ml
+++ b/clib/cList.ml
@@ -1019,20 +1019,12 @@ let rec factorize_left cmp = function
module Smart =
struct
- let rec map_loop f p = function
- | [] -> ()
- | x :: l' as l ->
- let x' = f x in
- map_loop f p l';
- if x' == x && !p == l' then p := l else p := x' :: !p
-
- let map f = function
- | [] -> []
- | x :: l' as l ->
- let p = ref [] in
- let x' = f x in
- map_loop f p l';
- if x' == x && !p == l' then l else x' :: !p
+ let rec map f l = match l with
+ | [] -> l
+ | h :: tl ->
+ let h' = f h in
+ let tl' = map f tl in
+ if h' == h && tl' == tl then l else h' :: tl'
end
diff --git a/clib/cString.ml b/clib/cString.ml
index dcada4c18f..9d2c3729b2 100644
--- a/clib/cString.ml
+++ b/clib/cString.ml
@@ -25,6 +25,7 @@ sig
val ordinal : int -> string
val is_sub : string -> string -> int -> bool
val is_prefix : string -> string -> bool
+ val is_suffix : string -> string -> bool
module Set : Set.S with type elt = t
module Map : CMap.ExtS with type key = t and module Set := Set
module List : CList.MonoS with type elt = t
@@ -105,6 +106,9 @@ let is_sub p s off =
let is_prefix p s =
is_sub p s 0
+let is_suffix p s =
+ is_sub p s (String.length s - String.length p)
+
let plural n s = if n<>1 then s^"s" else s
let conjugate_verb_to_be n = if n<>1 then "are" else "is"
diff --git a/clib/cString.mli b/clib/cString.mli
index 0f78e66573..be8a202b64 100644
--- a/clib/cString.mli
+++ b/clib/cString.mli
@@ -54,6 +54,9 @@ sig
val is_prefix : string -> string -> bool
(** [is_prefix p s] tests whether [p] is a prefix of [s]. *)
+ val is_suffix : string -> string -> bool
+ (** [is_suffix suf s] tests whether [suf] is a suffix of [s]. *)
+
(** {6 Generic operations} **)
module Set : Set.S with type elt = t