Screwed up checks.

This commit is contained in:
Adam Harrison 2021-11-07 15:01:03 -05:00 committed by Guldoman
parent d2cb596740
commit e4b05e6015
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
1 changed files with 4 additions and 4 deletions

View File

@ -672,9 +672,9 @@ static int f_fuzzy_match(lua_State *L) {
int score = 0, run = 0, increment = files ? -1 : 1; int score = 0, run = 0, increment = files ? -1 : 1;
const char* strTarget = files ? str + strLen - 1 : str; const char* strTarget = files ? str + strLen - 1 : str;
const char* ptnTarget = files ? ptn + ptnLen - 1 : ptn; const char* ptnTarget = files ? ptn + ptnLen - 1 : ptn;
while (*strTarget && *ptnTarget) { while (strTarget >= str && ptnTarget >= ptn && *strTarget && *ptnTarget) {
while (*strTarget == ' ') { strTarget += increment; } while (strTarget >= str && *strTarget == ' ') { strTarget += increment; }
while (*ptnTarget == ' ') { ptnTarget += increment; } while (ptnTarget >= ptn && *ptnTarget == ' ') { ptnTarget += increment; }
if (tolower(*strTarget) == tolower(*ptnTarget)) { if (tolower(*strTarget) == tolower(*ptnTarget)) {
score += run * 10 - (*strTarget != *ptnTarget); score += run * 10 - (*strTarget != *ptnTarget);
run++; run++;
@ -685,7 +685,7 @@ static int f_fuzzy_match(lua_State *L) {
} }
strTarget += increment; strTarget += increment;
} }
if (*ptnTarget) { return 0; } if (ptnTarget >= ptn && *ptnTarget) { return 0; }
lua_pushnumber(L, score - (int)strLen * 10); lua_pushnumber(L, score - (int)strLen * 10);
return 1; return 1;
} }