docodepoints

clojure.contrib.string

  • (docodepoints bindings & body)
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.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/string.clj:54 top

(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#))))))))))
Vars in clojure.contrib.string/docodepoints: = assert count defmacro let vector + < apply concat hash-map inc int list loop seq when with-meta
Used in 0 other vars

Comments top

No comments for docodepoints. Log in to add a comment.