From 36a08e45fc185d1f93b952f960edfadc28fce1c2 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 16 Jan 2023 04:43:55 +0100 Subject: compat/format: fix after fmtlib update --- compat/format.hpp | 30 ++++++++++++++++++++++++++++-- loader/atlas.cpp | 4 ++-- serialize/tile-atlas.cpp | 3 +-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/compat/format.hpp b/compat/format.hpp index faf776f0..1432d847 100644 --- a/compat/format.hpp +++ b/compat/format.hpp @@ -1,6 +1,22 @@ #pragma once #include #include +#include +#include + +namespace fmt { + +template<> struct formatter { + template static constexpr auto parse(ParseContext& ctx) { return ctx.begin(); } + template auto format(Corrade::Containers::StringView const& s, FormatContext& ctx); +}; + +template<> struct formatter { + template static constexpr auto parse(ParseContext& ctx) { return ctx.begin(); } + template auto format(Corrade::Containers::String const& s, FormatContext& ctx); +}; + +} // namespace fmt #if !FMT_USE_NONTYPE_TEMPLATE_ARGS namespace floormat::detail::fmt { @@ -18,8 +34,6 @@ struct fmt_string final { } // namespace floormat::detail::fmt #endif -namespace floormat { - #if !FMT_USE_NONTYPE_TEMPLATE_ARGS template<::floormat::detail::fmt::fmt_string s> consteval auto operator""_cf() noexcept @@ -30,6 +44,8 @@ consteval auto operator""_cf() noexcept using namespace fmt::literals; #endif +namespace floormat { + template std::size_t snformat(char(&buf)[N], Fmt&& fmt, Xs&&... args) { @@ -42,3 +58,13 @@ std::size_t snformat(char(&buf)[N], Fmt&& fmt, Xs&&... args) } } // namespace floormat + +template +auto fmt::formatter::format(Corrade::Containers::StringView const& s, FormatContext& ctx) { + return fmt::format_to(ctx.out(), "{}"_cf, basic_string_view{s.data(), s.size()}); +} + +template +auto fmt::formatter::format(Corrade::Containers::String const& s, FormatContext& ctx) { + return fmt::format_to(ctx.out(), "{}"_cf, basic_string_view{s.data(), s.size()}); +} diff --git a/loader/atlas.cpp b/loader/atlas.cpp index 89b988e9..bda6a46b 100644 --- a/loader/atlas.cpp +++ b/loader/atlas.cpp @@ -30,7 +30,7 @@ std::shared_ptr loader_impl::tile_atlas(StringView filename) fm_assert(!tile_atlas_map.empty()); auto it = tile_atlas_map.find(filename); if (it == tile_atlas_map.end()) - fm_throw("no such tile atlas '{}'"_cf, filename.data()); + fm_throw("no such tile atlas '{}'"_cf, filename); return it->second; } @@ -58,7 +58,7 @@ std::shared_ptr loader_impl::anim_atlas(StringView name, StringView auto it = std::find_if(anim_info.groups.cbegin(), anim_info.groups.cend(), [&](const anim_group& x) { return x.name == group.mirror_from; }); if (it == anim_info.groups.cend()) - fm_throw("can't find group '{}' to mirror from '{}'"_cf, group.mirror_from.data(), group.name.data()); + fm_throw("can't find group '{}' to mirror from '{}'"_cf, group.mirror_from, group.name); group.frames = it->frames; for (anim_frame& f : group.frames) f.ground = Vector2i((Int)f.size[0] - f.ground[0], f.ground[1]); diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp index cb58d1b4..068c1d9b 100644 --- a/serialize/tile-atlas.cpp +++ b/serialize/tile-atlas.cpp @@ -4,7 +4,6 @@ #include "serialize/magnum-vector2i.hpp" #include "loader/loader.hpp" #include "serialize/pass-mode.hpp" -#include #include #include #include @@ -55,7 +54,7 @@ void adl_serializer>::from_json(const json& j, std:: { int m = p2 ? int(*p2) : -1; const auto name = val->name(); - fm_throw("atlas {} wrong pass mode {} should be {}"_cf, std::string_view{name.data(), name.size()}, m, std::uint8_t(*p)); + fm_throw("atlas {} wrong pass mode {} should be {}"_cf, StringView{name.data(), name.size()}, m, std::uint8_t(*p)); } } } -- cgit v1.2.3