/// <summary> /// Creates a new ContainerPatternMatcher. /// </summary> /// <param name="patternParts">The pattern itself needs to be split up, to match against candidates. Suppose the user searches for Apple.Banana.Charlie using A.B.C, /// the compiler recognizes that these are namespaces, splits the pattern up and passes in { "A", "B", "C" }.</param> /// <param name="containerSplitCharacters">What characters should candidates be split on. In the above example, it would be { '.' }</param> /// <param name="culture">Important for some string operations.</param> /// <param name="allowFuzzyMatching">Do we tolerate mis-spellings?</param> /// <param name="allowSimpleSubstringMatching">Does a match not at a camel-case boundary count? (e.g. Does AppleBanana match 'ppl' as a search string?</param> /// <param name="includeMatchedSpans">Do we want to get spans back (performance impacting).</param> public ContainerPatternMatcher( string[] patternParts, IReadOnlyCollection <char> containerSplitCharacters, CultureInfo culture, bool allowFuzzyMatching = false, bool allowSimpleSubstringMatching = false, bool includeMatchedSpans = false, PatternMatcher linkedMatcher = null) : base(includeMatchedSpans, culture, allowFuzzyMatching, allowSimpleSubstringMatching, linkedMatcher) { _containerSplitCharacters = containerSplitCharacters.ToArray(); _patternSegments = patternParts .Select(text => new PatternSegment(text.Trim(), allowFuzzyMatching: allowFuzzyMatching)) .ToArray(); HasInvalidPattern = _patternSegments.Length == 0 || _patternSegments.Any(s => s.IsInvalid); }
internal static PatternMatcher CreateContainerPatternMatcher( string[] patternParts, IReadOnlyCollection <char> containerSplitCharacters, CultureInfo culture = null, bool allowFuzzyMatching = false, bool allowSimpleSubstringMatching = false, bool includeMatchedSpans = false, PatternMatcher linkedMatcher = null) { return(new ContainerPatternMatcher( patternParts, containerSplitCharacters, culture, allowFuzzyMatching, allowSimpleSubstringMatching, includeMatchedSpans, linkedMatcher)); }
#pragma warning disable CA1822 public IPatternMatcher CreatePatternMatcher(string pattern, PatternMatcherCreationOptions creationOptions, IPatternMatcher linkedMatcher) { if (string.IsNullOrWhiteSpace(pattern)) { throw new ArgumentException("A non-empty pattern is required to create a pattern matcher", nameof(pattern)); } if (creationOptions == null) { throw new ArgumentNullException(nameof(creationOptions)); } var matcher = linkedMatcher as PatternMatcher; if (creationOptions.ContainerSplitCharacters == null) { return(PatternMatcher.CreateSimplePatternMatcher( pattern, creationOptions.CultureInfo, creationOptions.Flags.HasFlag(IncludeMatchedSpans), creationOptions.Flags.HasFlag(AllowFuzzyMatching), creationOptions.Flags.HasFlag(AllowSimpleSubstringMatching), matcher)); } else { return(PatternMatcher.CreateContainerPatternMatcher( pattern.Split(creationOptions.ContainerSplitCharacters.ToArray()), creationOptions.ContainerSplitCharacters, creationOptions.CultureInfo, creationOptions.Flags.HasFlag(AllowFuzzyMatching), creationOptions.Flags.HasFlag(AllowSimpleSubstringMatching), creationOptions.Flags.HasFlag(IncludeMatchedSpans), matcher)); } }
private static PatternMatchKind GetKind(CamelCaseResult result) => PatternMatcher.GetCamelCaseKind(result);