| 92 | } |
| 93 | |
| 94 | std::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 |