Reduce include creep

This commit is contained in:
Maxime Coste 2025-04-02 17:45:11 +11:00
parent 63efcc06d5
commit 424a7ee8aa
3 changed files with 8 additions and 9 deletions

View file

@ -261,8 +261,8 @@ bool RankedMatch::operator<(const RankedMatch& other) const
const auto cp2 = utf8::read_codepoint(it2, end2);
if (cp1 != cp2)
{
const auto cplast1 = utf8::prev_codepoint(itsave1, begin1).value_or(Codepoint{0});
const auto cplast2 = utf8::prev_codepoint(itsave2, begin2).value_or(Codepoint{0});
const auto cplast1 = utf8::prev_codepoint(itsave1, begin1);
const auto cplast2 = utf8::prev_codepoint(itsave2, begin2);
const bool is_wb1 = is_word_boundary(cplast1, cp1);
const bool is_wb2 = is_word_boundary(cplast2, cp2);
if (is_wb1 != is_wb2)

View file

@ -6,6 +6,7 @@
#include "utf8.hh"
#include "utf8_iterator.hh"
#include "format.hh"
#include "optional.hh"
#include "vector.hh"
#include "utils.hh"
#include "ranges.hh"

View file

@ -4,7 +4,6 @@
#include "assert.hh"
#include "unicode.hh"
#include "units.hh"
#include "optional.hh"
namespace Kakoune
{
@ -263,14 +262,13 @@ Iterator character_start(Iterator it, const Sentinel& begin) noexcept
return it;
}
// returns an optional iterator to the first byte of the previous character
// or no value if it is at begin
template<typename Iterator, typename Sentinel>
static Optional<Codepoint> prev_codepoint(Iterator it, const Sentinel& begin) noexcept
template<typename InvalidPolicy = utf8::InvalidPolicy::Pass,
typename Iterator, typename Sentinel>
Codepoint prev_codepoint(Iterator it, const Sentinel& begin) noexcept
{
if (it <= begin)
return {};
return codepoint(character_start(it -1, begin), it);
return InvalidPolicy{}(-1);
return codepoint<InvalidPolicy>(character_start(it -1, begin), it);
}