ccls/src/fuzzy_match.hh

35 lines
841 B
C++
Raw Normal View History

2018-08-21 05:27:52 +00:00
// Copyright 2017-2018 ccls Authors
// SPDX-License-Identifier: Apache-2.0
#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>
namespace ccls {
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;
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:
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);
};
} // namespace ccls