diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/string/hex.h | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string/hex.h')
-rw-r--r-- | util/string/hex.h | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/util/string/hex.h b/util/string/hex.h index af3d2d528f..84f22ae97e 100644 --- a/util/string/hex.h +++ b/util/string/hex.h @@ -1,35 +1,35 @@ #pragma once - + #include <util/generic/string.h> #include <util/generic/yexception.h> #include <util/system/yassert.h> - -inline static char DigitToChar(unsigned char digit) { - if (digit < 10) { - return (char)digit + '0'; - } - - return (char)(digit - 10) + 'A'; -} - -extern const char* const Char2DigitTable; - -inline static int Char2Digit(char ch) { + +inline static char DigitToChar(unsigned char digit) { + if (digit < 10) { + return (char)digit + '0'; + } + + return (char)(digit - 10) + 'A'; +} + +extern const char* const Char2DigitTable; + +inline static int Char2Digit(char ch) { char result = Char2DigitTable[(unsigned char)ch]; Y_ENSURE(result != '\xff', "invalid hex character " << (int)ch); return result; -} - +} + //! Convert a hex string of exactly 2 chars to int /*! @example String2Byte("10") => 16 */ inline static int String2Byte(const char* s) { - return Char2Digit(*s) * 16 + Char2Digit(*(s + 1)); -} - + return Char2Digit(*s) * 16 + Char2Digit(*(s + 1)); +} + char* HexEncode(const void* in, size_t len, char* out); - + TString HexEncode(const void* in, size_t len); - + inline TString HexEncode(const TStringBuf h) { return HexEncode(h.data(), h.size()); } |