rewrite isNumber

This commit is contained in:
vaxerski 2022-09-28 15:32:53 +01:00
parent e3b1d3c3c5
commit ec5ffe8839

View file

@ -170,7 +170,25 @@ float getPlusMinusKeywordResult(std::string source, float relative) {
}
bool isNumber(const std::string& str, bool allowfloat) {
return std::ranges::all_of(str.begin(), str.end(), [&](char c) { return isdigit(c) != 0 || c == '-' || (allowfloat && c == '.'); });
std::string copy = str;
if (*copy.begin() == '-')
copy = copy.substr(1);
bool point = !allowfloat;
for (auto& c : copy) {
if (c == '.') {
if (point)
return false;
point = true;
break;
}
if (!std::isdigit(c))
return false;
}
return true;
}
bool isDirection(const std::string& arg) {