fuzzy_match: a pattern prefixed with a letter should not match underscore prefixed builtin names

This commit is contained in:
Fangrui Song 2018-12-20 00:00:42 -08:00
parent 8c16324964
commit 9d7a1e3bb3

View File

@ -108,6 +108,8 @@ FuzzyMatcher::FuzzyMatcher(std::string_view pattern, int sensitivity) {
}
int FuzzyMatcher::Match(std::string_view text) {
if (pat.empty() != text.empty())
return kMinScore;
int n = int(text.size());
if (n > kMaxText)
return kMinScore + 1;
@ -115,6 +117,8 @@ int FuzzyMatcher::Match(std::string_view text) {
for (int i = 0; i < n; i++)
low_text[i] = ::tolower(text[i]);
CalculateRoles(text, text_role, &text_set);
if (n && !!pat_role[0] != !!text_role[0])
return kMinScore;
dp[0][0][0] = dp[0][0][1] = 0;
for (int j = 0; j < n; j++) {
dp[0][j + 1][0] = dp[0][j][0] + MissScore(j, false);