diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-10-30 13:57:46 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-10-30 13:57:46 +0000 |
| commit | 2bf44b6b49dc9bf52ee424da6decdd5c8fcae665 (patch) | |
| tree | d1871e3eb04bfd4f154b09a466aadb1a8dfd1fe0 /src/ranked_match.cc | |
| parent | 92c3aa4d31e07c6681c2267cbef6ebc069195ba2 (diff) | |
Make word insert completion work better with unicode char
Diffstat (limited to 'src/ranked_match.cc')
| -rw-r--r-- | src/ranked_match.cc | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/ranked_match.cc b/src/ranked_match.cc index 9acaa8b4..a55df314 100644 --- a/src/ranked_match.cc +++ b/src/ranked_match.cc @@ -1,55 +1,59 @@ #include "ranked_match.hh" +#include "utf8_iterator.hh" #include "unit_tests.hh" namespace Kakoune { +using Utf8It = utf8::iterator<const char*>; + static int count_word_boundaries_match(StringView candidate, StringView query) { int count = 0; - auto it = query.begin(); - char prev = 0; - for (auto c : candidate) + Utf8It qit{query.begin(), query}; + Codepoint prev = 0; + for (Utf8It it{candidate.begin(), candidate}; it != candidate.end(); ++it) { + const Codepoint c = *it; const bool is_word_boundary = prev == 0 or - (ispunct(prev) and is_word(c)) or + (!iswalnum(prev) and iswalnum(c)) or (islower(prev) and isupper(c)); prev = c; if (not is_word_boundary) continue; - const char lc = tolower(c); - for (; it != query.end(); ++it) + const Codepoint lc = tolower(c); + for (; qit != query.end(); ++qit) { - const char qc = *it; + const Codepoint qc = *qit; if (qc == (islower(qc) ? lc : c)) { ++count; - ++it; + ++qit; break; } } - if (it == query.end()) + if (qit == query.end()) break; } return count; } -static bool smartcase_eq(char query, char candidate) +static bool smartcase_eq(Codepoint query, Codepoint candidate) { return query == (islower(query) ? tolower(candidate) : candidate); } static bool subsequence_match_smart_case(StringView str, StringView subseq) { - auto it = str.begin(); - for (auto& c : subseq) + Utf8It it{str.begin(), str}; + for (Utf8It subseq_it{subseq.begin(), subseq}; subseq_it != subseq.end(); ++subseq_it) { if (it == str.end()) return false; - while (not smartcase_eq(c, *it)) + while (not smartcase_eq(*subseq_it, *it)) { if (++it == str.end()) return false; @@ -98,9 +102,9 @@ bool RankedMatch::operator<(const RankedMatch& other) const return m_first_char_match; return std::lexicographical_compare( - m_candidate.begin(), m_candidate.end(), - other.m_candidate.begin(), other.m_candidate.end(), - [](char a, char b) { + Utf8It{m_candidate.begin(), m_candidate}, Utf8It{m_candidate.end(), m_candidate}, + Utf8It{other.m_candidate.begin(), other.m_candidate}, Utf8It{other.m_candidate.end(), other.m_candidate}, + [](Codepoint a, Codepoint b) { const bool low_a = islower(a), low_b = islower(b); return low_a == low_b ? a < b : low_a; }); |
