ArduinoCore-API icon indicating copy to clipboard operation
ArduinoCore-API copied to clipboard

Feature request: String::isInt() and String::isFloat() for more robust String parsing/conversion

Open Ben-Rheinland opened this issue 9 years ago • 1 comments

The current implementations of String::toInt() and String::toFloat() rely on atol() and atof(), respectively (See WString.cpp). As both atol() and atof() have no means of signaling a failed conversion due to improper input Strings (both return 0 upon error) I propose adding two new member functions to the String Class:

int String::isInt() Returns a value different from zero if String is a valid representation of an integer. Returns zero otherwise.

int String::isFloat() Returns a value different from zero if String is a valid representation of a floating point number. Returns zero otherwise.

Ben-Rheinland avatar Jun 04 '16 14:06 Ben-Rheinland

When using the current implementation a String "0.0" or "0" - which undoubtadly are valid representations of float and int - would be reportet as isFloat() == false / isInt() == false.

ScruffR avatar Jan 31 '18 12:01 ScruffR