mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Add is_number()
This will be used to check if a string is a valid integer. So negative numbers are accepted, unlike is_positive_num().
This commit is contained in:
parent
b8b616e282
commit
502d597aeb
2 changed files with 14 additions and 0 deletions
|
@ -205,6 +205,18 @@ void UtilityClass::updateglow()
|
|||
}
|
||||
}
|
||||
|
||||
bool is_number(const char* str)
|
||||
{
|
||||
for (int i = 0; str[i] != '\0'; i++)
|
||||
{
|
||||
if (!SDL_isdigit(static_cast<unsigned char>(str[i])) && (i != 0 || str[0] != '-'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_positive_num(const std::string& str, bool hex)
|
||||
{
|
||||
for (size_t i = 0; i < str.length(); i++)
|
||||
|
|
|
@ -11,6 +11,8 @@ std::vector<std::string> split(const std::string &s, char delim, std::vector<std
|
|||
|
||||
std::vector<std::string> split(const std::string &s, char delim);
|
||||
|
||||
bool is_number(const char* str);
|
||||
|
||||
bool is_positive_num(const std::string& str, bool hex);
|
||||
|
||||
bool endsWith(const std::string& str, const std::string& suffix);
|
||||
|
|
Loading…
Reference in a new issue