9#ifndef REAL_CHARCLASS_HPP
10#define REAL_CHARCLASS_HPP
31 std::array<std::uint64_t, 4>
bits {};
37 constexpr void set(std::uint8_t
byte)
39 const unsigned bit {
byte};
40 bits[bit >> 6U] |= std::uint64_t {1} << (bit & 63U);
55 for (
unsigned word = 0; word <
bits.size(); ++word) {
56 const unsigned word_low {word * 64U};
57 const unsigned word_high {word_low + 63U};
58 if (high < word_low || low > word_high) {
61 const unsigned a {low > word_low ? low - word_low : 0U};
62 const unsigned b {high < word_high ? high - word_low : 63U};
63 bits[word] |= (b - a == 63U)
65 : (((std::uint64_t {1} << (b - a + 1U)) - 1U) << a);
75 for (std::size_t i = 0; i <
bits.size(); ++i) {
97 for (
auto& word :
bits) {
107 [[nodiscard]]
constexpr bool test(std::uint8_t
byte)
const
109 const unsigned bit {
byte};
110 return ((
bits[bit >> 6U] >> (bit & 63U)) & 1U) != 0;
117 [[nodiscard]]
constexpr bool empty()
const
136 for (std::uint8_t upper =
'A'; upper <=
'Z'; ++upper) {
137 const auto lower {
static_cast<std::uint8_t
>(upper + 32)};
138 if (
klass.test(upper)) {
141 if (
klass.test(lower)) {
154 return (
byte >=
'0' &&
byte <=
'9') || (
byte >=
'A' &&
byte <=
'Z') ||
155 (
byte >=
'a' &&
byte <=
'z') ||
byte ==
'_';
201 result.
set(
char {0x1C});
202 result.
set(
char {0x1D});
203 result.
set(
char {0x1E});
204 result.
set(
char {0x1F});
constexpr char_class digit_set()
The ASCII digit set behind \d (Python re.ASCII semantics).
constexpr char_class utf8_lead3_set()
The lead-byte set of a 3-byte UTF-8 sequence.
constexpr char_class word_set()
The ASCII word set behind \w.
constexpr void fold_ascii_case(char_class &klass)
Closes klass under ASCII case folding.
constexpr char_class utf8_lead2_set()
The lead-byte set of a 2-byte UTF-8 sequence.
constexpr char_class utf8_lead4_set()
The lead-byte set of a 4-byte UTF-8 sequence.
constexpr char_class utf8_cont_set()
The UTF-8 continuation-byte set 10xxxxxx.
constexpr bool is_ascii_word_byte(std::uint8_t byte)
Reports whether byte is an ASCII "word" byte ([0-9A-Za-z_]).
constexpr char_class space_set()
The ASCII whitespace set behind \s.
@ klass
Consume one byte in classes[arg16]; fall through to pc+1.
A set of byte values (0–255) as a 256-bit bitmap.
constexpr void merge(const char_class &other)
Unions other into this set.
constexpr void set_range(std::uint8_t low, std::uint8_t high)
Adds the inclusive byte range [low, high] to the set.
constexpr bool test(std::uint8_t byte) const
Tests membership of byte byte.
constexpr void invert()
Full 256-bit complement (binary mode: raw bytes, no UTF-8).
constexpr bool operator==(const char_class &) const =default
constexpr void set(std::uint8_t byte)
Adds byte byte to the set.
constexpr bool empty() const
Reports whether the set has no members.
std::array< std::uint64_t, 4 > bits
Bitmap; bit byte is byte byte's membership.
constexpr void invert_ascii()
Complements the ASCII half (bytes 0–127) only.
REAL's version macros and the C++20 language-standard guard.