Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions include/rift/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,37 +264,51 @@ struct fmt::formatter<rift::Value> {
return ctx.begin();
}

template <typename FormatContext>
auto format(rift::Value const& value, FormatContext& ctx) const noexcept {
private:
// Helper to format a Value without triggering recursive type mapping.
// This avoids MSVC C2968 "recursive alias declaration" errors.
template <typename OutputIt>
OutputIt format_value(rift::Value const& value, OutputIt out) const noexcept {
switch (value.type()) {
case rift::Value::Type::String:
return fmt::format_to(ctx.out(), "{}", value.getString());
return fmt::format_to(out, "{}", value.getString());
case rift::Value::Type::Integer:
return fmt::format_to(ctx.out(), "{}", value.getInteger());
return fmt::format_to(out, "{}", value.getInteger());
case rift::Value::Type::Float:
return fmt::format_to(ctx.out(), "{:.2f}", value.getFloat());
return fmt::format_to(out, "{:.2f}", value.getFloat());
case rift::Value::Type::Boolean:
return fmt::format_to(ctx.out(), "{}", value.getBoolean() ? "true" : "false");
return fmt::format_to(out, "{}", value.getBoolean() ? "true" : "false");
case rift::Value::Type::Array: {
return fmt::format_to(ctx.out(), "[{}]", fmt::join(value.getArray(), ", "));;
auto& arr = value.getArray();
out = fmt::format_to(out, "[");
for (size_t i = 0; i < arr.size(); ++i) {
if (i > 0) out = fmt::format_to(out, ", ");
out = format_value(arr[i], out);
}
return fmt::format_to(out, "]");
}
case rift::Value::Type::Object: {
auto& obj = value.getObject();
out = fmt::format_to(out, "{{");
size_t i = 0;
auto count = obj.size();
fmt::format_to(ctx.out(), "{{");
for (auto const& [key, val] : obj) {
fmt::format_to(ctx.out(), "{}: {}", key, val);
if (i < count - 1) {
fmt::format_to(ctx.out(), ", ");
}
if (i > 0) out = fmt::format_to(out, ", ");
out = fmt::format_to(out, "{}: ", key);
out = format_value(val, out);
++i;
}
return fmt::format_to(ctx.out(), "}}");
return fmt::format_to(out, "}}");
}
default:
return fmt::format_to(ctx.out(), "null");
return fmt::format_to(out, "null");
}
}

public:
template <typename FormatContext>
auto format(rift::Value const& value, FormatContext& ctx) const noexcept {
return format_value(value, ctx.out());
}
};

#endif // RIFT_VALUE_HPP