Skip to content

Commit

Permalink
Get rid of stdlib wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Nov 11, 2024
1 parent ac4266e commit 3bd220f
Show file tree
Hide file tree
Showing 33 changed files with 134 additions and 132 deletions.
10 changes: 6 additions & 4 deletions src/core/builtins/builtins_files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,23 @@ let _ =
let pattern =
pattern
|> Option.map (fun s ->
Pcre.substitute ~rex:(Pcre.regexp "\\.")
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\\.")
~subst:(fun _ -> "\\.")
s)
|> Option.map (fun s ->
Pcre.substitute ~rex:(Pcre.regexp "\\*") ~subst:(fun _ -> ".*") s)
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\\*")
~subst:(fun _ -> ".*")
s)
|> Option.map (fun s -> "^" ^ s ^ "$")
|> Option.value ~default:""
in
let sorted = List.assoc "sorted" p |> Lang.to_bool in
let rex = Pcre.regexp pattern in
let rex = Re.Pcre.regexp pattern in
let dir = Lang.to_string (List.assoc "" p) in
let dir = Lang_string.home_unrelate dir in
let readdir dir =
Array.to_list (Sys.readdir dir)
|> List.filter (fun s -> Pcre.pmatch ~rex s)
|> List.filter (fun s -> Re.Pcre.pmatch ~rex s)
in
let files =
if not recursive then readdir dir
Expand Down
2 changes: 1 addition & 1 deletion src/core/builtins/builtins_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ let _ =
in
let f = Lang.assoc "" 2 p in
let f x = Lang.to_string (Lang.apply f [("", Lang.string x)]) in
let ns = Pcre.split ~rex:(Pcre.regexp "\\.") namespace in
let ns = Re.Pcre.split ~rex:(Re.Pcre.regexp "\\.") namespace in
Server.add ~ns ~usage ~descr command f;
Lang.unit)
4 changes: 2 additions & 2 deletions src/core/builtins/builtins_sqlite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ let error fmt =
fmt

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

let insert_value_constr =
let open Type in
Expand Down
3 changes: 2 additions & 1 deletion src/core/builtins/builtins_sys.ml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ let _ =
let a = Lang.to_string (Lang.assoc "" 2 p) in
let s = match a with "" -> c | _ -> c ^ " " ^ a in
let r = try Server.exec s with Not_found -> "Command not found!" in
Lang.list (List.map Lang.string (Pcre.split ~rex:(Pcre.regexp "\r?\n") r))
Lang.list
(List.map Lang.string (Re.Pcre.split ~rex:(Re.Pcre.regexp "\r?\n") r))
in
Lang.add_builtin ~base:Modules.server "execute" ~category ~descr params
return_t execute
Expand Down
1 change: 0 additions & 1 deletion src/core/dune
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
fileutils
liquidsoap-lang
liquidsoap-lang.console
liquidsoap_stdlib
menhirLib
camomile.lib
curl
Expand Down
4 changes: 2 additions & 2 deletions src/core/encoder/formats/ffmpeg_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ let to_string m =
| None -> `Var "none"
| Some d -> `String d);
Printf.sprintf "%%%s(%s%s)" name
(if Pcre.pmatch ~rex:(Pcre.regexp "video") name then ""
(if Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "video") name then ""
else "video_content,")
(string_of_options stream_opts)
:: opts
Expand All @@ -152,7 +152,7 @@ let to_string m =
Hashtbl.replace stream_opts "samplerate"
(`Int (Lazy.force options.samplerate));
Printf.sprintf "%s(%s%s)" name
(if Pcre.pmatch ~rex:(Pcre.regexp "audio") name then ""
(if Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "audio") name then ""
else "audio_content,")
(string_of_options stream_opts)
:: opts)
Expand Down
4 changes: 2 additions & 2 deletions src/core/encoder/lang/lang_ffmpeg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ let stream_media_type ~to_pos ~to_static_string name args =
match (name, args) with
| _ when has_content ~to_static_string "audio_content" args -> `Audio
| _ when has_content ~to_static_string "video_content" args -> `Video
| _ when Pcre.pmatch ~rex:(Pcre.regexp "audio") name -> `Audio
| _ when Pcre.pmatch ~rex:(Pcre.regexp "video") name -> `Video
| _ when Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "audio") name -> `Audio
| _ when Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "video") name -> `Video
| _ -> (
match List.assoc_opt "codec" args with
| Some t -> (
Expand Down
25 changes: 13 additions & 12 deletions src/core/harbor/harbor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct
let websocket_error n msg = Websocket.to_string (`Close (Some (n, msg)))

