Quote:
Originally Posted by fysiks
is_str_num("0") returns true properly. For negative numbers, it looks like this is a bug that should be reported here.
|
This is a stock in string_stocks and the description states it returns true if the string contains only digits, so it's 'technically' working as described. An entirely new stock would be needed to maintain reverse compatibility, or an optional 'NegativeSupport' boolean defaulted to false should be added. This should have been written to consider negative numbers.
PHP Code:
/**
* Returns whether a given string contains only digits.
* This returns false for zero-length strings.
*
* @param sString Character to test.
* @return True if string contains only digit, otherwise false.
*/
stock bool:is_str_num(const sString[])
{
new i = 0;
while (sString[i] && isdigit(sString[i]))
{
++i;
}
return sString[i] == 0 && i != 0;
}
PHP Code:
stock bool:is_str_num(const sString[] , bool:bNegativeSupport=false)
{
new i = 0 , szTempStr[ 13 ];
copy( szTempStr , charsmax( szTempStr ) , sString );
if ( bNegativeSupport && ( szTempStr[ 0 ] == '-' ) )
{
szTempStr[ i++ ] = '0';
}
while ( szTempStr[i] && isdigit(szTempStr[i] ) )
{
++i;
}
return szTempStr[i] == 0 && i != 0;
}
__________________