ccls/src/fuzzy_match.h

30 lines
685 B
C
Raw Normal View History

#pragma once
#include <string_view.h>
#include <limits.h>
2018-03-16 15:28:37 +00:00
#include <string>
2018-03-16 07:19:49 +00:00
class FuzzyMatcher {
public:
constexpr static int kMaxPat = 100;
constexpr static int kMaxText = 200;
// Negative but far from INT_MIN so that intermediate results are hard to
// overflow.
constexpr static int kMinScore = INT_MIN / 2;
2018-03-16 07:19:49 +00:00
FuzzyMatcher(std::string_view pattern);
int Match(std::string_view text);
private:
std::string pat;
std::string_view text;
int pat_set, text_set;
char low_pat[kMaxPat], low_text[kMaxText];
2018-03-16 15:28:37 +00:00
int pat_role[kMaxPat], text_role[kMaxText];
2018-03-16 07:19:49 +00:00
int dp[2][kMaxText + 1][2];
int MatchScore(int i, int j, bool last);
int MissScore(int j, bool last);
};