let parse_icy_request_line ~port h r =
let auth_data = Pcre.split ~rex:(Pcre.regexp ":") r in
let auth_data = Re.Pcre.split ~rex:(Re.Pcre.regexp ":") r in
let requested_user, password =
match auth_data with
| user :: password :: _ -> (user, password)
Expand All @@ -387,7 +387,7 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct

let parse_http_request_line r =
try
let data = Pcre.split ~rex:(Pcre.regexp "[ \t]+") r in
let data = Re.Pcre.split ~rex:(Re.Pcre.regexp "[ \t]+") r in
let protocol = verb_or_source_of_string (List.nth data 0) in
Duppy.Monad.return
( protocol,
Expand All @@ -409,9 +409,9 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct
let parse_headers headers =
let split_header h l =
try
let rex = Pcre.regexp "([^:\\r\\n]+):\\s*([^\\r\\n]+)" in
let sub = Pcre.exec ~rex h in
(Pcre.get_substring sub 1, Pcre.get_substring sub 2) :: l
let rex = Re.Pcre.regexp "([^:\\r\\n]+):\\s*([^\\r\\n]+)" in
let sub = Re.Pcre.exec ~rex h in
(Re.Pcre.get_substring sub 1, Re.Pcre.get_substring sub 2) :: l
with Not_found -> l
in
let f x = String.uppercase_ascii x in
Expand Down Expand Up @@ -449,11 +449,12 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct
try
(* HTTP authentication *)
let auth = assoc_uppercase "AUTHORIZATION" headers in
let data = Pcre.split ~rex:(Pcre.regexp "[ \t]+") auth in
let data = Re.Pcre.split ~rex:(Re.Pcre.regexp "[ \t]+") auth in
match data with
| "Basic" :: x :: _ -> (
let auth_data =
Pcre.split ~rex:(Pcre.regexp ":") (Lang_string.decode64 x)
Re.Pcre.split ~rex:(Re.Pcre.regexp ":")
(Lang_string.decode64 x)
in
match auth_data with
| x :: y :: _ -> (x, y)
Expand Down Expand Up @@ -767,11 +768,11 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct
| _ -> ans_500 uri

let handle_http_request ~hmethod ~hprotocol ~port h uri headers =
let rex = Pcre.regexp "^(.+)\\?(.+)$" in
let rex = Re.Pcre.regexp "^(.+)\\?(.+)$" in
let base_uri, args =
try
let sub = Pcre.exec ~rex uri in
(Pcre.get_substring sub 1, Pcre.get_substring sub 2)
let sub = Re.Pcre.exec ~rex uri in
(Re.Pcre.get_substring sub 1, Re.Pcre.get_substring sub 2)
with Not_found -> (uri, "")
in
let smethod = string_of_verb hmethod in
Expand Down Expand Up @@ -920,7 +921,7 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct
| false -> Duppy.Io.Split "[\r]?\n[\r]?\n")
h
in
let lines = Pcre.split ~rex:(Pcre.regexp "[\r]?\n") s in
let lines = Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r]?\n") s in
let* hmethod, huri, hprotocol =
let s = List.hd lines in
if icy then parse_icy_request_line ~port h s
Expand Down Expand Up @@ -1002,7 +1003,7 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct
~priority:`Non_blocking ~marker:(Duppy.Io.Split "[\r]?\n[\r]?\n")
h
in
let lines = Pcre.split ~rex:(Pcre.regexp "[\r]?\n") s in
let lines = Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r]?\n") s in
let headers = parse_headers lines in
handle_source_request ~port ~auth:true ~smethod:`Shout hprotocol h
huri headers
Expand Down
11 changes: 7 additions & 4 deletions src/core/io/ffmpeg_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,18 @@ class http_input ~autostart ~self_sync ~poll_delay ~debug ~on_error ~max_buffer
Avutil.Options.get_string ~search_children:true
~name:"icy_metadata_headers" (Av.input_obj input)
in
let icy_headers = Pcre.split ~rex:(Pcre.regexp "[\r]?\n") icy_headers in
let icy_headers =
Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r]?\n") icy_headers
in
List.fold_left
(fun ret header ->
if header <> "" then (
try
let res =
Pcre.exec ~rex:(Pcre.regexp "([^:]*):\\s*(.*)") header
Re.Pcre.exec ~rex:(Re.Pcre.regexp "([^:]*):\\s*(.*)") header
in
(Pcre.get_substring res 1, Pcre.get_substring res 2) :: ret
(Re.Pcre.get_substring res 1, Re.Pcre.get_substring res 2)
:: ret
with Not_found -> ret)
else ret)
[] icy_headers
Expand Down Expand Up @@ -556,7 +559,7 @@ let register_input is_http =
(Lang.apply fn [("", Lang.metadata_list m)])
| None ->
List.filter (fun (k, _) ->
not (Pcre.pmatch ~rex:(Pcre.regexp "^id3v2_priv") k))
not (Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "^id3v2_priv") k))
in
let deduplicate_metadata =
Lang.to_bool (List.assoc "deduplicate_metadata" p)
Expand Down
5 changes: 4 additions & 1 deletion src/core/io/srt_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ let log = Log.make ["srt"]

