11#ifndef REAL_ASSERT_EVAL_HPP
12#define REAL_ASSERT_EVAL_HPP
30 [[nodiscard]]
constexpr bool word_before(std::string_view text,
37 const auto prev {
static_cast<std::uint8_t
>(text[pos - 1])};
40 if (prev < 0x80U || ascii_word) {
43 std::size_t i {pos - 1};
44 std::size_t steps {0};
45 while (i > 0 && (
static_cast<std::uint8_t
>(text[i]) & 0xC0U) == 0x80U && steps < 3) {
50 if (!dc.valid || i + dc.length != pos) {
58 [[nodiscard]]
constexpr bool word_after(std::string_view text,
62 if (pos >= text.size()) {
65 const auto here {
static_cast<std::uint8_t
>(text[pos])};
66 if (here < 0x80U || ascii_word) {
82 std::string_view text,
86 const std::size_t len {text.size()};
87 const auto byte_at = [&](std::size_t i) {
return static_cast<std::uint8_t
>(text[i]); };
97 result = pos == len || (pos + 1 == len && byte_at(pos) ==
'\n');
100 result = pos == 0 || byte_at(pos - 1) ==
'\n';
103 result = pos == len || byte_at(pos) ==
'\n';
108 const bool before {
word_before(text, pos, ascii_word)};
109 const bool after {
word_after(text, pos, ascii_word)};
116 const bool before {
word_before(text, pos, ascii_word)};
117 const bool after {
word_after(text, pos, ascii_word)};
256-bit byte set with O(1) membership, fully constexpr.
constexpr decoded_codepoint decode_codepoint_strict(std::string_view text, std::size_t pos)
Strictly decodes and validates the UTF-8 sequence at text[pos].
constexpr bool word_after(std::string_view text, std::size_t pos, bool ascii_word)
Word-ness of the code point starting at pos — the right side of a boundary. False at the text end or ...
constexpr bool word_before(std::string_view text, std::size_t pos, bool ascii_word)
Word-ness of the code point ending at pos — the left side of a boundary. False at the text start or o...
constexpr bool is_word_cp(char32_t cp)
Whether cp is a Unicode word / digit / whitespace code point (== re \w/\d/\s).
constexpr bool is_ascii_word_byte(std::uint8_t byte)
Reports whether byte is an ASCII "word" byte ([0-9A-Za-z_]).
constexpr bool assertion_holds(assert_kind kind, std::string_view text, std::size_t pos, bool ascii_word)
Evaluates a zero-width assertion at pos in text.
assert_kind
Kind of zero-width assertion carried in assert_position's arg8.
@ word_start
< (non-word/start on the left, word on the right).
@ word_end
> (word on the left, non-word/end on the right).
@ line_start
^ with multiline.
@ line_end
$ with multiline.
@ word_boundary
\b (Unicode word-ness in text mode; ASCII in bytes / re.A).
@ text_start
\A, and ^ without multiline.
@ text_end_or_final_newline
$ without multiline (Python semantics).
Compiled form of a pattern and the public flags / error types.
The result of a strict UTF-8 decode: the code point, its byte length, and validity.
bool valid
Whether the sequence is a well-formed, canonical code point.
Unicode \w / \d / \s property ranges and their lookups.
UTF-8 position arithmetic for match iteration.