Compiles format-str into a compiled format which can be used as an argument
to cl-format just like a plain format string. Use this function for improved
performance when you're using the same format string repeatedly
(defn compile-format
"Compiles format-str into a compiled format which can be used as an argument
to cl-format just like a plain format string. Use this function for improved
performance when you're using the same format string repeatedly"
[ format-str ]
; (prlabel compiling format-str)
(binding [*format-str* format-str]
(process-nesting
(first
(consume
(fn [[^String s offset]]
(if (empty? s)
[nil s]
(let [tilde (.indexOf s (int \~))]
(cond
(neg? tilde) [(compile-raw-string s offset) ["" (+ offset (.length s))]]
(zero? tilde) (compile-directive (subs s 1) (inc offset))
true
[(compile-raw-string (subs s 0 tilde) offset) [(subs s tilde) (+ tilde offset)]]))))
[format-str 0])))))
Comments top
No comments for compile-format. Log in to add a comment.