Skip to content

Commit

Permalink
Add helper function
Browse files Browse the repository at this point in the history
From cppcheck#4701
Co-authored-by: gerboengels [email protected]
  • Loading branch information
chrchr-github committed Sep 18, 2023
1 parent ea9c537 commit 2d27ef6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion simplecpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace simplecpp {
name = (std::isalpha(static_cast<unsigned char>(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<unsigned char>(string[0])) || (string.size() > 1U && (string[0] == '-' || string[0] == '+') && std::isdigit(static_cast<unsigned char>(string[1])));
number = isNumberLike(string);
op = (string.size() == 1U && !name && !comment && !number) ? string[0] : '\0';
}

Expand All @@ -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<unsigned char>(str[0])) ||
(str.size() > 1U && (str[0] == '-' || str[0] == '+') && std::isdigit(static_cast<unsigned char>(str[1])));
}

TokenString macro;
char op;
Expand Down

0 comments on commit 2d27ef6

Please sign in to comment.