From 7e98a3c642222edc0813ced945d4b6e548cb8ca8 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 4 Jun 2015 12:03:09 +0200 Subject: 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. --- src/utilstrencodings.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/utilstrencodings.h') 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 std::string HexStr(const T itbegin, const T itend, bool fSpaces=false) { -- cgit v1.2.3