let log_handler { Srt.Log.message } =
let message =
Pcre.substitute ~rex:(Pcre.regexp "[ \r\n]+$") ~subst:(fun _ -> "") message
Re.Pcre.substitute
~rex:(Re.Pcre.regexp "[ \r\n]+$")
~subst:(fun _ -> "")
message
in
log#f conf_level#get "%s" message

Expand Down
9 changes: 5 additions & 4 deletions src/core/operators/chord.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ class chord metadata_name (source : source) =
| Some c -> (
try
let sub =
Pcre.exec
~rex:(Pcre.regexp "^([A-G-](?:b|#)?)(|M|m|M7|m7|dim)$")
Re.Pcre.exec
~rex:
(Re.Pcre.regexp "^([A-G-](?:b|#)?)(|M|m|M7|m7|dim)$")
c
in
let n = Pcre.get_substring sub 1 in
let n = Re.Pcre.get_substring sub 1 in
let n = note_of_string n in
let m = Pcre.get_substring sub 2 in
let m = Re.Pcre.get_substring sub 2 in
ans := (t, n, m) :: !ans
with Not_found ->
self#log#important "Could not parse chord '%s'." c))
Expand Down
10 changes: 7 additions & 3 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
Pcre.split ~rex:(Pcre.regexp ":") path
Re.Pcre.split ~rex:(Re.Pcre.regexp ":") path
with Not_found -> Frei0r.default_paths

class frei0r_filter ~name bgra instance params (source : source) =
Expand Down Expand Up @@ -317,15 +317,19 @@ let register_plugin fname =
let explanation =
let e = info.Frei0r.explanation in
let e = String.capitalize_ascii e in
let e = Pcre.substitute ~rex:(Pcre.regexp "@") ~subst:(fun _ -> "(at)") e in
let e =
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "@") ~subst:(fun _ -> "(at)") 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 = Pcre.substitute ~rex:(Pcre.regexp "@") ~subst:(fun _ -> "(at)") a in
let a =
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "@") ~subst:(fun _ -> "(at)") a
in
a
in
let descr = Printf.sprintf "%s (by %s)." explanation author in
Expand Down
2 changes: 1 addition & 1 deletion src/core/operators/ladspa_op.ml
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ let register_descr d =
in
let maker = d.plugin_maker in
let maker =
Pcre.substitute ~rex:(Pcre.regexp "@") ~subst:(fun _ -> "(at)") maker
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "@") ~subst:(fun _ -> "(at)") maker
in
let descr = Printf.sprintf "%s by %s." d.plugin_name maker in
let return_t =
Expand Down
2 changes: 1 addition & 1 deletion src/core/outputs/pipe_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ class virtual ['a] file_output_base p =
let filename = Lang_string.home_unrelate filename in
(* Avoid / in metas for filename.. *)
let subst m =
Pcre.substitute ~rex:(Pcre.regexp "/") ~subst:(fun _ -> "-") m
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "/") ~subst:(fun _ -> "-") m
in
self#interpolate ~subst filename
Expand Down
32 changes: 17 additions & 15 deletions src/core/playlists/playlist_basic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*****************************************************************************)

let log = Log.make ["playlist"; "basic"]
let split_lines buf = Pcre.split ~rex:(Pcre.regexp "[\r\n]+") buf
let split_lines buf = Re.Pcre.split ~rex:(Re.Pcre.regexp "[\r\n]+") buf

let parse_meta =
let processor =
Expand All @@ -48,20 +48,20 @@ let parse_meta =

