Emoji: Add function to detect if a character is an emoji

This commit is contained in:
lain 2019-09-13 02:11:02 +02:00
commit a697f0d791
3 changed files with 802 additions and 0 deletions

View file

@ -260,4 +260,29 @@ defmodule Pleroma.Emoji do
Enum.any?(patterns, matcher) && group
end)
end
{:ok, file} = File.read("lib/pleroma/emoji-data.txt")
@unicode_emoji file
|> String.split("\n")
|> Enum.filter(fn line -> String.starts_with?(line, ["1", "2", "3", "4"]) end)
|> Enum.map(fn line -> String.split(line) |> List.first() end)
|> Enum.map(fn line ->
case String.split(line, "..") do
[number] ->
String.to_integer(number, 16)
[first, last] ->
Range.new(String.to_integer(first, 16), String.to_integer(last, 16))
|> Enum.to_list()
end
end)
|> List.flatten()
|> Enum.filter(&is_integer/1)
|> Enum.uniq()
|> Enum.map(fn n -> :unicode.characters_to_binary([n], :utf32) end)
def is_unicode_emoji?(str) do
str in @unicode_emoji
end
end