gen_licenses: normalize paths with a Re regexp

This commit is contained in:
Matthieu Dubuget committed 2026-11-22 19:21:43 +01:00
1 parent 47d59988c2
commit b9e82711ec
1 file changed
+3 -9
+3 -9
View File
@@ -33,16 +33,10 @@ let line cmd =
(* Windows writes paths with backslashes (doubled in the .changes files, where (* Windows writes paths with backslashes (doubled in the .changes files, where
they are escaped), and drive letters in either case. *) they are escaped), and drive letters in either case. *)
let slashes = Re.compile (Re.rep1 (Re.set "/\\"))
let normalize s = let normalize s =
let b = Buffer.create (String.length s) in String.lowercase_ascii (Re.replace_string slashes ~by:"/" s)
String.iter
(fun c ->
let c = if c = '\\' then '/' else Char.lowercase_ascii c in
let n = Buffer.length b in
if not (c = '/' && n > 0 && Buffer.nth b (n - 1) = '/') then
Buffer.add_char b c)
s;
Buffer.contents b
let starts_with ~prefix s = let starts_with ~prefix s =
String.length s >= String.length prefix String.length s >= String.length prefix