提交 89568273 编写于 作者: J Johannes Rieken

fast-check for no-match, #22153

上级 24590b1d
......@@ -530,14 +530,22 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
const lowPattern = pattern.toLowerCase();
const lowWord = word.toLowerCase();
let i = 0;
let j = 0;
while (i < patternLen && j < wordLen) {
if (lowPattern[i] === lowWord[j]) {
i += 1;
}
j += 1;
}
if (i !== patternLen) {
// no simple matches found -> return early
return undefined;
}
let lastLowestMatch = -1;
let i: number;
let j: number;
for (i = 1; i <= patternLen; i++) {
let lowestMatch = -1;
let highestMatch = -1;
let lastLowWordChar = '';
for (j = 1; j <= wordLen; j++) {
......@@ -567,11 +575,6 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
} else {
score = 1;
}
highestMatch = j - 1;
if (lowestMatch === -1) {
lowestMatch = j - 1;
}
}
let diag = _table[i - 1][j - 1] + score;
......@@ -600,14 +603,6 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
lastLowWordChar = lowWordChar;
}
if (lowestMatch === -1 || highestMatch < lastLowestMatch) {
// return early when there was no match or when the
// match was only before the last lowest match
return undefined;
}
lastLowestMatch = lowestMatch;
}
if (_debug) {
......@@ -643,7 +638,6 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
// result, not by matching keep going left
i += 1;
} else {
// all good
total += value;
......@@ -652,12 +646,6 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
}
}
if (matches.length !== patternLen) {
// we didn't match all pattern
// characters in order
return undefined;
}
if (j > 3) {
j = 3;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册