kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

ranked_match.hh (1807B)


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