Skip to content

Instantly share code, notes, and snippets.

@galdolber
Created June 8, 2018 20:28
Show Gist options
  • Save galdolber/1568e767fe69f9439874cc20c755b80e to your computer and use it in GitHub Desktop.
Save galdolber/1568e767fe69f9439874cc20c755b80e to your computer and use it in GitHub Desktop.
Unicode
(ns api.unicode
(:refer-clojure :exclude [count seq subs]))
(def reg (if (exists? js/window)
(js* "/(\\P{Mark}\\p{Mark}*)/u")
(.build (js/require "xregexp") "(\\P{Mark}\\p{Mark}*)" "A")))
(defn seq [txt] (when txt (map first (re-seq reg txt))))
(defn count [txt] (cljs.core/count (seq txt)))
(defn subs
([txt from] (subs txt from (count txt)))
([txt from to]
(apply str (take (- to from) (drop from (seq txt))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment