in krabs/krabs/guid.hpp [169:211]
inline bool guid_parser::hex_octet_to_byte(const char* str_input, unsigned char& byte_output)
{
// Accepts chars '0' through '9' (0x30 to 0x39),
// 'A' through 'F' (0x41 to 0x46)
// 'a' through 'f' (0x61 to 0x66)
// Narrow the value later, for safety checking.
auto value = 0;
// most significant digit in the octet
auto msd = str_input[0];
// least significant digit in the octet
auto lsd = str_input[1];
if (msd >= '0' && msd <= '9')
{
value |= ((int)msd & 0x0F) << 4;
}
else if ((msd >= 'A' && msd <= 'F') || (msd >= 'a' && msd <= 'f'))
{
value |= (((int)msd & 0x0F) + 9) << 4;
}
else
{
return false;
}
if (lsd >= '0' && lsd <= '9')
{
value |= ((int)lsd & 0x0F);
}
else if ((lsd >= 'A' && lsd <= 'F') || (lsd >= 'a' && lsd <= 'f'))
{
value |= (((int)lsd & 0x0F) + 9);
}
else
{
return false;
}
assert(value >= 0 && value <= UCHAR_MAX);
byte_output = static_cast<unsigned char>(value);
return true;
}