mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
AK/Hex: Decode hex digit in constexpr context
Problem: - Hex digit decoding is not `constexpr`, but can be. Solution: - Move the body of the function to the header and decorate with `constexpr`. - Provide tests for run-time and compile-time evaluation.
This commit is contained in:
parent
0ac02b9084
commit
d462a56163
4 changed files with 94 additions and 14 deletions
11
AK/Hex.cpp
11
AK/Hex.cpp
|
@ -35,17 +35,6 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
u8 decode_hex_digit(char digit)
|
||||
{
|
||||
if (digit >= '0' && digit <= '9')
|
||||
return digit - '0';
|
||||
if (digit >= 'a' && digit <= 'f')
|
||||
return 10 + (digit - 'a');
|
||||
if (digit >= 'A' && digit <= 'F')
|
||||
return 10 + (digit - 'A');
|
||||
return 255;
|
||||
}
|
||||
|
||||
Optional<ByteBuffer> decode_hex(const StringView& input)
|
||||
{
|
||||
if ((input.length() % 2) != 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue