From aa2910208f6aae99d01fc2c09ac5bd492cd06c5a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 16 Mar 2018 08:28:37 -0700 Subject: [PATCH] Fix g++ build --- src/fuzzy_match.cc | 21 +++++++++++---------- src/fuzzy_match.h | 6 ++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/fuzzy_match.cc b/src/fuzzy_match.cc index 91f54d2d..db5a5d5f 100644 --- a/src/fuzzy_match.cc +++ b/src/fuzzy_match.cc @@ -3,11 +3,11 @@ #include #include -enum FuzzyMatcher::CharClass : int { Other, Lower, Upper }; -enum FuzzyMatcher::CharRole : int { None, Tail, Head }; +enum CharClass { Other, Lower, Upper }; +enum CharRole { None, Tail, Head }; namespace { -FuzzyMatcher::CharClass GetCharClass(int c) { +CharClass GetCharClass(int c) { if (islower(c)) return Lower; if (isupper(c)) @@ -15,14 +15,12 @@ FuzzyMatcher::CharClass GetCharClass(int c) { return Other; } -void CalculateRoles(std::string_view s, - FuzzyMatcher::CharRole roles[], - int* class_set) { +void CalculateRoles(std::string_view s, int roles[], int* class_set) { if (s.empty()) { *class_set = 0; return; } - FuzzyMatcher::CharClass pre = Other, cur = GetCharClass(s[0]), suc; + CharClass pre = Other, cur = GetCharClass(s[0]), suc; *class_set = 1 << cur; auto fn = [&]() { if (cur == Other) @@ -52,8 +50,11 @@ int FuzzyMatcher::MissScore(int j, bool last) { int FuzzyMatcher::MatchScore(int i, int j, bool last) { int s = 40; - if ((pat[i] == text[j] && ((pat_set & 1 << Upper) || i == j))) - s += 20; + if (pat[i] == text[j]) { + s++; + if ((pat_set & 1 << Upper) || i == j) + s += 20; + } if (pat_role[i] == Head && text_role[j] == Head) s += 50; if (text_role[j] == Tail && i && !last) @@ -93,7 +94,7 @@ int FuzzyMatcher::Match(std::string_view text) { } for (int i = 0; i < int(pat.size()); i++) { int(*pre)[2] = dp[i & 1]; - int(*cur)[2] = dp[i + 1 & 1]; + int(*cur)[2] = dp[(i + 1) & 1]; cur[0][0] = cur[0][1] = kMinScore; for (int j = 0; j < n; j++) { cur[j + 1][0] = std::max(cur[j][0] + MissScore(j, false), diff --git a/src/fuzzy_match.h b/src/fuzzy_match.h index 26bb59ee..a3b5191c 100644 --- a/src/fuzzy_match.h +++ b/src/fuzzy_match.h @@ -3,6 +3,7 @@ #include #include +#include class FuzzyMatcher { public: @@ -15,15 +16,12 @@ public: FuzzyMatcher(std::string_view pattern); int Match(std::string_view text); - enum CharClass : int; - enum CharRole : int; - private: std::string pat; std::string_view text; int pat_set, text_set; char low_pat[kMaxPat], low_text[kMaxText]; - CharRole pat_role[kMaxPat], text_role[kMaxText]; + int pat_role[kMaxPat], text_role[kMaxText]; int dp[2][kMaxText + 1][2]; int MatchScore(int i, int j, bool last);