From b9e82711ec691146afc4da51df352fd6a30e6e90 Mon Sep 17 00:00:00 2001 From: Matthieu Dubuget Date: Sun, 22 Nov 2026 19:21:43 +0100 Subject: [PATCH] gen_licenses: normalize paths with a Re regexp --- tools/gen_licenses.ml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tools/gen_licenses.ml b/tools/gen_licenses.ml index 308c8a0..7344e78 100644 --- a/tools/gen_licenses.ml +++ b/tools/gen_licenses.ml @@ -33,16 +33,10 @@ let line cmd = (* Windows writes paths with backslashes (doubled in the .changes files, where they are escaped), and drive letters in either case. *) +let slashes = Re.compile (Re.rep1 (Re.set "/\\")) + let normalize s = - let b = Buffer.create (String.length s) in - 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 + String.lowercase_ascii (Re.replace_string slashes ~by:"/" s) let starts_with ~prefix s = String.length s >= String.length prefix