diff options
author | dobrokot <dobrokot@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
commit | 8d57b69dee81198a59c39e64704f7dc9f04b4fbf (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util/string/hex.cpp | |
parent | 25d83bf841d8b3ce3886525078f1964ac3c293c5 (diff) | |
download | ydb-8d57b69dee81198a59c39e64704f7dc9f04b4fbf.tar.gz |
Restoring authorship annotation for <dobrokot@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/string/hex.cpp')
-rw-r--r-- | util/string/hex.cpp | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/util/string/hex.cpp b/util/string/hex.cpp index deea4e3ba7..667397987f 100644 --- a/util/string/hex.cpp +++ b/util/string/hex.cpp @@ -1,5 +1,5 @@ -#include "hex.h" - +#include "hex.h" + const char* const Char2DigitTable = ("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" @@ -16,48 +16,48 @@ const char* const Char2DigitTable = ("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"); - -char* HexEncode(const void* in, size_t len, char* out) { - const unsigned char* b = (const unsigned char*)in; - const unsigned char* e = b + len; - - while (b != e) { - *out++ = DigitToChar(*b / 16); - *out++ = DigitToChar(*b++ % 16); - } - - return out; -} - -void* HexDecode(const void* in, size_t len, void* ptr) { - const char* b = (const char*)in; - const char* e = b + len; + +char* HexEncode(const void* in, size_t len, char* out) { + const unsigned char* b = (const unsigned char*)in; + const unsigned char* e = b + len; + + while (b != e) { + *out++ = DigitToChar(*b / 16); + *out++ = DigitToChar(*b++ % 16); + } + + return out; +} + +void* HexDecode(const void* in, size_t len, void* ptr) { + const char* b = (const char*)in; + const char* e = b + len; Y_ENSURE(!(len & 1), TStringBuf("Odd buffer length passed to HexDecode")); - - char* out = (char*)ptr; - - while (b != e) { + + char* out = (char*)ptr; + + while (b != e) { *out++ = (char)String2Byte(b); - b += 2; - } - - return out; -} - + b += 2; + } + + return out; +} + TString HexEncode(const void* in, size_t len) { TString ret; - - ret.ReserveAndResize(len << 1); - HexEncode(in, len, ret.begin()); - - return ret; -} - + + ret.ReserveAndResize(len << 1); + HexEncode(in, len, ret.begin()); + + return ret; +} + TString HexDecode(const void* in, size_t len) { TString ret; - + ret.ReserveAndResize(len >> 1); HexDecode(in, len, ret.begin()); - - return ret; -} + + return ret; +} |