Last active
November 19, 2019 14:27
-
-
Save eneroth/f8d77629e45aa5e0e28b283505591e44 to your computer and use it in GitHub Desktop.
Trivial K/V parser for a string of args
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
(require '[clojure.string :as string]) | |
(def test-str "name\\=name=value\\=value;name=value;name=value\\;;name=value;") | |
(defn key-part [s] | |
(second (re-find #"(.*[^\\])=" s))) | |
(defn value-part [s] | |
(second (re-find #"[^\\]=(.*)" s))) | |
(defn parse [s] | |
(let [xf (comp (map second) | |
(map (juxt key-part value-part)))] | |
(sequence xf (re-seq #"(.*?[^\\]);" s)))) | |
(parse test-str) | |
;; => (["name\\=name" "value\\=value"] ["name" "value"] ["name" "value\\;"] ["name" "value"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment