(candidate, chunk, stringToWordSpans)
| 142453 | return spans; |
| 142454 | } |
| 142455 | function matchTextChunk(candidate, chunk, stringToWordSpans) { |
| 142456 | var index = indexOfIgnoringCase(candidate, chunk.textLowerCase); |
| 142457 | if (index === 0) { |
| 142458 | // a) Check if the word is a prefix of the candidate, in a case insensitive or |
| 142459 | // sensitive manner. If it does, return that there was an exact match if the word and candidate are the same length, else a prefix match. |
| 142460 | return createPatternMatch(chunk.text.length === candidate.length ? PatternMatchKind.exact : PatternMatchKind.prefix, /*isCaseSensitive:*/ ts.startsWith(candidate, chunk.text)); |
| 142461 | } |
| 142462 | if (chunk.isLowerCase) { |
| 142463 | if (index === -1) |
| 142464 | return undefined; |
| 142465 | // b) If the part is entirely lowercase, then check if it is contained anywhere in the |
| 142466 | // candidate in a case insensitive manner. If so, return that there was a substring |
| 142467 | // match. |
| 142468 | // |
| 142469 | // Note: We only have a substring match if the lowercase part is prefix match of some |
| 142470 | // word part. That way we don't match something like 'Class' when the user types 'a'. |
| 142471 | // But we would match 'FooAttribute' (since 'Attribute' starts with 'a'). |
| 142472 | var wordSpans = getWordSpans(candidate, stringToWordSpans); |
| 142473 | for (var _i = 0, wordSpans_1 = wordSpans; _i < wordSpans_1.length; _i++) { |
| 142474 | var span = wordSpans_1[_i]; |
| 142475 | if (partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ true)) { |
| 142476 | return createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive:*/ partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ false)); |
| 142477 | } |
| 142478 | } |
| 142479 | // c) Is the pattern a substring of the candidate starting on one of the candidate's word boundaries? |
| 142480 | // We could check every character boundary start of the candidate for the pattern. However, that's |
| 142481 | // an m * n operation in the wost case. Instead, find the first instance of the pattern |
| 142482 | // substring, and see if it starts on a capital letter. It seems unlikely that the user will try to |
| 142483 | // filter the list based on a substring that starts on a capital letter and also with a lowercase one. |
| 142484 | // (Pattern: fogbar, Candidate: quuxfogbarFogBar). |
| 142485 | if (chunk.text.length < candidate.length && isUpperCaseLetter(candidate.charCodeAt(index))) { |
| 142486 | return createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive:*/ false); |
| 142487 | } |
| 142488 | } |
| 142489 | else { |
| 142490 | // d) If the part was not entirely lowercase, then check if it is contained in the |
| 142491 | // candidate in a case *sensitive* manner. If so, return that there was a substring |
| 142492 | // match. |
| 142493 | if (candidate.indexOf(chunk.text) > 0) { |
| 142494 | return createPatternMatch(PatternMatchKind.substring, /*isCaseSensitive:*/ true); |
| 142495 | } |
| 142496 | // e) If the part was not entirely lowercase, then attempt a camel cased match as well. |
| 142497 | if (chunk.characterSpans.length > 0) { |
| 142498 | var candidateParts = getWordSpans(candidate, stringToWordSpans); |
| 142499 | var isCaseSensitive = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ false) ? true |
| 142500 | : tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ true) ? false : undefined; |
| 142501 | if (isCaseSensitive !== undefined) { |
| 142502 | return createPatternMatch(PatternMatchKind.camelCase, isCaseSensitive); |
| 142503 | } |
| 142504 | } |
| 142505 | } |
| 142506 | } |
| 142507 | function matchSegment(candidate, segment, stringToWordSpans) { |
| 142508 | // First check if the segment matches as is. This is also useful if the segment contains |
| 142509 | // characters we would normally strip when splitting into parts that we also may want to |
no test coverage detected