From bd2416ede8612e04bac9928bb4b5fa5bf8afbd30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Tue, 16 Apr 2024 14:31:44 +0200
Subject: [PATCH] [extlib] suppress deprecated string-suffix and string-prefix

---
 src/libraries/stdlib/extlib.ml  | 34 ++++++++-------------------------
 src/libraries/stdlib/extlib.mli | 19 ------------------
 2 files changed, 8 insertions(+), 45 deletions(-)

diff --git a/src/libraries/stdlib/extlib.ml b/src/libraries/stdlib/extlib.ml
index 39b641d9fe1..4d1eef922a1 100644
--- a/src/libraries/stdlib/extlib.ml
+++ b/src/libraries/stdlib/extlib.ml
@@ -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 =
diff --git a/src/libraries/stdlib/extlib.mli b/src/libraries/stdlib/extlib.mli
index 621e1e96829..6549dcbd1b7 100644
--- a/src/libraries/stdlib/extlib.mli
+++ b/src/libraries/stdlib/extlib.mli
@@ -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].
-- 
GitLab