MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ parse_xml_numbers()

template<typename T>
requires (std::is_integral_v<T> || std::is_floating_point_v<T>)
std::optional< std::vector< T > > MayaFlux::IO::parse_xml_numbers ( std::string_view source)
nodiscard

Definition at line 13 of file XmlTextCodec.hpp.

14{
15 const auto whitespace = [](char value) {
16 return value == ' ' || value == '\t' || value == '\n' || value == '\r';
17 };
18
19 std::vector<T> values;
20 const char* current = source.data();
21 const char* end = current + source.size();
22 while (current != end) {
23 while (current != end && whitespace(*current))
24 ++current;
25 if (current == end)
26 break;
27
28 const bool positive_sign = *current == '+';
29 if (positive_sign)
30 ++current;
31
32 T value {};
33 const auto [next, status] = std::from_chars(current, end, value);
34 if ((positive_sign && (current == end || *current == '+' || *current == '-'))
35 || status != std::errc {} || next == current
36 || (std::is_floating_point_v<T> && !std::isfinite(value))
37 || (next != end && !whitespace(*next))) {
38 return std::nullopt;
39 }
40 values.push_back(value);
41 current = next;
42 }
43 return values;
44}

References T.

Referenced by parse_xml_tuple().

Here is the caller graph for this function: