1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 10:09: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:
Misa 2020-08-06 21:22:10 -07:00 committed by Ethan Lee
parent b8b616e282
commit 502d597aeb
2 changed files with 14 additions and 0 deletions

View file

@ -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) bool is_positive_num(const std::string& str, bool hex)
{ {
for (size_t i = 0; i < str.length(); i++) for (size_t i = 0; i < str.length(); i++)

View file

@ -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); 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 is_positive_num(const std::string& str, bool hex);
bool endsWith(const std::string& str, const std::string& suffix); bool endsWith(const std::string& str, const std::string& suffix);