Example #1
0
        public static void UpdateEmojiReplacements(string inputString, EmojiConfig config, System.Action <string, int> onEmojiChar)
        {
            if (!string.IsNullOrEmpty(inputString))
            {
                inputString = EmojiParser.ParseEmoji(inputString);

                int i = 0;
                while (i < inputString.Length)
                {
                    string singleChar = inputString.Substring(i, 1);

                    if (singleChar.Equals("["))
                    {
                        int endIndex = inputString.IndexOf("]", i);
                        if (endIndex > i)
                        {
                            string emojiCode = inputString.Substring(i, endIndex - i + 1);
                            int    emojiIndex;
                            if (config.map.TryGetValue(emojiCode.Substring(1, emojiCode.Length - 2), out emojiIndex))
                            {
                                onEmojiChar(emojiCode, emojiIndex);
                                i += emojiCode.Length;
                            }
                            else
                            {
                                onEmojiChar(singleChar, -1);
                                i++;
                            }
                        }
                        else
                        {
                            onEmojiChar(singleChar, -1);
                            i++;
                        }
                    }
                    else
                    {
                        onEmojiChar(singleChar, -1);
                        i++;
                    }
                }
            }
        }