Coverage Report

Created: 2026-10-28 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibUnicode/Emoji.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2022-2023, Tim Flynn <trflynn89@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Forward.h>
10
#include <AK/Optional.h>
11
#include <AK/StringView.h>
12
#include <AK/Types.h>
13
14
namespace Unicode {
15
16
enum class EmojiGroup : u8 {
17
    Unknown,
18
19
    SmileysAndEmotion,
20
    PeopleAndBody,
21
    Component,
22
    AnimalsAndNature,
23
    FoodAndDrink,
24
    TravelAndPlaces,
25
    Activities,
26
    Objects,
27
    Symbols,
28
    Flags,
29
30
    // Non-standard emoji added for SerenityOS:
31
    SerenityOS,
32
};
33
34
struct Emoji {
35
    StringView name;
36
    Optional<StringView> image_path;
37
    EmojiGroup group { EmojiGroup::Unknown };
38
    u32 display_order { 0 };
39
    ReadonlySpan<u32> code_points;
40
};
41
42
Optional<Emoji> find_emoji_for_code_points(ReadonlySpan<u32> code_points);
43
44
template<size_t Size>
45
Optional<Emoji> find_emoji_for_code_points(u32 const (&code_points)[Size])
46
{
47
    return find_emoji_for_code_points(ReadonlySpan<u32> { code_points });
48
}
49
50
enum class SequenceType {
51
    Any,
52
    EmojiPresentation,
53
};
54
55
bool could_be_start_of_emoji_sequence(Utf8CodePointIterator const&, SequenceType = SequenceType::Any);
56
bool could_be_start_of_emoji_sequence(Utf32CodePointIterator const&, SequenceType = SequenceType::Any);
57
58
constexpr StringView emoji_group_to_string(EmojiGroup group)
59
0
{
60
0
    switch (group) {
61
0
    case EmojiGroup::Unknown:
62
0
        return "Unknown"sv;
63
0
    case EmojiGroup::SmileysAndEmotion:
64
0
        return "Smileys & Emotion"sv;
65
0
    case EmojiGroup::PeopleAndBody:
66
0
        return "People & Body"sv;
67
0
    case EmojiGroup::Component:
68
0
        return "Component"sv;
69
0
    case EmojiGroup::AnimalsAndNature:
70
0
        return "Animals & Nature"sv;
71
0
    case EmojiGroup::FoodAndDrink:
72
0
        return "Food & Drink"sv;
73
0
    case EmojiGroup::TravelAndPlaces:
74
0
        return "Travel & Places"sv;
75
0
    case EmojiGroup::Activities:
76
0
        return "Activities"sv;
77
0
    case EmojiGroup::Objects:
78
0
        return "Objects"sv;
79
0
    case EmojiGroup::Symbols:
80
0
        return "Symbols"sv;
81
0
    case EmojiGroup::Flags:
82
0
        return "Flags"sv;
83
0
    case EmojiGroup::SerenityOS:
84
0
        return "SerenityOS"sv;
85
0
    }
86
0
87
0
    VERIFY_NOT_REACHED();
88
0
}
89
90
constexpr EmojiGroup emoji_group_from_string(StringView group)
91
0
{
92
0
    if (group == "Unknown"sv)
93
0
        return EmojiGroup::Unknown;
94
0
    if (group == "Smileys & Emotion"sv)
95
0
        return EmojiGroup::SmileysAndEmotion;
96
0
    if (group == "People & Body"sv)
97
0
        return EmojiGroup::PeopleAndBody;
98
0
    if (group == "Component"sv)
99
0
        return EmojiGroup::Component;
100
0
    if (group == "Animals & Nature"sv)
101
0
        return EmojiGroup::AnimalsAndNature;
102
0
    if (group == "Food & Drink"sv)
103
0
        return EmojiGroup::FoodAndDrink;
104
0
    if (group == "Travel & Places"sv)
105
0
        return EmojiGroup::TravelAndPlaces;
106
0
    if (group == "Activities"sv)
107
0
        return EmojiGroup::Activities;
108
0
    if (group == "Objects"sv)
109
0
        return EmojiGroup::Objects;
110
0
    if (group == "Symbols"sv)
111
0
        return EmojiGroup::Symbols;
112
0
    if (group == "Flags"sv)
113
0
        return EmojiGroup::Flags;
114
0
    if (group == "SerenityOS"sv)
115
0
        return EmojiGroup::SerenityOS;
116
0
117
0
    VERIFY_NOT_REACHED();
118
0
}
119
120
}