mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-22 04:24:44 +00:00
custom u8string formatter for fmt library
This commit is contained in:
parent
662ae57435
commit
43aeee743f
1 changed files with 24 additions and 0 deletions
|
@ -19,3 +19,27 @@ struct fmt::formatter<T, std::enable_if_t<std::is_enum_v<T>, char>>
|
|||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace fmt {
|
||||
template <typename T = std::string_view>
|
||||
struct UTF {
|
||||
T data;
|
||||
|
||||
explicit UTF(const std::u8string_view view) {
|
||||
data = T{(const char*)&view.front(), (const char*)&view.back()};
|
||||
}
|
||||
|
||||
explicit UTF(const std::u8string& str)
|
||||
: UTF(std::u8string_view{str}) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<fmt::UTF<std::string_view>, char>
|
||||
: formatter<std::string_view> {
|
||||
template <typename FormatContext>
|
||||
auto format(const UTF<std::string_view>& wrapper, FormatContext& ctx) const {
|
||||
return formatter<std::string_view>::format(wrapper.data, ctx);
|
||||
}
|
||||
};
|
Loading…
Add table
Reference in a new issue