Skip to content

Instantly share code, notes, and snippets.

@eneroth
Last active November 19, 2019 14:27
Show Gist options
  • Save eneroth/f8d77629e45aa5e0e28b283505591e44 to your computer and use it in GitHub Desktop.
Save eneroth/f8d77629e45aa5e0e28b283505591e44 to your computer and use it in GitHub Desktop.
Trivial K/V parser for a string of args
(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