File indexing completed on 2026-05-03 08:13:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___FORMAT_FORMATTER_CHAR_H
0011 #define _LIBCPP___CXX03___FORMAT_FORMATTER_CHAR_H
0012
0013 #include <__cxx03/__concepts/same_as.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__format/concepts.h>
0016 #include <__cxx03/__format/format_parse_context.h>
0017 #include <__cxx03/__format/formatter.h>
0018 #include <__cxx03/__format/formatter_integral.h>
0019 #include <__cxx03/__format/formatter_output.h>
0020 #include <__cxx03/__format/parser_std_format_spec.h>
0021 #include <__cxx03/__format/write_escaped.h>
0022 #include <__cxx03/__type_traits/conditional.h>
0023 #include <__cxx03/__type_traits/make_unsigned.h>
0024
0025 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0026 # pragma GCC system_header
0027 #endif
0028
0029 _LIBCPP_BEGIN_NAMESPACE_STD
0030
0031 #if _LIBCPP_STD_VER >= 20
0032
0033 template <__fmt_char_type _CharT>
0034 struct _LIBCPP_TEMPLATE_VIS __formatter_char {
0035 public:
0036 template <class _ParseContext>
0037 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
0038 typename _ParseContext::iterator __result = __parser_.__parse(__ctx, __format_spec::__fields_integral);
0039 __format_spec::__process_parsed_char(__parser_, "a character");
0040 return __result;
0041 }
0042
0043 template <class _FormatContext>
0044 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(_CharT __value, _FormatContext& __ctx) const {
0045 if (__parser_.__type_ == __format_spec::__type::__default || __parser_.__type_ == __format_spec::__type::__char)
0046 return __formatter::__format_char(__value, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx));
0047
0048 # if _LIBCPP_STD_VER >= 23
0049 if (__parser_.__type_ == __format_spec::__type::__debug)
0050 return __formatter::__format_escaped_char(__value, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx));
0051 # endif
0052
0053 if constexpr (sizeof(_CharT) <= sizeof(unsigned))
0054 return __formatter::__format_integer(
0055 static_cast<unsigned>(static_cast<make_unsigned_t<_CharT>>(__value)),
0056 __ctx,
0057 __parser_.__get_parsed_std_specifications(__ctx));
0058 else
0059 return __formatter::__format_integer(
0060 static_cast<make_unsigned_t<_CharT>>(__value), __ctx, __parser_.__get_parsed_std_specifications(__ctx));
0061 }
0062
0063 template <class _FormatContext>
0064 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(char __value, _FormatContext& __ctx) const
0065 requires(same_as<_CharT, wchar_t>)
0066 {
0067 return format(static_cast<wchar_t>(static_cast<unsigned char>(__value)), __ctx);
0068 }
0069
0070 # if _LIBCPP_STD_VER >= 23
0071 _LIBCPP_HIDE_FROM_ABI constexpr void set_debug_format() { __parser_.__type_ = __format_spec::__type::__debug; }
0072 # endif
0073
0074 __format_spec::__parser<_CharT> __parser_;
0075 };
0076
0077 template <>
0078 struct _LIBCPP_TEMPLATE_VIS formatter<char, char> : public __formatter_char<char> {};
0079
0080 # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0081 template <>
0082 struct _LIBCPP_TEMPLATE_VIS formatter<char, wchar_t> : public __formatter_char<wchar_t> {};
0083
0084 template <>
0085 struct _LIBCPP_TEMPLATE_VIS formatter<wchar_t, wchar_t> : public __formatter_char<wchar_t> {};
0086
0087 # endif
0088
0089 #endif
0090
0091 _LIBCPP_END_NAMESPACE_STD
0092
0093 #endif