bindings => [name string]
Repeatedly executes body, with name bound to the integer code point
of each Unicode character in the string. Handles Unicode
supplementary characters (above U+FFFF) correctly.
(defmacro docodepoints
"bindings => [name string]
Repeatedly executes body, with name bound to the integer code point
of each Unicode character in the string. Handles Unicode
supplementary characters (above U+FFFF) correctly."
[bindings & body]
(assert (vector bindings))
(assert (= 2 (count bindings)))
(let [character (first bindings)
string (second bindings)]
`(let [^String s# ~string
len# (.length s#)]
(loop [i# 0]
(when (< i# len#)
(let [~character (.charAt s# i#)]
(if (Character/isHighSurrogate ~character)
(let [~character (.codePointAt s# i#)]
~@body
(recur (+ 2 i#)))
(let [~character (int ~character)]
~@body
(recur (inc i#))))))))))
Comments top
No comments for docodepoints. Log in to add a comment.