12 requires(std::is_integral_v<T> || std::is_floating_point_v<T>)
15 const auto whitespace = [](
char value) {
16 return value ==
' ' || value ==
'\t' || value ==
'\n' || value ==
'\r';
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))
28 const bool positive_sign = *current ==
'+';
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))) {
40 values.push_back(value);
46template <
typename T,
size_t N>
47[[nodiscard]] std::optional<std::array<T, N>>
parse_xml_tuple(std::string_view source,
55 if (values->size() !=
N) {
59 std::array<T, N> result;
60 std::ranges::copy(*values, result.begin());
69 requires((std::is_integral_v<T> || std::is_floating_point_v<T>)
70 && !std::same_as<T, bool>)
79 value = (*decoded)[0];
90 if (source ==
"true" || source ==
"1") {
94 if (source ==
"false" || source ==
"0") {
115 requires std::is_enum_v<T>
116struct XmlTextCodec<
T> {
117 static constexpr size_t extent = 0;
131template <GlmVectorType T>
132struct XmlTextCodec<
T> {
133 static constexpr size_t extent = glm_component_count<T>();
137 using Scalar =
typename T::value_type;
138 constexpr size_t count = glm_component_count<T>();
142 for (
size_t i = 0; i < count; ++i)
143 value[
static_cast<glm::length_t
>(i)] = (*decoded)[i];
154template <XmlTextDecodable T>
158 static bool decode(std::string_view source, std::optional<T>& value,
161 T decoded = value.value_or(
T {});
164 value = std::move(decoded);
std::optional< std::array< T, N > > parse_xml_tuple(std::string_view source, XmlTextError &error)
std::optional< std::vector< T > > parse_xml_numbers(std::string_view source)
constexpr std::optional< EnumType > string_to_enum(std::string_view str) noexcept
Universal string to enum converter using magic_enum (exact case match).
static constexpr size_t extent
static bool decode(std::string_view source, T &value, XmlTextError &error)
static bool decode(std::string_view source, bool &value, XmlTextError &error)
static constexpr size_t extent
static constexpr size_t extent
static bool decode(std::string_view source, std::optional< T > &value, XmlTextError &error)
static constexpr size_t extent
static bool decode(std::string_view source, std::string &value, XmlTextError &)
Convert XML attribute text to one described member value.