commit
5efafd2d9b
4 changed files with 30 additions and 4 deletions
|
|
@ -1,3 +1,7 @@
|
||||||
|
## 1.0.5-SNAPSHOT
|
||||||
|
|
||||||
|
* Add `regex-nav` navigator for regexes, which navigate to every match in a string and support replacement with a new substring.
|
||||||
|
|
||||||
## 1.0.4
|
## 1.0.4
|
||||||
|
|
||||||
* Add `indexed-vals` navigator, a variant of `INDEXED-VALS` that allows for a customized start index.
|
* Add `indexed-vals` navigator, a variant of `INDEXED-VALS` that allows for a customized start index.
|
||||||
|
|
|
||||||
|
|
@ -1068,6 +1068,13 @@
|
||||||
(swap! structure next-fn)
|
(swap! structure next-fn)
|
||||||
structure)))
|
structure)))
|
||||||
|
|
||||||
|
(defnav regex-nav [re]
|
||||||
|
(select* [this structure next-fn]
|
||||||
|
(doseqres NONE [s (re-seq re structure)]
|
||||||
|
(next-fn s)))
|
||||||
|
(transform* [this structure next-fn]
|
||||||
|
(clojure.string/replace structure re next-fn)))
|
||||||
|
|
||||||
(defdynamicnav selected?
|
(defdynamicnav selected?
|
||||||
"Filters the current value based on whether a path finds anything.
|
"Filters the current value based on whether a path finds anything.
|
||||||
e.g. (selected? :vals ALL even?) keeps the current element only if an
|
e.g. (selected? :vals ALL even?) keeps the current element only if an
|
||||||
|
|
|
||||||
|
|
@ -478,6 +478,7 @@
|
||||||
structure
|
structure
|
||||||
(updater structure next-fn))))
|
(updater structure next-fn))))
|
||||||
|
|
||||||
|
|
||||||
(defn- update-first-list [l afn]
|
(defn- update-first-list [l afn]
|
||||||
(let [newf (afn (first l))
|
(let [newf (afn (first l))
|
||||||
restl (rest l)]
|
restl (rest l)]
|
||||||
|
|
|
||||||
|
|
@ -1434,6 +1434,20 @@
|
||||||
(is (= "abq" (setval s/LAST "q" "abc")))
|
(is (= "abq" (setval s/LAST "q" "abc")))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(deftest regex-navigation-test
|
||||||
|
(is (= (select (s/regex-nav #"t") "test") ["t" "t"]))
|
||||||
|
(is (= (select [:a (s/regex-nav #"t")] {:a "test"}) ["t" "t"]))
|
||||||
|
(is (= (transform (s/regex-nav #"t") clojure.string/capitalize "test") "TesT"))
|
||||||
|
(is (= (transform [:a (s/regex-nav #"t")] clojure.string/capitalize {:a "test"}) {:a "TesT"}))
|
||||||
|
(is (= (transform (s/regex-nav #"\s+\w") clojure.string/triml "Hello World!") "HelloWorld!"))
|
||||||
|
(is (= (setval (s/regex-nav #"t") "z" "test") "zesz"))
|
||||||
|
(is (= (setval [:a (s/regex-nav #"t")] "z" {:a "test"}) {:a "zesz"}))
|
||||||
|
(is (= (transform (s/regex-nav #"aa*") (fn [s] (-> s count str)) "aadt") "2dt"))
|
||||||
|
(is (= (transform (s/regex-nav #"[Aa]+") (fn [s] (apply str (take (count s) (repeat "@")))) "Amsterdam Aardvarks") "@msterd@m @@rdv@rks"))
|
||||||
|
(is (= (select [(s/regex-nav #"(\S+):\ (\d+)") (s/nthpath 2)] "Mary: 1st George: 2nd Arthur: 3rd") ["1" "2" "3"]))
|
||||||
|
(is (= (transform (s/subselect (s/regex-nav #"\d\w+")) reverse "Mary: 1st George: 2nd Arthur: 3rd") "Mary: 3rd George: 2nd Arthur: 1st"))
|
||||||
|
)
|
||||||
|
|
||||||
(deftest single-value-none-navigators-test
|
(deftest single-value-none-navigators-test
|
||||||
(is (predand= vector? [1 2 3] (setval s/AFTER-ELEM 3 [1 2])))
|
(is (predand= vector? [1 2 3] (setval s/AFTER-ELEM 3 [1 2])))
|
||||||
(is (predand= list? '(1 2 3) (setval s/AFTER-ELEM 3 '(1 2))))
|
(is (predand= list? '(1 2 3) (setval s/AFTER-ELEM 3 '(1 2))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue