Added string to uint conversion and string splitting to StringService
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
namespace Services
|
namespace Services
|
||||||
{
|
{
|
||||||
@@ -70,4 +71,33 @@ namespace Services
|
|||||||
|
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::uint64_t StringService::toUint64(const std::string& str) {
|
||||||
|
return static_cast<std::uint64_t>(std::stoul(str, nullptr, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint32_t StringService::toUint32(const std::string& str) {
|
||||||
|
return static_cast<std::uint32_t>(StringService::toUint64(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint16_t StringService::toUint16(const std::string& str) {
|
||||||
|
return static_cast<std::uint16_t>(StringService::toUint64(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint8_t StringService::toUint8(const std::string& str) {
|
||||||
|
return static_cast<std::uint8_t>(StringService::toUint64(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string_view> StringService::split(std::string_view str, char delimiter) {
|
||||||
|
auto range = str |
|
||||||
|
std::ranges::views::split(delimiter) |
|
||||||
|
std::ranges::views::transform([](auto&& subRange) -> std::string_view {
|
||||||
|
return std::string_view(
|
||||||
|
subRange.begin(),
|
||||||
|
static_cast<std::size_t>(std::ranges::distance(subRange))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {std::ranges::begin(range), std::ranges::end(range)};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -20,5 +21,12 @@ namespace Services
|
|||||||
static std::string toHex(unsigned char value);
|
static std::string toHex(unsigned char value);
|
||||||
static std::string toHex(const std::vector<unsigned char>& data);
|
static std::string toHex(const std::vector<unsigned char>& data);
|
||||||
static std::string toHex(const std::string& data);
|
static std::string toHex(const std::string& data);
|
||||||
|
|
||||||
|
static std::uint64_t toUint64(const std::string& str);
|
||||||
|
static std::uint32_t toUint32(const std::string& str);
|
||||||
|
static std::uint16_t toUint16(const std::string& str);
|
||||||
|
static std::uint8_t toUint8(const std::string& str);
|
||||||
|
|
||||||
|
static std::vector<std::string_view> split(std::string_view str, char delimiter);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user