public static Func <string, bool> BuildPredicate(this SearchMetadata source) { const RegexOptions caseInsensitiveOptions = RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled | RegexOptions.IgnoreCase; const RegexOptions caseSensitiveOptions = RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled; Func <string, bool> predicate; if (!source.UseRegex) { var stringComparison = source.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; predicate = s => !string.IsNullOrEmpty(s) && s.Contains(source.SearchText, stringComparison); } else { var options = source.IgnoreCase ? caseInsensitiveOptions : caseSensitiveOptions; var regex = new Regex(source.SearchText, options); predicate = s => { if (s == null) { throw new ArgumentNullException(nameof(s)); } return(regex.IsMatch(s)); }; } return(predicate); }
public void Add([NotNull] SearchMetadata metadata) { if (metadata == null) { throw new ArgumentNullException(nameof(metadata)); } _searches.AddOrUpdate(metadata); }
public void AddorUpdate([NotNull] SearchMetadata metadata) { if (metadata == null) { throw new ArgumentNullException(nameof(metadata)); } _searches.AddOrUpdate(metadata); _logger.Info("Search metadata has changed: {0}", metadata); }
public SearchOptionsProxy(SearchMetadata searchMetadata, IEnumerable<Swatch> swatches, Action<SearchMetadata> removeAction) { Swatches = swatches; if (searchMetadata == null) throw new ArgumentNullException(nameof(searchMetadata)); if (swatches == null) throw new ArgumentNullException(nameof(swatches)); if (removeAction == null) throw new ArgumentNullException(nameof(removeAction)); _searchMetadata = searchMetadata; Highlight = _searchMetadata.Highlight; Filter = _searchMetadata.Filter; RemoveCommand = new Command(() => removeAction(searchMetadata)); }
public SearchState Map(SearchMetadata search) { return new SearchState ( search.SearchText, search.Position, search.UseRegex, search.Highlight, search.Filter, false, search.IgnoreCase, search.HighlightHue.Swatch, search.IconKind, search.HighlightHue.Name, search.IsExclusion); }
public static Optional <Regex> BuildRegEx(this SearchMetadata source) { const RegexOptions caseInsensitiveOptions = RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled | RegexOptions.IgnoreCase; const RegexOptions caseSensitiveOptions = RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled; if (source.UseRegex) { var options = source.IgnoreCase ? caseInsensitiveOptions : caseSensitiveOptions; return(new Regex(source.SearchText, options)); } return(Optional <Regex> .None); }
public SearchOptionsProxy(SearchMetadata searchMetadata, IEnumerable<Swatch> swatches, Action<SearchMetadata> removeAction) { Swatches = swatches; if (searchMetadata == null) throw new ArgumentNullException(nameof(searchMetadata)); if (swatches == null) throw new ArgumentNullException(nameof(swatches)); if (removeAction == null) throw new ArgumentNullException(nameof(removeAction)); _searchMetadata = searchMetadata; Highlight = _searchMetadata.Highlight; Filter = _searchMetadata.Filter; UseRegex = searchMetadata.UseRegex; IgnoreCase = searchMetadata.IgnoreCase; Status = searchMetadata.UseRegex ? SearchResultIndicatorStatus.Regex : SearchResultIndicatorStatus.Text; RemoveCommand = new Command(() => removeAction(searchMetadata)); }
public static IEnumerable<MatchedString> MatchString(this string source, SearchMetadata itemsToMatch) { return new SearchMetadataEnumerator(source, new []{ itemsToMatch }); }
public SearchOptionsViewModel(ICombinedSearchMetadataCollection combinedSearchMetadataCollection, ISearchProxyCollectionFactory searchProxyCollectionFactory, ISearchMetadataFactory searchMetadataFactory, ISchedulerProvider schedulerProvider, SearchHints searchHints) { SearchHints = searchHints; var global = combinedSearchMetadataCollection.Global; var local = combinedSearchMetadataCollection.Local; Action<SearchMetadata> changeScopeAction = meta => { if (meta.IsGlobal) { //make global global.Remove(meta.SearchText); var newValue = new SearchMetadata(meta, local.NextIndex(),false); local.AddorUpdate(newValue); } else { //make local local.Remove(meta.SearchText); var newValue = new SearchMetadata(meta, global.NextIndex(), true); global.AddorUpdate(newValue); } }; Local = searchProxyCollectionFactory.Create(local, Id, changeScopeAction); Global = searchProxyCollectionFactory.Create(global, Id, changeScopeAction); //command to add the current search to the tail collection var searchInvoker = SearchHints.SearchRequested .ObserveOn(schedulerProvider.Background) .Subscribe(request => { var isGlobal = SelectedIndex == 1; var nextIndex = isGlobal ? global.NextIndex() : local.NextIndex(); var meta = searchMetadataFactory.Create(request.Text, request.UseRegEx, nextIndex, false, isGlobal); if (isGlobal) { global.AddorUpdate(meta); } else { local.AddorUpdate(meta); } }); _cleanUp = new CompositeDisposable(searchInvoker, searchInvoker, SearchHints, Global, Local); }
public LineMatch(SearchMetadata searchMetadata) { _searchMetadata = searchMetadata; }