public CompiledTextSearchData Create(SearchParams searchParams, Func<FileName, bool> fileNamePathMatcher) {
      ParsedSearchString parsedSearchString;
      if (searchParams.Regex) {
        parsedSearchString = new ParsedSearchString(
          new ParsedSearchString.Entry { Text = searchParams.SearchString },
          Enumerable.Empty<ParsedSearchString.Entry>(),
          Enumerable.Empty<ParsedSearchString.Entry>());
      } else {
        var str = searchParams.SearchString ?? "";
        if (str.Length < MinimumSearchPatternLength) {
          throw new RecoverableErrorException(
            string.Format(
              "Search pattern must contain at least {0} characters",
              MinimumSearchPatternLength));
        }
        parsedSearchString = _searchStringParser.Parse(searchParams.SearchString ?? "");
      }

      var searchContentsAlgorithms = CreateSearchAlgorithms(
        parsedSearchString,
        new SearchProviderOptions {
          MatchCase = searchParams.MatchCase,
          MatchWholeWord = searchParams.MatchWholeWord,
          UseRegex = searchParams.Regex,
          UseRe2Engine = searchParams.UseRe2Engine
        });

      return new CompiledTextSearchData(
        parsedSearchString,
        searchContentsAlgorithms,
        fileNamePathMatcher);
    }
 public CompiledTextSearchData(
   ParsedSearchString parsedSearchString,
   IList<ICompiledTextSearchContainer> searchContainers,
   Func<FileName, bool> fileNameFilter) {
   _parsedSearchString = parsedSearchString;
   _searchContainers = searchContainers;
   _fileNameFilter = fileNameFilter;
 }
Esempio n. 3
0
 public TextSourceTextSearch(
   GetLineRangeFunction getLineRange,
   FindEntryFunction findEntry,
   ParsedSearchString parsedSearchString) {
   _findEntry = findEntry;
   _parsedSearchString = parsedSearchString;
   _getLineExtentCache = new GetLineExtentCache(getLineRange);
 }
Esempio n. 4
0
 public TextSourceTextSearch(
     GetLineRangeFunction getLineRange,
     FindEntryFunction findEntry,
     ParsedSearchString parsedSearchString)
 {
     _findEntry          = findEntry;
     _parsedSearchString = parsedSearchString;
     _getLineExtentCache = new GetLineExtentCache(getLineRange);
 }
 public CompiledTextSearchData(
     ParsedSearchString parsedSearchString,
     IList <ICompiledTextSearchContainer> searchContainers,
     Func <FileName, bool> fileNameFilter)
 {
     _parsedSearchString = parsedSearchString;
     _searchContainers   = searchContainers;
     _fileNameFilter     = fileNameFilter;
 }
 private List<ICompiledTextSearchContainer> CreateSearchAlgorithms(
   ParsedSearchString parsedSearchString, SearchProviderOptions options) {
   return parsedSearchString.EntriesBeforeMainEntry
     .Concat(new[] { parsedSearchString.MainEntry })
     .Concat(parsedSearchString.EntriesAfterMainEntry)
     .OrderBy(x => x.Index)
     .Select(entry => _compiledTextSearchProviderFactory.CreateProvider(entry.Text, options))
     .ToList();
 }
Esempio n. 7
0
 private List <ICompiledTextSearchContainer> CreateSearchAlgorithms(
     ParsedSearchString parsedSearchString, SearchProviderOptions options)
 {
     return(parsedSearchString.EntriesBeforeMainEntry
            .Concat(new[] { parsedSearchString.MainEntry })
            .Concat(parsedSearchString.EntriesAfterMainEntry)
            .OrderBy(x => x.Index)
            .Select(entry => _compiledTextSearchProviderFactory.CreateProvider(entry.Text, options))
            .ToList());
 }