let parse_extinf s =
try
let rex = Pcre.regexp "#EXTINF:(\\d*)\\s*(.*)" in
let sub = Pcre.exec ~rex s in
let rex = Re.Pcre.regexp "#EXTINF:(\\d*)\\s*(.*)" in
let sub = Re.Pcre.exec ~rex s in
let meta, song =
match Pcre.get_substring sub 2 with
match Re.Pcre.get_substring sub 2 with
| "" -> ([], "")
| s when s.[0] = ',' -> ([], String.sub s 1 (String.length s - 1))
| s -> parse_meta s
in
let meta =
match Pcre.get_substring sub 1 with
match Re.Pcre.get_substring sub 1 with
| "" -> meta
| duration -> ("extinf_duration", duration) :: meta
in
let lines = Pcre.split ~rex:(Pcre.regexp "\\s*-\\s*") song in
let lines = Re.Pcre.split ~rex:(Re.Pcre.regexp "\\s*-\\s*") song in
meta
@
match lines with
Expand All @@ -75,7 +75,7 @@ let parse_extinf s =
(* This parser cannot detect the format !! *)
let parse_mpegurl ?pwd string =
let lines = List.filter (fun x -> x <> "") (split_lines string) in
let is_info line = Pcre.pmatch ~rex:(Pcre.regexp "^#EXTINF") line in
let is_info line = Re.Pcre.pmatch ~rex:(Re.Pcre.regexp "^#EXTINF") line in
let skip_line line = line.[0] == '#' in
let rec get_urls cur lines =
match lines with
Expand All @@ -91,26 +91,26 @@ let parse_mpegurl ?pwd string =

let parse_scpls ?pwd string =
let string =
Pcre.substitute
~rex:(Pcre.regexp "#[^\\r\\n]*[\\n\\r]+")
Re.Pcre.substitute
~rex:(Re.Pcre.regexp "#[^\\r\\n]*[\\n\\r]+")
~subst:(fun _ -> "")
string
in
(* Format check, raise Not_found if invalid *)
ignore
(Pcre.exec
~rex:(Pcre.regexp "^[\\r\\n\\s]*\\[playlist\\]")
(Re.Pcre.exec
~rex:(Re.Pcre.regexp "^[\\r\\n\\s]*\\[playlist\\]")
(String.lowercase_ascii string));
let lines = split_lines string in
let urls =
List.map
(fun s ->
try
let rex =
Pcre.regexp ~flags:[`CASELESS] "file\\d*\\s*=\\s*(.*)\\s*"
Re.Pcre.regexp ~flags:[`CASELESS] "file\\d*\\s*=\\s*(.*)\\s*"
in
let sub = Pcre.exec ~rex s in
Pcre.get_substring sub 1
let sub = Re.Pcre.exec ~rex s in
Re.Pcre.get_substring sub 1
with Not_found -> "")
lines
in
Expand Down Expand Up @@ -233,7 +233,9 @@ let parse_cue ?pwd string =
let strings =
List.map
(fun string ->
Pcre.substitute ~rex:(Pcre.regexp "^\\s+") ~subst:(fun _ -> "") string)
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "^\\s+")
~subst:(fun _ -> "")
string)
strings
in
let strings = List.filter (fun s -> s <> "") strings in
Expand Down
4 changes: 2 additions & 2 deletions src/core/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ let pretty_date date =
let remove_file_proto s =
(* First remove file:// 🤮 *)
let s =
Pcre.substitute ~rex:(Pcre.regexp "^file://") ~subst:(fun _ -> "") s
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "^file://") ~subst:(fun _ -> "") s
in
(* Then remove file: 😇 *)
Pcre.substitute ~rex:(Pcre.regexp "^file:") ~subst:(fun _ -> "") s
Re.Pcre.substitute ~rex:(Re.Pcre.regexp "^file:") ~subst:(fun _ -> "") s

let home_unrelate s = Lang_string.home_unrelate (remove_file_proto s)

Expand Down
5 changes: 4 additions & 1 deletion src/core/source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ class virtual operator ?(stack = []) ?clock ?(name = "src") sources =

method set_id ?(definitive = true) s =
let s =
Pcre.substitute ~rex:(Pcre.regexp "[ \t\n.]") ~subst:(fun _ -> "_") s
Re.Pcre.substitute
~rex:(Re.Pcre.regexp "[ \t\n.]")
~subst:(fun _ -> "_")
s
in
if not definitive_id then (
id <- Lang_string.generate_id s;
Expand Down
Loading

0 comments on commit 3bd220f

Please sign in to comment.