From 98214577c36d9c8dd0e13c7b678a399b35450bd3 Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Thu, 5 Oct 2023 11:28:54 +0200 Subject: SL-20390 Emoji Completion floater - ignore symbols in shortcodes when searching by pattern --- indra/llui/llemojidictionary.cpp | 64 ++++++++++++++++++++++++++++++++++++++++ indra/llui/llemojidictionary.h | 20 +++++++++++++ 2 files changed, 84 insertions(+) (limited to 'indra/llui') diff --git a/indra/llui/llemojidictionary.cpp b/indra/llui/llemojidictionary.cpp index 1ee97ea2d2..bf7e53701d 100644 --- a/indra/llui/llemojidictionary.cpp +++ b/indra/llui/llemojidictionary.cpp @@ -143,6 +143,70 @@ LLWString LLEmojiDictionary::findMatchingEmojis(const std::string& needle) const return result; } +void LLEmojiDictionary::findByShortCode(std::vector& result, const std::string& needle) const +{ + result.clear(); + + if (needle.empty() || needle.front() != ':') + return; + + auto search = [needle](std::size_t& begin, std::size_t& end, const std::string& shortCode) -> bool + { + begin = 0; + end = 1; + std::size_t index = 1; + // Search for begin + char d = tolower(needle[index++]); + while (end < shortCode.size()) + { + char s = tolower(shortCode[end++]); + if (s == d) + { + begin = end - 1; + break; + } + } + if (!begin) + return false; + // Search for end + d = tolower(needle[index++]); + while (end < shortCode.size() && index <= needle.size()) + { + char s = tolower(shortCode[end++]); + if (s == d) + { + if (index == needle.size()) + return true; + d = tolower(needle[index++]); + continue; + } + switch (s) + { + case L'-': + case L'_': + case L'+': + continue; + } + break; + } + return false; + }; + + for (const LLEmojiDescriptor& d : mEmojis) + { + if (d.ShortCodes.empty()) + continue; + const std::string& shortCode = d.ShortCodes.front(); + if (shortCode.size() < needle.size() || shortCode.front() != needle.front()) + continue; + std::size_t begin, end; + if (search(begin, end, shortCode)) + { + result.emplace_back(d.Character, shortCode, begin, end); + } + } +} + const LLEmojiDescriptor* LLEmojiDictionary::getDescriptorFromEmoji(llwchar emoji) const { const auto it = mEmoji2Descr.find(emoji); diff --git a/indra/llui/llemojidictionary.h b/indra/llui/llemojidictionary.h index f6442684a7..66b564b70a 100644 --- a/indra/llui/llemojidictionary.h +++ b/indra/llui/llemojidictionary.h @@ -52,6 +52,25 @@ struct LLEmojiGroup std::list Categories; }; +// ============================================================================ +// LLEmojiSearchResult class +// + +struct LLEmojiSearchResult +{ + llwchar Character; + std::string String; + std::size_t Begin, End; + + LLEmojiSearchResult(llwchar character, const std::string& string, std::size_t begin, std::size_t end) + : Character(character) + , String(string) + , Begin(begin) + , End(end) + { + } +}; + // ============================================================================ // LLEmojiDictionary class // @@ -70,6 +89,7 @@ public: static void initClass(); LLWString findMatchingEmojis(const std::string& needle) const; + void findByShortCode(std::vector& result, const std::string& needle) const; const LLEmojiDescriptor* getDescriptorFromEmoji(llwchar emoji) const; const LLEmojiDescriptor* getDescriptorFromShortCode(const std::string& short_code) const; std::string getNameFromEmoji(llwchar ch) const; -- cgit v1.2.3