Created
February 7, 2017 09:33
-
-
Save peterwang/c8b044e706c48cbd18f1275fbfc30692 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; π https://codepoints.net/U+1f600 | |
;; π https://codepoints.net/U+1F60A | |
;; πͺ₯ https://codepoints.net/U+2A6A5 | |
(defn codepoint-seq [s] | |
(loop [i 0 e (.length s) acc []] | |
(if (>= i e) | |
acc | |
(let [cp (.codePointAt s i) | |
cc (Character/charCount cp)] | |
(recur (+ i cc) e (conj acc cp)))))) | |
(def utf8mb4-str "hello δ½ ε₯½ γγγ«γ‘γ― μλ νμΈμ πππͺ₯") | |
(->> utf8mb4-str | |
codepoint-seq | |
(map #(String. (Character/toChars %)))) | |
;; => ("h" "e" "l" "l" "o" " " "δ½ " "ε₯½" " " "γ" "γ" "γ«" "γ‘" "γ―" " " "μ" "λ " "ν" "μΈ" "μ" " " "π" "π" "πͺ₯") | |
(->> utf8mb4-str | |
seq | |
(map #(String. (Character/toChars (int %))))) | |
;; => ("h" "e" "l" "l" "o" " " "δ½ " "ε₯½" " " "γ" "γ" "γ«" "γ‘" "γ―" " " "μ" "λ " "ν" "μΈ" "μ" " " "?" "?" "?" "?" "?" "?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment