1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 15:55:46 +00:00

Introduce parse_number() helper function (#2659)

This commit is contained in:
Oxan van Leeuwen
2021-11-10 19:15:06 +01:00
committed by GitHub
parent 219b225ac0
commit 15f9677d33
15 changed files with 70 additions and 36 deletions

View File

@@ -279,20 +279,6 @@ std::string to_string(long double val) {
sprintf(buf, "%Lf", val);
return buf;
}
optional<float> parse_float(const std::string &str) {
char *end;
float value = ::strtof(str.c_str(), &end);
if (end == nullptr || end != str.end().base())
return {};
return value;
}
optional<int> parse_int(const std::string &str) {
char *end;
int value = ::strtol(str.c_str(), &end, 10);
if (end == nullptr || end != str.end().base())
return {};
return value;
}
optional<int> parse_hex(const char chr) {
int out = chr;