- Used <format> library in StringService
- Updated minimum GCC version to 13
This commit is contained in:
@@ -32,7 +32,7 @@ The accompanying package names are from the Debian (APT) package repositories -
|
||||
repositories.
|
||||
|
||||
- CMake version 3.22 or later
|
||||
- G++10 or later
|
||||
- G++13 or later
|
||||
- libusb v1.0 (`libusb-1.0-0-dev`)
|
||||
- libhidapi (0.11.2 or later) (`libhidapi-dev`)
|
||||
- yaml-cpp (version 0.7.0 or later) (`libyaml-cpp-dev`)
|
||||
|
||||
@@ -64,30 +64,6 @@ namespace Services
|
||||
});
|
||||
}
|
||||
|
||||
std::string StringService::toHex(std::uint64_t value) {
|
||||
auto stream = std::stringstream{};
|
||||
stream << std::hex << std::setfill('0') << std::setw(16) << static_cast<unsigned int>(value);
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string StringService::toHex(std::uint32_t value) {
|
||||
auto stream = std::stringstream{};
|
||||
stream << std::hex << std::setfill('0') << std::setw(8) << static_cast<unsigned int>(value);
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string StringService::toHex(std::uint16_t value) {
|
||||
auto stream = std::stringstream{};
|
||||
stream << std::hex << std::setfill('0') << std::setw(4) << static_cast<unsigned int>(value);
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string StringService::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 StringService::toHex(std::span<const unsigned char> data) {
|
||||
auto stream = std::stringstream{};
|
||||
stream << std::hex << std::setfill('0');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <format>
|
||||
|
||||
namespace Services
|
||||
{
|
||||
@@ -23,10 +24,29 @@ namespace Services
|
||||
static bool isNumeric(std::string_view str);
|
||||
static bool isBinary(std::string_view str);
|
||||
|
||||
static std::string toHex(std::uint64_t value);
|
||||
static std::string toHex(std::uint32_t value);
|
||||
static std::string toHex(std::uint16_t value);
|
||||
static std::string toHex(unsigned char value);
|
||||
template <typename Type>
|
||||
requires std::is_integral_v<Type>
|
||||
static std::string toHex(Type value) {
|
||||
if constexpr (sizeof(Type) == 1) {
|
||||
return std::format("{:02X}", value);
|
||||
}
|
||||
|
||||
if constexpr (sizeof(Type) == 2) {
|
||||
return std::format("{:04X}", value);
|
||||
}
|
||||
|
||||
if constexpr (sizeof(Type) == 4) {
|
||||
return std::format("{:08X}", value);
|
||||
}
|
||||
|
||||
if constexpr (sizeof(Type) == 8) {
|
||||
return std::format("{:016X}", value);
|
||||
|
||||
} else {
|
||||
return std::format("{:X}", value);
|
||||
}
|
||||
}
|
||||
|
||||
static std::string toHex(std::span<const unsigned char> data);
|
||||
static std::string toHex(std::string_view data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user