From ec5ffe8839c9c993fed4c23d72077969615dd298 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 28 Sep 2022 15:32:53 +0100 Subject: [PATCH] rewrite isNumber --- src/helpers/MiscFunctions.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 67debf32..b2f3a086 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -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) {