diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-06-04 12:03:09 +0200 |
---|---|---|
committer | Jonas Schnelli <jonas.schnelli@include7.ch> | 2015-06-04 13:18:46 +0200 |
commit | 7e98a3c642222edc0813ced945d4b6e548cb8ca8 (patch) | |
tree | 3d68ecdb7d2fe22093f7d48bd4b4eb7d8ac69f93 /src/utilstrencodings.h | |
parent | 043df2b56831bef4c4b726ae4fc761d4710b99be (diff) |
util: Add ParseInt64 and ParseDouble functions
Strict parsing functions for other numeric types.
- ParseInt64 analogous to ParseInt32, but for 64-bit values.
- ParseDouble for doubles.
- Make all three Parse* functions more strict (e.g. reject whitespace on
the inside)
Also add tests.
Diffstat (limited to 'src/utilstrencodings.h')
-rw-r--r-- | src/utilstrencodings.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h index b0edd8b542..fb3ef04281 100644 --- a/src/utilstrencodings.h +++ b/src/utilstrencodings.h @@ -49,6 +49,20 @@ int atoi(const std::string& str); */ bool ParseInt32(const std::string& str, int32_t *out); +/** + * Convert string to signed 64-bit integer with strict parse error feedback. + * @returns true if the entire string could be parsed as valid integer, + * false if not the entire string could be parsed or when overflow or underflow occurred. + */ +bool ParseInt64(const std::string& str, int64_t *out); + +/** + * Convert string to double with strict parse error feedback. + * @returns true if the entire string could be parsed as valid double, + * false if not the entire string could be parsed or when overflow or underflow occurred. + */ +bool ParseDouble(const std::string& str, double *out); + template<typename T> std::string HexStr(const T itbegin, const T itend, bool fSpaces=false) { |