Path: blob/main/contrib/llvm-project/libcxx/include/__locale_dir/time.h
213766 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___LOCALE_DIR_TIME_H9#define _LIBCPP___LOCALE_DIR_TIME_H1011#include <__algorithm/copy.h>12#include <__config>13#include <__locale_dir/get_c_locale.h>14#include <__locale_dir/scan_keyword.h>15#include <ios>1617#if _LIBCPP_HAS_LOCALIZATION1819# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)20# pragma GCC system_header21# endif2223_LIBCPP_BEGIN_NAMESPACE_STD2425template <class _CharT, class _InputIterator>26_LIBCPP_HIDE_FROM_ABI int __get_up_to_n_digits(27_InputIterator& __b, _InputIterator __e, ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) {28// Precondition: __n >= 129if (__b == __e) {30__err |= ios_base::eofbit | ios_base::failbit;31return 0;32}33// get first digit34_CharT __c = *__b;35if (!__ct.is(ctype_base::digit, __c)) {36__err |= ios_base::failbit;37return 0;38}39int __r = __ct.narrow(__c, 0) - '0';40for (++__b, (void)--__n; __b != __e && __n > 0; ++__b, (void)--__n) {41// get next digit42__c = *__b;43if (!__ct.is(ctype_base::digit, __c))44return __r;45__r = __r * 10 + __ct.narrow(__c, 0) - '0';46}47if (__b == __e)48__err |= ios_base::eofbit;49return __r;50}5152class _LIBCPP_EXPORTED_FROM_ABI time_base {53public:54enum dateorder { no_order, dmy, mdy, ymd, ydm };55};5657template <class _CharT>58class __time_get_c_storage {59protected:60typedef basic_string<_CharT> string_type;6162virtual const string_type* __weeks() const;63virtual const string_type* __months() const;64virtual const string_type* __am_pm() const;65virtual const string_type& __c() const;66virtual const string_type& __r() const;67virtual const string_type& __x() const;68virtual const string_type& __X() const;6970_LIBCPP_HIDE_FROM_ABI ~__time_get_c_storage() {}71};7273template <>74_LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__weeks() const;75template <>76_LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__months() const;77template <>78_LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__am_pm() const;79template <>80_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__c() const;81template <>82_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__r() const;83template <>84_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__x() const;85template <>86_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__X() const;8788# if _LIBCPP_HAS_WIDE_CHARACTERS89template <>90_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__weeks() const;91template <>92_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__months() const;93template <>94_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__am_pm() const;95template <>96_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__c() const;97template <>98_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__r() const;99template <>100_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__x() const;101template <>102_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__X() const;103# endif104105template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >106class time_get : public locale::facet, public time_base, private __time_get_c_storage<_CharT> {107public:108typedef _CharT char_type;109typedef _InputIterator iter_type;110typedef time_base::dateorder dateorder;111typedef basic_string<char_type> string_type;112113_LIBCPP_HIDE_FROM_ABI explicit time_get(size_t __refs = 0) : locale::facet(__refs) {}114115_LIBCPP_HIDE_FROM_ABI dateorder date_order() const { return this->do_date_order(); }116117_LIBCPP_HIDE_FROM_ABI iter_type118get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {119return do_get_time(__b, __e, __iob, __err, __tm);120}121122_LIBCPP_HIDE_FROM_ABI iter_type123get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {124return do_get_date(__b, __e, __iob, __err, __tm);125}126127_LIBCPP_HIDE_FROM_ABI iter_type128get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {129return do_get_weekday(__b, __e, __iob, __err, __tm);130}131132_LIBCPP_HIDE_FROM_ABI iter_type133get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {134return do_get_monthname(__b, __e, __iob, __err, __tm);135}136137_LIBCPP_HIDE_FROM_ABI iter_type138get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {139return do_get_year(__b, __e, __iob, __err, __tm);140}141142_LIBCPP_HIDE_FROM_ABI iter_type143get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod = 0)144const {145return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod);146}147148iter_type149get(iter_type __b,150iter_type __e,151ios_base& __iob,152ios_base::iostate& __err,153tm* __tm,154const char_type* __fmtb,155const char_type* __fmte) const;156157static locale::id id;158159protected:160_LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get() override {}161162virtual dateorder do_date_order() const;163virtual iter_type164do_get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;165virtual iter_type166do_get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;167virtual iter_type168do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;169virtual iter_type170do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;171virtual iter_type172do_get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;173virtual iter_type do_get(174iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod) const;175176private:177void __get_white_space(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;178void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;179180void __get_weekdayname(181int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;182void __get_monthname(183int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;184void __get_day(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;185void186__get_month(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;187void188__get_year(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;189void190__get_year4(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;191void192__get_hour(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;193void194__get_12_hour(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;195void196__get_am_pm(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;197void198__get_minute(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;199void200__get_second(int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;201void202__get_weekday(int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;203void __get_day_year_num(204int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;205};206207template <class _CharT, class _InputIterator>208locale::id time_get<_CharT, _InputIterator>::id;209210// time_get primitives211212template <class _CharT, class _InputIterator>213void time_get<_CharT, _InputIterator>::__get_weekdayname(214int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {215// Note: ignoring case comes from the POSIX strptime spec216const string_type* __wk = this->__weeks();217ptrdiff_t __i = std::__scan_keyword(__b, __e, __wk, __wk + 14, __ct, __err, false) - __wk;218if (__i < 14)219__w = __i % 7;220}221222template <class _CharT, class _InputIterator>223void time_get<_CharT, _InputIterator>::__get_monthname(224int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {225// Note: ignoring case comes from the POSIX strptime spec226const string_type* __month = this->__months();227ptrdiff_t __i = std::__scan_keyword(__b, __e, __month, __month + 24, __ct, __err, false) - __month;228if (__i < 24)229__m = __i % 12;230}231232template <class _CharT, class _InputIterator>233void time_get<_CharT, _InputIterator>::__get_day(234int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {235int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);236if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31)237__d = __t;238else239__err |= ios_base::failbit;240}241242template <class _CharT, class _InputIterator>243void time_get<_CharT, _InputIterator>::__get_month(244int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {245int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1;246if (!(__err & ios_base::failbit) && 0 <= __t && __t <= 11)247__m = __t;248else249__err |= ios_base::failbit;250}251252template <class _CharT, class _InputIterator>253void time_get<_CharT, _InputIterator>::__get_year(254int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {255int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);256if (!(__err & ios_base::failbit)) {257if (__t < 69)258__t += 2000;259else if (69 <= __t && __t <= 99)260__t += 1900;261__y = __t - 1900;262}263}264265template <class _CharT, class _InputIterator>266void time_get<_CharT, _InputIterator>::__get_year4(267int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {268int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);269if (!(__err & ios_base::failbit))270__y = __t - 1900;271}272273template <class _CharT, class _InputIterator>274void time_get<_CharT, _InputIterator>::__get_hour(275int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {276int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);277if (!(__err & ios_base::failbit) && __t <= 23)278__h = __t;279else280__err |= ios_base::failbit;281}282283template <class _CharT, class _InputIterator>284void time_get<_CharT, _InputIterator>::__get_12_hour(285int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {286int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);287if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12)288__h = __t;289else290__err |= ios_base::failbit;291}292293template <class _CharT, class _InputIterator>294void time_get<_CharT, _InputIterator>::__get_minute(295int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {296int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);297if (!(__err & ios_base::failbit) && __t <= 59)298__m = __t;299else300__err |= ios_base::failbit;301}302303template <class _CharT, class _InputIterator>304void time_get<_CharT, _InputIterator>::__get_second(305int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {306int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);307if (!(__err & ios_base::failbit) && __t <= 60)308__s = __t;309else310__err |= ios_base::failbit;311}312313template <class _CharT, class _InputIterator>314void time_get<_CharT, _InputIterator>::__get_weekday(315int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {316int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 1);317if (!(__err & ios_base::failbit) && __t <= 6)318__w = __t;319else320__err |= ios_base::failbit;321}322323template <class _CharT, class _InputIterator>324void time_get<_CharT, _InputIterator>::__get_day_year_num(325int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {326int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 3);327if (!(__err & ios_base::failbit) && __t <= 365)328__d = __t;329else330__err |= ios_base::failbit;331}332333template <class _CharT, class _InputIterator>334void time_get<_CharT, _InputIterator>::__get_white_space(335iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {336for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)337;338if (__b == __e)339__err |= ios_base::eofbit;340}341342template <class _CharT, class _InputIterator>343void time_get<_CharT, _InputIterator>::__get_am_pm(344int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {345const string_type* __ap = this->__am_pm();346if (__ap[0].size() + __ap[1].size() == 0) {347__err |= ios_base::failbit;348return;349}350ptrdiff_t __i = std::__scan_keyword(__b, __e, __ap, __ap + 2, __ct, __err, false) - __ap;351if (__i == 0 && __h == 12)352__h = 0;353else if (__i == 1 && __h < 12)354__h += 12;355}356357template <class _CharT, class _InputIterator>358void time_get<_CharT, _InputIterator>::__get_percent(359iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {360if (__b == __e) {361__err |= ios_base::eofbit | ios_base::failbit;362return;363}364if (__ct.narrow(*__b, 0) != '%')365__err |= ios_base::failbit;366else if (++__b == __e)367__err |= ios_base::eofbit;368}369370// time_get end primitives371372template <class _CharT, class _InputIterator>373_InputIterator time_get<_CharT, _InputIterator>::get(374iter_type __b,375iter_type __e,376ios_base& __iob,377ios_base::iostate& __err,378tm* __tm,379const char_type* __fmtb,380const char_type* __fmte) const {381const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());382__err = ios_base::goodbit;383while (__fmtb != __fmte && __err == ios_base::goodbit) {384if (__b == __e) {385__err = ios_base::failbit;386break;387}388if (__ct.narrow(*__fmtb, 0) == '%') {389if (++__fmtb == __fmte) {390__err = ios_base::failbit;391break;392}393char __cmd = __ct.narrow(*__fmtb, 0);394char __opt = '\0';395if (__cmd == 'E' || __cmd == '0') {396if (++__fmtb == __fmte) {397__err = ios_base::failbit;398break;399}400__opt = __cmd;401__cmd = __ct.narrow(*__fmtb, 0);402}403__b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt);404++__fmtb;405} else if (__ct.is(ctype_base::space, *__fmtb)) {406for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb)407;408for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)409;410} else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) {411++__b;412++__fmtb;413} else414__err = ios_base::failbit;415}416if (__b == __e)417__err |= ios_base::eofbit;418return __b;419}420421template <class _CharT, class _InputIterator>422typename time_get<_CharT, _InputIterator>::dateorder time_get<_CharT, _InputIterator>::do_date_order() const {423return mdy;424}425426template <class _CharT, class _InputIterator>427_InputIterator time_get<_CharT, _InputIterator>::do_get_time(428iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {429const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};430return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt) / sizeof(__fmt[0]));431}432433template <class _CharT, class _InputIterator>434_InputIterator time_get<_CharT, _InputIterator>::do_get_date(435iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {436const string_type& __fmt = this->__x();437return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());438}439440template <class _CharT, class _InputIterator>441_InputIterator time_get<_CharT, _InputIterator>::do_get_weekday(442iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {443const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());444__get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);445return __b;446}447448template <class _CharT, class _InputIterator>449_InputIterator time_get<_CharT, _InputIterator>::do_get_monthname(450iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {451const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());452__get_monthname(__tm->tm_mon, __b, __e, __err, __ct);453return __b;454}455456template <class _CharT, class _InputIterator>457_InputIterator time_get<_CharT, _InputIterator>::do_get_year(458iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {459const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());460__get_year(__tm->tm_year, __b, __e, __err, __ct);461return __b;462}463464template <class _CharT, class _InputIterator>465_InputIterator time_get<_CharT, _InputIterator>::do_get(466iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char) const {467__err = ios_base::goodbit;468const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());469switch (__fmt) {470case 'a':471case 'A':472__get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);473break;474case 'b':475case 'B':476case 'h':477__get_monthname(__tm->tm_mon, __b, __e, __err, __ct);478break;479case 'c': {480const string_type& __fm = this->__c();481__b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());482} break;483case 'd':484case 'e':485__get_day(__tm->tm_mday, __b, __e, __err, __ct);486break;487case 'D': {488const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};489__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));490} break;491case 'F': {492const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};493__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));494} break;495case 'H':496__get_hour(__tm->tm_hour, __b, __e, __err, __ct);497break;498case 'I':499__get_12_hour(__tm->tm_hour, __b, __e, __err, __ct);500break;501case 'j':502__get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct);503break;504case 'm':505__get_month(__tm->tm_mon, __b, __e, __err, __ct);506break;507case 'M':508__get_minute(__tm->tm_min, __b, __e, __err, __ct);509break;510case 'n':511case 't':512__get_white_space(__b, __e, __err, __ct);513break;514case 'p':515__get_am_pm(__tm->tm_hour, __b, __e, __err, __ct);516break;517case 'r': {518const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};519__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));520} break;521case 'R': {522const char_type __fm[] = {'%', 'H', ':', '%', 'M'};523__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));524} break;525case 'S':526__get_second(__tm->tm_sec, __b, __e, __err, __ct);527break;528case 'T': {529const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};530__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));531} break;532case 'w':533__get_weekday(__tm->tm_wday, __b, __e, __err, __ct);534break;535case 'x':536return do_get_date(__b, __e, __iob, __err, __tm);537case 'X': {538const string_type& __fm = this->__X();539__b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());540} break;541case 'y':542__get_year(__tm->tm_year, __b, __e, __err, __ct);543break;544case 'Y':545__get_year4(__tm->tm_year, __b, __e, __err, __ct);546break;547case '%':548__get_percent(__b, __e, __err, __ct);549break;550default:551__err |= ios_base::failbit;552}553return __b;554}555556extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>;557# if _LIBCPP_HAS_WIDE_CHARACTERS558extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>;559# endif560561class _LIBCPP_EXPORTED_FROM_ABI __time_get {562protected:563__locale::__locale_t __loc_;564565__time_get(const char* __nm);566__time_get(const string& __nm);567~__time_get();568};569570template <class _CharT>571class __time_get_storage : public __time_get {572protected:573typedef basic_string<_CharT> string_type;574575string_type __weeks_[14];576string_type __months_[24];577string_type __am_pm_[2];578string_type __c_;579string_type __r_;580string_type __x_;581string_type __X_;582583explicit __time_get_storage(const char* __nm);584explicit __time_get_storage(const string& __nm);585586_LIBCPP_HIDE_FROM_ABI ~__time_get_storage() {}587588time_base::dateorder __do_date_order() const;589590private:591void init(const ctype<_CharT>&);592string_type __analyze(char __fmt, const ctype<_CharT>&);593};594595# define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \596template <> \597_LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \598template <> \599_LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \600template <> \601_LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \602template <> \603_LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \604template <> \605_LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze( \606char, const ctype<_CharT>&); \607extern template _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() \608const; \609extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \610extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \611extern template _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \612extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type \613__time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&);614615_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char)616# if _LIBCPP_HAS_WIDE_CHARACTERS617_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t)618# endif619# undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION620621template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >622class time_get_byname : public time_get<_CharT, _InputIterator>, private __time_get_storage<_CharT> {623public:624typedef time_base::dateorder dateorder;625typedef _InputIterator iter_type;626typedef _CharT char_type;627typedef basic_string<char_type> string_type;628629_LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const char* __nm, size_t __refs = 0)630: time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {}631_LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const string& __nm, size_t __refs = 0)632: time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {}633634protected:635_LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get_byname() override {}636637_LIBCPP_HIDE_FROM_ABI_VIRTUAL dateorder do_date_order() const override { return this->__do_date_order(); }638639private:640_LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __weeks() const override { return this->__weeks_; }641_LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __months() const override { return this->__months_; }642_LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __am_pm() const override { return this->__am_pm_; }643_LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __c() const override { return this->__c_; }644_LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __r() const override { return this->__r_; }645_LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __x() const override { return this->__x_; }646_LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __X() const override { return this->__X_; }647};648649extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>;650# if _LIBCPP_HAS_WIDE_CHARACTERS651extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>;652# endif653654class _LIBCPP_EXPORTED_FROM_ABI __time_put {655__locale::__locale_t __loc_;656657protected:658_LIBCPP_HIDE_FROM_ABI __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {}659__time_put(const char* __nm);660__time_put(const string& __nm);661~__time_put();662void __do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const;663# if _LIBCPP_HAS_WIDE_CHARACTERS664void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const;665# endif666};667668template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >669class time_put : public locale::facet, private __time_put {670public:671typedef _CharT char_type;672typedef _OutputIterator iter_type;673674_LIBCPP_HIDE_FROM_ABI explicit time_put(size_t __refs = 0) : locale::facet(__refs) {}675676iter_type677put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe)678const;679680_LIBCPP_HIDE_FROM_ABI iter_type681put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, char __fmt, char __mod = 0) const {682return do_put(__s, __iob, __fl, __tm, __fmt, __mod);683}684685static locale::id id;686687protected:688_LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put() override {}689virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const;690691_LIBCPP_HIDE_FROM_ABI explicit time_put(const char* __nm, size_t __refs) : locale::facet(__refs), __time_put(__nm) {}692_LIBCPP_HIDE_FROM_ABI explicit time_put(const string& __nm, size_t __refs)693: locale::facet(__refs), __time_put(__nm) {}694};695696template <class _CharT, class _OutputIterator>697locale::id time_put<_CharT, _OutputIterator>::id;698699template <class _CharT, class _OutputIterator>700_OutputIterator time_put<_CharT, _OutputIterator>::put(701iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe)702const {703const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());704for (; __pb != __pe; ++__pb) {705if (__ct.narrow(*__pb, 0) == '%') {706if (++__pb == __pe) {707*__s++ = __pb[-1];708break;709}710char __mod = 0;711char __fmt = __ct.narrow(*__pb, 0);712if (__fmt == 'E' || __fmt == 'O') {713if (++__pb == __pe) {714*__s++ = __pb[-2];715*__s++ = __pb[-1];716break;717}718__mod = __fmt;719__fmt = __ct.narrow(*__pb, 0);720}721__s = do_put(__s, __iob, __fl, __tm, __fmt, __mod);722} else723*__s++ = *__pb;724}725return __s;726}727728template <class _CharT, class _OutputIterator>729_OutputIterator time_put<_CharT, _OutputIterator>::do_put(730iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const {731char_type __nar[100];732char_type* __nb = __nar;733char_type* __ne = __nb + 100;734__do_put(__nb, __ne, __tm, __fmt, __mod);735return std::copy(__nb, __ne, __s);736}737738extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>;739# if _LIBCPP_HAS_WIDE_CHARACTERS740extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>;741# endif742743template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >744class time_put_byname : public time_put<_CharT, _OutputIterator> {745public:746_LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const char* __nm, size_t __refs = 0)747: time_put<_CharT, _OutputIterator>(__nm, __refs) {}748749_LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const string& __nm, size_t __refs = 0)750: time_put<_CharT, _OutputIterator>(__nm, __refs) {}751752protected:753_LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put_byname() override {}754};755756extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>;757# if _LIBCPP_HAS_WIDE_CHARACTERS758extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>;759# endif760761_LIBCPP_END_NAMESPACE_STD762763#endif // _LIBCPP_HAS_LOCALIZATION764765#endif // _LIBCPP___LOCALE_DIR_TIME_H766767768