Ejemplo n.º 1
0
        private static IReadOnlyList <FoundEntry> FindEntries(InputParseResult input)
        {
            var        foundEntries = new List <FoundEntry>();
            AhoAutomat ahoAutomat   = GetAhoAutomatWithBuildedBohr(input.Entries);

            Dictionary <string, string> caseSensitiveEntries = input.Entries
                                                               .ToDictionary(x => x.ToLower(), x => x);

            for (int lineNumber = 0; lineNumber < input.Lines.Count; lineNumber++)
            {
                string line = input.Lines[lineNumber];
                for (int charPosition = 0; charPosition < line.Length; charPosition++)
                {
                    char ch = line[charPosition];
                    ahoAutomat.SetNextState(char.ToLowerInvariant(ch));
                    IReadOnlyList <string> currentEntries = ahoAutomat.GetCurrentEntries();

                    foreach (string currentEntry in currentEntries)
                    {
                        var entryWithEndPosition = new FoundEntry
                        {
                            Line     = lineNumber,
                            Position = charPosition,
                            Word     = caseSensitiveEntries[currentEntry]
                        };
                        foundEntries.Add(BuildEntryWithStartPosition(input.Lines, entryWithEndPosition));
                    }
                }
                ahoAutomat.SetNextState(' ');
            }

            return(foundEntries);
        }
Ejemplo n.º 2
0
        private static AhoAutomat GetAhoAutomatWithBuildedBohr(IEnumerable <string> entries)
        {
            var result = new AhoAutomat();

            foreach (string entry in entries)
            {
                result.AddEnrty(entry.ToLower());
            }

            return(result);
        }