aboutsummaryrefslogtreecommitdiff
path: root/src/utilstrencodings.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-06-04 12:03:09 +0200
committerJonas Schnelli <jonas.schnelli@include7.ch>2015-06-04 13:18:46 +0200
commit7e98a3c642222edc0813ced945d4b6e548cb8ca8 (patch)
tree3d68ecdb7d2fe22093f7d48bd4b4eb7d8ac69f93 /src/utilstrencodings.h
parent043df2b56831bef4c4b726ae4fc761d4710b99be (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.h14
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)
{