diff options
| author | Dan Engelbrecht <[email protected]> | 2022-03-22 23:58:44 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-03-31 11:29:26 +0200 |
| commit | 2fc631b23cba5f12ad47f685f99f6fbef4885c8a (patch) | |
| tree | 36ecf38c12aa56e4d6627011bf3656887e9a27ee | |
| parent | Just use one threadpool in threading test (diff) | |
| download | zen-2fc631b23cba5f12ad47f685f99f6fbef4885c8a.tar.xz zen-2fc631b23cba5f12ad47f685f99f6fbef4885c8a.zip | |
Move FormatHex and ParseHex to zencore/string
| -rw-r--r-- | zencore/include/zencore/string.h | 3 | ||||
| -rw-r--r-- | zencore/string.cpp | 27 | ||||
| -rw-r--r-- | zenstore/compactcas.cpp | 25 |
3 files changed, 30 insertions, 25 deletions
diff --git a/zencore/include/zencore/string.h b/zencore/include/zencore/string.h index 4c378730f..bbbb09004 100644 --- a/zencore/include/zencore/string.h +++ b/zencore/include/zencore/string.h @@ -553,6 +553,9 @@ ToHexBytes(const uint8_t* InputData, size_t ByteCount, char* OutString) } } +ZENCORE_API void FormatHex(uint32_t Value, char OutBlockHexString[9]); +ZENCORE_API bool ParseHex(const std::string HexString, uint32_t& OutValue); + ////////////////////////////////////////////////////////////////////////// // Format numbers for humans // diff --git a/zencore/string.cpp b/zencore/string.cpp index ad6ee78fc..f116ac477 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -335,6 +335,33 @@ NiceNumGeneral(uint64_t Num, std::span<char> Buffer, NicenumFormat Format) } } +bool +ParseHex(const std::string HexString, uint32_t& OutValue) +{ + if (HexString.length() != 8) + { + return false; + } + OutValue = strtoul(HexString.data(), 0, 16); + return true; +} + +static const char HexLUT[] = "0123456789abcdef"; + +void +FormatHex(uint32_t Value, char OutBlockHexString[9]) +{ + OutBlockHexString[0] = HexLUT[(Value >> 28) & 0xf]; + OutBlockHexString[1] = HexLUT[(Value >> 24) & 0xf]; + OutBlockHexString[2] = HexLUT[(Value >> 20) & 0xf]; + OutBlockHexString[3] = HexLUT[(Value >> 16) & 0xf]; + OutBlockHexString[4] = HexLUT[(Value >> 12) & 0xf]; + OutBlockHexString[5] = HexLUT[(Value >> 8) & 0xf]; + OutBlockHexString[6] = HexLUT[(Value >> 4) & 0xf]; + OutBlockHexString[7] = HexLUT[(Value >> 0) & 0xf]; + OutBlockHexString[8] = 0; +} + size_t NiceNumToBuffer(uint64_t Num, std::span<char> Buffer) { diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 82ecf1a83..d7929e42a 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -40,31 +40,6 @@ struct CasDiskIndexHeader static_assert(sizeof(CasDiskIndexHeader) == 32); namespace { - static const char* HexLUT = "0123456789abcdef"; - - bool ParseHex(const std::string HexString, uint32_t& OutValue) - { - if (HexString.length() != 8) - { - return false; - } - OutValue = strtoul(HexString.data(), 0, 16); - return true; - } - - void FormatHex(uint32_t Value, char OutBlockHexString[9]) - { - OutBlockHexString[0] = HexLUT[(Value >> 28) & 0xf]; - OutBlockHexString[1] = HexLUT[(Value >> 24) & 0xf]; - OutBlockHexString[2] = HexLUT[(Value >> 20) & 0xf]; - OutBlockHexString[3] = HexLUT[(Value >> 16) & 0xf]; - OutBlockHexString[4] = HexLUT[(Value >> 12) & 0xf]; - OutBlockHexString[5] = HexLUT[(Value >> 8) & 0xf]; - OutBlockHexString[6] = HexLUT[(Value >> 4) & 0xf]; - OutBlockHexString[7] = HexLUT[(Value >> 0) & 0xf]; - OutBlockHexString[8] = 0; - } - std::filesystem::path BuildUcasPath(const std::filesystem::path& BlocksBasePath, const uint32_t BlockIndex) { ExtendablePathBuilder<256> Path; |