2015-10-22 20:49:08 +02:00
|
|
|
#ifndef ranked_match_hh_INCLUDED
|
|
|
|
#define ranked_match_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "string.hh"
|
2017-03-15 18:55:34 +01:00
|
|
|
#include "meta.hh"
|
2015-10-22 20:49:08 +02:00
|
|
|
|
2023-03-01 04:36:44 +01:00
|
|
|
#include <cstdint>
|
|
|
|
|
2015-10-22 20:49:08 +02:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2016-03-25 21:35:57 +01: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 20:49:08 +02:00
|
|
|
struct RankedMatch
|
|
|
|
{
|
2015-10-27 22:25:18 +01:00
|
|
|
RankedMatch(StringView candidate, StringView query);
|
2016-03-25 21:35:57 +01:00
|
|
|
RankedMatch(StringView candidate, UsedLetters candidate_letters,
|
|
|
|
StringView query, UsedLetters query_letters);
|
2015-10-27 22:25:18 +01: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; }
|
|
|
|
|
2022-11-12 12:37:35 +01:00
|
|
|
explicit operator bool() const { return m_matches; }
|
2015-10-27 22:25:18 +01:00
|
|
|
|
|
|
|
private:
|
2016-03-25 21:35:57 +01:00
|
|
|
template<typename TestFunc>
|
|
|
|
RankedMatch(StringView candidate, StringView query, TestFunc test);
|
|
|
|
|
2016-08-30 00:56:22 +02:00
|
|
|
enum class Flags : int
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
// Order is important, the highest bit has precedence for comparison
|
2016-11-14 20:14:09 +01:00
|
|
|
FirstCharMatch = 1 << 0,
|
|
|
|
SingleWord = 1 << 1,
|
|
|
|
Contiguous = 1 << 2,
|
|
|
|
OnlyWordBoundary = 1 << 3,
|
|
|
|
Prefix = 1 << 4,
|
2017-07-19 20:18:47 +02:00
|
|
|
SmartFullMatch = 1 << 5,
|
|
|
|
FullMatch = 1 << 6,
|
2016-08-30 00:56:22 +02:00
|
|
|
};
|
2017-03-15 18:55:34 +01:00
|
|
|
friend constexpr bool with_bit_ops(Meta::Type<Flags>) { return true; }
|
2016-08-30 00:56:22 +02:00
|
|
|
|
2017-01-29 14:49:45 +01:00
|
|
|
StringView m_candidate{};
|
2022-11-12 12:37:35 +01:00
|
|
|
bool m_matches = false;
|
2016-08-30 00:56:22 +02:00
|
|
|
Flags m_flags = Flags::None;
|
2015-10-29 14:36:30 +01:00
|
|
|
int m_word_boundary_match_count = 0;
|
2016-08-30 01:30:15 +02:00
|
|
|
int m_max_index = 0;
|
2015-10-22 20:49:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ranked_match_hh_INCLUDED
|