Generally, I hate emoji and try to avoid them everywhere I could. Those colored faces look dull to me comparing to a good old text smile. But still, emoji might be helpful replacing icons with them. When you need a globe, a mail envelope or a flight sign, putting a proper emoji could be a fast and good enough solution.
After long Python experience, I though Java supports long unicode literals started with capital U and two bytes as follows (Python version):
>>> print len(u"\U0001F535") # prints 2
Surprisingly, it doesn’t. But I needed to put a blue circle sign that’s
U+1F535 number. So how should I turn that number into a string?
After googling for a while, I’ve done with a short Clojure function:
(defn unicode-to-string "Turns a hex unicode symbol into a string. Deals with such long numbers as 0x1F535 for example." [code] (-> code Character/toChars String.))
Adding it into business logic:
(let [caption "Some important feature" is-on? (get-feature-state) sign (if is-on? (unicode-to-string 0x1F535) ;; blue circle (unicode-to-string 0x26AA))] ;; white circle (str sign \space caption))
Depending on whether the feature was enabled or not, the result message will have either a blue (active) or white (inactive) circle in front of it.
Нашли ошибку? Выделите мышкой и нажмите Ctrl/⌘+Enter