Пример #1
0
        private void LogHitFilename(FileHit hit)
        {
            switch (_configuration.OutputMode)
            {
            case "HtmlUrl":
                Console.WriteLine($" {hit.FoundLineNumbers.Count} hits in {hit.HtmlUrl}");
                break;

            default:
                Console.WriteLine($" {hit.FoundLineNumbers.Count} hits in {hit.Path}");
                break;
            }
        }
Пример #2
0
        private bool FindAllOccurences(FileHit file, string searchToken)
        {
            int lineNr = 1;

            file.FoundLineNumbers = new List <int>();
            foreach (var line in file.Content.Split('\n'))
            {
                if (Regex.IsMatch(line, searchToken, RegexOptions.IgnoreCase))
                {
                    file.FoundLineNumbers.Add(lineNr);
                }

                lineNr++;
            }
            return(file.FoundLineNumbers.Any());
        }
Пример #3
0
        private void LogHitLines(FileHit hit, string searchToken)
        {
            var showLinesCount = _configuration.SurroundingLines;

            var lines = hit.Content.Split('\n');

            foreach (var line in hit.FoundLineNumbers)
            {
                var start = Math.Max(line - showLinesCount - 1, 0);
                var end   = Math.Min(line + showLinesCount, lines.Length);

                for (int i = start; i < end; i++)
                {
                    OutputWithHighlightedSearchtoken($"{i,5}: {lines[i]}", searchToken);
                }

                Console.WriteLine(new string('-', 70));
            }
        }
Пример #4
0
        private void LogHit(FileHit hit, string searchToken)
        {
            LogHitFilename(hit);

            LogHitLines(hit, searchToken);
        }