Skip to content
Snippets Groups Projects
Commit bd2416ed authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[extlib] suppress deprecated string-suffix and string-prefix

parent 043b86c5
No related branches found
No related tags found
No related merge requests found
......@@ -329,36 +329,18 @@ let temp_dir_cleanup_at_exit ?(debug=false) base =
(** Strings *)
(* ************************************************************************* *)
let compare_strings s1 s2 len =
try
for i = 0 to len - 1 do if s1.[i] <> s2.[i] then raise Exit; done;
true
with Exit -> false
| Invalid_argument _ -> raise (Invalid_argument "Extlib.compare_strings")
let string_prefix ?(strict=false) prefix s =
let add = if strict then 1 else 0 in
String.length s >= String.length prefix + add
&& compare_strings prefix s (String.length prefix)
let string_del_prefix ?(strict=false) prefix s =
if string_prefix ~strict prefix s then
Some
(String.sub s
(String.length prefix) (String.length s - String.length prefix))
if String.starts_with ~prefix s then
let n = String.length s in
let p = String.length prefix in
if not strict || n > p then Some (String.sub s p (n-p)) else None
else None
let string_suffix ?(strict=false) suffix s =
let len = String.length s in
let suf_len = String.length suffix in
let strict_len = if strict then suf_len + 1 else suf_len in
len >= strict_len &&
compare_strings suffix (String.sub s (len - suf_len) suf_len) suf_len
let string_del_suffix ?(strict=false) suffix s =
if string_suffix ~strict suffix s then
Some
(String.sub s 0 (String.length s - String.length suffix))
if String.ends_with ~suffix s then
let n = String.length s in
let p = String.length suffix in
if not strict || n > p then Some (String.sub s 0 (n-p)) else None
else None
let make_unique_name mem ?(sep=" ") ?(start=2) from =
......
......@@ -193,30 +193,11 @@ val opt_map2: ('a -> 'b -> 'c) -> 'a option -> 'b option -> 'c option
(** {2 Strings} *)
(* ************************************************************************* *)
val string_prefix: ?strict:bool -> string -> string -> bool
[@@alert deprecated "Use String.starts_with instead"]
(** [string_prefix ~strict p s] returns [true] if and only if [p] is a
prefix of the string [s]. If [strict] is true, the prefix must be strict
(that is, [s] must moreover be strictly longer than [p]). [strict]
is false by default.
@since Boron-20100401
@deprecated 28.0-Nickel use 'String.starts_with' instead
*)
val string_del_prefix: ?strict:bool -> string -> string -> string option
(** [string_del_prefix ~strict p s] returns [None] if [p] is not a prefix of
[s] and Some [s1] iff [s=p^s1].
@since Oxygen-20120901 *)
val string_suffix: ?strict:bool -> string -> string -> bool
[@@alert deprecated "Use String.ends_with instead"]
(** [string_suffix ~strict suf s] returns [true] iff [suf] is a suffix of
string [s]. [strict], which defaults to [false], indicates whether [s]
should be strictly longer than [p].
@since Aluminium-20160501
@deprecated 28.0-Nickel use 'String.ends_with' instead
*)
val string_del_suffix: ?strict:bool -> string -> string -> string option
(** [string_del_suffix ~strict suf s] returns [Some s1] when [s = s1 ^ suf]
and None of [suf] is not a suffix of [s].
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment