Emoji library for Crystal. Inspired by Emoji for Python
As a dependency in shard.yml
:
dependencies:
emoji:
github: veelenga/emoji.cr
branch: master
require "emoji"
puts Emoji.emojize("I ❤ �� and ��")
Will print the following in console:
Also it is possible to remove all emoji from the string:
str = Emoji.emojize("Girl on ��")
Emoji.sanitize(str) #=> "Girl on "
Sanitizing is based on Emoji regex. There are two options available:
:simple
emoji regex (default):generated
emoji regexSimple regex uses unicode ranges to find emojis and may give some incorrect results.Generated regex is quite big, but works correctly in 100% cases.However, it is much slower than a simple regex.
If you need more accuracy sanitizing emojis and don't care about performance, just use generated one:
Emoji.sanitize(str, regex: :generated)
require "emoji"
string = "String which contains all kinds of emoji:
- Singleton Emoji: (��)
- Textual singleton Emoji with Emoji variation: (▶️)
- Emoji with skin tone modifier: (����)
- Region flag: (����)
- Sub-Region flag: (��������������)
- Keycap sequence: (7️⃣)
- Sequence using ZWJ (zero width joiner): (��������)
"
string.scan(Emoji::GENERATED_EMOJI_REGEX) do |m|
puts "`#{m[0]}` - #{m[0].size} code points"
end
`��` - 1 code points
`▶️` - 2 code points
`����` - 2 code points
`����` - 2 code points
`��������������` - 7 code points
`7️⃣` - 3 code points
`��������` - 7 code points
You may also compile and use emojize
binary that just prints to console emojized string:
crystal build bin/emojize
./emojize It will boom: ��
坑爹的flutter正则; emoji过滤正则表达式:"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]" RegExp regexp=RegExp("[^\\u0020-\\u007E\\u0
mysql存储emoji表情报错的处理方法:更改编码为utf8mb4 uft-8编码可能2个字节、3个字节、4个字节,而MySql的uft-8只支持3字节的数据,而移动端的表情数据是4字节的字符。如果直接采用utf-8编码的数据库中插入表情数据,Java程序将报错: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94'