StringHelpers¶
ParseNumber¶
Internal helper function¶
static bool ParseNumber(const std::string str, bool& out_isInt, long double& out_number);
A static helper function.
Will parse numbers from a string.
Depending on if you have set JASONPP_NO_ADVANCED_FEATURESET it will parse of course regular numbers to a long double, but also exponential numbers (such as 3.14e4), hexadecimal numbers (such as 0xAFFE) and octal numbers (such as 015471).
This function is NOT case sensitive. 0xff is exactly the same as 0XFF or 3.14e4 is the exact same as 3.14E4.
Only supports negative signage!
You can prepent a -, but not +. + is default.
Example:¶
C++:¶
bool isInteger;
long double number;
if (StringHelpers::ParseNumber("0xff", isInteger, number))
{
if (isInteger)
{
long int foo = (long int)number;
std::cout << "My number is " << foo << "!" << std::endl;
}
else
{
std::cout << "My number is " << number << "!" << std::endl;
}
}
else
{
// Parsing did not succeed
}