Corrected string->int conversion bug in TargetPinDescriptor.
The `numericPosition` member should really be removed. Will revisit later.
This commit is contained in:
@@ -42,6 +42,12 @@ namespace Services
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StringService::isNumeric(const std::string& str) {
|
||||||
|
return !std::any_of(str.begin(), str.end(), [] (unsigned char character) {
|
||||||
|
return std::isdigit(character);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
std::string StringService::toHex(std::uint64_t value) {
|
std::string StringService::toHex(std::uint64_t value) {
|
||||||
auto stream = std::stringstream{};
|
auto stream = std::stringstream{};
|
||||||
stream << std::hex << std::setfill('0') << std::setw(16) << static_cast<unsigned int>(value);
|
stream << std::hex << std::setfill('0') << std::setw(16) << static_cast<unsigned int>(value);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ namespace Services
|
|||||||
static bool isAscii(const std::string& str);
|
static bool isAscii(const std::string& str);
|
||||||
static std::string replaceUnprintable(std::string str);
|
static std::string replaceUnprintable(std::string str);
|
||||||
|
|
||||||
|
static bool isNumeric(const std::string& str);
|
||||||
|
|
||||||
static std::string toHex(std::uint64_t value);
|
static std::string toHex(std::uint64_t value);
|
||||||
static std::string toHex(std::uint32_t value);
|
static std::string toHex(std::uint32_t value);
|
||||||
static std::string toHex(std::uint16_t value);
|
static std::string toHex(std::uint16_t value);
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ namespace Targets
|
|||||||
const std::optional<std::string>& padKey
|
const std::optional<std::string>& padKey
|
||||||
)
|
)
|
||||||
: position(position)
|
: position(position)
|
||||||
, numericPosition(Services::StringService::toUint16(this->position, 10))
|
, numericPosition(
|
||||||
|
Services::StringService::isNumeric(this->position)
|
||||||
|
? Services::StringService::toUint16(this->position, 10)
|
||||||
|
: 0
|
||||||
|
)
|
||||||
, padKey(padKey)
|
, padKey(padKey)
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Targets
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string position;
|
std::string position;
|
||||||
std::uint16_t numericPosition;
|
std::uint16_t numericPosition; // TODO: Consider removing this bodge. Review after v1.1.0
|
||||||
std::optional<std::string> padKey;
|
std::optional<std::string> padKey;
|
||||||
|
|
||||||
TargetPinDescriptor(
|
TargetPinDescriptor(
|
||||||
|
|||||||
Reference in New Issue
Block a user