Exemplo n.º 1
0
        public async Task <IActionResult> AddText(TextFile textfile)
        {
            var encodedString = Convert.ToBase64String(textfile.AvatarOne);

            byte[] data          = Convert.FromBase64String(encodedString);
            string decodedString = Encoding.UTF8.GetString(data);

            var helper         = new TextMatchHelper();
            var helperResponse = helper.PostText(decodedString);

            return(Ok(helperResponse));
        }
Exemplo n.º 2
0
        public TestMatchPerf()
        {
            var replacers = new Dictionary <string, string>();

            for (int i = 0; i < 1000; i++)
            {
                replacers.Add($":z{i}:", i.ToString());
            }
            replacers.Add(":abc:", "yes");

            matcher = new TextMatchHelper(new HashSet <string>(replacers.Keys));
        }
Exemplo n.º 3
0
        public override void Initialize()
        {
            var firstChars  = new HashSet <char>();
            var textToMatch = new HashSet <string>();

            foreach (var emoji in EmojiToUnicode)
            {
                firstChars.Add(emoji.Key[0]);
                textToMatch.Add(emoji.Key);
            }

            foreach (var smiley in SmileyToEmoji)
            {
                firstChars.Add(smiley.Key[0]);
                textToMatch.Add(smiley.Key);
            }

            textMatchHelper = new TextMatchHelper(textToMatch);

            OpeningCharacters = new List <char>(firstChars).ToArray();
            Array.Sort(OpeningCharacters);
        }
Exemplo n.º 4
0
        private void DocumentOnProcessInlinesBegin(InlineProcessor inlineProcessor, Inline inline)
        {
            inlineProcessor.Document.ProcessInlinesBegin -= DocumentOnProcessInlinesBegin;

            var abbreviations = inlineProcessor.Document.GetAbbreviations();

            // Should not happen, but another extension could decide to remove them, so...
            if (abbreviations == null)
            {
                return;
            }

            // Build a text matcher from the abbreviations labels
            var labels  = new HashSet <string>(abbreviations.Keys);
            var matcher = new TextMatchHelper(labels);

            inlineProcessor.LiteralInlineParser.PostMatch += (InlineProcessor processor, ref StringSlice slice) =>
            {
                var literal         = (LiteralInline)processor.Inline;
                var originalLiteral = literal;

                ContainerInline container = null;

                // This is slow, but we don't have much the choice
                var content = literal.Content;
                var text    = content.Text;
                for (int i = content.Start; i < content.End; i++)
                {
                    string match;
                    if (matcher.TryMatch(text, i, content.End - i + 1, out match) && IsValidAbbreviation(match, content, i))
                    {
                        var indexAfterMatch = i + match.Length;

                        // We should have a match, but in case...
                        Abbreviation abbr;
                        if (!abbreviations.TryGetValue(match, out abbr))
                        {
                            continue;
                        }

                        // If we don't have a container, create a new one
                        if (container == null)
                        {
                            container = literal.Parent ??
                                        new ContainerInline
                            {
                                Span   = originalLiteral.Span,
                                Line   = originalLiteral.Line,
                                Column = originalLiteral.Column,
                            };
                        }

                        int line;
                        int column;
                        var abbrInline = new AbbreviationInline(abbr)
                        {
                            Span =
                            {
                                Start = processor.GetSourcePosition(i, out line, out column),
                            },
                            Line   = line,
                            Column = column
                        };
                        abbrInline.Span.End = abbrInline.Span.Start + match.Length - 1;

                        // Append the previous literal
                        if (i > content.Start)
                        {
                            if (literal.Parent == null)
                            {
                                container.AppendChild(literal);
                            }
                        }
                        literal.Span.End = abbrInline.Span.Start - 1;
                        // Truncate it before the abbreviation
                        literal.Content.End = i - 1;


                        // Appned the abbreviation
                        container.AppendChild(abbrInline);

                        // If this is the end of the string, clear the literal
                        // and exit
                        if (content.End == indexAfterMatch - 1)
                        {
                            literal = null;
                            break;
                        }

                        // Process the remaining literal
                        literal = new LiteralInline()
                        {
                            Span   = new SourceSpan(abbrInline.Span.End + 1, literal.Span.End),
                            Line   = line,
                            Column = column + match.Length,
                        };
                        content.Start   = indexAfterMatch;
                        literal.Content = content;

                        i = indexAfterMatch - 1;
                    }
                }

                if (container != null)
                {
                    if (literal != null)
                    {
                        container.AppendChild(literal);
                    }
                    processor.Inline = container;
                }
            };
        }
Exemplo n.º 5
0
        public override void Initialize()
        {
            _textMatchHelper = new TextMatchHelper(new HashSet <string>(LinkRenderer.LinkTypesToMatch.Select(c => "%" + c)));

            OpeningCharacters = new[] { '%' };
        }