diff options
Diffstat (limited to 'libcxx/include/__format/formatter_string.h')
| -rw-r--r-- | libcxx/include/__format/formatter_string.h | 34 | 
1 files changed, 24 insertions, 10 deletions
| diff --git a/libcxx/include/__format/formatter_string.h b/libcxx/include/__format/formatter_string.h index 71bda4fcded1..606fb792499c 100644 --- a/libcxx/include/__format/formatter_string.h +++ b/libcxx/include/__format/formatter_string.h @@ -12,7 +12,7 @@  #include <__availability>  #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h>  #include <__format/format_parse_context.h>  #include <__format/formatter.h>  #include <__format/formatter_output.h> @@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD  #if _LIBCPP_STD_VER > 17 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT>  struct _LIBCPP_TEMPLATE_VIS __formatter_string {  public:    _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) @@ -40,14 +40,23 @@ public:    }    _LIBCPP_HIDE_FROM_ABI auto format(basic_string_view<_CharT> __str, auto& __ctx) const -> decltype(__ctx.out()) { +#  if _LIBCPP_STD_VER > 20 +    if (__parser_.__type_ == __format_spec::__type::__debug) +      return __formatter::__format_escaped_string(__str, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx)); +#  endif +      return __formatter::__write_string(__str, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx));    } -  __format_spec::__parser<_CharT> __parser_; +#  if _LIBCPP_STD_VER > 20 +  _LIBCPP_HIDE_FROM_ABI constexpr void set_debug_format() { __parser_.__type_ = __format_spec::__type::__debug; } +#  endif + +  __format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__left};  };  // Formatter const char*. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT>  struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const _CharT*, _CharT>      : public __formatter_string<_CharT> {    using _Base = __formatter_string<_CharT>; @@ -56,6 +65,12 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const _CharT*,      _LIBCPP_ASSERT(__str, "The basic_format_arg constructor should have "                            "prevented an invalid pointer."); +    __format_spec::__parsed_specifications<_CharT> __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx); +#  if _LIBCPP_STD_VER > 20 +    if (_Base::__parser_.__type_ == __format_spec::__type::__debug) +      return __formatter::__format_escaped_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs); +#  endif +      // When using a center or right alignment and the width option the length      // of __str must be known to add the padding upfront. This case is handled      // by the base class by converting the argument to a basic_string_view. @@ -67,7 +82,6 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const _CharT*,      // now these optimizations aren't implemented. Instead the base class      // handles these options.      // TODO FMT Implement these improvements. -    __format_spec::__parsed_specifications<_CharT> __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx);      if (__specs.__has_width() || __specs.__has_precision())        return __formatter::__write_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs); @@ -80,7 +94,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const _CharT*,  };  // Formatter char*. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT>  struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT*, _CharT>      : public formatter<const _CharT*, _CharT> {    using _Base = formatter<const _CharT*, _CharT>; @@ -91,7 +105,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT*, _Char  };  // Formatter char[]. -template <__formatter::__char_type _CharT, size_t _Size> +template <__fmt_char_type _CharT, size_t _Size>  struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT[_Size], _CharT>      : public __formatter_string<_CharT> {    using _Base = __formatter_string<_CharT>; @@ -102,7 +116,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT[_Size],  };  // Formatter const char[]. -template <__formatter::__char_type _CharT, size_t _Size> +template <__fmt_char_type _CharT, size_t _Size>  struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const _CharT[_Size], _CharT>      : public __formatter_string<_CharT> {    using _Base = __formatter_string<_CharT>; @@ -113,7 +127,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const _CharT[_  };  // Formatter std::string. -template <__formatter::__char_type _CharT, class _Traits, class _Allocator> +template <__fmt_char_type _CharT, class _Traits, class _Allocator>  struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<basic_string<_CharT, _Traits, _Allocator>, _CharT>      : public __formatter_string<_CharT> {    using _Base = __formatter_string<_CharT>; @@ -126,7 +140,7 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<basic_string<_  };  // Formatter std::string_view. -template <__formatter::__char_type _CharT, class _Traits> +template <__fmt_char_type _CharT, class _Traits>  struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<basic_string_view<_CharT, _Traits>, _CharT>      : public __formatter_string<_CharT> {    using _Base = __formatter_string<_CharT>; | 
