diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-09-07 13:39:31 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-09-08 23:12:31 +0100 |
commit | b61eca0a1e401202e8315629c3d87158381c9518 (patch) | |
tree | dda2f0ef4e7938707652e2d24b72510ecdfbb467 /Userland | |
parent | fff79379d4270ece49cce85e67d09f0e5ab7315d (diff) | |
download | serenity-b61eca0a1e401202e8315629c3d87158381c9518.zip |
LibUncode: Parse and generate emoji code point data
According to TR #51, the "best definition of the full set [of emojis] is
in the emoji-test.txt file". This defines not only the emoji themselves,
but the order in which they should be displayed, and what "group" of
emojis they belong to.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibUnicode/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibUnicode/Emoji.cpp | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibUnicode/Emoji.h | 97 | ||||
-rw-r--r-- | Userland/Libraries/LibUnicode/Forward.h | 2 |
4 files changed, 113 insertions, 0 deletions
diff --git a/Userland/Libraries/LibUnicode/CMakeLists.txt b/Userland/Libraries/LibUnicode/CMakeLists.txt index 1bacfa8375..c6210ab217 100644 --- a/Userland/Libraries/LibUnicode/CMakeLists.txt +++ b/Userland/Libraries/LibUnicode/CMakeLists.txt @@ -3,6 +3,7 @@ include(${SerenityOS_SOURCE_DIR}/Meta/CMake/unicode_data.cmake) set(SOURCES CharacterTypes.cpp CurrencyCode.cpp + Emoji.cpp ${UNICODE_DATA_SOURCES} ) diff --git a/Userland/Libraries/LibUnicode/Emoji.cpp b/Userland/Libraries/LibUnicode/Emoji.cpp new file mode 100644 index 0000000000..ce0974b9a8 --- /dev/null +++ b/Userland/Libraries/LibUnicode/Emoji.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibUnicode/Emoji.h> + +namespace Unicode { + +Optional<Emoji> __attribute__((weak)) find_emoji_for_code_points(Span<u32 const>) { return {}; } + +} diff --git a/Userland/Libraries/LibUnicode/Emoji.h b/Userland/Libraries/LibUnicode/Emoji.h new file mode 100644 index 0000000000..ca5d81b839 --- /dev/null +++ b/Userland/Libraries/LibUnicode/Emoji.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Optional.h> +#include <AK/StringView.h> +#include <AK/Types.h> + +namespace Unicode { + +enum class EmojiGroup : u8 { + SmileysAndEmotion, + PeopleAndBody, + Component, + AnimalsAndNature, + FoodAndDrink, + TravelAndPlaces, + Activities, + Objects, + Symbols, + Flags, +}; + +struct Emoji { + StringView name; + EmojiGroup group; + u32 display_order { 0 }; + Span<u32 const> code_points; +}; + +Optional<Emoji> find_emoji_for_code_points(Span<u32 const> code_points); + +template<size_t Size> +Optional<Emoji> find_emoji_for_code_points(u32 const (&code_points)[Size]) +{ + return find_emoji_for_code_points(Span<u32 const> { code_points }); +} + +constexpr StringView emoji_group_to_string(EmojiGroup group) +{ + switch (group) { + case EmojiGroup::SmileysAndEmotion: + return "Smileys & Emotion"sv; + case EmojiGroup::PeopleAndBody: + return "People & Body"sv; + case EmojiGroup::Component: + return "Component"sv; + case EmojiGroup::AnimalsAndNature: + return "Animals & Nature"sv; + case EmojiGroup::FoodAndDrink: + return "Food & Drink"sv; + case EmojiGroup::TravelAndPlaces: + return "Travel & Places"sv; + case EmojiGroup::Activities: + return "Activities"sv; + case EmojiGroup::Objects: + return "Objects"sv; + case EmojiGroup::Symbols: + return "Symbols"sv; + case EmojiGroup::Flags: + return "Flags"sv; + } + + VERIFY_NOT_REACHED(); +} + +constexpr EmojiGroup emoji_group_from_string(StringView group) +{ + if (group == "Smileys & Emotion"sv) + return EmojiGroup::SmileysAndEmotion; + if (group == "People & Body"sv) + return EmojiGroup::PeopleAndBody; + if (group == "Component"sv) + return EmojiGroup::Component; + if (group == "Animals & Nature"sv) + return EmojiGroup::AnimalsAndNature; + if (group == "Food & Drink"sv) + return EmojiGroup::FoodAndDrink; + if (group == "Travel & Places"sv) + return EmojiGroup::TravelAndPlaces; + if (group == "Activities"sv) + return EmojiGroup::Activities; + if (group == "Objects"sv) + return EmojiGroup::Objects; + if (group == "Symbols"sv) + return EmojiGroup::Symbols; + if (group == "Flags"sv) + return EmojiGroup::Flags; + + VERIFY_NOT_REACHED(); +} + +} diff --git a/Userland/Libraries/LibUnicode/Forward.h b/Userland/Libraries/LibUnicode/Forward.h index c3b08d3088..22cf7c698e 100644 --- a/Userland/Libraries/LibUnicode/Forward.h +++ b/Userland/Libraries/LibUnicode/Forward.h @@ -11,6 +11,7 @@ namespace Unicode { enum class Block : u16; +enum class EmojiGroup : u8; enum class GeneralCategory : u8; enum class GraphemeBreakProperty : u8; enum class Property : u8; @@ -19,6 +20,7 @@ enum class SentenceBreakProperty : u8; enum class WordBreakProperty : u8; struct CurrencyCode; +struct Emoji; struct SpecialCasing; } |