1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Emoji.Combinations do
6 # FE0F is the emoji variation sequence. It is used for fully-qualifying
7 # emoji, and that includes emoji combinations.
8 # This code generates combinations per emoji: for each FE0F, all possible
9 # combinations of the character being removed or staying will be generated.
10 # This is made as an attempt to find all partially-qualified and unqualified
11 # versions of a fully-qualified emoji.
12 # I have found *no cases* for which this would be a problem, after browsing
13 # the entire emoji list in emoji-test.txt. This is safe, and, sadly, most
16 defp qualification_combinations(codepoints) do
17 qualification_combinations([[]], codepoints)
20 defp qualification_combinations(acc, []), do: acc
22 defp qualification_combinations(acc, ["\uFE0F" | tail]) do
24 |> Enum.flat_map(fn x -> [x, x ++ ["\uFE0F"]] end)
25 |> qualification_combinations(tail)
28 defp qualification_combinations(acc, [codepoint | tail]) do
30 |> Enum.map(&Kernel.++(&1, [codepoint]))
31 |> qualification_combinations(tail)
34 def variate_emoji_qualification(emoji) when is_binary(emoji) do
36 |> String.codepoints()
37 |> qualification_combinations()
38 |> Enum.map(&List.to_string/1)
41 def variate_emoji_qualification(emoji) when is_list(emoji) do
43 |> Enum.map(fn emoji -> {emoji, variate_emoji_qualification(emoji)} end)