Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/ada/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ ada_really_inline constexpr bool is_single_dot_path_segment(
ada_really_inline constexpr bool is_lowercase_hex(const char c) noexcept;

/**
* @details Convert hex to binary.
* @details Convert hex to binary. Caller is responsible to ensure that
* the parameter is an hexadecimal digit (0-9, A-F, a-f).
*/
unsigned constexpr convert_hex_to_binary(char c) noexcept;

Expand Down
11 changes: 5 additions & 6 deletions src/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,12 @@ ada_really_inline constexpr bool is_lowercase_hex(const char c) noexcept {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
}

constexpr static char hex_to_binary_table[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11,
12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15};
unsigned constexpr convert_hex_to_binary(const char c) noexcept {
// this code can be optimized.
if (c <= '9') {
return c - '0';
}
char del = c >= 'a' ? 'a' : 'A';
return 10 + (c - del);
return hex_to_binary_table[c - '0'];
}

std::string percent_decode(const std::string_view input, size_t first_percent) {
Expand Down