Emoji.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <AK/StringView.h>
  9. #include <AK/Types.h>
  10. namespace Unicode {
  11. enum class EmojiGroup : u8 {
  12. Unknown,
  13. SmileysAndEmotion,
  14. PeopleAndBody,
  15. Component,
  16. AnimalsAndNature,
  17. FoodAndDrink,
  18. TravelAndPlaces,
  19. Activities,
  20. Objects,
  21. Symbols,
  22. Flags,
  23. // Non-standard emoji added for SerenityOS:
  24. SerenityOS,
  25. };
  26. struct Emoji {
  27. StringView name;
  28. EmojiGroup group { EmojiGroup::Unknown };
  29. u32 display_order { 0 };
  30. Span<u32 const> code_points;
  31. };
  32. Optional<Emoji> find_emoji_for_code_points(Span<u32 const> code_points);
  33. template<size_t Size>
  34. Optional<Emoji> find_emoji_for_code_points(u32 const (&code_points)[Size])
  35. {
  36. return find_emoji_for_code_points(Span<u32 const> { code_points });
  37. }
  38. constexpr StringView emoji_group_to_string(EmojiGroup group)
  39. {
  40. switch (group) {
  41. case EmojiGroup::Unknown:
  42. return "Unknown"sv;
  43. case EmojiGroup::SmileysAndEmotion:
  44. return "Smileys & Emotion"sv;
  45. case EmojiGroup::PeopleAndBody:
  46. return "People & Body"sv;
  47. case EmojiGroup::Component:
  48. return "Component"sv;
  49. case EmojiGroup::AnimalsAndNature:
  50. return "Animals & Nature"sv;
  51. case EmojiGroup::FoodAndDrink:
  52. return "Food & Drink"sv;
  53. case EmojiGroup::TravelAndPlaces:
  54. return "Travel & Places"sv;
  55. case EmojiGroup::Activities:
  56. return "Activities"sv;
  57. case EmojiGroup::Objects:
  58. return "Objects"sv;
  59. case EmojiGroup::Symbols:
  60. return "Symbols"sv;
  61. case EmojiGroup::Flags:
  62. return "Flags"sv;
  63. case EmojiGroup::SerenityOS:
  64. return "SerenityOS"sv;
  65. }
  66. VERIFY_NOT_REACHED();
  67. }
  68. constexpr EmojiGroup emoji_group_from_string(StringView group)
  69. {
  70. if (group == "Unknown"sv)
  71. return EmojiGroup::Unknown;
  72. if (group == "Smileys & Emotion"sv)
  73. return EmojiGroup::SmileysAndEmotion;
  74. if (group == "People & Body"sv)
  75. return EmojiGroup::PeopleAndBody;
  76. if (group == "Component"sv)
  77. return EmojiGroup::Component;
  78. if (group == "Animals & Nature"sv)
  79. return EmojiGroup::AnimalsAndNature;
  80. if (group == "Food & Drink"sv)
  81. return EmojiGroup::FoodAndDrink;
  82. if (group == "Travel & Places"sv)
  83. return EmojiGroup::TravelAndPlaces;
  84. if (group == "Activities"sv)
  85. return EmojiGroup::Activities;
  86. if (group == "Objects"sv)
  87. return EmojiGroup::Objects;
  88. if (group == "Symbols"sv)
  89. return EmojiGroup::Symbols;
  90. if (group == "Flags"sv)
  91. return EmojiGroup::Flags;
  92. if (group == "SerenityOS"sv)
  93. return EmojiGroup::SerenityOS;
  94. VERIFY_NOT_REACHED();
  95. }
  96. }