1515
1616#include < libunicode/support.h>
1717
18- #include < algorithm>
19- #include < array>
18+ #include < format>
2019#include < ostream>
21- #include < utility>
2220
2321namespace unicode
2422{
@@ -129,7 +127,6 @@ inline std::ostream& operator<<(std::ostream& os, EmojiSegmentationCategory valu
129127{
130128 switch (value)
131129 {
132- // clang-format off
133130 case unicode::EmojiSegmentationCategory::Invalid: return os << " Invalid" ;
134131 case unicode::EmojiSegmentationCategory::Emoji: return os << " Emoji" ;
135132 case unicode::EmojiSegmentationCategory::EmojiTextPresentation: return os << " EmojiTextPresentation" ;
@@ -140,66 +137,62 @@ inline std::ostream& operator<<(std::ostream& os, EmojiSegmentationCategory valu
140137 case unicode::EmojiSegmentationCategory::RegionalIndicator: return os << " RegionalIndicator" ;
141138 case unicode::EmojiSegmentationCategory::KeyCapBase: return os << " KeyCapBase" ;
142139 case unicode::EmojiSegmentationCategory::CombiningEnclosingKeyCap: return os << " CombiningEnclosingKeyCap" ;
143- case unicode::EmojiSegmentationCategory::CombiningEnclosingCircleBackslash: return os << " CombiningEnclosingCircleBackslash" ;
140+ case unicode::EmojiSegmentationCategory::CombiningEnclosingCircleBackslash:
141+ return os << " CombiningEnclosingCircleBackslash" ;
144142 case unicode::EmojiSegmentationCategory::ZWJ: return os << " ZWJ" ;
145143 case unicode::EmojiSegmentationCategory::VS15: return os << " VS15" ;
146144 case unicode::EmojiSegmentationCategory::VS16: return os << " VS16" ;
147145 case unicode::EmojiSegmentationCategory::TagBase: return os << " TagBase" ;
148146 case unicode::EmojiSegmentationCategory::TagSequence: return os << " TagSequence" ;
149147 case unicode::EmojiSegmentationCategory::TagTerm: return os << " TagTerm" ;
150- // clang-format off
151148 }
152149 return os;
153150}
154151
155152} // namespace unicode
156153
157- // clang-format off
158- #if __has_include(<fmt/ostream.h>)
159- #include < fmt/ostream.h>
160- #if FMT_VERSION >= (9 * 10000 + 1 * 100 + 0)
161- template <> struct fmt ::formatter<unicode::PresentationStyle>: fmt::ostream_formatter {};
162-
163-
164- namespace fmt
165- {
166154template <>
167- struct formatter <unicode::EmojiSegmentationCategory >
155+ struct std :: formatter<unicode::PresentationStyle>: std::formatter<std::string_view >
168156{
169- template <typename ParseContext>
170- constexpr auto parse (ParseContext& ctx)
157+ auto format (unicode::PresentationStyle value, auto & ctx) const
171158 {
172- return ctx.begin ();
159+ string_view name;
160+ switch (value)
161+ {
162+ case unicode::PresentationStyle::Text: name = " Text" ; break ;
163+ case unicode::PresentationStyle::Emoji: name = " Emoji" ; break ;
164+ }
165+ return formatter<string_view>::format (name, ctx);
173166 }
174- template <typename FormatContext>
175- auto format (unicode::EmojiSegmentationCategory value, FormatContext& ctx)
167+ };
168+
169+ template <>
170+ struct std ::formatter<unicode::EmojiSegmentationCategory>: std::formatter<std::string_view>
171+ {
172+ auto format (unicode::EmojiSegmentationCategory value, auto & ctx) const
176173 {
174+ using unicode::EmojiSegmentationCategory;
175+ string_view name;
177176 switch (value)
178177 {
179- // clang-format off
180- case unicode::EmojiSegmentationCategory::Invalid: return fmt::format_to (ctx.out (), " Invalid" );
181- case unicode::EmojiSegmentationCategory::Emoji: return fmt::format_to (ctx.out (), " Emoji" );
182- case unicode::EmojiSegmentationCategory::EmojiTextPresentation: return fmt::format_to (ctx.out (), " EmojiTextPresentation" );
183- case unicode::EmojiSegmentationCategory::EmojiEmojiPresentation: return fmt::format_to (ctx.out (), " EmojiEmojiPresentation" );
184- case unicode::EmojiSegmentationCategory::EmojiModifierBase: return fmt::format_to (ctx.out (), " EmojiModifierBase" );
185- case unicode::EmojiSegmentationCategory::EmojiModifier: return fmt::format_to (ctx.out (), " EmojiModifier" );
186- case unicode::EmojiSegmentationCategory::EmojiVSBase: return fmt::format_to (ctx.out (), " EmojiVSBase" );
187- case unicode::EmojiSegmentationCategory::RegionalIndicator: return fmt::format_to (ctx.out (), " RegionalIndicator" );
188- case unicode::EmojiSegmentationCategory::KeyCapBase: return fmt::format_to (ctx.out (), " KeyCapBase" );
189- case unicode::EmojiSegmentationCategory::CombiningEnclosingKeyCap: return fmt::format_to (ctx.out (), " CombiningEnclosingKeyCap" );
190- case unicode::EmojiSegmentationCategory::CombiningEnclosingCircleBackslash: return fmt::format_to (ctx.out (), " CombiningEnclosingCircleBackslash" );
191- case unicode::EmojiSegmentationCategory::ZWJ: return fmt::format_to (ctx.out (), " ZWJ" );
192- case unicode::EmojiSegmentationCategory::VS15: return fmt::format_to (ctx.out (), " VS15" );
193- case unicode::EmojiSegmentationCategory::VS16: return fmt::format_to (ctx.out (), " VS16" );
194- case unicode::EmojiSegmentationCategory::TagBase: return fmt::format_to (ctx.out (), " TagBase" );
195- case unicode::EmojiSegmentationCategory::TagSequence: return fmt::format_to (ctx.out (), " TagSequence" );
196- case unicode::EmojiSegmentationCategory::TagTerm: return fmt::format_to (ctx.out (), " TagTerm" );
197- // clang-format off
178+ case EmojiSegmentationCategory::Invalid: name = " Invalid" ; break ;
179+ case EmojiSegmentationCategory::Emoji: name = " Emoji" ; break ;
180+ case EmojiSegmentationCategory::EmojiTextPresentation: name = " EmojiTextPresentation" ; break ;
181+ case EmojiSegmentationCategory::EmojiEmojiPresentation: name = " EmojiEmojiPresentation" ; break ;
182+ case EmojiSegmentationCategory::EmojiModifierBase: name = " EmojiModifierBase" ; break ;
183+ case EmojiSegmentationCategory::EmojiModifier: name = " EmojiModifier" ; break ;
184+ case EmojiSegmentationCategory::EmojiVSBase: name = " EmojiVSBase" ; break ;
185+ case EmojiSegmentationCategory::RegionalIndicator: name = " RegionalIndicator" ; break ;
186+ case EmojiSegmentationCategory::KeyCapBase: name = " KeyCapBase" ; break ;
187+ case EmojiSegmentationCategory::CombiningEnclosingKeyCap: name = " CombiningEnclosingKeyCap" ; break ;
188+ case EmojiSegmentationCategory::CombiningEnclosingCircleBackslash: name = " CombiningEnclosingCircleBackslash" ; break ;
189+ case EmojiSegmentationCategory::ZWJ: name = " ZWJ" ; break ;
190+ case EmojiSegmentationCategory::VS15: name = " VS15" ; break ;
191+ case EmojiSegmentationCategory::VS16: name = " VS16" ; break ;
192+ case EmojiSegmentationCategory::TagBase: name = " TagBase" ; break ;
193+ case EmojiSegmentationCategory::TagSequence: name = " TagSequence" ; break ;
194+ case EmojiSegmentationCategory::TagTerm: name = " TagTerm" ; break ;
198195 }
199- return fmt::format_to (ctx. out (), " ({}) " , unsigned (value) );
200- }
196+ return formatter<string_view>:: format (name, ctx );
197+ }
201198};
202- }
203- #endif
204- #endif
205- // clang-format on
0 commit comments