aboutsummaryrefslogtreecommitdiff
path: root/src/util/strencodings.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-10-01 17:33:35 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-10-01 18:05:33 +0200
commitfa3cd2853530c86c261ac7266ffe4f1726fe9ce6 (patch)
tree6defa00c71da38b5286979f5fa8e4ae110223a2a /src/util/strencodings.h
parent35a31d5f7e9cd71a210c1ed10abc9d772ff36049 (diff)
downloadbitcoin-fa3cd2853530c86c261ac7266ffe4f1726fe9ce6.tar.xz
refactor: Remove unused ParsePrechecks from ParseIntegral
Also: * Remove redundant {} from return statement * Add missing failing c-string test case and "-" and "+" strings * Add missing failing test cases for non-int32_t integral types
Diffstat (limited to 'src/util/strencodings.h')
-rw-r--r--src/util/strencodings.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/util/strencodings.h b/src/util/strencodings.h
index 1217572c45..07e1966890 100644
--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -97,7 +97,9 @@ constexpr inline bool IsSpace(char c) noexcept {
}
/**
- * Convert string to integral type T.
+ * Convert string to integral type T. Leading whitespace, a leading +, or any
+ * trailing character fail the parsing. The required format expressed as regex
+ * is `-?[0-9]+`.
*
* @returns std::nullopt if the entire string could not be parsed, or if the
* parsed value is not in the range representable by the type T.
@@ -111,7 +113,7 @@ std::optional<T> ToIntegral(const std::string& str)
if (first_nonmatching != str.data() + str.size() || error_condition != std::errc{}) {
return std::nullopt;
}
- return {result};
+ return result;
}
/**