diff --git a/emoji.h b/emoji.h index 1cddd4b..e4162ff 100644 --- a/emoji.h +++ b/emoji.h @@ -1,9 +1,9 @@ -#include +#include #include namespace emojicpp { - static std::map EMOJIS = { + static std::unordered_map EMOJIS = { {":admission_tickets:" , u8"\U0001F39F"}, {":aerial_tramway:" , u8"\U0001F6A1"}, {":airplane:" , u8"\U00002708"}, @@ -1057,7 +1057,7 @@ namespace emojicpp { int index = -1; int sLen = s.size(); for (int i = 0; i < sLen; i++) { - if (s[i] == *L":") { + if (s[i] == ':') { // check if colon is escaped if(escape && i!=0 && s[i-1]=='\\') continue; @@ -1065,21 +1065,22 @@ namespace emojicpp { index = i; } else { - if (i - index==1) { + int textEmojiLen = i - index + 1; + if (textEmojiLen == 2) { index = i; continue; } - std::map::iterator it; - it = EMOJIS.find(s.substr(index, i - index + 1)); + std::unordered_map::iterator it; + it = EMOJIS.find(s.substr(index, textEmojiLen)); if (it == EMOJIS.end()) { index = i; continue; } std::string emo = it->second; // replace from index to i - //std::cout << s.substr(index, i - index + 1) << std::endl; // <---- uncomment to see what text is replaced, might be good for debugging - s.replace(index, i - index + 1 , emo); - int goBack = i - index + 1 - emo.size(); + //std::cout << s.substr(index, textEmojiLen) << std::endl; // <---- uncomment to see what text is replaced, might be good for debugging + s.replace(index, textEmojiLen, emo); + int goBack = textEmojiLen - emo.size(); sLen -= goBack; i -= goBack; index = -1;