From 94e6d2c7cbbb8243ed1d0ddb59d00cbdc2eb39f3 Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Wed, 27 Mar 2024 16:25:34 -0500 Subject: [PATCH] Switch to Re --- dune-project | 6 +++--- lastfm.opam | 9 +++++---- src/dune | 2 +- src/lastfm_generic.ml | 16 +++++++++------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/dune-project b/dune-project index 4344e92..4a925bd 100644 --- a/dune-project +++ b/dune-project @@ -1,5 +1,5 @@ -(lang dune 2.0) -(version 0.3.3) +(lang dune 3.14) +(version 0.3.4) (name lastfm) (source (github savonet/ocaml-lastfm)) (license LGPL-2.1) @@ -13,7 +13,7 @@ (synopsis "The lastfm library is an implementation of the API used by the last.fm to keep count of played songs") (depends xmlplaylist - pcre + re (dune (>= 2.0))) (depopts ocamlnet)) diff --git a/lastfm.opam b/lastfm.opam index a22feb0..51596ce 100644 --- a/lastfm.opam +++ b/lastfm.opam @@ -1,6 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" -version: "0.3.3" +version: "0.3.4" synopsis: "The lastfm library is an implementation of the API used by the last.fm to keep count of played songs" maintainer: ["The Savonet Team "] @@ -10,12 +10,13 @@ homepage: "https://github.com/savonet/ocaml-lastfm" bug-reports: "https://github.com/savonet/ocaml-lastfm/issues" depends: [ "xmlplaylist" - "pcre" - "dune" {>= "2.0"} + "re" + "dune" {>= "3.14" & >= "2.0"} + "odoc" {with-doc} ] depopts: ["ocamlnet"] build: [ - ["dune" "subst"] {pinned} + ["dune" "subst"] {dev} [ "dune" "build" diff --git a/src/dune b/src/dune index 275a5e3..73a15ba 100644 --- a/src/dune +++ b/src/dune @@ -3,7 +3,7 @@ (public_name lastfm) (wrapped false) (libraries - pcre + re xmlplaylist (select lastfm.ml diff --git a/src/lastfm_generic.ml b/src/lastfm_generic.ml index 2c66925..b906766 100644 --- a/src/lastfm_generic.ml +++ b/src/lastfm_generic.ml @@ -22,6 +22,8 @@ (* lastfm protocol API for ocaml *) +module Pcre = Re.Pcre + (* Records for client *) type client = { client : string; version : string } type login = { user : string; password : string } @@ -89,8 +91,8 @@ let of_hex1 c = let url_decode ?(plus = true) s = Pcre.substitute - ~pat: - "\\+|%.." + ~rex:(Pcre.regexp + "\\+|%..") (* TODO why do we match %. and % and seem to exclude them below ? *) ~subst:(fun s -> if s = "+" then if plus then " " else "+" @@ -132,7 +134,7 @@ let to_hex2 = Bytes.to_string s let url_encode ?(plus = true) s = - Pcre.substitute ~pat:"[^A-Za-z0-9_.!*-]" + Pcre.substitute ~rex:(Pcre.regexp "[^A-Za-z0-9_.!*-]") ~subst:(fun x -> if plus && x = " " then "+" else ( @@ -293,7 +295,7 @@ module Audioscrobbler_generic (Http : Http_t) = struct in let test (p, e) = try - ignore (Pcre.exec ~pat:p s); + ignore (Pcre.exec ~rex:(Pcre.regexp p) s); raise (Error e) with Not_found -> () in @@ -367,7 +369,7 @@ module Audioscrobbler_generic (Http : Http_t) = struct let ans = request ?timeout ~host ~port req in let state, id, v = try - let lines = Pcre.split ~pat:"[\r\n]+" ans in + let lines = Pcre.split ~rex:(Pcre.regexp "[\r\n]+") ans in match lines with | [state; id; a; b] -> (state, id, (a, b)) | _ -> raise (error_of_response ans) @@ -668,7 +670,7 @@ module Radio_generic (Http : Http_t) = struct let values = Pcre.split ~rex s in let split s l = try - let sub = Pcre.exec ~pat:"([^=]*)=(.*)" s in + let sub = Pcre.exec ~rex:(Pcre.regexp "([^=]*)=(.*)") s in (Pcre.get_substring sub 1, Pcre.get_substring sub 2) :: l with Not_found -> l in @@ -683,7 +685,7 @@ module Radio_generic (Http : Http_t) = struct with Not_found -> raise (Auth s) let adjust_pat = "response=OK" - let check_adjust s = Pcre.pmatch ~pat:adjust_pat s + let check_adjust s = Pcre.pmatch ~rex:(Pcre.regexp adjust_pat) s let opt_split_rex = Pcre.regexp "^([^?]+)\\?(.+)$" let opt_parse s =