1 #ifndef ranked_match_hh_INCLUDED
2 #define ranked_match_hh_INCLUDED
3
4 #include "string.hh"
5 #include "meta.hh"
6
7 namespace Kakoune
8 {
9
10 using UsedLetters = uint64_t;
11 UsedLetters used_letters(StringView str);
12
13 constexpr UsedLetters upper_mask = 0xFFFFFFC000000;
14
to_lower(UsedLetters letters)15 inline UsedLetters to_lower(UsedLetters letters)
16 {
17 return ((letters & upper_mask) >> 26) | (letters & (~upper_mask));
18 }
19
20 struct RankedMatch
21 {
22 RankedMatch(StringView candidate, StringView query);
23 RankedMatch(StringView candidate, UsedLetters candidate_letters,
24 StringView query, UsedLetters query_letters);
25
candidateKakoune::RankedMatch26 const StringView& candidate() const { return m_candidate; }
27 bool operator<(const RankedMatch& other) const;
operator ==Kakoune::RankedMatch28 bool operator==(const RankedMatch& other) const { return m_candidate == other.m_candidate; }
29
operator boolKakoune::RankedMatch30 explicit operator bool() const { return not m_candidate.empty(); }
31
32 private:
33 template<typename TestFunc>
34 RankedMatch(StringView candidate, StringView query, TestFunc test);
35
36 enum class Flags : int
37 {
38 None = 0,
39 // Order is important, the highest bit has precedence for comparison
40 FirstCharMatch = 1 << 0,
41 SingleWord = 1 << 1,
42 Contiguous = 1 << 2,
43 OnlyWordBoundary = 1 << 3,
44 Prefix = 1 << 4,
45 SmartFullMatch = 1 << 5,
46 FullMatch = 1 << 6,
47 };
with_bit_ops(Meta::Type<Flags>)48 friend constexpr bool with_bit_ops(Meta::Type<Flags>) { return true; }
49
50 StringView m_candidate{};
51 Flags m_flags = Flags::None;
52 int m_word_boundary_match_count = 0;
53 int m_max_index = 0;
54 };
55
56 }
57
58 #endif // ranked_match_hh_INCLUDED
59