1
0
mirror of https://github.com/MatMoul/g810-led.git synced 2024-12-23 01:06:11 +00:00

Add utility to convert string to uint16_t

Purpose for this is for command argument parsing of vendor and product
IDs

Signed-off-by: Kevin Pearson <pearson.kevin.m@gmail.com>
This commit is contained in:
Kevin Pearson 2017-04-27 11:56:57 -04:00
parent 4b2a1002e8
commit 53876ac54e
2 changed files with 9 additions and 0 deletions

View File

@ -216,4 +216,12 @@ namespace utils {
return true;
}
bool parseUInt16(std::string val, uint16_t &uint16) {
if (val.length() == 1) val = "0" + val;
if (val.length() == 2) val = "0" + val;
if (val.length() == 3) val = "0" + val;
if (val.length() != 4) return false;
uint16 = std::stoul("0x" + val, nullptr, 16);
return true;
}
}

View File

@ -16,6 +16,7 @@ namespace utils {
bool parseColor(std::string val, LedKeyboard::Color &color);
bool parseSpeed(std::string val, uint8_t &speed);
bool parseUInt8(std::string val, uint8_t &uint8);
bool parseUInt16(std::string val, uint16_t &uint16);
}