Skip to content

Commit

Permalink
Switch to Re
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Mar 27, 2024
1 parent 4dd875a commit 94e6d2c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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))
9 changes: 5 additions & 4 deletions lastfm.opam
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(public_name lastfm)
(wrapped false)
(libraries
pcre
re
xmlplaylist
(select
lastfm.ml
Expand Down
16 changes: 9 additions & 7 deletions src/lastfm_generic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 "+"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand Down

0 comments on commit 94e6d2c

Please sign in to comment.