From 2d27ef6190eb6212466b3dfdc295825bb52e4aef Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 18 Sep 2023 09:56:20 +0200 Subject: [PATCH] Add helper function From cppcheck#4701 Co-authored-by: gerboengels github@gerbo.org --- simplecpp.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/simplecpp.h b/simplecpp.h index b6124953..152cd9ff 100755 --- a/simplecpp.h +++ b/simplecpp.h @@ -120,7 +120,7 @@ namespace simplecpp { name = (std::isalpha(static_cast(string[0])) || string[0] == '_' || string[0] == '$') && (std::memchr(string.c_str(), '\'', string.size()) == nullptr); comment = string.size() > 1U && string[0] == '/' && (string[1] == '/' || string[1] == '*'); - number = std::isdigit(static_cast(string[0])) || (string.size() > 1U && (string[0] == '-' || string[0] == '+') && std::isdigit(static_cast(string[1]))); + number = isNumberLike(string); op = (string.size() == 1U && !name && !comment && !number) ? string[0] : '\0'; } @@ -135,6 +135,10 @@ namespace simplecpp { bool isOneOf(const char ops[]) const; bool startsWithOneOf(const char c[]) const; bool endsWithOneOf(const char c[]) const; + static bool SIMPLECPP_LIB isNumberLike(const std::string& str) { + return std::isdigit(static_cast(str[0])) || + (str.size() > 1U && (str[0] == '-' || str[0] == '+') && std::isdigit(static_cast(str[1]))); + } TokenString macro; char op;