Created
April 1, 2020 08:42
-
-
Save sw1nn/6592e3a304956418fdc907ece31ae28e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def input ", \t, , , UTF-8;q=0.8,shift_JIS;q=0.4,a,b") | |
(def rfc-7231-re #"(?x) | |
(?: | |
\s* # OWS | |
(?<charset>\*|[\w\d_-]+) | |
(?i: | |
;q= | |
(?<weight>0\.\d{1,3}|1\.0{1,3}) | |
)? | |
)+?,?") | |
(defn parse-rfc7231-accept-charset [s] | |
(->> s | |
(re-seq rfc-7231-re) | |
(keep (fn [m] | |
(when-let [[charset weight] (next m)] | |
(vector charset (when weight (Float/parseFloat weight)))))) | |
(into {}))) | |
(comment | |
(criterium.core/quick-bench | |
(parse-rfc7231-accept-charset input))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment