Returns a sequence of integer Unicode code points in s. Handles
Unicode supplementary characters (above U+FFFF) correctly.
(defn codepoints
"Returns a sequence of integer Unicode code points in s. Handles
Unicode supplementary characters (above U+FFFF) correctly."
[^String s]
(let [len (.length s)
f (fn thisfn [^String s i]
(when (< i len)
(let [c (.charAt s i)]
(if (Character/isHighSurrogate c)
(cons (.codePointAt s i) (thisfn s (+ 2 i)))
(cons (int c) (thisfn s (inc i)))))))]
(lazy-seq (f s 0))))
Comments top
No comments for codepoints. Log in to add a comment.