2015-10-22 21:49:08 +03:00
|
|
|
#ifndef ranked_match_hh_INCLUDED
|
|
|
|
#define ranked_match_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "string.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2016-03-25 23:35:57 +03:00
|
|
|
using UsedLetters = uint64_t;
|
|
|
|
UsedLetters used_letters(StringView str);
|
|
|
|
|
|
|
|
constexpr UsedLetters upper_mask = 0xFFFFFFC000000;
|
|
|
|
|
|
|
|
inline UsedLetters to_lower(UsedLetters letters)
|
|
|
|
{
|
|
|
|
return ((letters & upper_mask) >> 26) | (letters & (~upper_mask));
|
|
|
|
}
|
|
|
|
|
2015-10-22 21:49:08 +03:00
|
|
|
struct RankedMatch
|
|
|
|
{
|
2015-10-28 00:25:18 +03:00
|
|
|
RankedMatch(StringView candidate, StringView query);
|
2016-03-25 23:35:57 +03:00
|
|
|
RankedMatch(StringView candidate, UsedLetters candidate_letters,
|
|
|
|
StringView query, UsedLetters query_letters);
|
2015-10-28 00:25:18 +03:00
|
|
|
|
|
|
|
const StringView& candidate() const { return m_candidate; }
|
|
|
|
bool operator<(const RankedMatch& other) const;
|
|
|
|
bool operator==(const RankedMatch& other) const { return m_candidate == other.m_candidate; }
|
|
|
|
|
|
|
|
explicit operator bool() const { return not m_candidate.empty(); }
|
|
|
|
|
|
|
|
private:
|
2016-03-25 23:35:57 +03:00
|
|
|
template<typename TestFunc>
|
|
|
|
RankedMatch(StringView candidate, StringView query, TestFunc test);
|
|
|
|
|
2015-10-28 00:25:18 +03:00
|
|
|
StringView m_candidate;
|
2015-10-29 16:36:30 +03:00
|
|
|
bool m_first_char_match = false;
|
|
|
|
bool m_prefix = false;
|
|
|
|
int m_word_boundary_match_count = 0;
|
2016-03-25 01:04:56 +03:00
|
|
|
int m_match_index_sum = 0;
|
2015-10-29 16:36:30 +03:00
|
|
|
bool m_only_word_boundary = false;
|
2015-10-22 21:49:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ranked_match_hh_INCLUDED
|