MCPcopy Create free account
hub / github.com/ElementsProject/elements / ToIntegral

Function ToIntegral

src/util/strencodings.h:165–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163 */
164template <typename T>
165std::optional<T> ToIntegral(const std::string& str)
166{
167 static_assert(std::is_integral<T>::value);
168 T result;
169 const auto [first_nonmatching, error_condition] = std::from_chars(str.data(), str.data() + str.size(), result);
170 if (first_nonmatching != str.data() + str.size() || error_condition != std::errc{}) {
171 return std::nullopt;
172 }
173 return result;
174}
175
176/**
177 * Convert string to signed 32-bit integer with strict parse error feedback.

Callers

nothing calls this directly

Calls 2

dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected