account for uppercase hex

This commit is contained in:
Green Sky 2024-01-27 12:10:56 +01:00
parent db57a7c5e9
commit 390b123fb7
No known key found for this signature in database

View File

@ -4,12 +4,14 @@
namespace detail {
constexpr uint8_t nib_from_hex(char c) {
assert((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'));
assert((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
if (c >= '0' && c <= '9') {
return static_cast<uint8_t>(c) - '0';
} else if (c >= 'a' && c <= 'f') {
return (static_cast<uint8_t>(c) - 'a') + 10u;
} else if (c >= 'A' && c <= 'F') {
return (static_cast<uint8_t>(c) - 'A') + 10u;
} else {
return 0u;
}