mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 10:09:43 +01:00
Fix is_number() returning true for empty strings
Just like is_positive_num(), an empty string is not a number. I've also decided to unroll iteration 0 of the loop here so readability is improved; this happens to also knock out the whole "accepting empty string" thing, too.
This commit is contained in:
parent
b9bf2be436
commit
7ea70ad1d6
1 changed files with 7 additions and 2 deletions
|
@ -267,9 +267,14 @@ void UtilityClass::updateglow()
|
||||||
|
|
||||||
bool is_number(const char* str)
|
bool is_number(const char* str)
|
||||||
{
|
{
|
||||||
for (int i = 0; str[i] != '\0'; i++)
|
if (!SDL_isdigit(str[0]) && str[0] != '-')
|
||||||
{
|
{
|
||||||
if (!SDL_isdigit(str[i]) && (i != 0 || str[0] != '-'))
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; str[i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
if (!SDL_isdigit(str[i]))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue