mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
Merge pull request #2468 from MichaelDvP/dev
shuntingYard support empty strings
This commit is contained in:
@@ -346,7 +346,7 @@ std::deque<Token> shuntingYard(const std::deque<Token> & tokens) {
|
|||||||
|
|
||||||
// check if string is a number
|
// check if string is a number
|
||||||
bool isnum(const std::string & s) {
|
bool isnum(const std::string & s) {
|
||||||
if (s.find_first_not_of("0123456789.") == std::string::npos || (s[0] == '-' && s.find_first_not_of("0123456789.", 1) == std::string::npos)) {
|
if (!s.empty() && (s.find_first_not_of("0123456789.") == std::string::npos || (s[0] == '-' && s.find_first_not_of("0123456789.", 1) == std::string::npos))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -387,17 +387,13 @@ std::string commands(std::string & expr, bool quotes = true) {
|
|||||||
return expr = "";
|
return expr = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output["api_data"].is<std::string>()) {
|
std::string data = output["api_data"] | "";
|
||||||
std::string data = output["api_data"];
|
if (!isnum(data) && quotes) {
|
||||||
if (!isnum(data) && quotes) {
|
data.insert(data.begin(), '"');
|
||||||
data.insert(data.begin(), '"');
|
data.insert(data.end(), '"');
|
||||||
data.insert(data.end(), '"');
|
|
||||||
}
|
|
||||||
expr.replace(f, l, data);
|
|
||||||
e = f + data.length();
|
|
||||||
} else {
|
|
||||||
return expr = "";
|
|
||||||
}
|
}
|
||||||
|
expr.replace(f, l, data);
|
||||||
|
e = f + data.length();
|
||||||
expr_new = emsesp::Helpers::toLower(expr);
|
expr_new = emsesp::Helpers::toLower(expr);
|
||||||
f = expr_new.find(d, e);
|
f = expr_new.find(d, e);
|
||||||
}
|
}
|
||||||
@@ -407,6 +403,9 @@ std::string commands(std::string & expr, bool quotes = true) {
|
|||||||
|
|
||||||
// checks for logic value
|
// checks for logic value
|
||||||
int to_logic(const std::string & s) {
|
int to_logic(const std::string & s) {
|
||||||
|
if (s.empty()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
auto l = emsesp::Helpers::toLower(s);
|
auto l = emsesp::Helpers::toLower(s);
|
||||||
if (s[0] == '1' || l == "on" || l == "true") {
|
if (s[0] == '1' || l == "on" || l == "true") {
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user