mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-07-28 17:42:45 +00:00
use regex for isnum
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include "emsesp.h"
|
#include "emsesp.h"
|
||||||
|
|
||||||
#include "shuntingYard.h"
|
#include "shuntingYard.h"
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
@@ -333,6 +334,9 @@ 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) {
|
||||||
|
std::regex r("^[+-]?(\\d+\\.?\\d*)$");
|
||||||
|
return std::regex_match(s, r);
|
||||||
|
/*
|
||||||
if (s.empty() || s.find_first_of("0123456789") == std::string::npos) {
|
if (s.empty() || s.find_first_of("0123456789") == std::string::npos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -340,6 +344,7 @@ bool isnum(const std::string & s) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user