Moved String helper functions to service class
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
#include "String.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
namespace Bloom
|
||||
{
|
||||
std::string String::asciiToLower(std::string str) {
|
||||
std::transform(str.begin(), str.end(), str.begin(), [] (unsigned char character) {
|
||||
return std::tolower(character);
|
||||
});
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string String::asciiToUpper(std::string str) {
|
||||
std::transform(str.begin(), str.end(), str.begin(), [] (unsigned char character) {
|
||||
return std::toupper(character);
|
||||
});
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
bool String::isAscii(const std::string& str) {
|
||||
return !std::any_of(str.begin(), str.end(), [] (unsigned char character) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Bloom
|
||||
{
|
||||
class String
|
||||
{
|
||||
public:
|
||||
static std::string asciiToLower(std::string str);
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user