我想在ClojureScript中实现separate-humps
,但是没有re-matcher
或re-groups
。是否有其他替代方法?
(defn re-sub
[^String value pattern sub-func]
(loop [matcher (re-matcher pattern value)
result []
last-end 0]
(if (.find matcher)
(recur matcher
(conj result
(.substring value last-end (.start matcher))
(sub-func (re-groups matcher)))
(.end matcher))
(apply str (conj result (.substring value last-end))))))
(defonce +hump-pattern+ #"[a-z0-9][A-Z]")
(defn separate-humps
[^String value]
(re-sub value +hump-pattern+ #(string/join " " (seq %))))
(separate-humps "aTaTa")
;;=> "a Ta Ta"