43static char32_t utf8_next(
const uint8_t*& ptr)
noexcept {
45 if (b0 < 0x80u)
return static_cast<char32_t>(b0);
47 uint32_t cp = (b0 & 0x1Fu) << 6;
48 cp |= (*ptr++ & 0x3Fu);
49 return static_cast<char32_t>(cp);
52 uint32_t cp = (b0 & 0x0Fu) << 12;
53 cp |= ((*ptr++ & 0x3Fu) << 6);
54 cp |= (*ptr++ & 0x3Fu);
55 return static_cast<char32_t>(cp);
57 uint32_t cp = (b0 & 0x07u) << 18;
58 cp |= ((*ptr++ & 0x3Fu) << 12);
59 cp |= ((*ptr++ & 0x3Fu) << 6);
60 cp |= (*ptr++ & 0x3Fu);
61 return static_cast<char32_t>(cp);
71 }
else if (*ptr < 0xE0u) {
73 }
else if (*ptr < 0xF0u) {
83void ascii_map(
char* input,
size_t length) {
84 auto broadcast = [](uint8_t v) -> uint64_t {
85 return 0x101010101010101ull * v;
87 uint64_t broadcast_80 = broadcast(0x80);
88 uint64_t broadcast_Ap = broadcast(128 -
'A');
89 uint64_t broadcast_Zp = broadcast(128 -
'Z' - 1);
92 for (; i + 7 < length; i += 8) {
94 std::memcpy(&word, input + i,
sizeof(word));
96 (((word + broadcast_Ap) ^ (word + broadcast_Zp)) & broadcast_80) >> 2;
97 std::memcpy(input + i, &word,
sizeof(word));
101 std::memcpy(&word, input + i, length - i);
103 (((word + broadcast_Ap) ^ (word + broadcast_Zp)) & broadcast_80) >> 2;
104 std::memcpy(input + i, &word, length - i);
110bool map(std::u32string_view input, std::u32string& out) {
119 for (
char32_t x : input) {
120 uint16_t status =
idna_lookup(
static_cast<uint32_t
>(x));
135 out.resize(out_size);
137 for (
char32_t x : input) {
138 uint16_t status =
idna_lookup(
static_cast<uint32_t
>(x));
152std::u32string
map(std::u32string_view input) {
153 std::u32string answer;
154 if (!
map(input, answer)) {
void ascii_map(char *input, size_t length)
constexpr uint32_t IDNA_BLOCK_MASK
constexpr uint16_t IDNA_BOOL_FLAG
constexpr uint32_t IDNA_BLOCK_BITS
static uint16_t idna_lookup(uint32_t cp) noexcept
constexpr uint32_t IDNA_BLOCK_SIZE
constexpr uint16_t IDNA_VALID
static size_t utf8_count_codepoints(const uint8_t *ptr) noexcept
const uint16_t * idna_stage2
const uint16_t * idna_stage1
constexpr uint32_t IDNA_HIGH_IGNORED_START
bool ensure_tables() noexcept
constexpr uint32_t IDNA_LOW_RANGE_END
constexpr uint16_t IDNA_IGNORED
static char32_t utf8_next(const uint8_t *&ptr) noexcept
constexpr uint32_t IDNA_HIGH_IGNORED_END
std::u32string map(std::u32string_view input)
constexpr size_t idna_utf8_mappings_size
const uint8_t * idna_utf8_mappings
constexpr uint16_t IDNA_DISALLOWED
const uint64_t * idna_bool_blocks