Ada 2.9.2
Fast spec-compliant URL parser
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 <algorithm>
8#include "ada/unicode.h"
9
18namespace ada::unicode {
19ada_really_inline size_t percent_encode_index(const std::string_view input,
20 const uint8_t character_set[]) {
21 const char* data = input.data();
22 const size_t size = input.size();
23
24 // Process 8 bytes at a time using unrolled loop
25 size_t i = 0;
26 for (; i + 8 <= size; i += 8) {
27 unsigned char chunk[8];
28 std::memcpy(&chunk, data + i,
29 8); // entices compiler to unconditionally process 8 characters
30
31 // Check 8 characters at once
32 for (size_t j = 0; j < 8; j++) {
33 if (character_sets::bit_at(character_set, chunk[j])) {
34 return i + j;
35 }
36 }
37 }
38
39 // Handle remaining bytes
40 for (; i < size; i++) {
41 if (character_sets::bit_at(character_set, data[i])) {
42 return i;
43 }
44 }
45
46 return size;
47}
48} // namespace ada::unicode
49
50#endif // ADA_UNICODE_INL_H
#define ada_really_inline
Definition common_defs.h:77
ada_really_inline constexpr bool bit_at(const uint8_t a[], const uint8_t i)
Includes the declarations for unicode operations.
ada_really_inline size_t percent_encode_index(const std::string_view input, const uint8_t character_set[])
Definition unicode-inl.h:19
Definitions for all unicode specific functions.