Moved toHex functions to String helper class

This commit is contained in:
Nav
2023-01-21 13:37:56 +00:00
parent 662806769e
commit 6b4d3ecb26
12 changed files with 70 additions and 51 deletions

View File

@@ -2,6 +2,8 @@
#include <algorithm>
#include <cctype>
#include <sstream>
#include <iomanip>
namespace Bloom
{
@@ -26,4 +28,32 @@ namespace Bloom
return character > 127;
});
}
std::string String::toHex(unsigned char value) {
auto stream = std::stringstream();
stream << std::hex << std::setfill('0') << std::setw(2) << static_cast<unsigned int>(value);
return stream.str();
}
std::string String::toHex(const std::vector<unsigned char>& data) {
auto stream = std::stringstream();
stream << std::hex << std::setfill('0');
for (const auto& byte : data) {
stream << std::setw(2) << static_cast<unsigned int>(byte);
}
return stream.str();
}
std::string String::toHex(const std::string& data) {
std::stringstream stream;
stream << std::hex << std::setfill('0');
for (const auto& byte : data) {
stream << std::setw(2) << static_cast<unsigned int>(byte);
}
return stream.str();
}
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <vector>
namespace Bloom
{
@@ -12,5 +13,9 @@ namespace Bloom
static std::string asciiToUpper(std::string str);
static bool isAscii(const std::string& str);
static std::string toHex(unsigned char value);
static std::string toHex(const std::vector<unsigned char>& data);
static std::string toHex(const std::string& data);
};
}