| 10 | constexpr uint32_t kUnicodePointMask = ~static_cast<uint32_t>(0) >> 11; |
| 11 | |
| 12 | static UnicodeSequenceTrie* makeEmojiUnicodeTrie() { |
| 13 | auto* trie = new UnicodeSequenceTrie(); |
| 14 | SmallVector<uint32_t, 8> tmp; |
| 15 | |
| 16 | const uint32_t* begin = kVALDI_EMOJI_COMPRESSED_TABLE.data(); |
| 17 | const uint32_t* end = begin + kVALDI_EMOJI_COMPRESSED_TABLE.size(); |
| 18 | |
| 19 | const auto* it = begin; |
| 20 | while (it != end) { |
| 21 | auto current = *it; |
| 22 | it++; |
| 23 | |
| 24 | auto opcode = (current >> 29); |
| 25 | auto sequenceLength = (current >> 21) & 0xFF; |
| 26 | auto unicodePoint = current & kUnicodePointMask; |
| 27 | |
| 28 | if (opcode == kSINGLE_CODEPOINT_OPCODE) { |
| 29 | for (uint32_t i = unicodePoint; i < unicodePoint + sequenceLength; i++) { |
| 30 | trie->insert(i); |
| 31 | } |
| 32 | } else if (opcode == kEMOJI_SEQUENCE_OPCODE) { |
| 33 | for (size_t i = 0; i < sequenceLength; i++) { |
| 34 | auto entry = *it; |
| 35 | auto entriesNum = (entry >> 21) & 0xFF; |
| 36 | auto entryUnicodePoint = entry & kUnicodePointMask; |
| 37 | it++; |
| 38 | |
| 39 | for (uint32_t i = entryUnicodePoint; i < entryUnicodePoint + entriesNum; i++) { |
| 40 | uint32_t sequence[2] = {i, unicodePoint}; |
| 41 | trie->insert(sequence, 2); |
| 42 | } |
| 43 | } |
| 44 | } else if (opcode == kCOMPLEX_EMOJI_SEQUENCE_OPCODE) { |
| 45 | tmp.clear(); |
| 46 | tmp.emplace_back(unicodePoint); |
| 47 | for (size_t i = 1; i < sequenceLength; i++) { |
| 48 | auto nextUnicodePoint = *it; |
| 49 | it++; |
| 50 | tmp.emplace_back(nextUnicodePoint); |
| 51 | } |
| 52 | |
| 53 | trie->insert(tmp.data(), tmp.size()); |
| 54 | } else { |
| 55 | std::abort(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | trie->rebuildIndex(); |
| 60 | |
| 61 | return trie; |
| 62 | } |
| 63 | |
| 64 | const UnicodeSequenceTrie* getEmojiUnicodeTrie() { |
| 65 | static auto* kTrie = makeEmojiUnicodeTrie(); |
no test coverage detected