MCPcopy Create free account
hub / github.com/OpenImageDebugger/OpenImageDebugger / parse_int_field

Function parse_int_field

src/host/ui/text_input.cpp:94–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94std::optional<int> parse_int_field(std::string_view text) {
95 constexpr std::string_view whitespace = " \t\n\r\f\v";
96 const auto first = text.find_first_not_of(whitespace);
97 if (first == std::string_view::npos) {
98 return std::nullopt;
99 }
100 const auto last = text.find_last_not_of(whitespace);
101 text = text.substr(first, last - first + 1);
102
103 int value = 0;
104 const auto* begin = text.data();
105 const auto* end = text.data() + text.size();
106 const auto [ptr, ec] = std::from_chars(begin, end, value);
107 if (ec != std::errc{} || ptr != end) {
108 return std::nullopt;
109 }
110 return value;
111}
112
113} // namespace oid::host

Callers 3

parse_gotoMethod · 0.85
input_int_fieldFunction · 0.85
TESTFunction · 0.85

Calls 2

dataMethod · 0.45
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68