Esempio n. 8
0
        private static List <SearchContentsAlgorithms> CreateSearchAlgorithms(ParsedSearchString parsedSearchString, bool matchCase)
        {
            var searchOptions = matchCase ? NativeMethods.SearchOptions.kMatchCase : NativeMethods.SearchOptions.kNone;

            return(parsedSearchString.EntriesBeforeMainEntry
                   .Concat(new[] { parsedSearchString.MainEntry })
                   .Concat(parsedSearchString.EntriesAfterMainEntry)
                   .OrderBy(x => x.Index)
                   .Select(entry => {
                var a1 = AsciiFileContents.CreateSearchAlgo(entry.Text, searchOptions);
                var a2 = UTF16FileContents.CreateSearchAlgo(entry.Text, searchOptions);
                return new SearchContentsAlgorithms(a1, a2);
            })
                   .ToList());
        }
        public IEnumerable <FilePositionSpan> FilterOnOtherEntries(ParsedSearchString parsedSearchString, IEnumerable <FilePositionSpan> matches)
        {
            var getLineExtentCache = new GetLineExtentCache(_getLineExtent);

            return(matches
                   .Select(match => {
                var lineExtent = getLineExtentCache.GetLineExtent(match.Position);
                // We got the line extent, the offset at which we found the MainEntry.
                // Now we need to check that "OtherEntries" are present (in order) and
                // in appropriate intervals.
                var positionInterval1 = lineExtent.Position;
                var lengthInterval1 = match.Position - lineExtent.Position;
                var entriesInterval1 = parsedSearchString.EntriesBeforeMainEntry;
                var positionInterval2 = match.Position + match.Length;
                var lengthInterval2 = (lineExtent.Position + lineExtent.Length) - (match.Position + match.Length);
                var entriesInterval2 = parsedSearchString.EntriesAfterMainEntry;

                int foundPositionInterval1;
                int foundLengthInterval1;
                int foundPositionInterval2;
                int foundLengthInterval2;
                if (CheckEntriesInInterval(positionInterval1, lengthInterval1, entriesInterval1, out foundPositionInterval1, out foundLengthInterval1) &&
                    CheckEntriesInInterval(positionInterval2, lengthInterval2, entriesInterval2, out foundPositionInterval2, out foundLengthInterval2))
                {
                    // If there was no entries before MainEntry, adjust interval
                    // location to be the same as the main entry.
                    if (foundPositionInterval1 < 0)
                    {
                        foundPositionInterval1 = match.Position;
                        foundLengthInterval1 = match.Length;
                    }
                    // If there was no entries after MainEntry, adjust interval to be
                    // the same as the main entry.
                    if (foundPositionInterval2 < 0)
                    {
                        foundPositionInterval2 = match.Position;
                        foundLengthInterval2 = match.Length;
                    }
                    return new FilePositionSpan {
                        Position = foundPositionInterval1,
                        Length = foundPositionInterval2 + foundLengthInterval2 - foundPositionInterval1
                    };
                }
                return new FilePositionSpan();
            })
                   .Where(x => x.Length != default(FilePositionSpan).Length)
                   .ToList());
        }
        public IEnumerable<FilePositionSpan> FilterOnOtherEntries(ParsedSearchString parsedSearchString, IEnumerable<FilePositionSpan> matches)
        {
            var getLineExtentCache = new GetLineExtentCache(_getLineExtent);
              return matches
            .Select(match => {
              var lineExtent = getLineExtentCache.GetLineExtent(match.Position);
              // We got the line extent, the offset at which we found the MainEntry.
              // Now we need to check that "OtherEntries" are present (in order) and
              // in appropriate intervals.
              var positionInterval1 = lineExtent.Position;
              var lengthInterval1 = match.Position - lineExtent.Position;
              var entriesInterval1 = parsedSearchString.EntriesBeforeMainEntry;
              var positionInterval2 = match.Position + match.Length;
              var lengthInterval2 = (lineExtent.Position + lineExtent.Length) - (match.Position + match.Length);
              var entriesInterval2 = parsedSearchString.EntriesAfterMainEntry;

              int foundPositionInterval1;
              int foundLengthInterval1;
              int foundPositionInterval2;
              int foundLengthInterval2;
              if (CheckEntriesInInterval(positionInterval1, lengthInterval1, entriesInterval1, out foundPositionInterval1, out foundLengthInterval1) &&
              CheckEntriesInInterval(positionInterval2, lengthInterval2, entriesInterval2, out foundPositionInterval2, out foundLengthInterval2)) {

            // If there was no entries before MainEntry, adjust interval
            // location to be the same as the main entry.
            if (foundPositionInterval1 < 0) {
              foundPositionInterval1 = match.Position;
              foundLengthInterval1 = match.Length;
            }
            // If there was no entries after MainEntry, adjust interval to be
            // the same as the main entry.
            if (foundPositionInterval2 < 0) {
              foundPositionInterval2 = match.Position;
              foundLengthInterval2 = match.Length;
            }
            return new FilePositionSpan {
              Position = foundPositionInterval1,
              Length = foundPositionInterval2 + foundLengthInterval2 - foundPositionInterval1
            };
              }
              return new FilePositionSpan();
            })
            .Where(x => x.Length != default(FilePositionSpan).Length)
            .ToList();
        }
Esempio n. 11
0
        public CompiledTextSearchData Create(SearchParams searchParams, Func <FileName, bool> fileNamePathMatcher)
        {
            ParsedSearchString parsedSearchString;

            if (searchParams.Regex)
            {
                parsedSearchString = new ParsedSearchString(
                    new ParsedSearchString.Entry {
                    Text = searchParams.SearchString
                },
                    Enumerable.Empty <ParsedSearchString.Entry>(),
                    Enumerable.Empty <ParsedSearchString.Entry>());
            }
            else
            {
                var str = searchParams.SearchString ?? "";
                if (str.Length < MinimumSearchPatternLength)
                {
                    throw new RecoverableErrorException(
                              string.Format(
                                  "Search pattern must contain at least {0} characters",
                                  MinimumSearchPatternLength));
                }
                parsedSearchString = _searchStringParser.Parse(searchParams.SearchString ?? "");
            }

            var searchContentsAlgorithms = CreateSearchAlgorithms(
                parsedSearchString,
                new SearchProviderOptions {
                MatchCase      = searchParams.MatchCase,
                MatchWholeWord = searchParams.MatchWholeWord,
                UseRegex       = searchParams.Regex,
                UseRe2Engine   = searchParams.UseRe2Engine
            });

            return(new CompiledTextSearchData(
                       parsedSearchString,
                       searchContentsAlgorithms,
                       fileNamePathMatcher));
        }
 /// <summary>
 /// The list of algorithms for each entry in "ParsedSearchString".
 /// </summary>
 //public IList<SearchContentsAlgorithms> SearchAlgorithms { get { return _searchAlgorithms; } }
 public SearchContentsAlgorithms GetSearchAlgorithms(ParsedSearchString.Entry entry)
 {
     return _searchAlgorithms[entry.Index];
 }
 public SearchContentsData(ParsedSearchString parsedSearchString, IList<SearchContentsAlgorithms> searchAlgorithms)
 {
     _parsedSearchString = parsedSearchString;
       _searchAlgorithms = searchAlgorithms;
 }
Esempio n. 14
0
 /// <summary>
 /// Retrieve the <see cref="ICompiledTextSearchContainer"/> for a given
 /// search entry.
 /// </summary>
 public ICompiledTextSearchContainer GetSearchContainer(
   ParsedSearchString.Entry entry) {
   return _searchContainers[entry.Index];
 }
Esempio n. 15
0
 public SearchContentsData(ParsedSearchString parsedSearchString, IList <SearchContentsAlgorithms> searchAlgorithms)
 {
     _parsedSearchString = parsedSearchString;
     _searchAlgorithms   = searchAlgorithms;
 }