util: Add ParseHex<std::byte>() helper

This commit is contained in:
MarcoFalke
2021-11-10 10:49:58 +01:00
committed by MacroFake
parent fabdf81983
commit fae1006019
3 changed files with 11 additions and 4 deletions

View File

@@ -55,7 +55,9 @@ enum class ByteUnit : uint64_t {
* @return A new string without unsafe chars
*/
std::string SanitizeString(std::string_view str, int rule = SAFE_CHARS_DEFAULT);
std::vector<unsigned char> ParseHex(std::string_view str);
/** Parse the hex string into bytes (uint8_t or std::byte). Ignores whitespace. */
template <typename Byte = uint8_t>
std::vector<Byte> ParseHex(std::string_view str);
signed char HexDigit(char c);
/* Returns true if each character in str is a hex character, and has an even
* number of hex digits.*/