public override bool Match(InlineProcessor processor, ref StringSlice slice)
        {
            string match;

            // Previous char must be a space
            if (!slice.PeekCharExtra(-1).IsWhiteSpaceOrZero())
            {
                return(false);
            }

            // Try to match an existing emoji
            var startPosition = slice.Start;

            if (!textMatchHelper.TryMatch(slice.Text, slice.Start, slice.Length, out match))
            {
                return(false);
            }

            string emoji = match;

            if (EnableSmiley)
            {
                // If we have a smiley, we decode it to emoji
                if (!SmileyToEmoji.TryGetValue(match, out emoji))
                {
                    emoji = match;
                }
            }

            // Decode the eomji to unicode
            string unicode;

            if (!EmojiToUnicode.TryGetValue(emoji, out unicode))
            {
                // Should not happen but in case
                return(false);
            }

            // Move the cursor to the character after the matched string
            slice.Start += match.Length;

            // Push the EmojiInline
            int line;
            int column;

            processor.Inline = new EmojiInline(unicode)
            {
                Span =
                {
                    Start = processor.GetSourcePosition(startPosition, out line, out column),
                },
                Line   = line,
                Column = column,
                Match  = match
            };
            processor.Inline.Span.End = processor.Inline.Span.Start + match.Length - 1;

            return(true);
        }
예제 #2
0
        public override bool Match(InlineProcessor processor, ref StringSlice slice)
        {
            string match;
            var    startPosition = slice.Start;

            if (!textMatchHelper.TryMatch(slice.Text, slice.Start, slice.Length, out match))
            {
                return(false);
            }

            string emoji;

            if (!SmileyToEmoji.TryGetValue(match, out emoji))
            {
                emoji = match;
            }

            string unicode;

            if (!EmojiToUnicode.TryGetValue(emoji, out unicode))
            {
                // Should not happen but in case
                return(false);
            }

            // Move the cursor to the character after the matched string
            slice.Start += match.Length;

            // Push the EmojiInline
            int line;
            int column;

            processor.Inline = new EmojiInline(unicode)
            {
                Span =
                {
                    Start = processor.GetSourcePosition(startPosition, out line, out column),
                },
                Line   = line,
                Column = column,
                Match  = match
            };
            processor.Inline.Span.End = processor.Inline.Span.Start + match.Length - 1;

            return(true);
        }