aboutsummaryrefslogtreecommitdiff
path: root/src/utilstrencodings.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-06-08 10:23:25 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-06-08 10:28:51 +0200
commite012f3cea0ca4096dd4dd59a356a973c43651912 (patch)
tree2d6b478372ca006337efe387ad9f6818caec56d3 /src/utilstrencodings.h
parent0f24eaf253abe7d1479777ef10f8f4e8eeb9d06e (diff)
util: Add ParseUInt32 and ParseUInt64
Add error and range-checking parsers for unsigned 32 and 64 bit numbers. The 32-bit variant is required for parsing sequence numbers from the command line in `bitcoin-tx` (see #8164 for discussion). I've thrown in the 64-bit variant as a bonus, as I'm sure it will be needed at some point. Also adds tests, and updates `developer-notes.md`.
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 d40613cfc4..5744f78c6e 100644
--- a/src/utilstrencodings.h
+++ b/src/utilstrencodings.h
@@ -71,6 +71,20 @@ bool ParseInt32(const std::string& str, int32_t *out);
bool ParseInt64(const std::string& str, int64_t *out);
/**
+ * Convert decimal string to unsigned 32-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 ParseUInt32(const std::string& str, uint32_t *out);
+
+/**
+ * Convert decimal string to unsigned 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 ParseUInt64(const std::string& str, uint64_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.