summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--compat/format.hpp30
-rw-r--r--loader/atlas.cpp4
-rw-r--r--serialize/tile-atlas.cpp3
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 <fmt/core.h>
#include <fmt/compile.h>
+#include <Corrade/Containers/StringView.h>
+#include <Corrade/Containers/String.h>
+
+namespace fmt {
+
+template<> struct formatter<Corrade::Containers::StringView> {
+ template<typename ParseContext> static constexpr auto parse(ParseContext& ctx) { return ctx.begin(); }
+ template<typename FormatContext> auto format(Corrade::Containers::StringView const& s, FormatContext& ctx);
+};
+
+template<> struct formatter<Corrade::Containers::String> {
+ template<typename ParseContext> static constexpr auto parse(ParseContext& ctx) { return ctx.begin(); }
+ template<typename FormatContext> 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 N, typename Fmt, typename... Xs>
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<typename FormatContext>
+auto fmt::formatter<Corrade::Containers::StringView>::format(Corrade::Containers::StringView const& s, FormatContext& ctx) {
+ return fmt::format_to(ctx.out(), "{}"_cf, basic_string_view<char>{s.data(), s.size()});
+}
+
+template<typename FormatContext>
+auto fmt::formatter<Corrade::Containers::String>::format(Corrade::Containers::String const& s, FormatContext& ctx) {
+ return fmt::format_to(ctx.out(), "{}"_cf, basic_string_view<char>{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<struct tile_atlas> 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<anim_atlas> 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 <string_view>
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/String.h>
#include <nlohmann/json.hpp>
@@ -55,7 +54,7 @@ void adl_serializer<std::shared_ptr<tile_atlas>>::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));
}
}
}