#ifndef _LIBCPP___FORMAT_FORMATTER_STRING_H
#define _LIBCPP___FORMAT_FORMATTER_STRING_H
#include <__availability>
#include <__config>
#include <__format/format_fwd.h>
#include <__format/format_parse_context.h>
#include <__format/formatter.h>
#include <__format/formatter_output.h>
#include <__format/parser_std_format_spec.h>
#include <__utility/move.h>
#include <string>
#include <string_view>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER > 17
template <__formatter::__char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS __formatter_string {
public:
_LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx)
-> decltype(__parse_ctx.begin()) {
auto __result = __parser_.__parse(__parse_ctx, __format_spec::__fields_string);
__format_spec::__process_display_type_string(__parser_.__type_);
return __result;
}
_LIBCPP_HIDE_FROM_ABI auto format(basic_string_view<_CharT> __str, auto& __ctx) const -> decltype(__ctx.out()) {
return __formatter::__write_string(__str, __ctx.out(), __parser_.__get_parsed_std_specifications(__ctx));
}
__format_spec::__parser<_CharT> __parser_;
};
template <__formatter::__char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const _CharT*, _CharT>
: public __formatter_string<_CharT> {
using _Base = __formatter_string<_CharT>;
_LIBCPP_HIDE_FROM_ABI auto format(const _CharT* __str, auto& __ctx) const -> decltype(__ctx.out()) {
_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 (__specs.__has_width() || __specs.__has_precision())
return __formatter::__write_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs);
auto __out_it = __ctx.out();
while (*__str)
*__out_it++ = *__str++;
return __out_it;
}
};
template <__formatter::__char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT*, _CharT>
: public formatter<const _CharT*, _CharT> {
using _Base = formatter<const _CharT*, _CharT>;
_LIBCPP_HIDE_FROM_ABI auto format(_CharT* __str, auto& __ctx) const -> decltype(__ctx.out()) {
return _Base::format(__str, __ctx);
}
};
template <__formatter::__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>;
_LIBCPP_HIDE_FROM_ABI auto format(_CharT __str[_Size], auto& __ctx) const -> decltype(__ctx.out()) {
return _Base::format(basic_string_view<_CharT>(__str, _Size), __ctx);
}
};
template <__formatter::__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>;
_LIBCPP_HIDE_FROM_ABI auto format(const _CharT __str[_Size], auto& __ctx) const -> decltype(__ctx.out()) {
return _Base::format(basic_string_view<_CharT>(__str, _Size), __ctx);
}
};
template <__formatter::__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>;
_LIBCPP_HIDE_FROM_ABI auto format(const basic_string<_CharT, _Traits, _Allocator>& __str, auto& __ctx) const
-> decltype(__ctx.out()) {
return _Base::format(basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
}
};
template <__formatter::__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>;
_LIBCPP_HIDE_FROM_ABI auto format(basic_string_view<_CharT, _Traits> __str, auto& __ctx) const
-> decltype(__ctx.out()) {
return _Base::format(basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
}
};
#endif
_LIBCPP_END_NAMESPACE_STD
#endif