public void IsPrefix(CompareInfo compareInfo, string source, string value, CompareOptions options, bool expected, int expectedMatchLength) { if (options == CompareOptions.None) { Assert.Equal(expected, compareInfo.IsPrefix(source, value)); } Assert.Equal(expected, compareInfo.IsPrefix(source, value, options)); if ((compareInfo == s_invariantCompare) && ((options == CompareOptions.None) || (options == CompareOptions.IgnoreCase))) { StringComparison stringComparison = (options == CompareOptions.IgnoreCase) ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture; Assert.Equal(expected, source.StartsWith(value, stringComparison)); Assert.Equal(expected, source.AsSpan().StartsWith(value.AsSpan(), stringComparison)); } // Now test the span version - use BoundedMemory to detect buffer overruns using BoundedMemory <char> sourceBoundedMemory = BoundedMemory.AllocateFromExistingData <char>(source); sourceBoundedMemory.MakeReadonly(); using BoundedMemory <char> valueBoundedMemory = BoundedMemory.AllocateFromExistingData <char>(value); valueBoundedMemory.MakeReadonly(); Assert.Equal(expected, compareInfo.IsPrefix(sourceBoundedMemory.Span, valueBoundedMemory.Span, options)); Assert.Equal(expected, compareInfo.IsPrefix(sourceBoundedMemory.Span, valueBoundedMemory.Span, options, out int actualMatchLength)); Assert.Equal(expectedMatchLength, actualMatchLength); }
internal MergedCompiledCommandParameter GetMatchingParameter(string name, bool throwOnParameterNotFound, bool tryExactMatching, InvocationInfo invocationInfo) { if (string.IsNullOrEmpty(name)) { throw PSTraceSource.NewArgumentException("name"); } Collection <MergedCompiledCommandParameter> collection = new Collection <MergedCompiledCommandParameter>(); if ((name.Length > 0) && SpecialCharacters.IsDash(name[0])) { name = name.Substring(1); } foreach (string str in this.bindableParameters.Keys) { if (nameCompareInfo.IsPrefix(str, name, CompareOptions.IgnoreCase)) { if (tryExactMatching && string.Equals(str, name, StringComparison.OrdinalIgnoreCase)) { return(this.bindableParameters[str]); } collection.Add(this.bindableParameters[str]); } } foreach (string str2 in this.aliasedParameters.Keys) { if (nameCompareInfo.IsPrefix(str2, name, CompareOptions.IgnoreCase)) { if (tryExactMatching && string.Equals(str2, name, StringComparison.OrdinalIgnoreCase)) { return(this.aliasedParameters[str2]); } if (!collection.Contains(this.aliasedParameters[str2])) { collection.Add(this.aliasedParameters[str2]); } } } if (collection.Count > 1) { StringBuilder builder = new StringBuilder(); foreach (MergedCompiledCommandParameter parameter in collection) { builder.AppendFormat(" -{0}", parameter.Parameter.Name); } ParameterBindingException exception = new ParameterBindingException(ErrorCategory.InvalidArgument, invocationInfo, null, name, null, null, "ParameterBinderStrings", "AmbiguousParameter", new object[] { builder }); throw exception; } if ((collection.Count == 0) && throwOnParameterNotFound) { ParameterBindingException exception2 = new ParameterBindingException(ErrorCategory.InvalidArgument, invocationInfo, null, name, null, null, "ParameterBinderStrings", "NamedParameterNotFound", new object[0]); throw exception2; } MergedCompiledCommandParameter parameter2 = null; if (collection.Count > 0) { parameter2 = collection[0]; } return(parameter2); }
public void IsPrefix(CompareInfo compareInfo, string source, string value, CompareOptions options, bool expected) { if (options == CompareOptions.None) { Assert.Equal(expected, compareInfo.IsPrefix(source, value)); } Assert.Equal(expected, compareInfo.IsPrefix(source, value, options)); }
public static void IsPrefixBadCompareOptions() { CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo; Assert.Throws <ArgumentException>(() => ci.IsPrefix("aaa", "a", CompareOptions.Ordinal | CompareOptions.IgnoreWidth)); Assert.Throws <ArgumentException>(() => ci.IsPrefix("aaa", "a", CompareOptions.OrdinalIgnoreCase | CompareOptions.IgnoreWidth)); Assert.Throws <ArgumentException>(() => ci.IsPrefix("aaa", "a", CompareOptions.StringSort)); Assert.Throws <ArgumentException>(() => ci.IsPrefix("aaa", "a", (CompareOptions)(-1))); }
public void IsPrefix(CompareInfo compareInfo, string source, string value, CompareOptions options, bool expected) { if (options == CompareOptions.None) { Assert.Equal(expected, compareInfo.IsPrefix(source, value)); } Assert.Equal(expected, compareInfo.IsPrefix(source, value, options)); if ((compareInfo == s_invariantCompare) && ((options == CompareOptions.None) || (options == CompareOptions.IgnoreCase))) { StringComparison stringComparison = (options == CompareOptions.IgnoreCase) ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture; Assert.Equal(expected, source.StartsWith(value, stringComparison)); Assert.Equal(expected, source.AsSpan().StartsWith(value.AsSpan(), stringComparison)); } }
void SetBuffer() { if (_buffer == null) { return; } if (_buffer.Length > 0 && char.IsDigit(_buffer[0])) { SetSource(values); intelBox.SelectedIndex = -1; return; } List <string> t = values.Where(x => CompareInfo.IndexOf(x, _buffer, CompareOptions.IgnoreCase) >= 0).ToList(); if (t.Count > 0) { SetSource(t); List <string> t2 = t.Where(x => CompareInfo.IsPrefix(x, _buffer, CompareOptions.IgnoreCase)).ToList(); if (t2.Count > 0) { t.Sort(); t2.Sort(); int i = t.IndexOf(t2[0]); intelBox.SelectedIndex = i; } } else { //No matching value SetSource(values); intelBox.SelectedIndex = -1; } }
public void Test(CultureInfo culture, string str1, string str2, bool expected, CompareOptions options) { CompareInfo ci = culture.CompareInfo; bool i = ci.IsPrefix(str1, str2, options); Assert.Equal(expected, i); }
internal static bool MatchString(LimitChecker limitChecker, CultureInfo cultureInfo, string content, string pattern, ContentFlags flags) { if (!limitChecker.CheckAndIncrementContentRestrictionCount(1, content)) { return(false); } CompareOptions compareOptions = RestrictionEvaluator.GetCompareOptions(flags); ContentFlags contentFlags = flags & (ContentFlags.SubString | ContentFlags.Prefix); CompareInfo compareInfo = cultureInfo.CompareInfo; switch (contentFlags) { case ContentFlags.FullString: return(compareInfo.Compare(content, pattern, compareOptions) == 0); case ContentFlags.SubString: return(compareInfo.IndexOf(content, pattern, compareOptions) != -1); case ContentFlags.Prefix: return(compareInfo.IsPrefix(content, pattern, compareOptions)); default: throw new InvalidRuleException(string.Format("Not supported content flags {0}", flags)); } }
public bool TestOrd(CultureInfo culture, string str1, string str2, bool expected, CompareOptions options, string id) { CompareInfo ci = culture.CompareInfo; bool result = true; if (str1 == null || str2 == null || (str1.Length < 100 && str2.Length < 100)) { TestFramework.BeginScenario(id + ": Comparing " + ((str1 == null) ? "null" : str1) + " / " + ((str2 == null) ? "null" : str2) + "; options: " + options + "; culture: " + ci.Name); } else { TestFramework.BeginScenario(id + ": Comparing LongStr (" + str1.Length + ") / LongStr(" + str2.Length + "); options: " + options + "; culture: " + ci.Name); } try { bool i = ci.IsPrefix(str1, str2, options); if (i != expected) { result = false; TestFramework.LogError("001", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + expected); } } catch (Exception exc) { result = false; TestFramework.LogError("003", "Unexpected exception in " + id + ", excpetion: " + exc.ToString()); } return(result); }
public bool Test(CultureInfo culture, string str1, string str2, bool expected, CompareOptions options, string id) { if (!id.Contains("s") || !Utilities.IsVistaOrLater) //Due Windows 7 bug 130925 { expected = GlobLocHelper.OSIsPrefix(culture, str1, str2, options); } CompareInfo ci = culture.CompareInfo; bool result = true; if (str1 == null || str2 == null || (str1.Length < 100 && str2.Length < 100)) { TestFramework.BeginScenario(id + ": Comparing " + ((str1 == null) ? "null" : str1) + " / " + ((str2 == null) ? "null" : str2) + "; options: " + options + "; culture: " + ci.Name); } else { TestFramework.BeginScenario(id + ": Comparing LongStr (" + str1.Length + ") / LongStr(" + str2.Length + "); options: " + options + "; culture: " + ci.Name); } try { bool i = ci.IsPrefix(str1, str2, options); if (i != expected) { result = false; TestFramework.LogError("001z", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + expected); } } catch (Exception exc) { result = false; TestFramework.LogError("003z", "Unexpected exception in " + id + ", excpetion: " + exc.ToString()); } return(result); }
private int ParseValue(string str) { Debug.Assert(str != null); if (str.Length == 0) { throw new FormatException("A crontab field value cannot be empty."); } var firstChar = str[0]; if (firstChar >= '0' && firstChar <= '9') { return(int.Parse(str, CultureInfo.InvariantCulture)); } if (_names == null) { throw new FormatException(string.Format( "'{0}' is not a valid value for this crontab field. It must be a numeric value between {1} and {2} (all inclusive).", str, _minValue, _maxValue)); } for (var i = 0; i < _names.Length; i++) { if (Comparer.IsPrefix(_names[i], str, CompareOptions.IgnoreCase)) { return(i + _minValue); } } throw new FormatException(string.Format( "'{0}' is not a known value name. Use one of the following: {1}.", str, string.Join(", ", _names))); }
private static Sort GetSort(SortedField[] sortedFields) { if (sortedFields == null || sortedFields.Length == 0) { return(null); } return(new Sort(sortedFields.Select(x => { var sortOptions = SortOptions.String; if (x.Field == Constants.Indexing.Fields.IndexFieldScoreName) { return SortField.FIELD_SCORE; } if (InvariantCompare.IsPrefix(x.Field, Constants.Indexing.Fields.AlphaNumericFieldName, CompareOptions.None)) { var customFieldName = SortFieldHelper.ExtractName(x.Field); if (customFieldName.IsNullOrWhiteSpace()) { throw new InvalidOperationException("Alphanumeric sort: cannot figure out what field to sort on!"); } var anSort = new AlphaNumericComparatorSource(); return new SortField(customFieldName, anSort, x.Descending); } if (InvariantCompare.IsPrefix(x.Field, Constants.Indexing.Fields.RandomFieldName, CompareOptions.None)) { var customFieldName = SortFieldHelper.ExtractName(x.Field); if (customFieldName.IsNullOrWhiteSpace()) // truly random { return new RandomSortField(Guid.NewGuid().ToString()); } return new RandomSortField(customFieldName); } if (InvariantCompare.IsSuffix(x.Field, Constants.Indexing.Fields.RangeFieldSuffix, CompareOptions.None)) { sortOptions = SortOptions.NumericDouble; // TODO arek - it seems to be working fine with long values as well however needs to be verified } return new SortField(IndexField.ReplaceInvalidCharactersInFieldName(x.Field), (int)sortOptions, x.Descending); }).ToArray())); }
public static void Main() { // Defines the strings to compare. String myStr1 = "calle"; String myStr2 = "llegar"; String myXfix = "lle"; // Uses the CompareInfo property of the InvariantCulture. CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo; // Determines whether myXfix is a prefix of "calle" and "llegar". Console.WriteLine("IsPrefix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsPrefix(myStr1, myXfix)); Console.WriteLine("IsPrefix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsPrefix(myStr2, myXfix)); // Determines whether myXfix is a suffix of "calle" and "llegar". Console.WriteLine("IsSuffix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsSuffix(myStr1, myXfix)); Console.WriteLine("IsSuffix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsSuffix(myStr2, myXfix)); }
private bool CheckPath(string path) { CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo; if (compareInfo.IsPrefix(path, "/", CompareOptions.Ordinal)) { return(path == this.currentXmlPath); } return(compareInfo.IsSuffix(this.currentXmlPath, path, CompareOptions.Ordinal)); }
public void TestExc <T>(CultureInfo culture, string str1, string str2, CompareOptions options) where T : Exception { CompareInfo ci = culture.CompareInfo; Assert.Throws <T>(() => { bool i = ci.IsPrefix(str1, str2, options); }); }
public void IsPrefix(string culture, string source, string prefix, CompareOptions options) { CompareInfo compareInfo = CultureInfo.GetCultureInfo(culture).CompareInfo; foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { compareInfo.IsPrefix(source, prefix, options); } } }
bool CheckPath(string path) { CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo; if (ci.IsPrefix(path, "/", CompareOptions.Ordinal)) { return(path == currentXmlPath); } else { return(ci.IsSuffix(currentXmlPath, path, CompareOptions.Ordinal)); } }
public static string NormalizeUrl(string url) { string normalizedUrl; CompareInfo cmpUrl = CultureInfo.InvariantCulture.CompareInfo; if (!string.IsNullOrEmpty(url) && !cmpUrl.IsPrefix(url, "file:") && !cmpUrl.IsPrefix(url, "\\") && !cmpUrl.IsPrefix(url, "ftp:") && !cmpUrl.IsPrefix(url, "http:") && !cmpUrl.IsPrefix(url, "https:") && (url.Length > 1 && url[1] != ':')) { normalizedUrl = "http://" + url; } else { normalizedUrl = url; } return(normalizedUrl); }
// Here is a more elaborate hack to test for anonymous type: // http://stackoverflow.com/questions/2483023/how-to-test-if-a-type-is-anonymous // compiler generated classes are always recreatable and need not additional references to check for. public static bool IsAnonymousType(Type type) { if (type != null) { // HACK: The only way to detect anonymous types right now. CompareInfo myComp = CultureInfo.CurrentCulture.CompareInfo; return(CustomAttributeExtensions.IsDefined(type, typeof(CompilerGeneratedAttribute), false) && type.IsGenericType && type.Name.Contains("AnonymousType") && (myComp.IsPrefix(type.Name, "<>", CompareOptions.IgnoreCase) || myComp.IsPrefix(type.Name, "VB$", CompareOptions.IgnoreCase)) && (type.Attributes & TypeAttributes.NotPublic) == TypeAttributes.NotPublic); } return(false); }
public static void Main() { // Defines the strings to compare. String myStr1 = "calle"; String myStr2 = "llegar"; String myXfix = "LLE"; // Uses the CompareInfo property of the InvariantCulture. CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo; Console.WriteLine("IsSuffix \"{0}\", \"{1}\"", myStr1, myXfix); Console.WriteLine(" With no CompareOptions : {0}", myComp.IsSuffix(myStr1, myXfix)); Console.WriteLine(" With None : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.None)); Console.WriteLine(" With Ordinal : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.Ordinal)); Console.WriteLine(" With IgnoreCase : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.IgnoreCase)); Console.WriteLine("IsPrefix \"{0}\", \"{1}\"", myStr2, myXfix); Console.WriteLine(" With no CompareOptions : {0}", myComp.IsPrefix(myStr2, myXfix)); Console.WriteLine(" With None : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.None)); Console.WriteLine(" With Ordinal : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.Ordinal)); Console.WriteLine(" With IgnoreCase : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.IgnoreCase)); }
public void IsPrefix_Invalid() { // Source is null Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsPrefix(null, "")); Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsPrefix(null, "", CompareOptions.None)); // Value is null Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsPrefix("", null)); Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsPrefix("", null, CompareOptions.None)); // Source and prefix are null Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsPrefix(null, null)); Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsPrefix(null, null, CompareOptions.None)); // Options are invalid Assert.Throws <ArgumentException>(() => s_invariantCompare.IsPrefix("Test's", "Tests", CompareOptions.StringSort)); Assert.Throws <ArgumentException>(() => s_invariantCompare.IsPrefix("Test's", "Tests", (CompareOptions)(-1))); Assert.Throws <ArgumentException>(() => s_invariantCompare.IsPrefix("Test's", "Tests", (CompareOptions)0x11111111)); }
public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context) { string val = value as string; if (!string.IsNullOrEmpty(val)) { CompareInfo compareInfo = CultureInfo.CurrentCulture.CompareInfo; if (compareInfo.IsPrefix(val, "ERROR", CompareOptions.IgnoreCase)) { return(new ValidationResult(false, val)); } } return(new ValidationResult(true, null)); }
public static bool StartsWithCultureIgnoreCaseHelper(ReadOnlySpan <char> span, ReadOnlySpan <char> value, CompareInfo compareInfo) { Debug.Assert(value.Length != 0); if (GlobalizationMode.Invariant) { return(StartsWithOrdinalIgnoreCaseHelper(span, value)); } if (span.Length == 0) { return(false); } return(compareInfo.IsPrefix(span, value, CompareOptions.IgnoreCase)); }
private static string FindPrefix(string str) { CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo; foreach (HashSet.Entry e in _prefixes) { string prefix = (string)e.Key; if (ci.IsPrefix(str, prefix, CompareOptions.IgnoreCase)) { return(prefix); } } return(null); }
/// <summary> /// Handles the request. /// </summary> /// <param name="url">The URL.</param> /// <param name="ext">The extension.</param> /// <returns>Type.</returns> public override string HandleRequest(string url, string ext) { CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo; bool x = ci.IsPrefix(url, "mailto:"); if (x) { return("email"); } else if (Successor != null) { return(Successor.HandleRequest(url, ext)); } else { return("other"); } }
public static void IsPrefixArgumentNullException() { CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo; Assert.Throws <ArgumentNullException>(() => ci.IsPrefix(null, "")); Assert.Throws <ArgumentNullException>(() => ci.IsPrefix(null, "", CompareOptions.Ordinal)); Assert.Throws <ArgumentNullException>(() => ci.IsPrefix("", null)); Assert.Throws <ArgumentNullException>(() => ci.IsPrefix("", null, CompareOptions.Ordinal)); Assert.Throws <ArgumentNullException>(() => ci.IsPrefix(null, null)); Assert.Throws <ArgumentNullException>(() => ci.IsPrefix(null, null, CompareOptions.Ordinal)); }
static void Main(string[] args) { int inputs = int.Parse(Console.ReadLine()); CompareInfo compare = CultureInfo.InvariantCulture.CompareInfo; while (inputs-- != 0) { int phoneNumbers = int.Parse(Console.ReadLine()); //var numberArr = new string[phoneNumbers]; var numberArr = new List <string>(); for (int j = 0; j < phoneNumbers; j++) { numberArr.Add(Console.ReadLine()); } numberArr.Sort(); //numberArr.OrderBy(x => x); bool containPrefix = true; //var tmpArr = numberArr.ToArray(); //Array.Sort(tmpArr); for (int j = 1; j < phoneNumbers; j++) { if (numberArr[j].Length > numberArr[j - 1].Length) { if (compare.IsPrefix(numberArr[j], numberArr[j - 1])) { containPrefix = false; break; } } //if (tmpArr[j].StartsWith(tmpArr[j - 1])) //{ // containPrefix = false; // break; //} } Console.WriteLine(containPrefix ? "YES" : "NO"); } }
public bool TestExc(CultureInfo culture, string str1, string str2, Type expected, CompareOptions options, string id) { CompareInfo ci = culture.CompareInfo; bool result = true; TestFramework.BeginScenario(id + ": Comparing " + str1 + " / " + str2 + "; options: " + options + "; culture: " + ci.Name); try { bool i = ci.IsPrefix(str1, str2, options); result = false; TestFramework.LogError("004", "Error in " + id + ", expected exception did not occur. Comparison result: " + i); } catch (Exception exc) { if (!exc.GetType().Equals(expected)) { result = false; TestFramework.LogError("005", "Unexpected exception in " + id + ", excpetion: " + exc.ToString()); } } return(result); }
/// <summary> /// Returns the external file infos for the given video. /// </summary> /// <param name="video">The <see cref="Video"/> object to search external files for.</param> /// <param name="directoryService">The directory service to search for files.</param> /// <param name="clearCache">True if the directory service cache should be cleared before searching.</param> /// <returns>The external file paths located.</returns> public IReadOnlyList <ExternalPathParserResult> GetExternalFiles( Video video, IDirectoryService directoryService, bool clearCache) { if (!video.IsFileProtocol) { return(Array.Empty <ExternalPathParserResult>()); } // Check if video folder exists string folder = video.ContainingFolderPath; if (!Directory.Exists(folder)) { return(Array.Empty <ExternalPathParserResult>()); } var externalPathInfos = new List <ExternalPathParserResult>(); var files = directoryService.GetFilePaths(folder, clearCache).ToList(); files.AddRange(directoryService.GetFilePaths(video.GetInternalMetadataPath(), clearCache)); if (!files.Any()) { return(Array.Empty <ExternalPathParserResult>()); } foreach (var file in files) { var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file); if (_compareInfo.IsPrefix(fileNameWithoutExtension, video.FileNameWithoutExtension, CompareOptions, out int matchLength) && (fileNameWithoutExtension.Length == matchLength || _namingOptions.MediaFlagDelimiters.Contains(fileNameWithoutExtension[matchLength].ToString()))) { var externalPathInfo = _externalPathParser.ParseFile(file, fileNameWithoutExtension[matchLength..]);
private PatternMatch?NonFuzzyMatchPatternChunk( string candidate, TextChunk patternChunk, bool punctuationStripped) { var candidateLength = candidate.Length; var caseInsensitiveIndex = _compareInfo.IndexOf(candidate, patternChunk.Text, CompareOptions.IgnoreCase); if (caseInsensitiveIndex == 0) { // We found the pattern at the start of the candidate. This is either an exact or // prefix match. if (patternChunk.Text.Length == candidateLength) { // Lengths were the same, this is either a case insensitive or sensitive exact match. return(new PatternMatch( PatternMatchKind.Exact, punctuationStripped, isCaseSensitive: candidate == patternChunk.Text, matchedSpan: GetMatchedSpan(0, candidateLength))); } else { // Lengths were the same, this is either a case insensitive or sensitive prefix match. return(new PatternMatch( PatternMatchKind.Prefix, punctuationStripped, isCaseSensitive: _compareInfo.IsPrefix(candidate, patternChunk.Text), matchedSpan: GetMatchedSpan(0, patternChunk.Text.Length))); } } ArrayBuilder <TextSpan> candidateHumpsOpt = null; try { var patternIsLowercase = patternChunk.IsLowercase; if (caseInsensitiveIndex > 0) { // We found the pattern somewhere in the candidate. This could be a substring match. // However, we don't want to be overaggressive in returning just any substring results. // So do a few more checks to make sure this is a good result. if (!patternIsLowercase) { // Pattern contained uppercase letters. This is a strong indication from the // user that they expect the same letters to be uppercase in the result. As // such, only return this if we can find this pattern exactly in the candidate. var caseSensitiveIndex = _compareInfo.IndexOf(candidate, patternChunk.Text, CompareOptions.None); if (caseSensitiveIndex > 0) { return(new PatternMatch( PatternMatchKind.Substring, punctuationStripped, isCaseSensitive: true, matchedSpan: GetMatchedSpan(caseSensitiveIndex, patternChunk.Text.Length))); } } else { // Pattern was all lowercase. This can lead to lots of false positives. For // example, we don't want "bin" to match "CombineUnits". Instead, we want it // to match "BinaryOperator". As such, make sure our match looks like it's // starting an actual word in the candidate. // Do a quick check to avoid the expensive work of having to go get the candidate // humps. if (char.IsUpper(candidate[caseInsensitiveIndex])) { return(new PatternMatch(PatternMatchKind.Substring, punctuationStripped, isCaseSensitive: false, matchedSpan: GetMatchedSpan(caseInsensitiveIndex, patternChunk.Text.Length))); } candidateHumpsOpt = StringBreaker.GetWordParts(candidate); for (int i = 0, n = candidateHumpsOpt.Count; i < n; i++) { var hump = TextSpan.FromBounds(candidateHumpsOpt[i].Start, candidateLength); if (PartStartsWith(candidate, hump, patternChunk.Text, CompareOptions.IgnoreCase)) { return(new PatternMatch(PatternMatchKind.Substring, punctuationStripped, isCaseSensitive: PartStartsWith(candidate, hump, patternChunk.Text, CompareOptions.None), matchedSpan: GetMatchedSpan(hump.Start, patternChunk.Text.Length))); } } } } // Didn't have an exact/prefix match, or a high enough quality substring match. // See if we can find a camel case match. if (candidateHumpsOpt == null) { candidateHumpsOpt = StringBreaker.GetWordParts(candidate); } // Didn't have an exact/prefix match, or a high enough quality substring match. // See if we can find a camel case match. return(TryCamelCaseMatch( candidate, patternChunk, punctuationStripped, patternIsLowercase, candidateHumpsOpt)); } finally { candidateHumpsOpt?.Free(); } }