forked from gzt/A8000
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
547 B
20 lines
547 B
/**
|
|
* 模糊匹配函数,判断 target 的字符是否按顺序出现在 source 中
|
|
* @param source 源字符串
|
|
* @param target 目标字符串
|
|
* @returns 是否匹配
|
|
*/
|
|
export function fuzzyMatchBySequence(source: string, target: string): boolean {
|
|
const sourceLower = source.toLowerCase();
|
|
const targetLower = target.toLowerCase();
|
|
|
|
let i = 0;
|
|
let j = 0;
|
|
while (i < sourceLower.length && j < targetLower.length) {
|
|
if (sourceLower[i] === targetLower[j]) {
|
|
j++;
|
|
}
|
|
i++;
|
|
}
|
|
return j === targetLower.length;
|
|
}
|