mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Release Cosmopolitan v3.6.0
This release is an atomic upgrade to GCC 14.1.0 with C23 and C++23
This commit is contained in:
parent
62ace3623a
commit
5660ec4741
1585 changed files with 117353 additions and 271644 deletions
299
third_party/libcxx/__chrono/formatter.h
vendored
299
third_party/libcxx/__chrono/formatter.h
vendored
|
@ -10,6 +10,7 @@
|
|||
#ifndef _LIBCPP___CHRONO_FORMATTER_H
|
||||
#define _LIBCPP___CHRONO_FORMATTER_H
|
||||
|
||||
#include <__algorithm/ranges_copy.h>
|
||||
#include <__chrono/calendar.h>
|
||||
#include <__chrono/concepts.h>
|
||||
#include <__chrono/convert_to_tm.h>
|
||||
|
@ -17,12 +18,14 @@
|
|||
#include <__chrono/duration.h>
|
||||
#include <__chrono/file_clock.h>
|
||||
#include <__chrono/hh_mm_ss.h>
|
||||
#include <__chrono/local_info.h>
|
||||
#include <__chrono/month.h>
|
||||
#include <__chrono/month_weekday.h>
|
||||
#include <__chrono/monthday.h>
|
||||
#include <__chrono/ostream.h>
|
||||
#include <__chrono/parser_std_format_spec.h>
|
||||
#include <__chrono/statically_widen.h>
|
||||
#include <__chrono/sys_info.h>
|
||||
#include <__chrono/system_clock.h>
|
||||
#include <__chrono/time_point.h>
|
||||
#include <__chrono/weekday.h>
|
||||
|
@ -30,6 +33,7 @@
|
|||
#include <__chrono/year_month.h>
|
||||
#include <__chrono/year_month_day.h>
|
||||
#include <__chrono/year_month_weekday.h>
|
||||
#include <__chrono/zoned_time.h>
|
||||
#include <__concepts/arithmetic.h>
|
||||
#include <__concepts/same_as.h>
|
||||
#include <__config>
|
||||
|
@ -38,13 +42,14 @@
|
|||
#include <__format/format_functions.h>
|
||||
#include <__format/format_parse_context.h>
|
||||
#include <__format/formatter.h>
|
||||
#include <__format/formatter_output.h>
|
||||
#include <__format/parser_std_format_spec.h>
|
||||
#include <__format/write_escaped.h>
|
||||
#include <__memory/addressof.h>
|
||||
#include <__type_traits/is_specialization.h>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
|
@ -80,12 +85,15 @@ namespace __formatter {
|
|||
// small). Therefore a duration uses its own conversion.
|
||||
template <class _CharT, class _Rep, class _Period>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
__format_sub_seconds(const chrono::duration<_Rep, _Period>& __value, basic_stringstream<_CharT>& __sstr) {
|
||||
__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::duration<_Rep, _Period>& __value) {
|
||||
__sstr << std::use_facet<numpunct<_CharT>>(__sstr.getloc()).decimal_point();
|
||||
|
||||
using __duration = chrono::duration<_Rep, _Period>;
|
||||
|
||||
auto __fraction = __value - chrono::duration_cast<chrono::seconds>(__value);
|
||||
// Converts a negative fraction to its positive value.
|
||||
if (__value < chrono::seconds{0} && __fraction != __duration{0})
|
||||
__fraction += chrono::seconds{1};
|
||||
if constexpr (chrono::treat_as_floating_point_v<_Rep>)
|
||||
// When the floating-point value has digits itself they are ignored based
|
||||
// on the wording in [tab:time.format.spec]
|
||||
|
@ -101,23 +109,23 @@ __format_sub_seconds(const chrono::duration<_Rep, _Period>& __value, basic_strin
|
|||
// https://godbolt.org/z/6dsbnW8ba
|
||||
std::format_to(std::ostreambuf_iterator<_CharT>{__sstr},
|
||||
_LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"),
|
||||
__fraction.count(),
|
||||
chrono::duration_cast<typename chrono::hh_mm_ss<__duration>::precision>(__fraction).count(),
|
||||
chrono::hh_mm_ss<__duration>::fractional_width);
|
||||
else
|
||||
std::format_to(std::ostreambuf_iterator<_CharT>{__sstr},
|
||||
_LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}}"),
|
||||
__fraction.count(),
|
||||
chrono::duration_cast<typename chrono::hh_mm_ss<__duration>::precision>(__fraction).count(),
|
||||
chrono::hh_mm_ss<__duration>::fractional_width);
|
||||
}
|
||||
|
||||
template <class _CharT, __is_time_point _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI void __format_sub_seconds(const _Tp& __value, basic_stringstream<_CharT>& __sstr) {
|
||||
__formatter::__format_sub_seconds(__value.time_since_epoch(), __sstr);
|
||||
_LIBCPP_HIDE_FROM_ABI void __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const _Tp& __value) {
|
||||
__formatter::__format_sub_seconds(__sstr, __value.time_since_epoch());
|
||||
}
|
||||
|
||||
template <class _CharT, class _Duration>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
__format_sub_seconds(const chrono::hh_mm_ss<_Duration>& __value, basic_stringstream<_CharT>& __sstr) {
|
||||
__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::hh_mm_ss<_Duration>& __value) {
|
||||
__sstr << std::use_facet<numpunct<_CharT>>(__sstr.getloc()).decimal_point();
|
||||
if constexpr (chrono::treat_as_floating_point_v<typename _Duration::rep>)
|
||||
std::format_to(std::ostreambuf_iterator<_CharT>{__sstr},
|
||||
|
@ -131,10 +139,24 @@ __format_sub_seconds(const chrono::hh_mm_ss<_Duration>& __value, basic_stringstr
|
|||
__value.fractional_width);
|
||||
}
|
||||
|
||||
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
|
||||
!defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
template <class _CharT, class _Duration, class _TimeZonePtr>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::zoned_time<_Duration, _TimeZonePtr>& __value) {
|
||||
__formatter::__format_sub_seconds(__sstr, __value.get_local_time().time_since_epoch());
|
||||
}
|
||||
# endif
|
||||
|
||||
template <class _Tp>
|
||||
consteval bool __use_fraction() {
|
||||
if constexpr (__is_time_point<_Tp>)
|
||||
return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
|
||||
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
|
||||
!defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
|
||||
return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
|
||||
# endif
|
||||
else if constexpr (chrono::__is_duration<_Tp>::value)
|
||||
return chrono::hh_mm_ss<_Tp>::fractional_width;
|
||||
else if constexpr (__is_hh_mm_ss<_Tp>)
|
||||
|
@ -144,7 +166,7 @@ consteval bool __use_fraction() {
|
|||
}
|
||||
|
||||
template <class _CharT>
|
||||
_LIBCPP_HIDE_FROM_ABI void __format_year(int __year, basic_stringstream<_CharT>& __sstr) {
|
||||
_LIBCPP_HIDE_FROM_ABI void __format_year(basic_stringstream<_CharT>& __sstr, int __year) {
|
||||
if (__year < 0) {
|
||||
__sstr << _CharT('-');
|
||||
__year = -__year;
|
||||
|
@ -160,7 +182,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_year(int __year, basic_stringstream<_CharT>&
|
|||
}
|
||||
|
||||
template <class _CharT>
|
||||
_LIBCPP_HIDE_FROM_ABI void __format_century(int __year, basic_stringstream<_CharT>& __sstr) {
|
||||
_LIBCPP_HIDE_FROM_ABI void __format_century(basic_stringstream<_CharT>& __sstr, int __year) {
|
||||
// TODO FMT Write an issue
|
||||
// [tab:time.format.spec]
|
||||
// %C The year divided by 100 using floored division. If the result is a
|
||||
|
@ -171,10 +193,56 @@ _LIBCPP_HIDE_FROM_ABI void __format_century(int __year, basic_stringstream<_Char
|
|||
__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __century);
|
||||
}
|
||||
|
||||
// Implements the %z format specifier according to [tab:time.format.spec], where
|
||||
// '__modifier' signals %Oz or %Ez were used. (Both modifiers behave the same,
|
||||
// so there is no need to distinguish between them.)
|
||||
template <class _CharT>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
__format_zone_offset(basic_stringstream<_CharT>& __sstr, chrono::seconds __offset, bool __modifier) {
|
||||
if (__offset < 0s) {
|
||||
__sstr << _CharT('-');
|
||||
__offset = -__offset;
|
||||
} else {
|
||||
__sstr << _CharT('+');
|
||||
}
|
||||
|
||||
chrono::hh_mm_ss __hms{__offset};
|
||||
std::ostreambuf_iterator<_CharT> __out_it{__sstr};
|
||||
// Note HMS does not allow formatting hours > 23, but the offset is not limited to 24H.
|
||||
std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __hms.hours().count());
|
||||
if (__modifier)
|
||||
__sstr << _CharT(':');
|
||||
std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __hms.minutes().count());
|
||||
}
|
||||
|
||||
// Helper to store the time zone information needed for formatting.
|
||||
struct _LIBCPP_HIDE_FROM_ABI __time_zone {
|
||||
// Typically these abbreviations are short and fit in the string's internal
|
||||
// buffer.
|
||||
string __abbrev;
|
||||
chrono::seconds __offset;
|
||||
};
|
||||
|
||||
template <class _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] const _Tp& __value) {
|
||||
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
if constexpr (same_as<_Tp, chrono::sys_info>)
|
||||
return {__value.abbrev, __value.offset};
|
||||
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
|
||||
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
|
||||
return __formatter::__convert_to_time_zone(__value.get_info());
|
||||
# endif
|
||||
else
|
||||
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
return {"UTC", chrono::seconds{0}};
|
||||
}
|
||||
|
||||
template <class _CharT, class _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
|
||||
const _Tp& __value, basic_stringstream<_CharT>& __sstr, basic_string_view<_CharT> __chrono_specs) {
|
||||
basic_stringstream<_CharT>& __sstr, const _Tp& __value, basic_string_view<_CharT> __chrono_specs) {
|
||||
tm __t = std::__convert_to_tm<tm>(__value);
|
||||
__time_zone __z = __formatter::__convert_to_time_zone(__value);
|
||||
const auto& __facet = std::use_facet<time_put<_CharT>>(__sstr.getloc());
|
||||
for (auto __it = __chrono_specs.begin(); __it != __chrono_specs.end(); ++__it) {
|
||||
if (*__it == _CharT('%')) {
|
||||
|
@ -197,9 +265,10 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
|
|||
// strftime's output is only defined in the range [00, 99].
|
||||
int __year = __t.tm_year + 1900;
|
||||
if (__year < 1000 || __year > 9999)
|
||||
__formatter::__format_century(__year, __sstr);
|
||||
__formatter::__format_century(__sstr, __year);
|
||||
else
|
||||
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
__facet.put(
|
||||
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
} break;
|
||||
|
||||
case _CharT('j'):
|
||||
|
@ -210,7 +279,8 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
|
|||
// an intemediate step.
|
||||
__sstr << chrono::duration_cast<chrono::days>(chrono::duration_cast<chrono::seconds>(__value)).count();
|
||||
else
|
||||
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
__facet.put(
|
||||
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
break;
|
||||
|
||||
case _CharT('q'):
|
||||
|
@ -238,9 +308,10 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
|
|||
|
||||
case _CharT('S'):
|
||||
case _CharT('T'):
|
||||
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
__facet.put(
|
||||
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
if constexpr (__use_fraction<_Tp>())
|
||||
__formatter::__format_sub_seconds(__value, __sstr);
|
||||
__formatter::__format_sub_seconds(__sstr, __value);
|
||||
break;
|
||||
|
||||
// Unlike time_put and strftime the formatting library requires %Y
|
||||
|
@ -281,21 +352,24 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
|
|||
// Depending on the platform's libc the range of supported years is
|
||||
// limited. Intead of of testing all conditions use the internal
|
||||
// implementation unconditionally.
|
||||
__formatter::__format_year(__t.tm_year + 1900, __sstr);
|
||||
__formatter::__format_year(__sstr, __t.tm_year + 1900);
|
||||
break;
|
||||
|
||||
case _CharT('F'): {
|
||||
int __year = __t.tm_year + 1900;
|
||||
if (__year < 1000) {
|
||||
__formatter::__format_year(__year, __sstr);
|
||||
__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
|
||||
} else
|
||||
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
} break;
|
||||
case _CharT('F'):
|
||||
// Depending on the platform's libc the range of supported years is
|
||||
// limited. Instead of testing all conditions use the internal
|
||||
// implementation unconditionally.
|
||||
__formatter::__format_year(__sstr, __t.tm_year + 1900);
|
||||
__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
|
||||
break;
|
||||
|
||||
case _CharT('z'):
|
||||
__formatter::__format_zone_offset(__sstr, __z.__offset, false);
|
||||
break;
|
||||
|
||||
case _CharT('Z'):
|
||||
// TODO FMT Add proper timezone support.
|
||||
__sstr << _LIBCPP_STATICALLY_WIDEN(_CharT, "UTC");
|
||||
// __abbrev is always a char so the copy may convert.
|
||||
ranges::copy(__z.__abbrev, std::ostreambuf_iterator<_CharT>{__sstr});
|
||||
break;
|
||||
|
||||
case _CharT('O'):
|
||||
|
@ -305,17 +379,25 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
|
|||
// fractional part should be formatted.
|
||||
if (*(__it + 1) == 'S') {
|
||||
++__it;
|
||||
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
__formatter::__format_sub_seconds(__value, __sstr);
|
||||
__facet.put(
|
||||
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
__formatter::__format_sub_seconds(__sstr, __value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Oz produces the same output as Ez below.
|
||||
[[fallthrough]];
|
||||
case _CharT('E'):
|
||||
++__it;
|
||||
if (*__it == 'z') {
|
||||
__formatter::__format_zone_offset(__sstr, __z.__offset, true);
|
||||
break;
|
||||
}
|
||||
[[fallthrough]];
|
||||
default:
|
||||
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
__facet.put(
|
||||
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -360,6 +442,17 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const _Tp& __value) {
|
|||
return __value.weekday().ok();
|
||||
else if constexpr (__is_hh_mm_ss<_Tp>)
|
||||
return true;
|
||||
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
else if constexpr (same_as<_Tp, chrono::sys_info>)
|
||||
return true;
|
||||
else if constexpr (same_as<_Tp, chrono::local_info>)
|
||||
return true;
|
||||
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
|
||||
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
|
||||
return true;
|
||||
# endif
|
||||
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
else
|
||||
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
|
||||
}
|
||||
|
@ -400,6 +493,17 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_name_ok(const _Tp& __value) {
|
|||
return __value.weekday().ok();
|
||||
else if constexpr (__is_hh_mm_ss<_Tp>)
|
||||
return true;
|
||||
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
else if constexpr (same_as<_Tp, chrono::sys_info>)
|
||||
return true;
|
||||
else if constexpr (same_as<_Tp, chrono::local_info>)
|
||||
return true;
|
||||
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
|
||||
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
|
||||
return true;
|
||||
# endif
|
||||
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
else
|
||||
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
|
||||
}
|
||||
|
@ -440,6 +544,17 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __date_ok(const _Tp& __value) {
|
|||
return __value.ok();
|
||||
else if constexpr (__is_hh_mm_ss<_Tp>)
|
||||
return true;
|
||||
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
else if constexpr (same_as<_Tp, chrono::sys_info>)
|
||||
return true;
|
||||
else if constexpr (same_as<_Tp, chrono::local_info>)
|
||||
return true;
|
||||
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
|
||||
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
|
||||
return true;
|
||||
# endif
|
||||
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
else
|
||||
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
|
||||
}
|
||||
|
@ -480,6 +595,17 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __month_name_ok(const _Tp& __value) {
|
|||
return __value.month().ok();
|
||||
else if constexpr (__is_hh_mm_ss<_Tp>)
|
||||
return true;
|
||||
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
else if constexpr (same_as<_Tp, chrono::sys_info>)
|
||||
return true;
|
||||
else if constexpr (same_as<_Tp, chrono::local_info>)
|
||||
return true;
|
||||
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
|
||||
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
|
||||
return true;
|
||||
# endif
|
||||
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
else
|
||||
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
|
||||
}
|
||||
|
@ -505,28 +631,35 @@ __format_chrono(const _Tp& __value,
|
|||
__sstr << __value;
|
||||
else {
|
||||
if constexpr (chrono::__is_duration<_Tp>::value) {
|
||||
if (__value < __value.zero())
|
||||
__sstr << _CharT('-');
|
||||
__formatter::__format_chrono_using_chrono_specs(chrono::abs(__value), __sstr, __chrono_specs);
|
||||
// A duration can be a user defined arithmetic type. Users may specialize
|
||||
// numeric_limits, but they may not specialize is_signed.
|
||||
if constexpr (numeric_limits<typename _Tp::rep>::is_signed) {
|
||||
if (__value < __value.zero()) {
|
||||
__sstr << _CharT('-');
|
||||
__formatter::__format_chrono_using_chrono_specs(__sstr, -__value, __chrono_specs);
|
||||
} else
|
||||
__formatter::__format_chrono_using_chrono_specs(__sstr, __value, __chrono_specs);
|
||||
} else
|
||||
__formatter::__format_chrono_using_chrono_specs(__sstr, __value, __chrono_specs);
|
||||
// TODO FMT When keeping the precision it will truncate the string.
|
||||
// Note that the behaviour what the precision does isn't specified.
|
||||
__specs.__precision_ = -1;
|
||||
} else {
|
||||
// Test __weekday_name_ before __weekday_ to give a better error.
|
||||
if (__specs.__chrono_.__weekday_name_ && !__formatter::__weekday_name_ok(__value))
|
||||
std::__throw_format_error("formatting a weekday name needs a valid weekday");
|
||||
std::__throw_format_error("Formatting a weekday name needs a valid weekday");
|
||||
|
||||
if (__specs.__chrono_.__weekday_ && !__formatter::__weekday_ok(__value))
|
||||
std::__throw_format_error("formatting a weekday needs a valid weekday");
|
||||
std::__throw_format_error("Formatting a weekday needs a valid weekday");
|
||||
|
||||
if (__specs.__chrono_.__day_of_year_ && !__formatter::__date_ok(__value))
|
||||
std::__throw_format_error("formatting a day of year needs a valid date");
|
||||
std::__throw_format_error("Formatting a day of year needs a valid date");
|
||||
|
||||
if (__specs.__chrono_.__week_of_year_ && !__formatter::__date_ok(__value))
|
||||
std::__throw_format_error("formatting a week of year needs a valid date");
|
||||
std::__throw_format_error("Formatting a week of year needs a valid date");
|
||||
|
||||
if (__specs.__chrono_.__month_name_ && !__formatter::__month_name_ok(__value))
|
||||
std::__throw_format_error("formatting a month name from an invalid month number");
|
||||
std::__throw_format_error("Formatting a month name from an invalid month number");
|
||||
|
||||
if constexpr (__is_hh_mm_ss<_Tp>) {
|
||||
// Note this is a pedantic intepretation of the Standard. A hh_mm_ss
|
||||
|
@ -545,13 +678,13 @@ __format_chrono(const _Tp& __value,
|
|||
// - Write it as not valid,
|
||||
// - or write the number of days.
|
||||
if (__specs.__chrono_.__hour_ && __value.hours().count() > 23)
|
||||
std::__throw_format_error("formatting a hour needs a valid value");
|
||||
std::__throw_format_error("Formatting a hour needs a valid value");
|
||||
|
||||
if (__value.is_negative())
|
||||
__sstr << _CharT('-');
|
||||
}
|
||||
|
||||
__formatter::__format_chrono_using_chrono_specs(__value, __sstr, __chrono_specs);
|
||||
__formatter::__format_chrono_using_chrono_specs(__sstr, __value, __chrono_specs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -635,8 +768,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::day, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::day, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -647,8 +779,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -659,8 +790,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -671,8 +801,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -683,8 +812,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_indexed, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_indexed, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -695,8 +823,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_last, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_last, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -707,8 +834,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -719,8 +845,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day_last, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day_last, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -731,8 +856,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -743,8 +867,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday_last, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -755,8 +878,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -767,8 +889,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -779,8 +900,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day_last, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day_last, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -791,8 +911,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -803,8 +922,7 @@ public:
|
|||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday_last, _CharT>
|
||||
: public __formatter_chrono<_CharT> {
|
||||
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
|
@ -824,6 +942,47 @@ public:
|
|||
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__time);
|
||||
}
|
||||
};
|
||||
|
||||
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
template <__fmt_char_type _CharT>
|
||||
struct formatter<chrono::sys_info, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
template <class _ParseContext>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
|
||||
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__time_zone);
|
||||
}
|
||||
};
|
||||
|
||||
template <__fmt_char_type _CharT>
|
||||
struct formatter<chrono::local_info, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
template <class _ParseContext>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
|
||||
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags{});
|
||||
}
|
||||
};
|
||||
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
|
||||
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
// Note due to how libc++'s formatters are implemented there is no need to add
|
||||
// the exposition only local-time-format-t abstraction.
|
||||
template <class _Duration, class _TimeZonePtr, __fmt_char_type _CharT>
|
||||
struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT> : public __formatter_chrono<_CharT> {
|
||||
public:
|
||||
using _Base = __formatter_chrono<_CharT>;
|
||||
|
||||
template <class _ParseContext>
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
|
||||
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock);
|
||||
}
|
||||
};
|
||||
# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&
|
||||
// !defined(_LIBCPP_HAS_NO_LOCALIZATION)
|
||||
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
||||
|
||||
#endif // if _LIBCPP_STD_VER >= 20
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue