2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_LOCALE
11 #define _LIBCPP_LOCALE
27 static const category // values assigned here are for exposition only
35 all = collate | ctype | monetary | numeric | time | messages;
37 // construct/copy/destroy:
39 locale(const locale& other) noexcept;
40 explicit locale(const char* std_name);
41 explicit locale(const string& std_name);
42 locale(const locale& other, const char* std_name, category);
43 locale(const locale& other, const string& std_name, category);
44 template <class Facet> locale(const locale& other, Facet* f);
45 locale(const locale& other, const locale& one, category);
47 ~locale(); // not virtual
49 const locale& operator=(const locale& other) noexcept;
51 template <class Facet> locale combine(const locale& other) const;
54 basic_string<char> name() const;
55 bool operator==(const locale& other) const;
56 bool operator!=(const locale& other) const; // removed C++20
57 template <class charT, class Traits, class Allocator>
58 bool operator()(const basic_string<charT,Traits,Allocator>& s1,
59 const basic_string<charT,Traits,Allocator>& s2) const;
61 // global locale objects:
62 static locale global(const locale&);
63 static const locale& classic();
66 template <class Facet> const Facet& use_facet(const locale&);
67 template <class Facet> bool has_facet(const locale&) noexcept;
69 // 22.3.3, convenience interfaces:
70 template <class charT> bool isspace (charT c, const locale& loc);
71 template <class charT> bool isprint (charT c, const locale& loc);
72 template <class charT> bool iscntrl (charT c, const locale& loc);
73 template <class charT> bool isupper (charT c, const locale& loc);
74 template <class charT> bool islower (charT c, const locale& loc);
75 template <class charT> bool isalpha (charT c, const locale& loc);
76 template <class charT> bool isdigit (charT c, const locale& loc);
77 template <class charT> bool ispunct (charT c, const locale& loc);
78 template <class charT> bool isxdigit(charT c, const locale& loc);
79 template <class charT> bool isalnum (charT c, const locale& loc);
80 template <class charT> bool isgraph (charT c, const locale& loc);
81 template <class charT> charT toupper(charT c, const locale& loc);
82 template <class charT> charT tolower(charT c, const locale& loc);
84 template<class Codecvt, class Elem = wchar_t,
85 class Wide_alloc = allocator<Elem>,
86 class Byte_alloc = allocator<char>>
87 class wstring_convert // Removed in C++26
90 typedef basic_string<char, char_traits<char>, Byte_alloc> byte_string;
91 typedef basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
92 typedef typename Codecvt::state_type state_type;
93 typedef typename wide_string::traits_type::int_type int_type;
95 wstring_convert(Codecvt* pcvt = new Codecvt); // before C++14
96 explicit wstring_convert(Codecvt* pcvt = new Codecvt); // before C++20
97 wstring_convert() : wstring_convert(new Codecvt) {} // C++20
98 explicit wstring_convert(Codecvt* pcvt); // C++20
100 wstring_convert(Codecvt* pcvt, state_type state);
101 explicit wstring_convert(const byte_string& byte_err, // explicit in C++14
102 const wide_string& wide_err = wide_string());
103 wstring_convert(const wstring_convert&) = delete; // C++14
104 wstring_convert & operator=(const wstring_convert &) = delete; // C++14
107 wide_string from_bytes(char byte);
108 wide_string from_bytes(const char* ptr);
109 wide_string from_bytes(const byte_string& str);
110 wide_string from_bytes(const char* first, const char* last);
112 byte_string to_bytes(Elem wchar);
113 byte_string to_bytes(const Elem* wptr);
114 byte_string to_bytes(const wide_string& wstr);
115 byte_string to_bytes(const Elem* first, const Elem* last);
117 size_t converted() const; // noexcept in C++14
118 state_type state() const;
121 template <class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem>>
122 class wbuffer_convert // Removed in C++26
123 : public basic_streambuf<Elem, Tr>
126 typedef typename Tr::state_type state_type;
128 wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt,
129 state_type state = state_type()); // before C++14
130 explicit wbuffer_convert(streambuf* bytebuf = nullptr, Codecvt* pcvt = new Codecvt,
131 state_type state = state_type()); // before C++20
132 wbuffer_convert() : wbuffer_convert(nullptr) {} // C++20
133 explicit wbuffer_convert(streambuf* bytebuf, Codecvt* pcvt = new Codecvt,
134 state_type state = state_type()); // C++20
136 wbuffer_convert(const wbuffer_convert&) = delete; // C++14
137 wbuffer_convert & operator=(const wbuffer_convert &) = delete; // C++14
138 ~wbuffer_convert(); // C++14
140 streambuf* rdbuf() const;
141 streambuf* rdbuf(streambuf* bytebuf);
143 state_type state() const;
146 // 22.4.1 and 22.4.1.3, ctype:
148 template <class charT> class ctype;
149 template <> class ctype<char>; // specialization
150 template <class charT> class ctype_byname;
151 template <> class ctype_byname<char>; // specialization
154 template <class internT, class externT, class stateT> class codecvt;
155 template <class internT, class externT, class stateT> class codecvt_byname;
157 // 22.4.2 and 22.4.3, numeric:
158 template <class charT, class InputIterator> class num_get;
159 template <class charT, class OutputIterator> class num_put;
160 template <class charT> class numpunct;
161 template <class charT> class numpunct_byname;
163 // 22.4.4, col lation:
164 template <class charT> class collate;
165 template <class charT> class collate_byname;
167 // 22.4.5, date and time:
169 template <class charT, class InputIterator> class time_get;
170 template <class charT, class InputIterator> class time_get_byname;
171 template <class charT, class OutputIterator> class time_put;
172 template <class charT, class OutputIterator> class time_put_byname;
176 template <class charT, class InputIterator> class money_get;
177 template <class charT, class OutputIterator> class money_put;
178 template <class charT, bool Intl> class moneypunct;
179 template <class charT, bool Intl> class moneypunct_byname;
181 // 22.4.7, message retrieval:
183 template <class charT> class messages;
184 template <class charT> class messages_byname;
192 #if _LIBCPP_HAS_LOCALIZATION
194 # include <__algorithm/copy.h>
195 # include <__algorithm/equal.h>
196 # include <__algorithm/find.h>
197 # include <__algorithm/max.h>
198 # include <__algorithm/reverse.h>
199 # include <__algorithm/unwrap_iter.h>
201 # include <__iterator/access.h>
202 # include <__iterator/back_insert_iterator.h>
203 # include <__iterator/istreambuf_iterator.h>
204 # include <__iterator/ostreambuf_iterator.h>
206 # include <__locale_dir/pad_and_output.h>
207 # include <__memory/unique_ptr.h>
208 # include <__type_traits/make_unsigned.h>
216 # include <streambuf>
219 // TODO: Properly qualify calls now that __bsd_locale_defaults.h defines functions instead of macros
220 // NOLINTBEGIN(libcpp-robust-against-adl)
222 # if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
223 // Most unix variants have catopen. These are the specific ones that don't.
224 # if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
225 # define _LIBCPP_HAS_CATOPEN 1
226 # include <nl_types.h>
228 # define _LIBCPP_HAS_CATOPEN 0
231 # define _LIBCPP_HAS_CATOPEN 0
234 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
235 # pragma GCC system_header
239 # include <__undef_macros>
241 _LIBCPP_BEGIN_NAMESPACE_STD
243 # if defined(__APPLE__) || defined(__FreeBSD__)
244 # define _LIBCPP_GET_C_LOCALE 0
245 # elif defined(__NetBSD__)
246 # define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
248 # define _LIBCPP_GET_C_LOCALE __cloc()
249 // Get the C locale object
250 _LIBCPP_EXPORTED_FROM_ABI __locale::__locale_t __cloc();
251 # define __cloc_defined
255 // Scans [__b, __e) until a match is found in the basic_strings range
256 // [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke).
257 // __b will be incremented (visibly), consuming CharT until a match is found
258 // or proved to not exist. A keyword may be "", in which will match anything.
259 // If one keyword is a prefix of another, and the next CharT in the input
260 // might match another keyword, the algorithm will attempt to find the longest
261 // matching keyword. If the longer matching keyword ends up not matching, then
262 // no keyword match is found. If no keyword match is found, __ke is returned
263 // and failbit is set in __err.
264 // Else an iterator pointing to the matching keyword is found. If more than
265 // one keyword matches, an iterator to the first matching keyword is returned.
266 // If on exit __b == __e, eofbit is set in __err. If __case_sensitive is false,
267 // __ct is used to force to lower case before comparing characters.
269 // Keywords: "a", "abb"
270 // If the input is "a", the first keyword matches and eofbit is set.
271 // If the input is "abc", no match is found and "ab" are consumed.
272 template <class _InputIterator, class _ForwardIterator, class _Ctype>
273 _LIBCPP_HIDE_FROM_ABI _ForwardIterator __scan_keyword(
276 _ForwardIterator __kb,
277 _ForwardIterator __ke,
279 ios_base::iostate& __err,
280 bool __case_sensitive = true) {
281 typedef typename iterator_traits<_InputIterator>::value_type _CharT;
282 size_t __nkw = static_cast<size_t>(std::distance(__kb, __ke));
283 const unsigned char __doesnt_match = '\0';
284 const unsigned char __might_match = '\1';
285 const unsigned char __does_match = '\2';
286 unsigned char __statbuf[100];
287 unsigned char* __status = __statbuf;
288 unique_ptr<unsigned char, void (*)(void*)> __stat_hold(nullptr, free);
289 if (__nkw > sizeof(__statbuf)) {
290 __status = (unsigned char*)malloc(__nkw);
291 if (__status == nullptr)
293 __stat_hold.reset(__status);
295 size_t __n_might_match = __nkw; // At this point, any keyword might match
296 size_t __n_does_match = 0; // but none of them definitely do
297 // Initialize all statuses to __might_match, except for "" keywords are __does_match
298 unsigned char* __st = __status;
299 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) {
301 *__st = __might_match;
303 *__st = __does_match;
308 // While there might be a match, test keywords against the next CharT
309 for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx) {
310 // Peek at the next CharT but don't consume it
312 if (!__case_sensitive)
313 __c = __ct.toupper(__c);
314 bool __consume = false;
315 // For each keyword which might match, see if the __indx character is __c
316 // If a match if found, consume __c
317 // If a match is found, and that is the last character in the keyword,
318 // then that keyword matches.
319 // If the keyword doesn't match this character, then change the keyword
322 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) {
323 if (*__st == __might_match) {
324 _CharT __kc = (*__ky)[__indx];
325 if (!__case_sensitive)
326 __kc = __ct.toupper(__kc);
329 if (__ky->size() == __indx + 1) {
330 *__st = __does_match;
335 *__st = __doesnt_match;
340 // consume if we matched a character
343 // If we consumed a character and there might be a matched keyword that
344 // was marked matched on a previous iteration, then such keywords
345 // which are now marked as not matching.
346 if (__n_might_match + __n_does_match > 1) {
348 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) {
349 if (*__st == __does_match && __ky->size() != __indx + 1) {
350 *__st = __doesnt_match;
357 // We've exited the loop because we hit eof and/or we have no more "might matches".
359 __err |= ios_base::eofbit;
360 // Return the first matching result
361 for (__st = __status; __kb != __ke; ++__kb, (void)++__st)
362 if (*__st == __does_match)
365 __err |= ios_base::failbit;
369 struct _LIBCPP_EXPORTED_FROM_ABI __num_get_base {
370 static const int __num_get_buf_sz = 40;
372 static int __get_base(ios_base&);
373 static const char __src[33]; // "0123456789abcdefABCDEFxX+-pPiInN"
374 // count of leading characters in __src used for parsing integers ("012..X+-")
375 static const size_t __int_chr_cnt = 26;
376 // count of leading characters in __src used for parsing floating-point values ("012..-pP")
377 static const size_t __fp_chr_cnt = 28;
380 _LIBCPP_EXPORTED_FROM_ABI void
381 __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err);
383 template <class _CharT>
384 struct __num_get : protected __num_get_base {
385 static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep);
387 static int __stage2_float_loop(
393 _CharT __decimal_point,
394 _CharT __thousands_sep,
395 const string& __grouping,
400 # ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
401 static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
402 static int __stage2_int_loop(
408 _CharT __thousands_sep,
409 const string& __grouping,
415 static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep) {
416 locale __loc = __iob.getloc();
417 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
418 __thousands_sep = __np.thousands_sep();
419 return __np.grouping();
422 const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const { return __do_widen_p(__iob, __atoms); }
424 static int __stage2_int_loop(
430 _CharT __thousands_sep,
431 const string& __grouping,
434 const _CharT* __atoms);
437 template <typename _Tp>
438 const _Tp* __do_widen_p(ios_base& __iob, _Tp* __atoms) const {
439 locale __loc = __iob.getloc();
440 use_facet<ctype<_Tp> >(__loc).widen(__src, __src + __int_chr_cnt, __atoms);
444 const char* __do_widen_p(ios_base& __iob, char* __atoms) const {
452 # ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
453 template <class _CharT>
454 string __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) {
455 locale __loc = __iob.getloc();
456 std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + __int_chr_cnt, __atoms);
457 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc);
458 __thousands_sep = __np.thousands_sep();
459 return __np.grouping();
463 template <class _CharT>
464 string __num_get<_CharT>::__stage2_float_prep(
465 ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep) {
466 locale __loc = __iob.getloc();
467 std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + __fp_chr_cnt, __atoms);
468 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc);
469 __decimal_point = __np.decimal_point();
470 __thousands_sep = __np.thousands_sep();
471 return __np.grouping();
474 template <class _CharT>
476 # ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
477 __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
478 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
479 unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
481 __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
482 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
483 unsigned* __g, unsigned*& __g_end, const _CharT* __atoms)
487 if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) {
488 *__a_end++ = __ct == __atoms[24] ? '+' : '-';
492 if (__grouping.size() != 0 && __ct == __thousands_sep) {
493 if (__g_end - __g < __num_get_buf_sz) {
499 ptrdiff_t __f = std::find(__atoms, __atoms + __int_chr_cnt, __ct) - __atoms;
511 if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0') {
513 *__a_end++ = __src[__f];
518 *__a_end++ = __src[__f];
523 template <class _CharT>
524 int __num_get<_CharT>::__stage2_float_loop(
530 _CharT __decimal_point,
531 _CharT __thousands_sep,
532 const string& __grouping,
537 if (__ct == __decimal_point) {
542 if (__grouping.size() != 0 && __g_end - __g < __num_get_buf_sz)
546 if (__ct == __thousands_sep && __grouping.size() != 0) {
549 if (__g_end - __g < __num_get_buf_sz) {
555 ptrdiff_t __f = std::find(__atoms, __atoms + __num_get_base::__fp_chr_cnt, __ct) - __atoms;
556 if (__f >= static_cast<ptrdiff_t>(__num_get_base::__fp_chr_cnt))
558 char __x = __src[__f];
559 if (__x == '-' || __x == '+') {
560 if (__a_end == __a || (std::toupper(__a_end[-1]) == std::toupper(__exp))) {
566 if (__x == 'x' || __x == 'X')
568 else if (std::toupper(__x) == __exp) {
569 __exp = std::tolower(__exp);
572 if (__grouping.size() != 0 && __g_end - __g < __num_get_buf_sz)
583 extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>;
584 # if _LIBCPP_HAS_WIDE_CHARACTERS
585 extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>;
588 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
589 class _LIBCPP_TEMPLATE_VIS num_get : public locale::facet, private __num_get<_CharT> {
591 typedef _CharT char_type;
592 typedef _InputIterator iter_type;
594 _LIBCPP_HIDE_FROM_ABI explicit num_get(size_t __refs = 0) : locale::facet(__refs) {}
596 _LIBCPP_HIDE_FROM_ABI iter_type
597 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const {
598 return do_get(__b, __e, __iob, __err, __v);
601 _LIBCPP_HIDE_FROM_ABI iter_type
602 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const {
603 return do_get(__b, __e, __iob, __err, __v);
606 _LIBCPP_HIDE_FROM_ABI iter_type
607 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const {
608 return do_get(__b, __e, __iob, __err, __v);
611 _LIBCPP_HIDE_FROM_ABI iter_type
612 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const {
613 return do_get(__b, __e, __iob, __err, __v);
616 _LIBCPP_HIDE_FROM_ABI iter_type
617 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const {
618 return do_get(__b, __e, __iob, __err, __v);
621 _LIBCPP_HIDE_FROM_ABI iter_type
622 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const {
623 return do_get(__b, __e, __iob, __err, __v);
626 _LIBCPP_HIDE_FROM_ABI iter_type
627 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const {
628 return do_get(__b, __e, __iob, __err, __v);
631 _LIBCPP_HIDE_FROM_ABI iter_type
632 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const {
633 return do_get(__b, __e, __iob, __err, __v);
636 _LIBCPP_HIDE_FROM_ABI iter_type
637 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const {
638 return do_get(__b, __e, __iob, __err, __v);
641 _LIBCPP_HIDE_FROM_ABI iter_type
642 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
643 return do_get(__b, __e, __iob, __err, __v);
646 _LIBCPP_HIDE_FROM_ABI iter_type
647 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const {
648 return do_get(__b, __e, __iob, __err, __v);
651 static locale::id id;
654 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_get() override {}
657 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type
658 __do_get_floating_point(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Fp& __v) const;
660 template <class _Signed>
661 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type
662 __do_get_signed(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Signed& __v) const;
664 template <class _Unsigned>
665 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type
666 __do_get_unsigned(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Unsigned& __v) const;
668 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const;
670 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const {
671 return this->__do_get_signed(__b, __e, __iob, __err, __v);
675 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const {
676 return this->__do_get_signed(__b, __e, __iob, __err, __v);
680 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const {
681 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
685 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const {
686 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
690 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const {
691 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
695 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const {
696 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
699 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const {
700 return this->__do_get_floating_point(__b, __e, __iob, __err, __v);
703 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const {
704 return this->__do_get_floating_point(__b, __e, __iob, __err, __v);
708 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
709 return this->__do_get_floating_point(__b, __e, __iob, __err, __v);
712 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const;
715 template <class _CharT, class _InputIterator>
716 locale::id num_get<_CharT, _InputIterator>::id;
719 _LIBCPP_HIDE_FROM_ABI _Tp
720 __num_get_signed_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) {
721 if (__a != __a_end) {
722 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
725 long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
726 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
727 if (__current_errno == 0)
728 errno = __save_errno;
729 if (__p2 != __a_end) {
730 __err = ios_base::failbit;
732 } else if (__current_errno == ERANGE || __ll < numeric_limits<_Tp>::min() || numeric_limits<_Tp>::max() < __ll) {
733 __err = ios_base::failbit;
735 return numeric_limits<_Tp>::max();
737 return numeric_limits<_Tp>::min();
739 return static_cast<_Tp>(__ll);
741 __err = ios_base::failbit;
746 _LIBCPP_HIDE_FROM_ABI _Tp
747 __num_get_unsigned_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) {
748 if (__a != __a_end) {
749 const bool __negate = *__a == '-';
750 if (__negate && ++__a == __a_end) {
751 __err = ios_base::failbit;
754 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
757 unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
758 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
759 if (__current_errno == 0)
760 errno = __save_errno;
761 if (__p2 != __a_end) {
762 __err = ios_base::failbit;
764 } else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll) {
765 __err = ios_base::failbit;
766 return numeric_limits<_Tp>::max();
768 _Tp __res = static_cast<_Tp>(__ll);
773 __err = ios_base::failbit;
778 _LIBCPP_HIDE_FROM_ABI _Tp __do_strtod(const char* __a, char** __p2);
781 inline _LIBCPP_HIDE_FROM_ABI float __do_strtod<float>(const char* __a, char** __p2) {
782 return strtof_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
786 inline _LIBCPP_HIDE_FROM_ABI double __do_strtod<double>(const char* __a, char** __p2) {
787 return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
791 inline _LIBCPP_HIDE_FROM_ABI long double __do_strtod<long double>(const char* __a, char** __p2) {
792 return strtold_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
796 _LIBCPP_HIDE_FROM_ABI _Tp __num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) {
797 if (__a != __a_end) {
798 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
801 _Tp __ld = std::__do_strtod<_Tp>(__a, &__p2);
802 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
803 if (__current_errno == 0)
804 errno = __save_errno;
805 if (__p2 != __a_end) {
806 __err = ios_base::failbit;
808 } else if (__current_errno == ERANGE)
809 __err = ios_base::failbit;
812 __err = ios_base::failbit;
816 template <class _CharT, class _InputIterator>
817 _InputIterator num_get<_CharT, _InputIterator>::do_get(
818 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const {
819 if ((__iob.flags() & ios_base::boolalpha) == 0) {
821 __b = do_get(__b, __e, __iob, __err, __lv);
831 __err = ios_base::failbit;
836 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__iob.getloc());
837 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__iob.getloc());
838 typedef typename numpunct<_CharT>::string_type string_type;
839 const string_type __names[2] = {__np.truename(), __np.falsename()};
840 const string_type* __i = std::__scan_keyword(__b, __e, __names, __names + 2, __ct, __err);
841 __v = __i == __names;
847 template <class _CharT, class _InputIterator>
848 template <class _Signed>
849 _InputIterator num_get<_CharT, _InputIterator>::__do_get_signed(
850 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Signed& __v) const {
852 int __base = this->__get_base(__iob);
854 char_type __thousands_sep;
855 const int __atoms_size = __num_get_base::__int_chr_cnt;
856 # ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
857 char_type __atoms1[__atoms_size];
858 const char_type* __atoms = this->__do_widen(__iob, __atoms1);
859 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
861 char_type __atoms[__atoms_size];
862 string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
865 __buf.resize(__buf.capacity());
866 char* __a = &__buf[0];
868 unsigned __g[__num_get_base::__num_get_buf_sz];
869 unsigned* __g_end = __g;
871 for (; __b != __e; ++__b) {
872 if (__a_end == __a + __buf.size()) {
873 size_t __tmp = __buf.size();
874 __buf.resize(2 * __buf.size());
875 __buf.resize(__buf.capacity());
877 __a_end = __a + __tmp;
879 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms))
882 if (__grouping.size() != 0 && __g_end - __g < __num_get_base::__num_get_buf_sz)
885 __v = std::__num_get_signed_integral<_Signed>(__a, __a_end, __err, __base);
886 // Digit grouping checked
887 __check_grouping(__grouping, __g, __g_end, __err);
890 __err |= ios_base::eofbit;
896 template <class _CharT, class _InputIterator>
897 template <class _Unsigned>
898 _InputIterator num_get<_CharT, _InputIterator>::__do_get_unsigned(
899 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Unsigned& __v) const {
901 int __base = this->__get_base(__iob);
903 char_type __thousands_sep;
904 const int __atoms_size = __num_get_base::__int_chr_cnt;
905 # ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
906 char_type __atoms1[__atoms_size];
907 const char_type* __atoms = this->__do_widen(__iob, __atoms1);
908 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
910 char_type __atoms[__atoms_size];
911 string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
914 __buf.resize(__buf.capacity());
915 char* __a = &__buf[0];
917 unsigned __g[__num_get_base::__num_get_buf_sz];
918 unsigned* __g_end = __g;
920 for (; __b != __e; ++__b) {
921 if (__a_end == __a + __buf.size()) {
922 size_t __tmp = __buf.size();
923 __buf.resize(2 * __buf.size());
924 __buf.resize(__buf.capacity());
926 __a_end = __a + __tmp;
928 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms))
931 if (__grouping.size() != 0 && __g_end - __g < __num_get_base::__num_get_buf_sz)
934 __v = std::__num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base);
935 // Digit grouping checked
936 __check_grouping(__grouping, __g, __g_end, __err);
939 __err |= ios_base::eofbit;
945 template <class _CharT, class _InputIterator>
947 _InputIterator num_get<_CharT, _InputIterator>::__do_get_floating_point(
948 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Fp& __v) const {
949 // Stage 1, nothing to do
951 char_type __atoms[__num_get_base::__fp_chr_cnt];
952 char_type __decimal_point;
953 char_type __thousands_sep;
954 string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep);
956 __buf.resize(__buf.capacity());
957 char* __a = &__buf[0];
959 unsigned __g[__num_get_base::__num_get_buf_sz];
960 unsigned* __g_end = __g;
962 bool __in_units = true;
964 bool __is_leading_parsed = false;
965 for (; __b != __e; ++__b) {
966 if (__a_end == __a + __buf.size()) {
967 size_t __tmp = __buf.size();
968 __buf.resize(2 * __buf.size());
969 __buf.resize(__buf.capacity());
971 __a_end = __a + __tmp;
973 if (this->__stage2_float_loop(
988 // the leading character excluding the sign must be a decimal digit
989 if (!__is_leading_parsed) {
990 if (__a_end - __a >= 1 && __a[0] != '-' && __a[0] != '+') {
991 if (('0' <= __a[0] && __a[0] <= '9') || __a[0] == '.')
992 __is_leading_parsed = true;
995 } else if (__a_end - __a >= 2 && (__a[0] == '-' || __a[0] == '+')) {
996 if (('0' <= __a[1] && __a[1] <= '9') || __a[1] == '.')
997 __is_leading_parsed = true;
1003 if (__grouping.size() != 0 && __in_units && __g_end - __g < __num_get_base::__num_get_buf_sz)
1006 __v = std::__num_get_float<_Fp>(__a, __a_end, __err);
1007 // Digit grouping checked
1008 __check_grouping(__grouping, __g, __g_end, __err);
1011 __err |= ios_base::eofbit;
1015 template <class _CharT, class _InputIterator>
1016 _InputIterator num_get<_CharT, _InputIterator>::do_get(
1017 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const {
1021 char_type __atoms[__num_get_base::__int_chr_cnt];
1022 char_type __thousands_sep = char_type();
1024 std::use_facet<ctype<_CharT> >(__iob.getloc())
1025 .widen(__num_get_base::__src, __num_get_base::__src + __num_get_base::__int_chr_cnt, __atoms);
1027 __buf.resize(__buf.capacity());
1028 char* __a = &__buf[0];
1029 char* __a_end = __a;
1030 unsigned __g[__num_get_base::__num_get_buf_sz];
1031 unsigned* __g_end = __g;
1033 for (; __b != __e; ++__b) {
1034 if (__a_end == __a + __buf.size()) {
1035 size_t __tmp = __buf.size();
1036 __buf.resize(2 * __buf.size());
1037 __buf.resize(__buf.capacity());
1039 __a_end = __a + __tmp;
1041 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms))
1045 __buf.resize(__a_end - __a);
1046 if (__locale::__sscanf(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
1047 __err = ios_base::failbit;
1050 __err |= ios_base::eofbit;
1054 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>;
1055 # if _LIBCPP_HAS_WIDE_CHARACTERS
1056 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>;
1059 struct _LIBCPP_EXPORTED_FROM_ABI __num_put_base {
1061 static void __format_int(char* __fmt, const char* __len, bool __signd, ios_base::fmtflags __flags);
1062 static bool __format_float(char* __fmt, const char* __len, ios_base::fmtflags __flags);
1063 static char* __identify_padding(char* __nb, char* __ne, const ios_base& __iob);
1066 template <class _CharT>
1067 struct __num_put : protected __num_put_base {
1068 static void __widen_and_group_int(
1069 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc);
1070 static void __widen_and_group_float(
1071 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc);
1074 template <class _CharT>
1075 void __num_put<_CharT>::__widen_and_group_int(
1076 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) {
1077 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__loc);
1078 const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc);
1079 string __grouping = __npt.grouping();
1080 if (__grouping.empty()) {
1081 __ct.widen(__nb, __ne, __ob);
1082 __oe = __ob + (__ne - __nb);
1086 if (*__nf == '-' || *__nf == '+')
1087 *__oe++ = __ct.widen(*__nf++);
1088 if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) {
1089 *__oe++ = __ct.widen(*__nf++);
1090 *__oe++ = __ct.widen(*__nf++);
1092 std::reverse(__nf, __ne);
1093 _CharT __thousands_sep = __npt.thousands_sep();
1096 for (char* __p = __nf; __p < __ne; ++__p) {
1097 if (static_cast<unsigned>(__grouping[__dg]) > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) {
1098 *__oe++ = __thousands_sep;
1100 if (__dg < __grouping.size() - 1)
1103 *__oe++ = __ct.widen(*__p);
1106 std::reverse(__ob + (__nf - __nb), __oe);
1111 __op = __ob + (__np - __nb);
1114 template <class _CharT>
1115 void __num_put<_CharT>::__widen_and_group_float(
1116 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) {
1117 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__loc);
1118 const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc);
1119 string __grouping = __npt.grouping();
1122 if (*__nf == '-' || *__nf == '+')
1123 *__oe++ = __ct.widen(*__nf++);
1125 if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) {
1126 *__oe++ = __ct.widen(*__nf++);
1127 *__oe++ = __ct.widen(*__nf++);
1128 for (__ns = __nf; __ns < __ne; ++__ns)
1129 if (!__locale::__isxdigit(*__ns, _LIBCPP_GET_C_LOCALE))
1132 for (__ns = __nf; __ns < __ne; ++__ns)
1133 if (!__locale::__isdigit(*__ns, _LIBCPP_GET_C_LOCALE))
1136 if (__grouping.empty()) {
1137 __ct.widen(__nf, __ns, __oe);
1138 __oe += __ns - __nf;
1140 std::reverse(__nf, __ns);
1141 _CharT __thousands_sep = __npt.thousands_sep();
1144 for (char* __p = __nf; __p < __ns; ++__p) {
1145 if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) {
1146 *__oe++ = __thousands_sep;
1148 if (__dg < __grouping.size() - 1)
1151 *__oe++ = __ct.widen(*__p);
1154 std::reverse(__ob + (__nf - __nb), __oe);
1156 for (__nf = __ns; __nf < __ne; ++__nf) {
1158 *__oe++ = __npt.decimal_point();
1162 *__oe++ = __ct.widen(*__nf);
1164 __ct.widen(__nf, __ne, __oe);
1165 __oe += __ne - __nf;
1169 __op = __ob + (__np - __nb);
1172 extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>;
1173 # if _LIBCPP_HAS_WIDE_CHARACTERS
1174 extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>;
1177 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
1178 class _LIBCPP_TEMPLATE_VIS num_put : public locale::facet, private __num_put<_CharT> {
1180 typedef _CharT char_type;
1181 typedef _OutputIterator iter_type;
1183 _LIBCPP_HIDE_FROM_ABI explicit num_put(size_t __refs = 0) : locale::facet(__refs) {}
1185 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const {
1186 return do_put(__s, __iob, __fl, __v);
1189 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const {
1190 return do_put(__s, __iob, __fl, __v);
1193 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const {
1194 return do_put(__s, __iob, __fl, __v);
1197 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const {
1198 return do_put(__s, __iob, __fl, __v);
1201 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const {
1202 return do_put(__s, __iob, __fl, __v);
1205 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const {
1206 return do_put(__s, __iob, __fl, __v);
1209 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const {
1210 return do_put(__s, __iob, __fl, __v);
1213 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const {
1214 return do_put(__s, __iob, __fl, __v);
1217 static locale::id id;
1220 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_put() override {}
1222 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const;
1223 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const;
1224 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const;
1225 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long) const;
1226 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long) const;
1227 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const;
1228 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const;
1229 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const;
1231 template <class _Integral>
1232 _LIBCPP_HIDE_FROM_ABI inline _OutputIterator
1233 __do_put_integral(iter_type __s, ios_base& __iob, char_type __fl, _Integral __v, char const* __len) const;
1235 template <class _Float>
1236 _LIBCPP_HIDE_FROM_ABI inline _OutputIterator
1237 __do_put_floating_point(iter_type __s, ios_base& __iob, char_type __fl, _Float __v, char const* __len) const;
1240 template <class _CharT, class _OutputIterator>
1241 locale::id num_put<_CharT, _OutputIterator>::id;
1243 template <class _CharT, class _OutputIterator>
1245 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const {
1246 if ((__iob.flags() & ios_base::boolalpha) == 0)
1247 return do_put(__s, __iob, __fl, (unsigned long)__v);
1248 const numpunct<char_type>& __np = std::use_facet<numpunct<char_type> >(__iob.getloc());
1249 typedef typename numpunct<char_type>::string_type string_type;
1250 string_type __nm = __v ? __np.truename() : __np.falsename();
1251 for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s)
1256 template <class _CharT, class _OutputIterator>
1257 template <class _Integral>
1258 _LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::__do_put_integral(
1259 iter_type __s, ios_base& __iob, char_type __fl, _Integral __v, char const* __len) const {
1260 // Stage 1 - Get number in narrow char
1261 char __fmt[8] = {'%', 0};
1262 this->__format_int(__fmt + 1, __len, is_signed<_Integral>::value, __iob.flags());
1263 // Worst case is octal, with showbase enabled. Note that octal is always
1264 // printed as an unsigned value.
1265 using _Unsigned = typename make_unsigned<_Integral>::type;
1266 _LIBCPP_CONSTEXPR const unsigned __nbuf =
1267 (numeric_limits<_Unsigned>::digits / 3) // 1 char per 3 bits
1268 + ((numeric_limits<_Unsigned>::digits % 3) != 0) // round up
1269 + 2; // base prefix + terminating null character
1271 _LIBCPP_DIAGNOSTIC_PUSH
1272 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1273 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1274 int __nc = __locale::__snprintf(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1275 _LIBCPP_DIAGNOSTIC_POP
1276 char* __ne = __nar + __nc;
1277 char* __np = this->__identify_padding(__nar, __ne, __iob);
1278 // Stage 2 - Widen __nar while adding thousands separators
1279 char_type __o[2 * (__nbuf - 1) - 1];
1280 char_type* __op; // pad here
1281 char_type* __oe; // end of output
1282 this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1283 // [__o, __oe) contains thousands_sep'd wide number
1285 return std::__pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1288 template <class _CharT, class _OutputIterator>
1290 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const {
1291 return this->__do_put_integral(__s, __iob, __fl, __v, "l");
1294 template <class _CharT, class _OutputIterator>
1296 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const {
1297 return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
1300 template <class _CharT, class _OutputIterator>
1302 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const {
1303 return this->__do_put_integral(__s, __iob, __fl, __v, "l");
1306 template <class _CharT, class _OutputIterator>
1308 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const {
1309 return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
1312 template <class _CharT, class _OutputIterator>
1313 template <class _Float>
1314 _LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::__do_put_floating_point(
1315 iter_type __s, ios_base& __iob, char_type __fl, _Float __v, char const* __len) const {
1316 // Stage 1 - Get number in narrow char
1317 char __fmt[8] = {'%', 0};
1318 bool __specify_precision = this->__format_float(__fmt + 1, __len, __iob.flags());
1319 const unsigned __nbuf = 30;
1323 _LIBCPP_DIAGNOSTIC_PUSH
1324 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1325 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1326 if (__specify_precision)
1327 __nc = __locale::__snprintf(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1329 __nc = __locale::__snprintf(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1330 unique_ptr<char, void (*)(void*)> __nbh(nullptr, free);
1331 if (__nc > static_cast<int>(__nbuf - 1)) {
1332 if (__specify_precision)
1333 __nc = __locale::__asprintf(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1335 __nc = __locale::__asprintf(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1337 __throw_bad_alloc();
1340 _LIBCPP_DIAGNOSTIC_POP
1341 char* __ne = __nb + __nc;
1342 char* __np = this->__identify_padding(__nb, __ne, __iob);
1343 // Stage 2 - Widen __nar while adding thousands separators
1344 char_type __o[2 * (__nbuf - 1) - 1];
1345 char_type* __ob = __o;
1346 unique_ptr<char_type, void (*)(void*)> __obh(0, free);
1347 if (__nb != __nar) {
1348 __ob = (char_type*)malloc(2 * static_cast<size_t>(__nc) * sizeof(char_type));
1350 __throw_bad_alloc();
1353 char_type* __op; // pad here
1354 char_type* __oe; // end of output
1355 this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
1356 // [__o, __oe) contains thousands_sep'd wide number
1358 __s = std::__pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
1362 template <class _CharT, class _OutputIterator>
1364 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const {
1365 return this->__do_put_floating_point(__s, __iob, __fl, __v, "");
1368 template <class _CharT, class _OutputIterator>
1370 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const {
1371 return this->__do_put_floating_point(__s, __iob, __fl, __v, "L");
1374 template <class _CharT, class _OutputIterator>
1376 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const {
1377 // Stage 1 - Get pointer in narrow char
1378 const unsigned __nbuf = 20;
1380 int __nc = __locale::__snprintf(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, "%p", __v);
1381 char* __ne = __nar + __nc;
1382 char* __np = this->__identify_padding(__nar, __ne, __iob);
1383 // Stage 2 - Widen __nar
1384 char_type __o[2 * (__nbuf - 1) - 1];
1385 char_type* __op; // pad here
1386 char_type* __oe; // end of output
1387 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1388 __ct.widen(__nar, __ne, __o);
1389 __oe = __o + (__ne - __nar);
1393 __op = __o + (__np - __nar);
1394 // [__o, __oe) contains wide number
1396 return std::__pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1399 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>;
1400 # if _LIBCPP_HAS_WIDE_CHARACTERS
1401 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>;
1404 template <class _CharT, class _InputIterator>
1405 _LIBCPP_HIDE_FROM_ABI int __get_up_to_n_digits(
1406 _InputIterator& __b, _InputIterator __e, ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) {
1407 // Precondition: __n >= 1
1409 __err |= ios_base::eofbit | ios_base::failbit;
1414 if (!__ct.is(ctype_base::digit, __c)) {
1415 __err |= ios_base::failbit;
1418 int __r = __ct.narrow(__c, 0) - '0';
1419 for (++__b, (void)--__n; __b != __e && __n > 0; ++__b, (void)--__n) {
1422 if (!__ct.is(ctype_base::digit, __c))
1424 __r = __r * 10 + __ct.narrow(__c, 0) - '0';
1427 __err |= ios_base::eofbit;
1431 class _LIBCPP_EXPORTED_FROM_ABI time_base {
1433 enum dateorder { no_order, dmy, mdy, ymd, ydm };
1436 template <class _CharT>
1437 class _LIBCPP_TEMPLATE_VIS __time_get_c_storage {
1439 typedef basic_string<_CharT> string_type;
1441 virtual const string_type* __weeks() const;
1442 virtual const string_type* __months() const;
1443 virtual const string_type* __am_pm() const;
1444 virtual const string_type& __c() const;
1445 virtual const string_type& __r() const;
1446 virtual const string_type& __x() const;
1447 virtual const string_type& __X() const;
1449 _LIBCPP_HIDE_FROM_ABI ~__time_get_c_storage() {}
1453 _LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__weeks() const;
1455 _LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__months() const;
1457 _LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__am_pm() const;
1459 _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__c() const;
1461 _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__r() const;
1463 _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__x() const;
1465 _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__X() const;
1467 # if _LIBCPP_HAS_WIDE_CHARACTERS
1469 _LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__weeks() const;
1471 _LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__months() const;
1473 _LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__am_pm() const;
1475 _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__c() const;
1477 _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__r() const;
1479 _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__x() const;
1481 _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__X() const;
1484 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
1485 class _LIBCPP_TEMPLATE_VIS time_get : public locale::facet, public time_base, private __time_get_c_storage<_CharT> {
1487 typedef _CharT char_type;
1488 typedef _InputIterator iter_type;
1489 typedef time_base::dateorder dateorder;
1490 typedef basic_string<char_type> string_type;
1492 _LIBCPP_HIDE_FROM_ABI explicit time_get(size_t __refs = 0) : locale::facet(__refs) {}
1494 _LIBCPP_HIDE_FROM_ABI dateorder date_order() const { return this->do_date_order(); }
1496 _LIBCPP_HIDE_FROM_ABI iter_type
1497 get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1498 return do_get_time(__b, __e, __iob, __err, __tm);
1501 _LIBCPP_HIDE_FROM_ABI iter_type
1502 get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1503 return do_get_date(__b, __e, __iob, __err, __tm);
1506 _LIBCPP_HIDE_FROM_ABI iter_type
1507 get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1508 return do_get_weekday(__b, __e, __iob, __err, __tm);
1511 _LIBCPP_HIDE_FROM_ABI iter_type
1512 get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1513 return do_get_monthname(__b, __e, __iob, __err, __tm);
1516 _LIBCPP_HIDE_FROM_ABI iter_type
1517 get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1518 return do_get_year(__b, __e, __iob, __err, __tm);
1521 _LIBCPP_HIDE_FROM_ABI iter_type
1522 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod = 0)
1524 return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod);
1531 ios_base::iostate& __err,
1533 const char_type* __fmtb,
1534 const char_type* __fmte) const;
1536 static locale::id id;
1539 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get() override {}
1541 virtual dateorder do_date_order() const;
1543 do_get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1545 do_get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1547 do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1549 do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1551 do_get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1552 virtual iter_type do_get(
1553 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod) const;
1556 void __get_white_space(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1557 void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1559 void __get_weekdayname(
1560 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1561 void __get_monthname(
1562 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1563 void __get_day(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1565 __get_month(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1567 __get_year(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1569 __get_year4(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1571 __get_hour(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1573 __get_12_hour(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1575 __get_am_pm(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1577 __get_minute(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1579 __get_second(int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1581 __get_weekday(int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1582 void __get_day_year_num(
1583 int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1586 template <class _CharT, class _InputIterator>
1587 locale::id time_get<_CharT, _InputIterator>::id;
1589 // time_get primitives
1591 template <class _CharT, class _InputIterator>
1592 void time_get<_CharT, _InputIterator>::__get_weekdayname(
1593 int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1594 // Note: ignoring case comes from the POSIX strptime spec
1595 const string_type* __wk = this->__weeks();
1596 ptrdiff_t __i = std::__scan_keyword(__b, __e, __wk, __wk + 14, __ct, __err, false) - __wk;
1601 template <class _CharT, class _InputIterator>
1602 void time_get<_CharT, _InputIterator>::__get_monthname(
1603 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1604 // Note: ignoring case comes from the POSIX strptime spec
1605 const string_type* __month = this->__months();
1606 ptrdiff_t __i = std::__scan_keyword(__b, __e, __month, __month + 24, __ct, __err, false) - __month;
1611 template <class _CharT, class _InputIterator>
1612 void time_get<_CharT, _InputIterator>::__get_day(
1613 int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1614 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1615 if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31)
1618 __err |= ios_base::failbit;
1621 template <class _CharT, class _InputIterator>
1622 void time_get<_CharT, _InputIterator>::__get_month(
1623 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1624 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1;
1625 if (!(__err & ios_base::failbit) && 0 <= __t && __t <= 11)
1628 __err |= ios_base::failbit;
1631 template <class _CharT, class _InputIterator>
1632 void time_get<_CharT, _InputIterator>::__get_year(
1633 int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1634 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);
1635 if (!(__err & ios_base::failbit)) {
1638 else if (69 <= __t && __t <= 99)
1644 template <class _CharT, class _InputIterator>
1645 void time_get<_CharT, _InputIterator>::__get_year4(
1646 int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1647 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);
1648 if (!(__err & ios_base::failbit))
1652 template <class _CharT, class _InputIterator>
1653 void time_get<_CharT, _InputIterator>::__get_hour(
1654 int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1655 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1656 if (!(__err & ios_base::failbit) && __t <= 23)
1659 __err |= ios_base::failbit;
1662 template <class _CharT, class _InputIterator>
1663 void time_get<_CharT, _InputIterator>::__get_12_hour(
1664 int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1665 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1666 if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12)
1669 __err |= ios_base::failbit;
1672 template <class _CharT, class _InputIterator>
1673 void time_get<_CharT, _InputIterator>::__get_minute(
1674 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1675 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1676 if (!(__err & ios_base::failbit) && __t <= 59)
1679 __err |= ios_base::failbit;
1682 template <class _CharT, class _InputIterator>
1683 void time_get<_CharT, _InputIterator>::__get_second(
1684 int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1685 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1686 if (!(__err & ios_base::failbit) && __t <= 60)
1689 __err |= ios_base::failbit;
1692 template <class _CharT, class _InputIterator>
1693 void time_get<_CharT, _InputIterator>::__get_weekday(
1694 int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1695 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 1);
1696 if (!(__err & ios_base::failbit) && __t <= 6)
1699 __err |= ios_base::failbit;
1702 template <class _CharT, class _InputIterator>
1703 void time_get<_CharT, _InputIterator>::__get_day_year_num(
1704 int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1705 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 3);
1706 if (!(__err & ios_base::failbit) && __t <= 365)
1709 __err |= ios_base::failbit;
1712 template <class _CharT, class _InputIterator>
1713 void time_get<_CharT, _InputIterator>::__get_white_space(
1714 iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1715 for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
1718 __err |= ios_base::eofbit;
1721 template <class _CharT, class _InputIterator>
1722 void time_get<_CharT, _InputIterator>::__get_am_pm(
1723 int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1724 const string_type* __ap = this->__am_pm();
1725 if (__ap[0].size() + __ap[1].size() == 0) {
1726 __err |= ios_base::failbit;
1729 ptrdiff_t __i = std::__scan_keyword(__b, __e, __ap, __ap + 2, __ct, __err, false) - __ap;
1730 if (__i == 0 && __h == 12)
1732 else if (__i == 1 && __h < 12)
1736 template <class _CharT, class _InputIterator>
1737 void time_get<_CharT, _InputIterator>::__get_percent(
1738 iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1740 __err |= ios_base::eofbit | ios_base::failbit;
1743 if (__ct.narrow(*__b, 0) != '%')
1744 __err |= ios_base::failbit;
1745 else if (++__b == __e)
1746 __err |= ios_base::eofbit;
1749 // time_get end primitives
1751 template <class _CharT, class _InputIterator>
1752 _InputIterator time_get<_CharT, _InputIterator>::get(
1756 ios_base::iostate& __err,
1758 const char_type* __fmtb,
1759 const char_type* __fmte) const {
1760 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1761 __err = ios_base::goodbit;
1762 while (__fmtb != __fmte && __err == ios_base::goodbit) {
1764 __err = ios_base::failbit;
1767 if (__ct.narrow(*__fmtb, 0) == '%') {
1768 if (++__fmtb == __fmte) {
1769 __err = ios_base::failbit;
1772 char __cmd = __ct.narrow(*__fmtb, 0);
1774 if (__cmd == 'E' || __cmd == '0') {
1775 if (++__fmtb == __fmte) {
1776 __err = ios_base::failbit;
1780 __cmd = __ct.narrow(*__fmtb, 0);
1782 __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt);
1784 } else if (__ct.is(ctype_base::space, *__fmtb)) {
1785 for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb)
1787 for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
1789 } else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) {
1793 __err = ios_base::failbit;
1796 __err |= ios_base::eofbit;
1800 template <class _CharT, class _InputIterator>
1801 typename time_get<_CharT, _InputIterator>::dateorder time_get<_CharT, _InputIterator>::do_date_order() const {
1805 template <class _CharT, class _InputIterator>
1806 _InputIterator time_get<_CharT, _InputIterator>::do_get_time(
1807 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1808 const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
1809 return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt) / sizeof(__fmt[0]));
1812 template <class _CharT, class _InputIterator>
1813 _InputIterator time_get<_CharT, _InputIterator>::do_get_date(
1814 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1815 const string_type& __fmt = this->__x();
1816 return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
1819 template <class _CharT, class _InputIterator>
1820 _InputIterator time_get<_CharT, _InputIterator>::do_get_weekday(
1821 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1822 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1823 __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
1827 template <class _CharT, class _InputIterator>
1828 _InputIterator time_get<_CharT, _InputIterator>::do_get_monthname(
1829 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1830 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1831 __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
1835 template <class _CharT, class _InputIterator>
1836 _InputIterator time_get<_CharT, _InputIterator>::do_get_year(
1837 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1838 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1839 __get_year(__tm->tm_year, __b, __e, __err, __ct);
1843 template <class _CharT, class _InputIterator>
1844 _InputIterator time_get<_CharT, _InputIterator>::do_get(
1845 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char) const {
1846 __err = ios_base::goodbit;
1847 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1851 __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
1856 __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
1859 const string_type& __fm = this->__c();
1860 __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
1864 __get_day(__tm->tm_mday, __b, __e, __err, __ct);
1867 const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
1868 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1871 const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
1872 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1875 __get_hour(__tm->tm_hour, __b, __e, __err, __ct);
1878 __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct);
1881 __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct);
1884 __get_month(__tm->tm_mon, __b, __e, __err, __ct);
1887 __get_minute(__tm->tm_min, __b, __e, __err, __ct);
1891 __get_white_space(__b, __e, __err, __ct);
1894 __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct);
1897 const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
1898 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1901 const char_type __fm[] = {'%', 'H', ':', '%', 'M'};
1902 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1905 __get_second(__tm->tm_sec, __b, __e, __err, __ct);
1908 const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
1909 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1912 __get_weekday(__tm->tm_wday, __b, __e, __err, __ct);
1915 return do_get_date(__b, __e, __iob, __err, __tm);
1917 const string_type& __fm = this->__X();
1918 __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
1921 __get_year(__tm->tm_year, __b, __e, __err, __ct);
1924 __get_year4(__tm->tm_year, __b, __e, __err, __ct);
1927 __get_percent(__b, __e, __err, __ct);
1930 __err |= ios_base::failbit;
1935 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>;
1936 # if _LIBCPP_HAS_WIDE_CHARACTERS
1937 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>;
1940 class _LIBCPP_EXPORTED_FROM_ABI __time_get {
1942 __locale::__locale_t __loc_;
1944 __time_get(const char* __nm);
1945 __time_get(const string& __nm);
1949 template <class _CharT>
1950 class _LIBCPP_TEMPLATE_VIS __time_get_storage : public __time_get {
1952 typedef basic_string<_CharT> string_type;
1954 string_type __weeks_[14];
1955 string_type __months_[24];
1956 string_type __am_pm_[2];
1962 explicit __time_get_storage(const char* __nm);
1963 explicit __time_get_storage(const string& __nm);
1965 _LIBCPP_HIDE_FROM_ABI ~__time_get_storage() {}
1967 time_base::dateorder __do_date_order() const;
1970 void init(const ctype<_CharT>&);
1971 string_type __analyze(char __fmt, const ctype<_CharT>&);
1974 # define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \
1976 _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
1978 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
1980 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
1982 _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
1984 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze( \
1985 char, const ctype<_CharT>&); \
1986 extern template _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() \
1988 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
1989 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
1990 extern template _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
1991 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type \
1992 __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \
1995 _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char)
1996 # if _LIBCPP_HAS_WIDE_CHARACTERS
1997 _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t)
1999 # undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION
2001 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
2002 class _LIBCPP_TEMPLATE_VIS time_get_byname
2003 : public time_get<_CharT, _InputIterator>,
2004 private __time_get_storage<_CharT> {
2006 typedef time_base::dateorder dateorder;
2007 typedef _InputIterator iter_type;
2008 typedef _CharT char_type;
2009 typedef basic_string<char_type> string_type;
2011 _LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const char* __nm, size_t __refs = 0)
2012 : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {}
2013 _LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const string& __nm, size_t __refs = 0)
2014 : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {}
2017 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get_byname() override {}
2019 _LIBCPP_HIDE_FROM_ABI_VIRTUAL dateorder do_date_order() const override { return this->__do_date_order(); }
2022 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __weeks() const override { return this->__weeks_; }
2023 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __months() const override { return this->__months_; }
2024 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __am_pm() const override { return this->__am_pm_; }
2025 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __c() const override { return this->__c_; }
2026 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __r() const override { return this->__r_; }
2027 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __x() const override { return this->__x_; }
2028 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __X() const override { return this->__X_; }
2031 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>;
2032 # if _LIBCPP_HAS_WIDE_CHARACTERS
2033 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>;
2036 class _LIBCPP_EXPORTED_FROM_ABI __time_put {
2037 __locale::__locale_t __loc_;
2040 _LIBCPP_HIDE_FROM_ABI __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {}
2041 __time_put(const char* __nm);
2042 __time_put(const string& __nm);
2044 void __do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const;
2045 # if _LIBCPP_HAS_WIDE_CHARACTERS
2046 void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const;
2050 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2051 class _LIBCPP_TEMPLATE_VIS time_put : public locale::facet, private __time_put {
2053 typedef _CharT char_type;
2054 typedef _OutputIterator iter_type;
2056 _LIBCPP_HIDE_FROM_ABI explicit time_put(size_t __refs = 0) : locale::facet(__refs) {}
2059 put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe)
2062 _LIBCPP_HIDE_FROM_ABI iter_type
2063 put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, char __fmt, char __mod = 0) const {
2064 return do_put(__s, __iob, __fl, __tm, __fmt, __mod);
2067 static locale::id id;
2070 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put() override {}
2071 virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const;
2073 _LIBCPP_HIDE_FROM_ABI explicit time_put(const char* __nm, size_t __refs) : locale::facet(__refs), __time_put(__nm) {}
2074 _LIBCPP_HIDE_FROM_ABI explicit time_put(const string& __nm, size_t __refs)
2075 : locale::facet(__refs), __time_put(__nm) {}
2078 template <class _CharT, class _OutputIterator>
2079 locale::id time_put<_CharT, _OutputIterator>::id;
2081 template <class _CharT, class _OutputIterator>
2082 _OutputIterator time_put<_CharT, _OutputIterator>::put(
2083 iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe)
2085 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
2086 for (; __pb != __pe; ++__pb) {
2087 if (__ct.narrow(*__pb, 0) == '%') {
2088 if (++__pb == __pe) {
2093 char __fmt = __ct.narrow(*__pb, 0);
2094 if (__fmt == 'E' || __fmt == 'O') {
2095 if (++__pb == __pe) {
2101 __fmt = __ct.narrow(*__pb, 0);
2103 __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod);
2110 template <class _CharT, class _OutputIterator>
2111 _OutputIterator time_put<_CharT, _OutputIterator>::do_put(
2112 iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const {
2113 char_type __nar[100];
2114 char_type* __nb = __nar;
2115 char_type* __ne = __nb + 100;
2116 __do_put(__nb, __ne, __tm, __fmt, __mod);
2117 return std::copy(__nb, __ne, __s);
2120 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>;
2121 # if _LIBCPP_HAS_WIDE_CHARACTERS
2122 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>;
2125 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2126 class _LIBCPP_TEMPLATE_VIS time_put_byname : public time_put<_CharT, _OutputIterator> {
2128 _LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const char* __nm, size_t __refs = 0)
2129 : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
2131 _LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const string& __nm, size_t __refs = 0)
2132 : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
2135 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put_byname() override {}
2138 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>;
2139 # if _LIBCPP_HAS_WIDE_CHARACTERS
2140 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>;
2145 class _LIBCPP_EXPORTED_FROM_ABI money_base {
2147 enum part { none, space, symbol, sign, value };
2152 _LIBCPP_HIDE_FROM_ABI money_base() {}
2157 template <class _CharT, bool _International = false>
2158 class _LIBCPP_TEMPLATE_VIS moneypunct : public locale::facet, public money_base {
2160 typedef _CharT char_type;
2161 typedef basic_string<char_type> string_type;
2163 _LIBCPP_HIDE_FROM_ABI explicit moneypunct(size_t __refs = 0) : locale::facet(__refs) {}
2165 _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }
2166 _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }
2167 _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }
2168 _LIBCPP_HIDE_FROM_ABI string_type curr_symbol() const { return do_curr_symbol(); }
2169 _LIBCPP_HIDE_FROM_ABI string_type positive_sign() const { return do_positive_sign(); }
2170 _LIBCPP_HIDE_FROM_ABI string_type negative_sign() const { return do_negative_sign(); }
2171 _LIBCPP_HIDE_FROM_ABI int frac_digits() const { return do_frac_digits(); }
2172 _LIBCPP_HIDE_FROM_ABI pattern pos_format() const { return do_pos_format(); }
2173 _LIBCPP_HIDE_FROM_ABI pattern neg_format() const { return do_neg_format(); }
2175 static locale::id id;
2176 static const bool intl = _International;
2179 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct() override {}
2181 virtual char_type do_decimal_point() const { return numeric_limits<char_type>::max(); }
2182 virtual char_type do_thousands_sep() const { return numeric_limits<char_type>::max(); }
2183 virtual string do_grouping() const { return string(); }
2184 virtual string_type do_curr_symbol() const { return string_type(); }
2185 virtual string_type do_positive_sign() const { return string_type(); }
2186 virtual string_type do_negative_sign() const { return string_type(1, '-'); }
2187 virtual int do_frac_digits() const { return 0; }
2188 virtual pattern do_pos_format() const {
2189 pattern __p = {{symbol, sign, none, value}};
2192 virtual pattern do_neg_format() const {
2193 pattern __p = {{symbol, sign, none, value}};
2198 template <class _CharT, bool _International>
2199 locale::id moneypunct<_CharT, _International>::id;
2201 template <class _CharT, bool _International>
2202 const bool moneypunct<_CharT, _International>::intl;
2204 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>;
2205 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>;
2206 # if _LIBCPP_HAS_WIDE_CHARACTERS
2207 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>;
2208 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>;
2211 // moneypunct_byname
2213 template <class _CharT, bool _International = false>
2214 class _LIBCPP_TEMPLATE_VIS moneypunct_byname : public moneypunct<_CharT, _International> {
2216 typedef money_base::pattern pattern;
2217 typedef _CharT char_type;
2218 typedef basic_string<char_type> string_type;
2220 _LIBCPP_HIDE_FROM_ABI explicit moneypunct_byname(const char* __nm, size_t __refs = 0)
2221 : moneypunct<_CharT, _International>(__refs) {
2225 _LIBCPP_HIDE_FROM_ABI explicit moneypunct_byname(const string& __nm, size_t __refs = 0)
2226 : moneypunct<_CharT, _International>(__refs) {
2231 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct_byname() override {}
2233 char_type do_decimal_point() const override { return __decimal_point_; }
2234 char_type do_thousands_sep() const override { return __thousands_sep_; }
2235 string do_grouping() const override { return __grouping_; }
2236 string_type do_curr_symbol() const override { return __curr_symbol_; }
2237 string_type do_positive_sign() const override { return __positive_sign_; }
2238 string_type do_negative_sign() const override { return __negative_sign_; }
2239 int do_frac_digits() const override { return __frac_digits_; }
2240 pattern do_pos_format() const override { return __pos_format_; }
2241 pattern do_neg_format() const override { return __neg_format_; }
2244 char_type __decimal_point_;
2245 char_type __thousands_sep_;
2247 string_type __curr_symbol_;
2248 string_type __positive_sign_;
2249 string_type __negative_sign_;
2251 pattern __pos_format_;
2252 pattern __neg_format_;
2254 void init(const char*);
2258 _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, false>::init(const char*);
2260 _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, true>::init(const char*);
2261 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>;
2262 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>;
2264 # if _LIBCPP_HAS_WIDE_CHARACTERS
2266 _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, false>::init(const char*);
2268 _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, true>::init(const char*);
2269 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>;
2270 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>;
2275 template <class _CharT>
2278 typedef _CharT char_type;
2279 typedef basic_string<char_type> string_type;
2281 _LIBCPP_HIDE_FROM_ABI __money_get() {}
2283 static void __gather_info(
2285 const locale& __loc,
2286 money_base::pattern& __pat,
2296 template <class _CharT>
2297 void __money_get<_CharT>::__gather_info(
2299 const locale& __loc,
2300 money_base::pattern& __pat,
2309 const moneypunct<char_type, true>& __mp = std::use_facet<moneypunct<char_type, true> >(__loc);
2310 __pat = __mp.neg_format();
2311 __nsn = __mp.negative_sign();
2312 __psn = __mp.positive_sign();
2313 __dp = __mp.decimal_point();
2314 __ts = __mp.thousands_sep();
2315 __grp = __mp.grouping();
2316 __sym = __mp.curr_symbol();
2317 __fd = __mp.frac_digits();
2319 const moneypunct<char_type, false>& __mp = std::use_facet<moneypunct<char_type, false> >(__loc);
2320 __pat = __mp.neg_format();
2321 __nsn = __mp.negative_sign();
2322 __psn = __mp.positive_sign();
2323 __dp = __mp.decimal_point();
2324 __ts = __mp.thousands_sep();
2325 __grp = __mp.grouping();
2326 __sym = __mp.curr_symbol();
2327 __fd = __mp.frac_digits();
2331 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>;
2332 # if _LIBCPP_HAS_WIDE_CHARACTERS
2333 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>;
2336 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
2337 class _LIBCPP_TEMPLATE_VIS money_get : public locale::facet, private __money_get<_CharT> {
2339 typedef _CharT char_type;
2340 typedef _InputIterator iter_type;
2341 typedef basic_string<char_type> string_type;
2343 _LIBCPP_HIDE_FROM_ABI explicit money_get(size_t __refs = 0) : locale::facet(__refs) {}
2345 _LIBCPP_HIDE_FROM_ABI iter_type
2346 get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
2347 return do_get(__b, __e, __intl, __iob, __err, __v);
2350 _LIBCPP_HIDE_FROM_ABI iter_type
2351 get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const {
2352 return do_get(__b, __e, __intl, __iob, __err, __v);
2355 static locale::id id;
2358 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_get() override {}
2361 do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const;
2363 do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const;
2366 static bool __do_get(
2370 const locale& __loc,
2371 ios_base::fmtflags __flags,
2372 ios_base::iostate& __err,
2374 const ctype<char_type>& __ct,
2375 unique_ptr<char_type, void (*)(void*)>& __wb,
2380 template <class _CharT, class _InputIterator>
2381 locale::id money_get<_CharT, _InputIterator>::id;
2383 _LIBCPP_EXPORTED_FROM_ABI void __do_nothing(void*);
2385 template <class _Tp>
2386 _LIBCPP_HIDE_FROM_ABI void __double_or_nothing(unique_ptr<_Tp, void (*)(void*)>& __b, _Tp*& __n, _Tp*& __e) {
2387 bool __owns = __b.get_deleter() != __do_nothing;
2388 size_t __cur_cap = static_cast<size_t>(__e - __b.get()) * sizeof(_Tp);
2389 size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ? 2 * __cur_cap : numeric_limits<size_t>::max();
2391 __new_cap = sizeof(_Tp);
2392 size_t __n_off = static_cast<size_t>(__n - __b.get());
2393 _Tp* __t = (_Tp*)std::realloc(__owns ? __b.get() : 0, __new_cap);
2395 __throw_bad_alloc();
2398 __b = unique_ptr<_Tp, void (*)(void*)>(__t, free);
2399 __new_cap /= sizeof(_Tp);
2400 __n = __b.get() + __n_off;
2401 __e = __b.get() + __new_cap;
2405 template <class _CharT, class _InputIterator>
2406 bool money_get<_CharT, _InputIterator>::__do_get(
2410 const locale& __loc,
2411 ios_base::fmtflags __flags,
2412 ios_base::iostate& __err,
2414 const ctype<char_type>& __ct,
2415 unique_ptr<char_type, void (*)(void*)>& __wb,
2419 __err |= ios_base::failbit;
2422 const unsigned __bz = 100;
2423 unsigned __gbuf[__bz];
2424 unique_ptr<unsigned, void (*)(void*)> __gb(__gbuf, __do_nothing);
2425 unsigned* __gn = __gb.get();
2426 unsigned* __ge = __gn + __bz;
2427 money_base::pattern __pat;
2434 // Capture the spaces read into money_base::{space,none} so they
2435 // can be compared to initial spaces in __sym.
2436 string_type __spaces;
2438 __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp, __sym, __psn, __nsn, __fd);
2439 const string_type* __trailing_sign = 0;
2441 for (unsigned __p = 0; __p < 4 && __b != __e; ++__p) {
2442 switch (__pat.field[__p]) {
2443 case money_base::space:
2445 if (__ct.is(ctype_base::space, *__b))
2446 __spaces.push_back(*__b++);
2448 __err |= ios_base::failbit;
2452 _LIBCPP_FALLTHROUGH();
2453 case money_base::none:
2455 while (__b != __e && __ct.is(ctype_base::space, *__b))
2456 __spaces.push_back(*__b++);
2459 case money_base::sign:
2460 if (__psn.size() > 0 && *__b == __psn[0]) {
2463 if (__psn.size() > 1)
2464 __trailing_sign = &__psn;
2467 if (__nsn.size() > 0 && *__b == __nsn[0]) {
2470 if (__nsn.size() > 1)
2471 __trailing_sign = &__nsn;
2474 if (__psn.size() > 0 && __nsn.size() > 0) { // sign is required
2475 __err |= ios_base::failbit;
2478 if (__psn.size() == 0 && __nsn.size() == 0)
2479 // locale has no way of specifying a sign. Use the initial value of __neg as a default
2481 __neg = (__nsn.size() == 0);
2483 case money_base::symbol: {
2484 bool __more_needed =
2485 __trailing_sign || (__p < 2) || (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none));
2486 bool __sb = (__flags & ios_base::showbase) != 0;
2487 if (__sb || __more_needed) {
2488 typename string_type::const_iterator __sym_space_end = __sym.begin();
2489 if (__p > 0 && (__pat.field[__p - 1] == money_base::none || __pat.field[__p - 1] == money_base::space)) {
2490 // Match spaces we've already read against spaces at
2491 // the beginning of __sym.
2492 while (__sym_space_end != __sym.end() && __ct.is(ctype_base::space, *__sym_space_end))
2494 const size_t __num_spaces = __sym_space_end - __sym.begin();
2495 if (__num_spaces > __spaces.size() ||
2496 !std::equal(__spaces.end() - __num_spaces, __spaces.end(), __sym.begin())) {
2497 // No match. Put __sym_space_end back at the
2498 // beginning of __sym, which will prevent a
2499 // match in the next loop.
2500 __sym_space_end = __sym.begin();
2503 typename string_type::const_iterator __sym_curr_char = __sym_space_end;
2504 while (__sym_curr_char != __sym.end() && __b != __e && *__b == *__sym_curr_char) {
2508 if (__sb && __sym_curr_char != __sym.end()) {
2509 __err |= ios_base::failbit;
2514 case money_base::value: {
2516 for (; __b != __e; ++__b) {
2517 char_type __c = *__b;
2518 if (__ct.is(ctype_base::digit, __c)) {
2520 std::__double_or_nothing(__wb, __wn, __we);
2523 } else if (__grp.size() > 0 && __ng > 0 && __c == __ts) {
2525 std::__double_or_nothing(__gb, __gn, __ge);
2531 if (__gb.get() != __gn && __ng > 0) {
2533 std::__double_or_nothing(__gb, __gn, __ge);
2537 if (__b == __e || *__b != __dp) {
2538 __err |= ios_base::failbit;
2541 for (++__b; __fd > 0; --__fd, ++__b) {
2542 if (__b == __e || !__ct.is(ctype_base::digit, *__b)) {
2543 __err |= ios_base::failbit;
2547 std::__double_or_nothing(__wb, __wn, __we);
2551 if (__wn == __wb.get()) {
2552 __err |= ios_base::failbit;
2558 if (__trailing_sign) {
2559 for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) {
2560 if (__b == __e || *__b != (*__trailing_sign)[__i]) {
2561 __err |= ios_base::failbit;
2566 if (__gb.get() != __gn) {
2567 ios_base::iostate __et = ios_base::goodbit;
2568 __check_grouping(__grp, __gb.get(), __gn, __et);
2570 __err |= ios_base::failbit;
2577 template <class _CharT, class _InputIterator>
2578 _InputIterator money_get<_CharT, _InputIterator>::do_get(
2579 iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
2580 const int __bz = 100;
2581 char_type __wbuf[__bz];
2582 unique_ptr<char_type, void (*)(void*)> __wb(__wbuf, __do_nothing);
2584 char_type* __we = __wbuf + __bz;
2585 locale __loc = __iob.getloc();
2586 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
2588 if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) {
2589 const char __src[] = "0123456789";
2590 char_type __atoms[sizeof(__src) - 1];
2591 __ct.widen(__src, __src + (sizeof(__src) - 1), __atoms);
2593 char* __nc = __nbuf;
2594 unique_ptr<char, void (*)(void*)> __h(nullptr, free);
2595 if (__wn - __wb.get() > __bz - 2) {
2596 __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2)));
2597 if (__h.get() == nullptr)
2598 __throw_bad_alloc();
2603 for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc)
2604 *__nc = __src[std::find(__atoms, std::end(__atoms), *__w) - __atoms];
2606 if (sscanf(__nbuf, "%Lf", &__v) != 1)
2607 __throw_runtime_error("money_get error");
2610 __err |= ios_base::eofbit;
2614 template <class _CharT, class _InputIterator>
2615 _InputIterator money_get<_CharT, _InputIterator>::do_get(
2616 iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const {
2617 const int __bz = 100;
2618 char_type __wbuf[__bz];
2619 unique_ptr<char_type, void (*)(void*)> __wb(__wbuf, __do_nothing);
2621 char_type* __we = __wbuf + __bz;
2622 locale __loc = __iob.getloc();
2623 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
2625 if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) {
2628 __v.push_back(__ct.widen('-'));
2629 char_type __z = __ct.widen('0');
2631 for (__w = __wb.get(); __w < __wn - 1; ++__w)
2634 __v.append(__w, __wn);
2637 __err |= ios_base::eofbit;
2641 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>;
2642 # if _LIBCPP_HAS_WIDE_CHARACTERS
2643 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>;
2648 template <class _CharT>
2651 typedef _CharT char_type;
2652 typedef basic_string<char_type> string_type;
2654 _LIBCPP_HIDE_FROM_ABI __money_put() {}
2656 static void __gather_info(
2659 const locale& __loc,
2660 money_base::pattern& __pat,
2667 static void __format(
2671 ios_base::fmtflags __flags,
2672 const char_type* __db,
2673 const char_type* __de,
2674 const ctype<char_type>& __ct,
2676 const money_base::pattern& __pat,
2679 const string& __grp,
2680 const string_type& __sym,
2681 const string_type& __sn,
2685 template <class _CharT>
2686 void __money_put<_CharT>::__gather_info(
2689 const locale& __loc,
2690 money_base::pattern& __pat,
2698 const moneypunct<char_type, true>& __mp = std::use_facet<moneypunct<char_type, true> >(__loc);
2700 __pat = __mp.neg_format();
2701 __sn = __mp.negative_sign();
2703 __pat = __mp.pos_format();
2704 __sn = __mp.positive_sign();
2706 __dp = __mp.decimal_point();
2707 __ts = __mp.thousands_sep();
2708 __grp = __mp.grouping();
2709 __sym = __mp.curr_symbol();
2710 __fd = __mp.frac_digits();
2712 const moneypunct<char_type, false>& __mp = std::use_facet<moneypunct<char_type, false> >(__loc);
2714 __pat = __mp.neg_format();
2715 __sn = __mp.negative_sign();
2717 __pat = __mp.pos_format();
2718 __sn = __mp.positive_sign();
2720 __dp = __mp.decimal_point();
2721 __ts = __mp.thousands_sep();
2722 __grp = __mp.grouping();
2723 __sym = __mp.curr_symbol();
2724 __fd = __mp.frac_digits();
2728 template <class _CharT>
2729 void __money_put<_CharT>::__format(
2733 ios_base::fmtflags __flags,
2734 const char_type* __db,
2735 const char_type* __de,
2736 const ctype<char_type>& __ct,
2738 const money_base::pattern& __pat,
2741 const string& __grp,
2742 const string_type& __sym,
2743 const string_type& __sn,
2746 for (char __p : __pat.field) {
2748 case money_base::none:
2751 case money_base::space:
2753 *__me++ = __ct.widen(' ');
2755 case money_base::sign:
2759 case money_base::symbol:
2760 if (!__sym.empty() && (__flags & ios_base::showbase))
2761 __me = std::copy(__sym.begin(), __sym.end(), __me);
2763 case money_base::value: {
2764 // remember start of value so we can reverse it
2765 char_type* __t = __me;
2766 // find beginning of digits
2769 // find end of digits
2770 const char_type* __d;
2771 for (__d = __db; __d < __de; ++__d)
2772 if (!__ct.is(ctype_base::digit, *__d))
2774 // print fractional part
2777 for (__f = __fd; __d > __db && __f > 0; --__f)
2779 char_type __z = __f > 0 ? __ct.widen('0') : char_type();
2780 for (; __f > 0; --__f)
2786 *__me++ = __ct.widen('0');
2790 unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max() : static_cast<unsigned>(__grp[__ig]);
2791 while (__d != __db) {
2795 if (++__ig < __grp.size())
2796 __gl = __grp[__ig] == numeric_limits<char>::max()
2797 ? numeric_limits<unsigned>::max()
2798 : static_cast<unsigned>(__grp[__ig]);
2805 std::reverse(__t, __me);
2809 // print rest of sign, if any
2810 if (__sn.size() > 1)
2811 __me = std::copy(__sn.begin() + 1, __sn.end(), __me);
2813 if ((__flags & ios_base::adjustfield) == ios_base::left)
2815 else if ((__flags & ios_base::adjustfield) != ios_base::internal)
2819 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>;
2820 # if _LIBCPP_HAS_WIDE_CHARACTERS
2821 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>;
2824 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2825 class _LIBCPP_TEMPLATE_VIS money_put : public locale::facet, private __money_put<_CharT> {
2827 typedef _CharT char_type;
2828 typedef _OutputIterator iter_type;
2829 typedef basic_string<char_type> string_type;
2831 _LIBCPP_HIDE_FROM_ABI explicit money_put(size_t __refs = 0) : locale::facet(__refs) {}
2833 _LIBCPP_HIDE_FROM_ABI iter_type
2834 put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const {
2835 return do_put(__s, __intl, __iob, __fl, __units);
2838 _LIBCPP_HIDE_FROM_ABI iter_type
2839 put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const {
2840 return do_put(__s, __intl, __iob, __fl, __digits);
2843 static locale::id id;
2846 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_put() override {}
2848 virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const;
2850 do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const;
2853 template <class _CharT, class _OutputIterator>
2854 locale::id money_put<_CharT, _OutputIterator>::id;
2856 template <class _CharT, class _OutputIterator>
2857 _OutputIterator money_put<_CharT, _OutputIterator>::do_put(
2858 iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const {
2860 const size_t __bs = 100;
2863 char_type __digits[__bs];
2864 char_type* __db = __digits;
2865 int __n = snprintf(__bb, __bs, "%.0Lf", __units);
2866 unique_ptr<char, void (*)(void*)> __hn(nullptr, free);
2867 unique_ptr<char_type, void (*)(void*)> __hd(0, free);
2868 // secure memory for digit storage
2869 if (static_cast<size_t>(__n) > __bs - 1) {
2870 __n = __locale::__asprintf(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units);
2872 __throw_bad_alloc();
2874 __hd.reset((char_type*)malloc(static_cast<size_t>(__n) * sizeof(char_type)));
2875 if (__hd == nullptr)
2876 __throw_bad_alloc();
2880 locale __loc = __iob.getloc();
2881 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
2882 __ct.widen(__bb, __bb + __n, __db);
2883 bool __neg = __n > 0 && __bb[0] == '-';
2884 money_base::pattern __pat;
2891 this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
2892 // secure memory for formatting
2893 char_type __mbuf[__bs];
2894 char_type* __mb = __mbuf;
2895 unique_ptr<char_type, void (*)(void*)> __hw(0, free);
2896 size_t __exn = __n > __fd ? (static_cast<size_t>(__n) - static_cast<size_t>(__fd)) * 2 + __sn.size() + __sym.size() +
2897 static_cast<size_t>(__fd) + 1
2898 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
2900 __hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
2903 __throw_bad_alloc();
2909 __mb, __mi, __me, __iob.flags(), __db, __db + __n, __ct, __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
2910 return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
2913 template <class _CharT, class _OutputIterator>
2914 _OutputIterator money_put<_CharT, _OutputIterator>::do_put(
2915 iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const {
2917 locale __loc = __iob.getloc();
2918 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
2919 bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-');
2920 money_base::pattern __pat;
2927 this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
2928 // secure memory for formatting
2929 char_type __mbuf[100];
2930 char_type* __mb = __mbuf;
2931 unique_ptr<char_type, void (*)(void*)> __h(0, free);
2933 static_cast<int>(__digits.size()) > __fd
2934 ? (__digits.size() - static_cast<size_t>(__fd)) * 2 + __sn.size() + __sym.size() + static_cast<size_t>(__fd) +
2936 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
2938 __h.reset((char_type*)malloc(__exn * sizeof(char_type)));
2941 __throw_bad_alloc();
2952 __digits.data() + __digits.size(),
2962 return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
2965 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>;
2966 # if _LIBCPP_HAS_WIDE_CHARACTERS
2967 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>;
2972 class _LIBCPP_EXPORTED_FROM_ABI messages_base {
2974 typedef intptr_t catalog;
2976 _LIBCPP_HIDE_FROM_ABI messages_base() {}
2979 template <class _CharT>
2980 class _LIBCPP_TEMPLATE_VIS messages : public locale::facet, public messages_base {
2982 typedef _CharT char_type;
2983 typedef basic_string<_CharT> string_type;
2985 _LIBCPP_HIDE_FROM_ABI explicit messages(size_t __refs = 0) : locale::facet(__refs) {}
2987 _LIBCPP_HIDE_FROM_ABI catalog open(const basic_string<char>& __nm, const locale& __loc) const {
2988 return do_open(__nm, __loc);
2991 _LIBCPP_HIDE_FROM_ABI string_type get(catalog __c, int __set, int __msgid, const string_type& __dflt) const {
2992 return do_get(__c, __set, __msgid, __dflt);
2995 _LIBCPP_HIDE_FROM_ABI void close(catalog __c) const { do_close(__c); }
2997 static locale::id id;
3000 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages() override {}
3002 virtual catalog do_open(const basic_string<char>&, const locale&) const;
3003 virtual string_type do_get(catalog, int __set, int __msgid, const string_type& __dflt) const;
3004 virtual void do_close(catalog) const;
3007 template <class _CharT>
3008 locale::id messages<_CharT>::id;
3010 template <class _CharT>
3011 typename messages<_CharT>::catalog messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const {
3012 # if _LIBCPP_HAS_CATOPEN
3013 return (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
3014 # else // !_LIBCPP_HAS_CATOPEN
3017 # endif // _LIBCPP_HAS_CATOPEN
3020 template <class _CharT>
3021 typename messages<_CharT>::string_type
3022 messages<_CharT>::do_get(catalog __c, int __set, int __msgid, const string_type& __dflt) const {
3023 # if _LIBCPP_HAS_CATOPEN
3025 __narrow_to_utf8<sizeof(char_type) * __CHAR_BIT__>()(
3026 std::back_inserter(__ndflt), __dflt.c_str(), __dflt.c_str() + __dflt.size());
3027 nl_catd __cat = (nl_catd)__c;
3028 static_assert(sizeof(catalog) >= sizeof(nl_catd), "Unexpected nl_catd type");
3029 char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str());
3031 __widen_from_utf8<sizeof(char_type) * __CHAR_BIT__>()(std::back_inserter(__w), __n, __n + std::strlen(__n));
3033 # else // !_LIBCPP_HAS_CATOPEN
3038 # endif // _LIBCPP_HAS_CATOPEN
3041 template <class _CharT>
3042 void messages<_CharT>::do_close(catalog __c) const {
3043 # if _LIBCPP_HAS_CATOPEN
3044 catclose((nl_catd)__c);
3045 # else // !_LIBCPP_HAS_CATOPEN
3047 # endif // _LIBCPP_HAS_CATOPEN
3050 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>;
3051 # if _LIBCPP_HAS_WIDE_CHARACTERS
3052 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>;
3055 template <class _CharT>
3056 class _LIBCPP_TEMPLATE_VIS messages_byname : public messages<_CharT> {
3058 typedef messages_base::catalog catalog;
3059 typedef basic_string<_CharT> string_type;
3061 _LIBCPP_HIDE_FROM_ABI explicit messages_byname(const char*, size_t __refs = 0) : messages<_CharT>(__refs) {}
3063 _LIBCPP_HIDE_FROM_ABI explicit messages_byname(const string&, size_t __refs = 0) : messages<_CharT>(__refs) {}
3066 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages_byname() override {}
3069 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>;
3070 # if _LIBCPP_HAS_WIDE_CHARACTERS
3071 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>;
3074 # if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
3076 template <class _Codecvt,
3077 class _Elem = wchar_t,
3078 class _WideAlloc = allocator<_Elem>,
3079 class _ByteAlloc = allocator<char> >
3080 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 wstring_convert {
3082 typedef basic_string<char, char_traits<char>, _ByteAlloc> byte_string;
3083 typedef basic_string<_Elem, char_traits<_Elem>, _WideAlloc> wide_string;
3084 typedef typename _Codecvt::state_type state_type;
3085 typedef typename wide_string::traits_type::int_type int_type;
3088 byte_string __byte_err_string_;
3089 wide_string __wide_err_string_;
3090 _Codecvt* __cvtptr_;
3091 state_type __cvtstate_;
3095 # ifndef _LIBCPP_CXX03_LANG
3096 _LIBCPP_HIDE_FROM_ABI wstring_convert() : wstring_convert(new _Codecvt) {}
3097 _LIBCPP_HIDE_FROM_ABI explicit wstring_convert(_Codecvt* __pcvt);
3099 _LIBCPP_HIDE_FROM_ABI _LIBCPP_EXPLICIT_SINCE_CXX14 wstring_convert(_Codecvt* __pcvt = new _Codecvt);
3102 _LIBCPP_HIDE_FROM_ABI wstring_convert(_Codecvt* __pcvt, state_type __state);
3103 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
3104 wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err = wide_string());
3105 # ifndef _LIBCPP_CXX03_LANG
3106 _LIBCPP_HIDE_FROM_ABI wstring_convert(wstring_convert&& __wc);
3108 _LIBCPP_HIDE_FROM_ABI ~wstring_convert();
3110 wstring_convert(const wstring_convert& __wc) = delete;
3111 wstring_convert& operator=(const wstring_convert& __wc) = delete;
3113 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(char __byte) { return from_bytes(&__byte, &__byte + 1); }
3114 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __ptr) {
3115 return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));
3117 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const byte_string& __str) {
3118 return from_bytes(__str.data(), __str.data() + __str.size());
3120 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __first, const char* __last);
3122 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(_Elem __wchar) { return to_bytes(&__wchar, &__wchar + 1); }
3123 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __wptr) {
3124 return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));
3126 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const wide_string& __wstr) {
3127 return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());
3129 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __first, const _Elem* __last);
3131 _LIBCPP_HIDE_FROM_ABI size_t converted() const _NOEXCEPT { return __cvtcount_; }
3132 _LIBCPP_HIDE_FROM_ABI state_type state() const { return __cvtstate_; }
3135 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3136 template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3137 inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(_Codecvt* __pcvt)
3138 : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) {}
3139 _LIBCPP_SUPPRESS_DEPRECATED_POP
3141 template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3142 inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(_Codecvt* __pcvt, state_type __state)
3143 : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) {}
3145 template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3146 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(
3147 const byte_string& __byte_err, const wide_string& __wide_err)
3148 : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), __cvtstate_(), __cvtcount_(0) {
3149 __cvtptr_ = new _Codecvt;
3152 # ifndef _LIBCPP_CXX03_LANG
3154 template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3155 inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(wstring_convert&& __wc)
3156 : __byte_err_string_(std::move(__wc.__byte_err_string_)),
3157 __wide_err_string_(std::move(__wc.__wide_err_string_)),
3158 __cvtptr_(__wc.__cvtptr_),
3159 __cvtstate_(__wc.__cvtstate_),
3160 __cvtcount_(__wc.__cvtcount_) {
3161 __wc.__cvtptr_ = nullptr;
3164 # endif // _LIBCPP_CXX03_LANG
3166 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3167 template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3168 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::~wstring_convert() {
3172 template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3173 typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wide_string
3174 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::from_bytes(const char* __frm, const char* __frm_end) {
3175 _LIBCPP_SUPPRESS_DEPRECATED_POP
3177 if (__cvtptr_ != nullptr) {
3178 wide_string __ws(2 * (__frm_end - __frm), _Elem());
3179 if (__frm != __frm_end)
3180 __ws.resize(__ws.capacity());
3181 codecvt_base::result __r = codecvt_base::ok;
3182 state_type __st = __cvtstate_;
3183 if (__frm != __frm_end) {
3184 _Elem* __to = &__ws[0];
3185 _Elem* __to_end = __to + __ws.size();
3186 const char* __frm_nxt;
3189 __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
3190 __cvtcount_ += __frm_nxt - __frm;
3191 if (__frm_nxt == __frm) {
3192 __r = codecvt_base::error;
3193 } else if (__r == codecvt_base::noconv) {
3194 __ws.resize(__to - &__ws[0]);
3195 // This only gets executed if _Elem is char
3196 __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end);
3198 __r = codecvt_base::ok;
3199 } else if (__r == codecvt_base::ok) {
3200 __ws.resize(__to_nxt - &__ws[0]);
3202 } else if (__r == codecvt_base::partial) {
3203 ptrdiff_t __s = __to_nxt - &__ws[0];
3204 __ws.resize(2 * __s);
3205 __to = &__ws[0] + __s;
3206 __to_end = &__ws[0] + __ws.size();
3209 } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
3211 if (__r == codecvt_base::ok)
3215 if (__wide_err_string_.empty())
3216 __throw_range_error("wstring_convert: from_bytes error");
3218 return __wide_err_string_;
3221 template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3222 typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::byte_string
3223 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::to_bytes(const _Elem* __frm, const _Elem* __frm_end) {
3225 if (__cvtptr_ != nullptr) {
3226 byte_string __bs(2 * (__frm_end - __frm), char());
3227 if (__frm != __frm_end)
3228 __bs.resize(__bs.capacity());
3229 codecvt_base::result __r = codecvt_base::ok;
3230 state_type __st = __cvtstate_;
3231 if (__frm != __frm_end) {
3232 char* __to = &__bs[0];
3233 char* __to_end = __to + __bs.size();
3234 const _Elem* __frm_nxt;
3237 __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
3238 __cvtcount_ += __frm_nxt - __frm;
3239 if (__frm_nxt == __frm) {
3240 __r = codecvt_base::error;
3241 } else if (__r == codecvt_base::noconv) {
3242 __bs.resize(__to - &__bs[0]);
3243 // This only gets executed if _Elem is char
3244 __bs.append((const char*)__frm, (const char*)__frm_end);
3246 __r = codecvt_base::ok;
3247 } else if (__r == codecvt_base::ok) {
3248 __bs.resize(__to_nxt - &__bs[0]);
3250 } else if (__r == codecvt_base::partial) {
3251 ptrdiff_t __s = __to_nxt - &__bs[0];
3252 __bs.resize(2 * __s);
3253 __to = &__bs[0] + __s;
3254 __to_end = &__bs[0] + __bs.size();
3257 } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
3259 if (__r == codecvt_base::ok) {
3260 size_t __s = __bs.size();
3261 __bs.resize(__bs.capacity());
3262 char* __to = &__bs[0] + __s;
3263 char* __to_end = __to + __bs.size();
3266 __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt);
3267 if (__r == codecvt_base::noconv) {
3268 __bs.resize(__to - &__bs[0]);
3269 __r = codecvt_base::ok;
3270 } else if (__r == codecvt_base::ok) {
3271 __bs.resize(__to_nxt - &__bs[0]);
3272 } else if (__r == codecvt_base::partial) {
3273 ptrdiff_t __sp = __to_nxt - &__bs[0];
3274 __bs.resize(2 * __sp);
3275 __to = &__bs[0] + __sp;
3276 __to_end = &__bs[0] + __bs.size();
3278 } while (__r == codecvt_base::partial);
3279 if (__r == codecvt_base::ok)
3284 if (__byte_err_string_.empty())
3285 __throw_range_error("wstring_convert: to_bytes error");
3287 return __byte_err_string_;
3290 template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> >
3291 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 wbuffer_convert : public basic_streambuf<_Elem, _Tr> {
3294 typedef _Elem char_type;
3295 typedef _Tr traits_type;
3296 typedef typename traits_type::int_type int_type;
3297 typedef typename traits_type::pos_type pos_type;
3298 typedef typename traits_type::off_type off_type;
3299 typedef typename _Codecvt::state_type state_type;
3303 const char* __extbufnext_;
3304 const char* __extbufend_;
3305 char __extbuf_min_[8];
3307 char_type* __intbuf_;
3309 streambuf* __bufptr_;
3312 ios_base::openmode __cm_;
3315 bool __always_noconv_;
3318 # ifndef _LIBCPP_CXX03_LANG
3319 _LIBCPP_HIDE_FROM_ABI wbuffer_convert() : wbuffer_convert(nullptr) {}
3320 explicit _LIBCPP_HIDE_FROM_ABI
3321 wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
3323 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
3324 wbuffer_convert(streambuf* __bytebuf = nullptr, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
3327 _LIBCPP_HIDE_FROM_ABI ~wbuffer_convert();
3329 _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf() const { return __bufptr_; }
3330 _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf(streambuf* __bytebuf) {
3331 streambuf* __r = __bufptr_;
3332 __bufptr_ = __bytebuf;
3336 wbuffer_convert(const wbuffer_convert&) = delete;
3337 wbuffer_convert& operator=(const wbuffer_convert&) = delete;
3339 _LIBCPP_HIDE_FROM_ABI state_type state() const { return __st_; }
3342 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type underflow();
3343 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type pbackfail(int_type __c = traits_type::eof());
3344 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type overflow(int_type __c = traits_type::eof());
3345 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n);
3346 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type
3347 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out);
3348 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type
3349 seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out);
3350 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int sync();
3353 _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool __read_mode();
3354 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __write_mode();
3355 _LIBCPP_HIDE_FROM_ABI_VIRTUAL wbuffer_convert* __close();
3358 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3359 template <class _Codecvt, class _Elem, class _Tr>
3360 wbuffer_convert<_Codecvt, _Elem, _Tr>::wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state)
3361 : __extbuf_(nullptr),
3362 __extbufnext_(nullptr),
3363 __extbufend_(nullptr),
3367 __bufptr_(__bytebuf),
3373 __always_noconv_(__cv_ ? __cv_->always_noconv() : false) {
3377 template <class _Codecvt, class _Elem, class _Tr>
3378 wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() {
3387 template <class _Codecvt, class _Elem, class _Tr>
3388 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() {
3389 _LIBCPP_SUPPRESS_DEPRECATED_POP
3390 if (__cv_ == 0 || __bufptr_ == nullptr)
3391 return traits_type::eof();
3392 bool __initial = __read_mode();
3394 if (this->gptr() == 0)
3395 this->setg(&__1buf, &__1buf + 1, &__1buf + 1);
3396 const size_t __unget_sz = __initial ? 0 : std::min<size_t>((this->egptr() - this->eback()) / 2, 4);
3397 int_type __c = traits_type::eof();
3398 if (this->gptr() == this->egptr()) {
3399 std::memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
3400 if (__always_noconv_) {
3401 streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz);
3402 __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb);
3404 this->setg(this->eback(), this->eback() + __unget_sz, this->eback() + __unget_sz + __nmemb);
3405 __c = *this->gptr();
3408 if (__extbufend_ != __extbufnext_) {
3409 _LIBCPP_ASSERT_NON_NULL(__extbufnext_ != nullptr, "underflow moving from nullptr");
3410 _LIBCPP_ASSERT_NON_NULL(__extbuf_ != nullptr, "underflow moving into nullptr");
3411 std::memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
3413 __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
3414 __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
3415 streamsize __nmemb = std::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz),
3416 static_cast<streamsize>(__extbufend_ - __extbufnext_));
3417 codecvt_base::result __r;
3418 // FIXME: Do we ever need to restore the state here?
3419 // state_type __svs = __st_;
3420 streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb);
3422 __extbufend_ = __extbufnext_ + __nr;
3425 __st_, __extbuf_, __extbufend_, __extbufnext_, this->eback() + __unget_sz, this->egptr(), __inext);
3426 if (__r == codecvt_base::noconv) {
3427 this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)const_cast<char*>(__extbufend_));
3428 __c = *this->gptr();
3429 } else if (__inext != this->eback() + __unget_sz) {
3430 this->setg(this->eback(), this->eback() + __unget_sz, __inext);
3431 __c = *this->gptr();
3436 __c = *this->gptr();
3437 if (this->eback() == &__1buf)
3438 this->setg(0, 0, 0);
3442 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3443 template <class _Codecvt, class _Elem, class _Tr>
3444 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
3445 wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) {
3446 _LIBCPP_SUPPRESS_DEPRECATED_POP
3447 if (__cv_ != 0 && __bufptr_ && this->eback() < this->gptr()) {
3448 if (traits_type::eq_int_type(__c, traits_type::eof())) {
3450 return traits_type::not_eof(__c);
3452 if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) {
3454 *this->gptr() = traits_type::to_char_type(__c);
3458 return traits_type::eof();
3461 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3462 template <class _Codecvt, class _Elem, class _Tr>
3463 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) {
3464 _LIBCPP_SUPPRESS_DEPRECATED_POP
3465 if (__cv_ == 0 || !__bufptr_)
3466 return traits_type::eof();
3469 char_type* __pb_save = this->pbase();
3470 char_type* __epb_save = this->epptr();
3471 if (!traits_type::eq_int_type(__c, traits_type::eof())) {
3472 if (this->pptr() == 0)
3473 this->setp(&__1buf, &__1buf + 1);
3474 *this->pptr() = traits_type::to_char_type(__c);
3477 if (this->pptr() != this->pbase()) {
3478 if (__always_noconv_) {
3479 streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase());
3480 if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
3481 return traits_type::eof();
3483 char* __extbe = __extbuf_;
3484 codecvt_base::result __r;
3486 const char_type* __e;
3487 __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe);
3488 if (__e == this->pbase())
3489 return traits_type::eof();
3490 if (__r == codecvt_base::noconv) {
3491 streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
3492 if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
3493 return traits_type::eof();
3494 } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) {
3495 streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_);
3496 if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
3497 return traits_type::eof();
3498 if (__r == codecvt_base::partial) {
3499 this->setp(const_cast<char_type*>(__e), this->pptr());
3500 this->__pbump(this->epptr() - this->pbase());
3503 return traits_type::eof();
3504 } while (__r == codecvt_base::partial);
3506 this->setp(__pb_save, __epb_save);
3508 return traits_type::not_eof(__c);
3511 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3512 template <class _Codecvt, class _Elem, class _Tr>
3513 basic_streambuf<_Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n) {
3514 _LIBCPP_SUPPRESS_DEPRECATED_POP
3515 this->setg(0, 0, 0);
3522 if (__ebs_ > sizeof(__extbuf_min_)) {
3523 if (__always_noconv_ && __s) {
3524 __extbuf_ = (char*)__s;
3527 __extbuf_ = new char[__ebs_];
3531 __extbuf_ = __extbuf_min_;
3532 __ebs_ = sizeof(__extbuf_min_);
3535 if (!__always_noconv_) {
3536 __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_));
3537 if (__s && __ibs_ >= sizeof(__extbuf_min_)) {
3541 __intbuf_ = new char_type[__ibs_];
3552 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3553 template <class _Codecvt, class _Elem, class _Tr>
3554 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
3555 wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __om) {
3556 int __width = __cv_->encoding();
3557 if (__cv_ == 0 || !__bufptr_ || (__width <= 0 && __off != 0) || sync())
3558 return pos_type(off_type(-1));
3559 // __width > 0 || __off == 0, now check __way
3560 if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end)
3561 return pos_type(off_type(-1));
3562 pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om);
3567 template <class _Codecvt, class _Elem, class _Tr>
3568 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
3569 wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) {
3570 if (__cv_ == 0 || !__bufptr_ || sync())
3571 return pos_type(off_type(-1));
3572 if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1)))
3573 return pos_type(off_type(-1));
3577 template <class _Codecvt, class _Elem, class _Tr>
3578 int wbuffer_convert<_Codecvt, _Elem, _Tr>::sync() {
3579 _LIBCPP_SUPPRESS_DEPRECATED_POP
3580 if (__cv_ == 0 || !__bufptr_)
3582 if (__cm_ & ios_base::out) {
3583 if (this->pptr() != this->pbase())
3584 if (overflow() == traits_type::eof())
3586 codecvt_base::result __r;
3589 __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
3590 streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_);
3591 if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
3593 } while (__r == codecvt_base::partial);
3594 if (__r == codecvt_base::error)
3596 if (__bufptr_->pubsync())
3598 } else if (__cm_ & ios_base::in) {
3600 if (__always_noconv_)
3601 __c = this->egptr() - this->gptr();
3603 int __width = __cv_->encoding();
3604 __c = __extbufend_ - __extbufnext_;
3606 __c += __width * (this->egptr() - this->gptr());
3608 if (this->gptr() != this->egptr()) {
3609 std::reverse(this->gptr(), this->egptr());
3610 codecvt_base::result __r;
3611 const char_type* __e = this->gptr();
3614 __r = __cv_->out(__st_, __e, this->egptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe);
3616 case codecvt_base::noconv:
3617 __c += this->egptr() - this->gptr();
3619 case codecvt_base::ok:
3620 case codecvt_base::partial:
3621 __c += __extbe - __extbuf_;
3626 } while (__r == codecvt_base::partial);
3630 if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1)))
3632 this->setg(0, 0, 0);
3638 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3639 template <class _Codecvt, class _Elem, class _Tr>
3640 bool wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode() {
3641 if (!(__cm_ & ios_base::in)) {
3643 if (__always_noconv_)
3644 this->setg((char_type*)__extbuf_, (char_type*)__extbuf_ + __ebs_, (char_type*)__extbuf_ + __ebs_);
3646 this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_);
3647 __cm_ = ios_base::in;
3653 template <class _Codecvt, class _Elem, class _Tr>
3654 void wbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode() {
3655 if (!(__cm_ & ios_base::out)) {
3656 this->setg(0, 0, 0);
3657 if (__ebs_ > sizeof(__extbuf_min_)) {
3658 if (__always_noconv_)
3659 this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__ebs_ - 1));
3661 this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1));
3664 __cm_ = ios_base::out;
3668 template <class _Codecvt, class _Elem, class _Tr>
3669 wbuffer_convert<_Codecvt, _Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::__close() {
3670 wbuffer_convert* __rt = nullptr;
3671 if (__cv_ != nullptr && __bufptr_ != nullptr) {
3673 if ((__cm_ & ios_base::out) && sync())
3679 _LIBCPP_SUPPRESS_DEPRECATED_POP
3681 # endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
3683 _LIBCPP_END_NAMESPACE_STD
3687 // NOLINTEND(libcpp-robust-against-adl)
3689 #endif // _LIBCPP_HAS_LOCALIZATION
3691 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
3693 # include <concepts>
3695 # include <iterator>
3697 # include <stdexcept>
3698 # include <type_traits>
3699 # include <typeinfo>
3702 #endif // _LIBCPP_LOCALE