Ada
4.1.1
Fast spec-compliant URL parser
Toggle main menu visibility
Loading...
Searching...
No Matches
unicode-inl.h
Go to the documentation of this file.
1
5
#ifndef ADA_UNICODE_INL_H
6
#define ADA_UNICODE_INL_H
7
#include "
ada/unicode.h
"
8
#include "
ada/character_sets.h
"
9
10
#include <cstddef>
11
#include <cstdint>
12
#include <cstring>
13
#include <string_view>
14
23
namespace
ada::unicode
{
24
ada_really_inline
size_t
percent_encode_index
(
const
std::string_view input,
25
const
uint8_t character_set[]) {
26
const
char
* data = input.data();
27
const
size_t
size = input.size();
28
29
// Process 8 bytes at a time using unrolled loop
30
size_t
i = 0;
31
for
(; i + 8 <= size; i += 8) {
32
unsigned
char
chunk[8];
33
std::memcpy(&chunk, data + i,
34
8);
// entices compiler to unconditionally process 8 characters
35
36
// Check 8 characters at once
37
for
(
size_t
j = 0; j < 8; j++) {
38
if
(
character_sets::bit_at
(character_set, chunk[j])) {
39
return
i + j;
40
}
41
}
42
}
43
44
// Handle remaining bytes
45
for
(; i < size; i++) {
46
if
(
character_sets::bit_at
(character_set, data[i])) {
47
return
i;
48
}
49
}
50
51
return
size;
52
}
53
}
// namespace ada::unicode
54
55
#endif
// ADA_UNICODE_INL_H
character_sets.h
Declaration of the character sets used by unicode functions.
ada_really_inline
#define ada_really_inline
Definition
common_defs.h:85
ada::character_sets::bit_at
ada_really_inline constexpr bool bit_at(const uint8_t a[], const uint8_t i)
Definition
character_sets-inl.h:517
ada::unicode
Includes the declarations for unicode operations.
ada::unicode::percent_encode_index
ada_really_inline size_t percent_encode_index(const std::string_view input, const uint8_t character_set[])
Definition
unicode-inl.h:24
unicode.h
Definitions for all unicode specific functions.