Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup regexp usages #4224

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/core/builtins/builtins_files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,8 @@ let _ =
let pattern =
pattern
|> Option.map (fun s ->
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\\.")
~subst:(fun _ -> "\\.")
s)
|> Option.map (fun s ->
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\\*")
~subst:(fun _ -> ".*")
s)
String.concat "\\." (String.split_on_char '.' s))
|> Option.map (fun s -> String.concat ".*" (String.split_on_char '*' s))
|> Option.map (fun s -> "^" ^ s ^ "$")
|> Option.value ~default:""
in
Expand Down
4 changes: 1 addition & 3 deletions src/core/builtins/builtins_sqlite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ let error fmt =
(fun message -> Runtime_error.raise ~pos:[] ~message "sqlite")
fmt

let escape =
let rex = Re.Pcre.regexp "'" in
fun s -> "'" ^ Re.Pcre.substitute ~rex ~subst:(fun _ -> "''") s ^ "'"
let escape s = "'" ^ String.concat "''" (String.split_on_char '\'' s) ^ "'"

let insert_value_constr =
let open Type in
Expand Down
11 changes: 3 additions & 8 deletions src/core/operators/frei0r_op.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let frei0r_enable =
let plugin_dirs =
try
let path = Unix.getenv "LIQ_FREI0R_PATH" in
Re.Pcre.split ~rex:(Re.Pcre.regexp ":") path
String.split_on_char ':' path
with Not_found -> Frei0r.default_paths

class frei0r_filter ~name bgra instance params (source : source) =
Expand Down Expand Up @@ -317,20 +317,15 @@ let register_plugin fname =
let explanation =
let e = info.Frei0r.explanation in
let e = String.capitalize_ascii e in
let e =
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "@") ~subst:(fun _ -> "(at)") e
in
let e = String.concat "(at)" (String.split_on_char '@' e) in
if e = "" then e
else if e.[String.length e - 1] = '.' then
String.sub e 0 (String.length e - 1)
else e
in
let author =
let a = info.Frei0r.author in
let a =
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "@") ~subst:(fun _ -> "(at)") a
in
a
String.concat "(at)" (String.split_on_char '@' a)
in
let descr = Printf.sprintf "%s (by %s)." explanation author in
ignore
Expand Down
4 changes: 1 addition & 3 deletions src/core/operators/ladspa_op.ml
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,7 @@ let register_descr d =
@ if ni = 0 then [] else [("", Lang.source_t input_t, None, None)]
in
let maker = d.plugin_maker in
let maker =
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "@") ~subst:(fun _ -> "(at)") maker
in
let maker = String.concat "(at)" (String.split_on_char '@' maker) in
let descr = Printf.sprintf "%s by %s." d.plugin_name maker in
let return_t =
if mono then input_t
Expand Down
4 changes: 1 addition & 3 deletions src/core/outputs/pipe_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,7 @@ class virtual ['a] file_output_base p =
let filename = filename () in
let filename = Lang_string.home_unrelate filename in
(* Avoid / in metas for filename.. *)
let subst m =
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "/") ~subst:(fun _ -> "-") m
in
let subst m = String.concat "-" (String.split_on_char '/' m) in
self#interpolate ~subst filename

method virtual open_out_gen : open_flag list -> int -> string -> 'a
Expand Down
4 changes: 2 additions & 2 deletions src/core/synth/dssi_op.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ let dssi_enable =
let dssi_load =
try
let venv = Unix.getenv "LIQ_DSSI_LOAD" in
Re.Pcre.split ~rex:(Re.Pcre.regexp ":") venv
String.split_on_char ':' venv
with Not_found -> []

let plugin_dirs =
try
let path = Unix.getenv "LIQ_DSSI_PATH" in
Re.Pcre.split ~rex:(Re.Pcre.regexp ":") path
String.split_on_char ':' path
with Not_found -> ["/usr/lib/dssi"; "/usr/local/lib/dssi"]

(* Number of channels to synthesize when in all mode *)
Expand Down
8 changes: 4 additions & 4 deletions src/core/tools/liq_http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let user_agent = Configure.vendor
let args_split s =
let args = Hashtbl.create 2 in
let fill_arg arg =
match Re.Pcre.split ~rex:(Re.Pcre.regexp "=") arg with
match String.split_on_char '=' arg with
| e :: l ->
(* There should be only arg=value *)
List.iter
Expand All @@ -105,7 +105,7 @@ let args_split s =
l
| [] -> ()
in
List.iter fill_arg (Re.Pcre.split ~rex:(Re.Pcre.regexp "&") s);
List.iter fill_arg (String.split_on_char '&' s);
args

let parse_url url =
Expand Down Expand Up @@ -196,7 +196,7 @@ let really_read ~timeout (socket : socket) len =
let read_chunked ~timeout (socket : socket) =
let read = read_crlf ~count:1 ~timeout socket in
let len = List.hd (Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r]?\n") read) in
let len = List.hd (Re.Pcre.split ~rex:(Re.Pcre.regexp ";") len) in
let len = List.hd (String.split_on_char ':' len) in
let len = int_of_string ("0x" ^ len) in
let s = really_read socket ~timeout len in
ignore (read_crlf ~count:1 ~timeout socket);
Expand All @@ -210,7 +210,7 @@ let set_socket_default ~read_timeout ~write_timeout fd =
type auth = { user : string; password : string }

let parse_auth s =
match Re.Pcre.split ~rex:(Re.Pcre.regexp ":") s with
match String.split_on_char ':' s with
| user :: (_ :: _ as password) ->
{ user; password = String.concat ":" password }
| _ -> raise Not_found
2 changes: 1 addition & 1 deletion src/core/tools/sandbox.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let conf_setenv =
let get_setenv () =
List.fold_left
(fun cur s ->
match Re.Pcre.split ~rex:(Re.Pcre.regexp "=") s with
match String.split_on_char '=' s with
| [] -> cur
| lbl :: l -> (lbl, String.concat "=" l) :: cur)
[] conf_setenv#get
Expand Down
2 changes: 1 addition & 1 deletion src/core/tools/tutils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ let create ~queue f x s =
(Printexc.to_string e);
Printexc.raise_with_backtrace e raw_bt
with e ->
let l = Re.Pcre.split ~rex:(Re.Pcre.regexp "\n") bt in
let l = String.split_on_char '\n' bt in
List.iter (log#info "%s") l;
Mutex_utils.mutexify lock
(fun () ->
Expand Down
2 changes: 1 addition & 1 deletion src/lang/builtins_string.ml
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ let _ =
in
Lang.string
(if space_sensitive then (
let l = Re.Pcre.split ~rex:(Re.Pcre.regexp " ") string in
let l = String.split_on_char ' ' string in
let l = List.map f l in
String.concat " " l)
else f string))
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ let format_doc s =
let prefix = "\t " in
let indent = 8 + 2 in
let max_width = 80 in
let s = Re.Pcre.split ~rex:(Re.Pcre.regexp " ") s in
let s = String.split_on_char ' ' s in
let s =
let rec join line width = function
| [] -> [line]
Expand Down
Loading