2018-02-12 09:01:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <limits.h>
|
2018-03-16 15:28:37 +00:00
|
|
|
#include <string>
|
2018-03-31 08:01:32 +00:00
|
|
|
#include <string_view>
|
2018-02-12 09:01:02 +00:00
|
|
|
|
2018-03-16 07:19:49 +00:00
|
|
|
class FuzzyMatcher {
|
2018-08-09 17:08:14 +00:00
|
|
|
public:
|
2018-03-16 07:19:49 +00:00
|
|
|
constexpr static int kMaxPat = 100;
|
|
|
|
constexpr static int kMaxText = 200;
|
|
|
|
// Negative but far from INT_MIN so that intermediate results are hard to
|
|
|
|
// overflow.
|
2018-03-18 19:17:40 +00:00
|
|
|
constexpr static int kMinScore = INT_MIN / 4;
|
2018-02-12 09:01:02 +00:00
|
|
|
|
2018-04-14 18:57:23 +00:00
|
|
|
FuzzyMatcher(std::string_view pattern, int case_sensitivity);
|
2018-03-16 07:19:49 +00:00
|
|
|
int Match(std::string_view text);
|
|
|
|
|
2018-08-09 17:08:14 +00:00
|
|
|
private:
|
2018-04-14 18:57:23 +00:00
|
|
|
int case_sensitivity;
|
2018-03-16 07:19:49 +00:00
|
|
|
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);
|
|
|
|
};
|