emojiprops.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // © 2021 and later: Unicode, Inc. and others.
  2. // License & terms of use: https://www.unicode.org/copyright.html
  3. // emojiprops.h
  4. // created: 2021sep03 Markus W. Scherer
  5. #ifndef __EMOJIPROPS_H__
  6. #define __EMOJIPROPS_H__
  7. #include "unicode/utypes.h"
  8. #include "unicode/ucptrie.h"
  9. #include "unicode/udata.h"
  10. #include "unicode/uobject.h"
  11. #include "uset_imp.h"
  12. U_NAMESPACE_BEGIN
  13. class EmojiProps : public UMemory {
  14. public:
  15. // @internal
  16. EmojiProps(UErrorCode &errorCode) { load(errorCode); }
  17. ~EmojiProps();
  18. static const EmojiProps *getSingleton(UErrorCode &errorCode);
  19. static UBool hasBinaryProperty(UChar32 c, UProperty which);
  20. static UBool hasBinaryProperty(const char16_t *s, int32_t length, UProperty which);
  21. void addPropertyStarts(const USetAdder *sa, UErrorCode &errorCode) const;
  22. void addStrings(const USetAdder *sa, UProperty which, UErrorCode &errorCode) const;
  23. enum {
  24. // Byte offsets from the start of the data, after the generic header,
  25. // in ascending order.
  26. // UCPTrie=CodePointTrie, follows the indexes
  27. IX_CPTRIE_OFFSET,
  28. IX_RESERVED1,
  29. IX_RESERVED2,
  30. IX_RESERVED3,
  31. // UCharsTrie=CharsTrie
  32. IX_BASIC_EMOJI_TRIE_OFFSET,
  33. IX_EMOJI_KEYCAP_SEQUENCE_TRIE_OFFSET,
  34. IX_RGI_EMOJI_MODIFIER_SEQUENCE_TRIE_OFFSET,
  35. IX_RGI_EMOJI_FLAG_SEQUENCE_TRIE_OFFSET,
  36. IX_RGI_EMOJI_TAG_SEQUENCE_TRIE_OFFSET,
  37. IX_RGI_EMOJI_ZWJ_SEQUENCE_TRIE_OFFSET,
  38. IX_RESERVED10,
  39. IX_RESERVED11,
  40. IX_RESERVED12,
  41. IX_TOTAL_SIZE,
  42. // Not initially byte offsets.
  43. IX_RESERVED14,
  44. IX_RESERVED15,
  45. IX_COUNT // 16
  46. };
  47. // Properties in the code point trie.
  48. enum {
  49. // https://www.unicode.org/reports/tr51/#Emoji_Properties
  50. BIT_EMOJI,
  51. BIT_EMOJI_PRESENTATION,
  52. BIT_EMOJI_MODIFIER,
  53. BIT_EMOJI_MODIFIER_BASE,
  54. BIT_EMOJI_COMPONENT,
  55. BIT_EXTENDED_PICTOGRAPHIC,
  56. // https://www.unicode.org/reports/tr51/#Emoji_Sets
  57. BIT_BASIC_EMOJI
  58. };
  59. private:
  60. static UBool U_CALLCONV
  61. isAcceptable(void *context, const char *type, const char *name, const UDataInfo *pInfo);
  62. /** Input i: One of the IX_..._TRIE_OFFSET indexes into the data file indexes[] array. */
  63. static int32_t getStringTrieIndex(int32_t i) {
  64. return i - IX_BASIC_EMOJI_TRIE_OFFSET;
  65. }
  66. void load(UErrorCode &errorCode);
  67. UBool hasBinaryPropertyImpl(UChar32 c, UProperty which) const;
  68. UBool hasBinaryPropertyImpl(const char16_t *s, int32_t length, UProperty which) const;
  69. UDataMemory *memory = nullptr;
  70. UCPTrie *cpTrie = nullptr;
  71. const char16_t *stringTries[6] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
  72. };
  73. U_NAMESPACE_END
  74. #endif // __EMOJIPROPS_H__