Skip to content

A group of packages that helps you provide lightning-fast detection of emoji's in text and conversion to image urls.

License

Notifications You must be signed in to change notification settings

ErisApps/CatCore.Emoji

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CatCore.Emoji

CatCore.Emoji is a project that consists of a group of packages that provide source generators to generate emoji lookup tables at compile-time. At the time of writing, has support for both Google Noto (GNoto) and Twemoji emojis.

Usage

  1. Install either CatCore.Emoji.SourceGeneration.GNoto or CatCore.Emoji.SourceGeneration.Twemoji from the GitHub package registry. (Make sure not to install both, they will conflict with each other)

  2. Get the emoji reference file (emoji-test.txt) for the Unicode version you want to get the lookup table for. It can be found here, also make sure to double-check whether either GNoto or Twemoji project already supports the Unicode standard you want to use.

  3. Drop the emoji reference file from the previous step in a folder of your project and add the following snippet in your .csproj file as well. Make sure that the path to the file is correct. Also, make sure to define a name for the generated class as well, it will be generated in the CatCore.Emoji namespace.

<ItemGroup>
	<PackageReference Include="CatCore.Emoji.SourceGeneration.Twemoji" Version="1.0.1" OutputItemType="Analyzer" />
</ItemGroup>

<ItemGroup>
	<AdditionalFiles Include=".\Resources\Unicode14_0_EmojiTest.txt" ClassName="{{Choose the name of the generated class}}" />
</ItemGroup>
  1. If everything went well, you should be able to use the generated lookup table from code. The example below should give you an idea on how to use it.
var emojiReferenceData = CatCore.Emoji.Twemoji.EmojiTesting14_0.EmojiReferenceData;
var testEntries = new[] { "😸", "I 🧡 Twemoji! 🥳", "I've eaten Chinese food 😱😍🍱🍣🍥🍙🍘🍚🍜🍱🍣🍥🍙🍘🍚🍜", "🧝‍♀️", "🏳️‍⚧️" };

foreach (var entry in testEntries)
{
    for (var i = 0; i < entry.Length; i++)
    {
        var emojiTreeLeaf = emojiReferenceData.LookupLeaf(entry, i);
        if (emojiTreeLeaf != null)
        {
            Console.WriteLine($"Found emote between indexes [{i}-{i + emojiTreeLeaf.Depth}[ (Length: {emojiTreeLeaf.Depth})\n" +
                              $"  Twemoji url: {emojiTreeLeaf.Url}");
            i += emojiTreeLeaf.Depth;
        }
    }
}

About

A group of packages that helps you provide lightning-fast detection of emoji's in text and conversion to image urls.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages