8#include "../assert.hpp"
11#include "../unicode/unicode_description.hpp"
16namespace hi::inline v1 {
32 constexpr text_cursor(
size_t index,
bool after,
size_t size)
noexcept
38 }
else if (
static_cast<ptrdiff_t
>(index) < 0) {
42 }
else if (index >= size) {
48 _value = (index << 1) | static_cast<size_t>(after);
60 return {index() - 1,
true, size};
62 return {index() + 1,
false, size};
66 [[nodiscard]]
constexpr text_cursor after_neighbor(
size_t size)
const noexcept
68 return before() ? neighbor(size) : *this;
71 [[nodiscard]]
constexpr text_cursor before_neighbor(
size_t size)
const noexcept
73 return after() ? neighbor(size) : *this;
76 [[nodiscard]]
constexpr bool start_of_text() const noexcept
81 [[nodiscard]]
constexpr bool end_of_text(
size_t size)
const noexcept
83 return size == 0 or (index() == size - 1 and after()) or index() >= size;
86 [[nodiscard]] constexpr
size_t index() const noexcept
91 [[nodiscard]]
constexpr bool after() const noexcept
93 return static_cast<bool>(_value & 1);
96 [[nodiscard]]
constexpr bool before() const noexcept
101 [[nodiscard]]
constexpr friend bool operator==(text_cursor
const &, text_cursor
const &) =
default;
102 [[nodiscard]]
constexpr friend auto operator<=>(text_cursor
const &, text_cursor
const &) =
default;
This file includes required definitions.
Definition text_cursor.hpp:18
constexpr text_cursor neighbor(size_t size) const noexcept
Return the neighbor cursor.
Definition text_cursor.hpp:57
constexpr text_cursor(size_t index, bool after, size_t size) noexcept
Create a new text cursor.
Definition text_cursor.hpp:32