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>>
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
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;
190 #include <__algorithm/copy.h>
191 #include <__algorithm/equal.h>
192 #include <__algorithm/find.h>
193 #include <__algorithm/max.h>
194 #include <__algorithm/reverse.h>
195 #include <__algorithm/unwrap_iter.h>
196 #include <__assert> // all public C++ headers provide the assertion handler
198 #include <__iterator/access.h>
199 #include <__iterator/back_insert_iterator.h>
200 #include <__iterator/istreambuf_iterator.h>
201 #include <__iterator/ostreambuf_iterator.h>
203 #include <__memory/unique_ptr.h>
204 #include <__type_traits/make_unsigned.h>
215 // TODO: Fix __bsd_locale_defaults.h
216 // NOLINTBEGIN(libcpp-robust-against-adl)
218 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
219 // Most unix variants have catopen. These are the specific ones that don't.
220 # if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
221 # define _LIBCPP_HAS_CATOPEN 1
222 # include <nl_types.h>
226 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
227 # include <__locale_dir/locale_base_api/bsd_locale_defaults.h>
229 # include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
232 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
233 # pragma GCC system_header
237 #include <__undef_macros>
240 _LIBCPP_BEGIN_NAMESPACE_STD
242 #if defined(__APPLE__) || defined(__FreeBSD__)
243 # define _LIBCPP_GET_C_LOCALE 0
244 #elif defined(__NetBSD__)
245 # define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
247 # define _LIBCPP_GET_C_LOCALE __cloc()
248 // Get the C locale object
249 _LIBCPP_EXPORTED_FROM_ABI locale_t __cloc();
250 #define __cloc_defined
254 // Scans [__b, __e) until a match is found in the basic_strings range
255 // [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke).
256 // __b will be incremented (visibly), consuming CharT until a match is found
257 // or proved to not exist. A keyword may be "", in which will match anything.
258 // If one keyword is a prefix of another, and the next CharT in the input
259 // might match another keyword, the algorithm will attempt to find the longest
260 // matching keyword. If the longer matching keyword ends up not matching, then
261 // no keyword match is found. If no keyword match is found, __ke is returned
262 // and failbit is set in __err.
263 // Else an iterator pointing to the matching keyword is found. If more than
264 // one keyword matches, an iterator to the first matching keyword is returned.
265 // If on exit __b == __e, eofbit is set in __err. If __case_sensitive is false,
266 // __ct is used to force to lower case before comparing characters.
268 // Keywords: "a", "abb"
269 // If the input is "a", the first keyword matches and eofbit is set.
270 // If the input is "abc", no match is found and "ab" are consumed.
271 template <class _InputIterator, class _ForwardIterator, class _Ctype>
272 _LIBCPP_HIDE_FROM_ABI
274 __scan_keyword(_InputIterator& __b, _InputIterator __e,
275 _ForwardIterator __kb, _ForwardIterator __ke,
276 const _Ctype& __ct, ios_base::iostate& __err,
277 bool __case_sensitive = true)
279 typedef typename iterator_traits<_InputIterator>::value_type _CharT;
280 size_t __nkw = static_cast<size_t>(_VSTD::distance(__kb, __ke));
281 const unsigned char __doesnt_match = '\0';
282 const unsigned char __might_match = '\1';
283 const unsigned char __does_match = '\2';
284 unsigned char __statbuf[100];
285 unsigned char* __status = __statbuf;
286 unique_ptr<unsigned char, void(*)(void*)> __stat_hold(nullptr, free);
287 if (__nkw > sizeof(__statbuf))
289 __status = (unsigned char*)malloc(__nkw);
290 if (__status == nullptr)
292 __stat_hold.reset(__status);
294 size_t __n_might_match = __nkw; // At this point, any keyword might match
295 size_t __n_does_match = 0; // but none of them definitely do
296 // Initialize all statuses to __might_match, except for "" keywords are __does_match
297 unsigned char* __st = __status;
298 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
301 *__st = __might_match;
304 *__st = __does_match;
309 // While there might be a match, test keywords against the next CharT
310 for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx)
312 // Peek at the next CharT but don't consume it
314 if (!__case_sensitive)
315 __c = __ct.toupper(__c);
316 bool __consume = false;
317 // For each keyword which might match, see if the __indx character is __c
318 // If a match if found, consume __c
319 // If a match is found, and that is the last character in the keyword,
320 // then that keyword matches.
321 // If the keyword doesn't match this character, then change the keyword
324 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
326 if (*__st == __might_match)
328 _CharT __kc = (*__ky)[__indx];
329 if (!__case_sensitive)
330 __kc = __ct.toupper(__kc);
334 if (__ky->size() == __indx+1)
336 *__st = __does_match;
343 *__st = __doesnt_match;
348 // consume if we matched a character
352 // If we consumed a character and there might be a matched keyword that
353 // was marked matched on a previous iteration, then such keywords
354 // which are now marked as not matching.
355 if (__n_might_match + __n_does_match > 1)
358 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
360 if (*__st == __does_match && __ky->size() != __indx+1)
362 *__st = __doesnt_match;
369 // We've exited the loop because we hit eof and/or we have no more "might matches".
371 __err |= ios_base::eofbit;
372 // Return the first matching result
373 for (__st = __status; __kb != __ke; ++__kb, (void) ++__st)
374 if (*__st == __does_match)
377 __err |= ios_base::failbit;
381 struct _LIBCPP_EXPORTED_FROM_ABI __num_get_base
383 static const int __num_get_buf_sz = 40;
385 static int __get_base(ios_base&);
386 static const char __src[33];
389 _LIBCPP_EXPORTED_FROM_ABI void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
390 ios_base::iostate& __err);
392 template <class _CharT>
394 : protected __num_get_base
396 static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
397 _CharT& __thousands_sep);
399 static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp,
400 char* __a, char*& __a_end,
401 _CharT __decimal_point, _CharT __thousands_sep,
402 const string& __grouping, unsigned* __g,
403 unsigned*& __g_end, unsigned& __dc, _CharT* __atoms);
404 #ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
405 static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
406 static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
407 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
408 unsigned* __g, unsigned*& __g_end, _CharT* __atoms);
411 static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep)
413 locale __loc = __iob.getloc();
414 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
415 __thousands_sep = __np.thousands_sep();
416 return __np.grouping();
419 const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const
421 return __do_widen_p(__iob, __atoms);
425 static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
426 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
427 unsigned* __g, unsigned*& __g_end, const _CharT* __atoms);
429 template<typename _Tp>
430 const _Tp* __do_widen_p(ios_base& __iob, _Tp* __atoms) const
432 locale __loc = __iob.getloc();
433 use_facet<ctype<_Tp> >(__loc).widen(__src, __src + 26, __atoms);
437 const char* __do_widen_p(ios_base& __iob, char* __atoms) const
446 #ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
447 template <class _CharT>
449 __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep)
451 locale __loc = __iob.getloc();
452 std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 26, __atoms);
453 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc);
454 __thousands_sep = __np.thousands_sep();
455 return __np.grouping();
459 template <class _CharT>
461 __num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
462 _CharT& __thousands_sep)
464 locale __loc = __iob.getloc();
465 std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 32, __atoms);
466 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc);
467 __decimal_point = __np.decimal_point();
468 __thousands_sep = __np.thousands_sep();
469 return __np.grouping();
472 template <class _CharT>
474 #ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
475 __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
476 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
477 unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
479 __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
480 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
481 unsigned* __g, unsigned*& __g_end, const _CharT* __atoms)
485 if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25]))
487 *__a_end++ = __ct == __atoms[24] ? '+' : '-';
491 if (__grouping.size() != 0 && __ct == __thousands_sep)
493 if (__g_end-__g < __num_get_buf_sz)
500 ptrdiff_t __f = std::find(__atoms, __atoms + 26, __ct) - __atoms;
513 if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0')
516 *__a_end++ = __src[__f];
521 *__a_end++ = __src[__f];
526 template <class _CharT>
528 __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end,
529 _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping,
530 unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms)
532 if (__ct == __decimal_point)
538 if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
542 if (__ct == __thousands_sep && __grouping.size() != 0)
546 if (__g_end-__g < __num_get_buf_sz)
553 ptrdiff_t __f = std::find(__atoms, __atoms + 32, __ct) - __atoms;
556 char __x = __src[__f];
557 if (__x == '-' || __x == '+')
559 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)
570 __exp = std::tolower(__exp);
574 if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
585 extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>;
586 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
587 extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>;
590 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
591 class _LIBCPP_TEMPLATE_VIS num_get
592 : public locale::facet,
593 private __num_get<_CharT>
596 typedef _CharT char_type;
597 typedef _InputIterator iter_type;
599 _LIBCPP_INLINE_VISIBILITY
600 explicit num_get(size_t __refs = 0)
601 : locale::facet(__refs) {}
603 _LIBCPP_INLINE_VISIBILITY
604 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
605 ios_base::iostate& __err, bool& __v) const
607 return do_get(__b, __e, __iob, __err, __v);
610 _LIBCPP_INLINE_VISIBILITY
611 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
612 ios_base::iostate& __err, long& __v) const
614 return do_get(__b, __e, __iob, __err, __v);
617 _LIBCPP_INLINE_VISIBILITY
618 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
619 ios_base::iostate& __err, long long& __v) const
621 return do_get(__b, __e, __iob, __err, __v);
624 _LIBCPP_INLINE_VISIBILITY
625 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
626 ios_base::iostate& __err, unsigned short& __v) const
628 return do_get(__b, __e, __iob, __err, __v);
631 _LIBCPP_INLINE_VISIBILITY
632 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
633 ios_base::iostate& __err, unsigned int& __v) const
635 return do_get(__b, __e, __iob, __err, __v);
638 _LIBCPP_INLINE_VISIBILITY
639 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
640 ios_base::iostate& __err, unsigned long& __v) const
642 return do_get(__b, __e, __iob, __err, __v);
645 _LIBCPP_INLINE_VISIBILITY
646 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
647 ios_base::iostate& __err, unsigned long long& __v) const
649 return do_get(__b, __e, __iob, __err, __v);
652 _LIBCPP_INLINE_VISIBILITY
653 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
654 ios_base::iostate& __err, float& __v) const
656 return do_get(__b, __e, __iob, __err, __v);
659 _LIBCPP_INLINE_VISIBILITY
660 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
661 ios_base::iostate& __err, double& __v) const
663 return do_get(__b, __e, __iob, __err, __v);
666 _LIBCPP_INLINE_VISIBILITY
667 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
668 ios_base::iostate& __err, long double& __v) const
670 return do_get(__b, __e, __iob, __err, __v);
673 _LIBCPP_INLINE_VISIBILITY
674 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
675 ios_base::iostate& __err, void*& __v) const
677 return do_get(__b, __e, __iob, __err, __v);
680 static locale::id id;
683 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_get() override {}
686 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
687 iter_type __do_get_floating_point
688 (iter_type __b, iter_type __e, ios_base& __iob,
689 ios_base::iostate& __err, _Fp& __v) const;
691 template <class _Signed>
692 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
693 iter_type __do_get_signed
694 (iter_type __b, iter_type __e, ios_base& __iob,
695 ios_base::iostate& __err, _Signed& __v) const;
697 template <class _Unsigned>
698 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
699 iter_type __do_get_unsigned
700 (iter_type __b, iter_type __e, ios_base& __iob,
701 ios_base::iostate& __err, _Unsigned& __v) const;
704 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
705 ios_base::iostate& __err, bool& __v) const;
707 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
708 ios_base::iostate& __err, long& __v) const
709 { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); }
711 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
712 ios_base::iostate& __err, long long& __v) const
713 { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); }
715 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
716 ios_base::iostate& __err, unsigned short& __v) const
717 { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
719 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
720 ios_base::iostate& __err, unsigned int& __v) const
721 { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
723 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
724 ios_base::iostate& __err, unsigned long& __v) const
725 { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
727 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
728 ios_base::iostate& __err, unsigned long long& __v) const
729 { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
731 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
732 ios_base::iostate& __err, float& __v) const
733 { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); }
735 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
736 ios_base::iostate& __err, double& __v) const
737 { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); }
739 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
740 ios_base::iostate& __err, long double& __v) const
741 { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); }
743 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
744 ios_base::iostate& __err, void*& __v) const;
747 template <class _CharT, class _InputIterator>
749 num_get<_CharT, _InputIterator>::id;
752 _LIBCPP_HIDE_FROM_ABI _Tp
753 __num_get_signed_integral(const char* __a, const char* __a_end,
754 ios_base::iostate& __err, int __base)
758 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
761 long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
762 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
763 if (__current_errno == 0)
764 errno = __save_errno;
767 __err = ios_base::failbit;
770 else if (__current_errno == ERANGE ||
771 __ll < numeric_limits<_Tp>::min() ||
772 numeric_limits<_Tp>::max() < __ll)
774 __err = ios_base::failbit;
776 return numeric_limits<_Tp>::max();
778 return numeric_limits<_Tp>::min();
780 return static_cast<_Tp>(__ll);
782 __err = ios_base::failbit;
787 _LIBCPP_HIDE_FROM_ABI _Tp
788 __num_get_unsigned_integral(const char* __a, const char* __a_end,
789 ios_base::iostate& __err, int __base)
793 const bool __negate = *__a == '-';
794 if (__negate && ++__a == __a_end) {
795 __err = ios_base::failbit;
798 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
801 unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
802 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
803 if (__current_errno == 0)
804 errno = __save_errno;
807 __err = ios_base::failbit;
810 else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll)
812 __err = ios_base::failbit;
813 return numeric_limits<_Tp>::max();
815 _Tp __res = static_cast<_Tp>(__ll);
816 if (__negate) __res = -__res;
819 __err = ios_base::failbit;
824 _LIBCPP_INLINE_VISIBILITY
825 _Tp __do_strtod(const char* __a, char** __p2);
828 inline _LIBCPP_INLINE_VISIBILITY
829 float __do_strtod<float>(const char* __a, char** __p2) {
830 return strtof_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
834 inline _LIBCPP_INLINE_VISIBILITY
835 double __do_strtod<double>(const char* __a, char** __p2) {
836 return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
840 inline _LIBCPP_INLINE_VISIBILITY
841 long double __do_strtod<long double>(const char* __a, char** __p2) {
842 return strtold_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
846 _LIBCPP_HIDE_FROM_ABI
848 __num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err)
852 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
855 _Tp __ld = std::__do_strtod<_Tp>(__a, &__p2);
856 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
857 if (__current_errno == 0)
858 errno = __save_errno;
861 __err = ios_base::failbit;
864 else if (__current_errno == ERANGE)
865 __err = ios_base::failbit;
868 __err = ios_base::failbit;
872 template <class _CharT, class _InputIterator>
874 num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
876 ios_base::iostate& __err,
879 if ((__iob.flags() & ios_base::boolalpha) == 0)
882 __b = do_get(__b, __e, __iob, __err, __lv);
893 __err = ios_base::failbit;
898 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__iob.getloc());
899 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__iob.getloc());
900 typedef typename numpunct<_CharT>::string_type string_type;
901 const string_type __names[2] = {__np.truename(), __np.falsename()};
902 const string_type* __i = _VSTD::__scan_keyword(__b, __e, __names, __names+2,
904 __v = __i == __names;
910 template <class _CharT, class _InputIterator>
911 template <class _Signed>
913 num_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e,
915 ios_base::iostate& __err,
919 int __base = this->__get_base(__iob);
921 char_type __thousands_sep;
922 const int __atoms_size = 26;
923 #ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
924 char_type __atoms1[__atoms_size];
925 const char_type *__atoms = this->__do_widen(__iob, __atoms1);
926 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
928 char_type __atoms[__atoms_size];
929 string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
932 __buf.resize(__buf.capacity());
933 char* __a = &__buf[0];
935 unsigned __g[__num_get_base::__num_get_buf_sz];
936 unsigned* __g_end = __g;
938 for (; __b != __e; ++__b)
940 if (__a_end == __a + __buf.size())
942 size_t __tmp = __buf.size();
943 __buf.resize(2*__buf.size());
944 __buf.resize(__buf.capacity());
946 __a_end = __a + __tmp;
948 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
949 __thousands_sep, __grouping, __g, __g_end,
953 if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
956 __v = std::__num_get_signed_integral<_Signed>(__a, __a_end, __err, __base);
957 // Digit grouping checked
958 __check_grouping(__grouping, __g, __g_end, __err);
961 __err |= ios_base::eofbit;
967 template <class _CharT, class _InputIterator>
968 template <class _Unsigned>
970 num_get<_CharT, _InputIterator>::__do_get_unsigned(iter_type __b, iter_type __e,
972 ios_base::iostate& __err,
973 _Unsigned& __v) const
976 int __base = this->__get_base(__iob);
978 char_type __thousands_sep;
979 const int __atoms_size = 26;
980 #ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
981 char_type __atoms1[__atoms_size];
982 const char_type *__atoms = this->__do_widen(__iob, __atoms1);
983 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
985 char_type __atoms[__atoms_size];
986 string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
989 __buf.resize(__buf.capacity());
990 char* __a = &__buf[0];
992 unsigned __g[__num_get_base::__num_get_buf_sz];
993 unsigned* __g_end = __g;
995 for (; __b != __e; ++__b)
997 if (__a_end == __a + __buf.size())
999 size_t __tmp = __buf.size();
1000 __buf.resize(2*__buf.size());
1001 __buf.resize(__buf.capacity());
1003 __a_end = __a + __tmp;
1005 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
1006 __thousands_sep, __grouping, __g, __g_end,
1010 if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
1013 __v = std::__num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base);
1014 // Digit grouping checked
1015 __check_grouping(__grouping, __g, __g_end, __err);
1018 __err |= ios_base::eofbit;
1024 template <class _CharT, class _InputIterator>
1025 template <class _Fp>
1027 num_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_type __e,
1029 ios_base::iostate& __err,
1032 // Stage 1, nothing to do
1034 char_type __atoms[32];
1035 char_type __decimal_point;
1036 char_type __thousands_sep;
1037 string __grouping = this->__stage2_float_prep(__iob, __atoms,
1041 __buf.resize(__buf.capacity());
1042 char* __a = &__buf[0];
1043 char* __a_end = __a;
1044 unsigned __g[__num_get_base::__num_get_buf_sz];
1045 unsigned* __g_end = __g;
1047 bool __in_units = true;
1049 for (; __b != __e; ++__b)
1051 if (__a_end == __a + __buf.size())
1053 size_t __tmp = __buf.size();
1054 __buf.resize(2*__buf.size());
1055 __buf.resize(__buf.capacity());
1057 __a_end = __a + __tmp;
1059 if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
1060 __decimal_point, __thousands_sep,
1061 __grouping, __g, __g_end,
1065 if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
1068 __v = std::__num_get_float<_Fp>(__a, __a_end, __err);
1069 // Digit grouping checked
1070 __check_grouping(__grouping, __g, __g_end, __err);
1073 __err |= ios_base::eofbit;
1077 template <class _CharT, class _InputIterator>
1079 num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
1081 ios_base::iostate& __err,
1087 char_type __atoms[26];
1088 char_type __thousands_sep = char_type();
1090 std::use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src,
1091 __num_get_base::__src + 26, __atoms);
1093 __buf.resize(__buf.capacity());
1094 char* __a = &__buf[0];
1095 char* __a_end = __a;
1096 unsigned __g[__num_get_base::__num_get_buf_sz];
1097 unsigned* __g_end = __g;
1099 for (; __b != __e; ++__b)
1101 if (__a_end == __a + __buf.size())
1103 size_t __tmp = __buf.size();
1104 __buf.resize(2*__buf.size());
1105 __buf.resize(__buf.capacity());
1107 __a_end = __a + __tmp;
1109 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
1110 __thousands_sep, __grouping,
1111 __g, __g_end, __atoms))
1115 __buf.resize(__a_end - __a);
1116 if (__libcpp_sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
1117 __err = ios_base::failbit;
1120 __err |= ios_base::eofbit;
1124 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>;
1125 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1126 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>;
1129 struct _LIBCPP_EXPORTED_FROM_ABI __num_put_base
1132 static void __format_int(char* __fmt, const char* __len, bool __signd,
1133 ios_base::fmtflags __flags);
1134 static bool __format_float(char* __fmt, const char* __len,
1135 ios_base::fmtflags __flags);
1136 static char* __identify_padding(char* __nb, char* __ne,
1137 const ios_base& __iob);
1140 template <class _CharT>
1142 : protected __num_put_base
1144 static void __widen_and_group_int(char* __nb, char* __np, char* __ne,
1145 _CharT* __ob, _CharT*& __op, _CharT*& __oe,
1146 const locale& __loc);
1147 static void __widen_and_group_float(char* __nb, char* __np, char* __ne,
1148 _CharT* __ob, _CharT*& __op, _CharT*& __oe,
1149 const locale& __loc);
1152 template <class _CharT>
1154 __num_put<_CharT>::__widen_and_group_int(char* __nb, char* __np, char* __ne,
1155 _CharT* __ob, _CharT*& __op, _CharT*& __oe,
1156 const locale& __loc)
1158 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> > (__loc);
1159 const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc);
1160 string __grouping = __npt.grouping();
1161 if (__grouping.empty())
1163 __ct.widen(__nb, __ne, __ob);
1164 __oe = __ob + (__ne - __nb);
1170 if (*__nf == '-' || *__nf == '+')
1171 *__oe++ = __ct.widen(*__nf++);
1172 if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' ||
1175 *__oe++ = __ct.widen(*__nf++);
1176 *__oe++ = __ct.widen(*__nf++);
1178 std::reverse(__nf, __ne);
1179 _CharT __thousands_sep = __npt.thousands_sep();
1182 for (char* __p = __nf; __p < __ne; ++__p)
1184 if (static_cast<unsigned>(__grouping[__dg]) > 0 &&
1185 __dc == static_cast<unsigned>(__grouping[__dg]))
1187 *__oe++ = __thousands_sep;
1189 if (__dg < __grouping.size()-1)
1192 *__oe++ = __ct.widen(*__p);
1195 std::reverse(__ob + (__nf - __nb), __oe);
1200 __op = __ob + (__np - __nb);
1203 template <class _CharT>
1205 __num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne,
1206 _CharT* __ob, _CharT*& __op, _CharT*& __oe,
1207 const locale& __loc)
1209 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> > (__loc);
1210 const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc);
1211 string __grouping = __npt.grouping();
1214 if (*__nf == '-' || *__nf == '+')
1215 *__oe++ = __ct.widen(*__nf++);
1217 if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' ||
1220 *__oe++ = __ct.widen(*__nf++);
1221 *__oe++ = __ct.widen(*__nf++);
1222 for (__ns = __nf; __ns < __ne; ++__ns)
1223 if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE))
1228 for (__ns = __nf; __ns < __ne; ++__ns)
1229 if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE))
1232 if (__grouping.empty())
1234 __ct.widen(__nf, __ns, __oe);
1235 __oe += __ns - __nf;
1239 std::reverse(__nf, __ns);
1240 _CharT __thousands_sep = __npt.thousands_sep();
1243 for (char* __p = __nf; __p < __ns; ++__p)
1245 if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg]))
1247 *__oe++ = __thousands_sep;
1249 if (__dg < __grouping.size()-1)
1252 *__oe++ = __ct.widen(*__p);
1255 std::reverse(__ob + (__nf - __nb), __oe);
1257 for (__nf = __ns; __nf < __ne; ++__nf)
1261 *__oe++ = __npt.decimal_point();
1266 *__oe++ = __ct.widen(*__nf);
1268 __ct.widen(__nf, __ne, __oe);
1269 __oe += __ne - __nf;
1273 __op = __ob + (__np - __nb);
1276 extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>;
1277 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1278 extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>;
1281 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
1282 class _LIBCPP_TEMPLATE_VIS num_put
1283 : public locale::facet,
1284 private __num_put<_CharT>
1287 typedef _CharT char_type;
1288 typedef _OutputIterator iter_type;
1290 _LIBCPP_INLINE_VISIBILITY
1291 explicit num_put(size_t __refs = 0)
1292 : locale::facet(__refs) {}
1294 _LIBCPP_INLINE_VISIBILITY
1295 iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1298 return do_put(__s, __iob, __fl, __v);
1301 _LIBCPP_INLINE_VISIBILITY
1302 iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1305 return do_put(__s, __iob, __fl, __v);
1308 _LIBCPP_INLINE_VISIBILITY
1309 iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1310 long long __v) const
1312 return do_put(__s, __iob, __fl, __v);
1315 _LIBCPP_INLINE_VISIBILITY
1316 iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1317 unsigned long __v) const
1319 return do_put(__s, __iob, __fl, __v);
1322 _LIBCPP_INLINE_VISIBILITY
1323 iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1324 unsigned long long __v) const
1326 return do_put(__s, __iob, __fl, __v);
1329 _LIBCPP_INLINE_VISIBILITY
1330 iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1333 return do_put(__s, __iob, __fl, __v);
1336 _LIBCPP_INLINE_VISIBILITY
1337 iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1338 long double __v) const
1340 return do_put(__s, __iob, __fl, __v);
1343 _LIBCPP_INLINE_VISIBILITY
1344 iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1345 const void* __v) const
1347 return do_put(__s, __iob, __fl, __v);
1350 static locale::id id;
1353 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_put() override {}
1355 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1357 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1359 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1360 long long __v) const;
1361 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1362 unsigned long) const;
1363 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1364 unsigned long long) const;
1365 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1367 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1368 long double __v) const;
1369 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1370 const void* __v) const;
1372 template <class _Integral>
1373 _LIBCPP_HIDE_FROM_ABI inline
1374 _OutputIterator __do_put_integral(iter_type __s, ios_base& __iob,
1375 char_type __fl, _Integral __v,
1376 char const* __len) const;
1378 template <class _Float>
1379 _LIBCPP_HIDE_FROM_ABI inline
1380 _OutputIterator __do_put_floating_point(iter_type __s, ios_base& __iob,
1381 char_type __fl, _Float __v,
1382 char const* __len) const;
1385 template <class _CharT, class _OutputIterator>
1387 num_put<_CharT, _OutputIterator>::id;
1389 template <class _CharT, class _OutputIterator>
1390 _LIBCPP_HIDE_FROM_ABI
1392 __pad_and_output(_OutputIterator __s,
1393 const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
1394 ios_base& __iob, _CharT __fl)
1396 streamsize __sz = __oe - __ob;
1397 streamsize __ns = __iob.width();
1402 for (;__ob < __op; ++__ob, ++__s)
1404 for (; __ns; --__ns, ++__s)
1406 for (; __ob < __oe; ++__ob, ++__s)
1412 template <class _CharT, class _Traits>
1413 _LIBCPP_HIDE_FROM_ABI
1414 ostreambuf_iterator<_CharT, _Traits>
1415 __pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s,
1416 const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
1417 ios_base& __iob, _CharT __fl)
1419 if (__s.__sbuf_ == nullptr)
1421 streamsize __sz = __oe - __ob;
1422 streamsize __ns = __iob.width();
1427 streamsize __np = __op - __ob;
1430 if (__s.__sbuf_->sputn(__ob, __np) != __np)
1432 __s.__sbuf_ = nullptr;
1438 basic_string<_CharT, _Traits> __sp(__ns, __fl);
1439 if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns)
1441 __s.__sbuf_ = nullptr;
1448 if (__s.__sbuf_->sputn(__op, __np) != __np)
1450 __s.__sbuf_ = nullptr;
1458 template <class _CharT, class _OutputIterator>
1460 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1461 char_type __fl, bool __v) const
1463 if ((__iob.flags() & ios_base::boolalpha) == 0)
1464 return do_put(__s, __iob, __fl, (unsigned long)__v);
1465 const numpunct<char_type>& __np = std::use_facet<numpunct<char_type> >(__iob.getloc());
1466 typedef typename numpunct<char_type>::string_type string_type;
1467 string_type __nm = __v ? __np.truename() : __np.falsename();
1468 for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s)
1473 template <class _CharT, class _OutputIterator>
1474 template <class _Integral>
1475 _LIBCPP_HIDE_FROM_ABI inline
1477 num_put<_CharT, _OutputIterator>::__do_put_integral(iter_type __s, ios_base& __iob,
1478 char_type __fl, _Integral __v,
1479 char const* __len) const
1481 // Stage 1 - Get number in narrow char
1482 char __fmt[8] = {'%', 0};
1483 this->__format_int(__fmt+1, __len, is_signed<_Integral>::value, __iob.flags());
1484 // Worst case is octal, with showbase enabled. Note that octal is always
1485 // printed as an unsigned value.
1486 using _Unsigned = typename make_unsigned<_Integral>::type;
1487 _LIBCPP_CONSTEXPR const unsigned __nbuf
1488 = (numeric_limits<_Unsigned>::digits / 3) // 1 char per 3 bits
1489 + ((numeric_limits<_Unsigned>::digits % 3) != 0) // round up
1490 + 2; // base prefix + terminating null character
1492 _LIBCPP_DIAGNOSTIC_PUSH
1493 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1494 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1495 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1496 _LIBCPP_DIAGNOSTIC_POP
1497 char* __ne = __nar + __nc;
1498 char* __np = this->__identify_padding(__nar, __ne, __iob);
1499 // Stage 2 - Widen __nar while adding thousands separators
1500 char_type __o[2*(__nbuf-1) - 1];
1501 char_type* __op; // pad here
1502 char_type* __oe; // end of output
1503 this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1504 // [__o, __oe) contains thousands_sep'd wide number
1506 return std::__pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1509 template <class _CharT, class _OutputIterator>
1511 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1512 char_type __fl, long __v) const
1514 return this->__do_put_integral(__s, __iob, __fl, __v, "l");
1517 template <class _CharT, class _OutputIterator>
1519 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1520 char_type __fl, long long __v) const
1522 return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
1525 template <class _CharT, class _OutputIterator>
1527 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1528 char_type __fl, unsigned long __v) const
1530 return this->__do_put_integral(__s, __iob, __fl, __v, "l");
1533 template <class _CharT, class _OutputIterator>
1535 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1536 char_type __fl, unsigned long long __v) const
1538 return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
1541 template <class _CharT, class _OutputIterator>
1542 template <class _Float>
1543 _LIBCPP_HIDE_FROM_ABI inline
1545 num_put<_CharT, _OutputIterator>::__do_put_floating_point(iter_type __s, ios_base& __iob,
1546 char_type __fl, _Float __v,
1547 char const* __len) const
1549 // Stage 1 - Get number in narrow char
1550 char __fmt[8] = {'%', 0};
1551 bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
1552 const unsigned __nbuf = 30;
1556 _LIBCPP_DIAGNOSTIC_PUSH
1557 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1558 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1559 if (__specify_precision)
1560 __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
1561 (int)__iob.precision(), __v);
1563 __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1564 unique_ptr<char, void(*)(void*)> __nbh(nullptr, free);
1565 if (__nc > static_cast<int>(__nbuf-1))
1567 if (__specify_precision)
1568 __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1570 __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1572 __throw_bad_alloc();
1575 _LIBCPP_DIAGNOSTIC_POP
1576 char* __ne = __nb + __nc;
1577 char* __np = this->__identify_padding(__nb, __ne, __iob);
1578 // Stage 2 - Widen __nar while adding thousands separators
1579 char_type __o[2*(__nbuf-1) - 1];
1580 char_type* __ob = __o;
1581 unique_ptr<char_type, void(*)(void*)> __obh(0, free);
1584 __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
1586 __throw_bad_alloc();
1589 char_type* __op; // pad here
1590 char_type* __oe; // end of output
1591 this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
1592 // [__o, __oe) contains thousands_sep'd wide number
1594 __s = std::__pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
1598 template <class _CharT, class _OutputIterator>
1600 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1601 char_type __fl, double __v) const
1603 return this->__do_put_floating_point(__s, __iob, __fl, __v, "");
1606 template <class _CharT, class _OutputIterator>
1608 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1609 char_type __fl, long double __v) const
1611 return this->__do_put_floating_point(__s, __iob, __fl, __v, "L");
1614 template <class _CharT, class _OutputIterator>
1616 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1617 char_type __fl, const void* __v) const
1619 // Stage 1 - Get pointer in narrow char
1620 const unsigned __nbuf = 20;
1622 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, "%p", __v);
1623 char* __ne = __nar + __nc;
1624 char* __np = this->__identify_padding(__nar, __ne, __iob);
1625 // Stage 2 - Widen __nar
1626 char_type __o[2*(__nbuf-1) - 1];
1627 char_type* __op; // pad here
1628 char_type* __oe; // end of output
1629 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1630 __ct.widen(__nar, __ne, __o);
1631 __oe = __o + (__ne - __nar);
1635 __op = __o + (__np - __nar);
1636 // [__o, __oe) contains wide number
1638 return std::__pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1641 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>;
1642 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1643 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>;
1646 template <class _CharT, class _InputIterator>
1647 _LIBCPP_HIDE_FROM_ABI
1649 __get_up_to_n_digits(_InputIterator& __b, _InputIterator __e,
1650 ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n)
1652 // Precondition: __n >= 1
1655 __err |= ios_base::eofbit | ios_base::failbit;
1660 if (!__ct.is(ctype_base::digit, __c))
1662 __err |= ios_base::failbit;
1665 int __r = __ct.narrow(__c, 0) - '0';
1666 for (++__b, (void) --__n; __b != __e && __n > 0; ++__b, (void) --__n)
1670 if (!__ct.is(ctype_base::digit, __c))
1672 __r = __r * 10 + __ct.narrow(__c, 0) - '0';
1675 __err |= ios_base::eofbit;
1679 class _LIBCPP_EXPORTED_FROM_ABI time_base
1682 enum dateorder {no_order, dmy, mdy, ymd, ydm};
1685 template <class _CharT>
1686 class _LIBCPP_TEMPLATE_VIS __time_get_c_storage
1689 typedef basic_string<_CharT> string_type;
1691 virtual const string_type* __weeks() const;
1692 virtual const string_type* __months() const;
1693 virtual const string_type* __am_pm() const;
1694 virtual const string_type& __c() const;
1695 virtual const string_type& __r() const;
1696 virtual const string_type& __x() const;
1697 virtual const string_type& __X() const;
1699 _LIBCPP_INLINE_VISIBILITY
1700 ~__time_get_c_storage() {}
1703 template <> _LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__weeks() const;
1704 template <> _LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__months() const;
1705 template <> _LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__am_pm() const;
1706 template <> _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__c() const;
1707 template <> _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__r() const;
1708 template <> _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__x() const;
1709 template <> _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__X() const;
1711 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1712 template <> _LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__weeks() const;
1713 template <> _LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__months() const;
1714 template <> _LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__am_pm() const;
1715 template <> _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__c() const;
1716 template <> _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__r() const;
1717 template <> _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__x() const;
1718 template <> _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__X() const;
1721 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
1722 class _LIBCPP_TEMPLATE_VIS time_get
1723 : public locale::facet,
1725 private __time_get_c_storage<_CharT>
1728 typedef _CharT char_type;
1729 typedef _InputIterator iter_type;
1730 typedef time_base::dateorder dateorder;
1731 typedef basic_string<char_type> string_type;
1733 _LIBCPP_INLINE_VISIBILITY
1734 explicit time_get(size_t __refs = 0)
1735 : locale::facet(__refs) {}
1737 _LIBCPP_INLINE_VISIBILITY
1738 dateorder date_order() const
1740 return this->do_date_order();
1743 _LIBCPP_INLINE_VISIBILITY
1744 iter_type get_time(iter_type __b, iter_type __e, ios_base& __iob,
1745 ios_base::iostate& __err, tm* __tm) const
1747 return do_get_time(__b, __e, __iob, __err, __tm);
1750 _LIBCPP_INLINE_VISIBILITY
1751 iter_type get_date(iter_type __b, iter_type __e, ios_base& __iob,
1752 ios_base::iostate& __err, tm* __tm) const
1754 return do_get_date(__b, __e, __iob, __err, __tm);
1757 _LIBCPP_INLINE_VISIBILITY
1758 iter_type get_weekday(iter_type __b, iter_type __e, ios_base& __iob,
1759 ios_base::iostate& __err, tm* __tm) const
1761 return do_get_weekday(__b, __e, __iob, __err, __tm);
1764 _LIBCPP_INLINE_VISIBILITY
1765 iter_type get_monthname(iter_type __b, iter_type __e, ios_base& __iob,
1766 ios_base::iostate& __err, tm* __tm) const
1768 return do_get_monthname(__b, __e, __iob, __err, __tm);
1771 _LIBCPP_INLINE_VISIBILITY
1772 iter_type get_year(iter_type __b, iter_type __e, ios_base& __iob,
1773 ios_base::iostate& __err, tm* __tm) const
1775 return do_get_year(__b, __e, __iob, __err, __tm);
1778 _LIBCPP_INLINE_VISIBILITY
1779 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
1780 ios_base::iostate& __err, tm *__tm,
1781 char __fmt, char __mod = 0) const
1783 return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod);
1786 iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
1787 ios_base::iostate& __err, tm* __tm,
1788 const char_type* __fmtb, const char_type* __fmte) const;
1790 static locale::id id;
1793 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get() override {}
1795 virtual dateorder do_date_order() const;
1796 virtual iter_type do_get_time(iter_type __b, iter_type __e, ios_base& __iob,
1797 ios_base::iostate& __err, tm* __tm) const;
1798 virtual iter_type do_get_date(iter_type __b, iter_type __e, ios_base& __iob,
1799 ios_base::iostate& __err, tm* __tm) const;
1800 virtual iter_type do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob,
1801 ios_base::iostate& __err, tm* __tm) const;
1802 virtual iter_type do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob,
1803 ios_base::iostate& __err, tm* __tm) const;
1804 virtual iter_type do_get_year(iter_type __b, iter_type __e, ios_base& __iob,
1805 ios_base::iostate& __err, tm* __tm) const;
1806 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
1807 ios_base::iostate& __err, tm* __tm,
1808 char __fmt, char __mod) const;
1810 void __get_white_space(iter_type& __b, iter_type __e,
1811 ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1812 void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err,
1813 const ctype<char_type>& __ct) const;
1815 void __get_weekdayname(int& __m,
1816 iter_type& __b, iter_type __e,
1817 ios_base::iostate& __err,
1818 const ctype<char_type>& __ct) const;
1819 void __get_monthname(int& __m,
1820 iter_type& __b, iter_type __e,
1821 ios_base::iostate& __err,
1822 const ctype<char_type>& __ct) const;
1823 void __get_day(int& __d,
1824 iter_type& __b, iter_type __e,
1825 ios_base::iostate& __err,
1826 const ctype<char_type>& __ct) const;
1827 void __get_month(int& __m,
1828 iter_type& __b, iter_type __e,
1829 ios_base::iostate& __err,
1830 const ctype<char_type>& __ct) const;
1831 void __get_year(int& __y,
1832 iter_type& __b, iter_type __e,
1833 ios_base::iostate& __err,
1834 const ctype<char_type>& __ct) const;
1835 void __get_year4(int& __y,
1836 iter_type& __b, iter_type __e,
1837 ios_base::iostate& __err,
1838 const ctype<char_type>& __ct) const;
1839 void __get_hour(int& __d,
1840 iter_type& __b, iter_type __e,
1841 ios_base::iostate& __err,
1842 const ctype<char_type>& __ct) const;
1843 void __get_12_hour(int& __h,
1844 iter_type& __b, iter_type __e,
1845 ios_base::iostate& __err,
1846 const ctype<char_type>& __ct) const;
1847 void __get_am_pm(int& __h,
1848 iter_type& __b, iter_type __e,
1849 ios_base::iostate& __err,
1850 const ctype<char_type>& __ct) const;
1851 void __get_minute(int& __m,
1852 iter_type& __b, iter_type __e,
1853 ios_base::iostate& __err,
1854 const ctype<char_type>& __ct) const;
1855 void __get_second(int& __s,
1856 iter_type& __b, iter_type __e,
1857 ios_base::iostate& __err,
1858 const ctype<char_type>& __ct) const;
1859 void __get_weekday(int& __w,
1860 iter_type& __b, iter_type __e,
1861 ios_base::iostate& __err,
1862 const ctype<char_type>& __ct) const;
1863 void __get_day_year_num(int& __w,
1864 iter_type& __b, iter_type __e,
1865 ios_base::iostate& __err,
1866 const ctype<char_type>& __ct) const;
1869 template <class _CharT, class _InputIterator>
1871 time_get<_CharT, _InputIterator>::id;
1873 // time_get primitives
1875 template <class _CharT, class _InputIterator>
1877 time_get<_CharT, _InputIterator>::__get_weekdayname(int& __w,
1878 iter_type& __b, iter_type __e,
1879 ios_base::iostate& __err,
1880 const ctype<char_type>& __ct) const
1882 // Note: ignoring case comes from the POSIX strptime spec
1883 const string_type* __wk = this->__weeks();
1884 ptrdiff_t __i = _VSTD::__scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk;
1889 template <class _CharT, class _InputIterator>
1891 time_get<_CharT, _InputIterator>::__get_monthname(int& __m,
1892 iter_type& __b, iter_type __e,
1893 ios_base::iostate& __err,
1894 const ctype<char_type>& __ct) const
1896 // Note: ignoring case comes from the POSIX strptime spec
1897 const string_type* __month = this->__months();
1898 ptrdiff_t __i = _VSTD::__scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month;
1903 template <class _CharT, class _InputIterator>
1905 time_get<_CharT, _InputIterator>::__get_day(int& __d,
1906 iter_type& __b, iter_type __e,
1907 ios_base::iostate& __err,
1908 const ctype<char_type>& __ct) const
1910 int __t = _VSTD::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1911 if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31)
1914 __err |= ios_base::failbit;
1917 template <class _CharT, class _InputIterator>
1919 time_get<_CharT, _InputIterator>::__get_month(int& __m,
1920 iter_type& __b, iter_type __e,
1921 ios_base::iostate& __err,
1922 const ctype<char_type>& __ct) const
1924 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1;
1925 if (!(__err & ios_base::failbit) && 0 <= __t && __t <= 11)
1928 __err |= ios_base::failbit;
1931 template <class _CharT, class _InputIterator>
1933 time_get<_CharT, _InputIterator>::__get_year(int& __y,
1934 iter_type& __b, iter_type __e,
1935 ios_base::iostate& __err,
1936 const ctype<char_type>& __ct) const
1938 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);
1939 if (!(__err & ios_base::failbit))
1943 else if (69 <= __t && __t <= 99)
1949 template <class _CharT, class _InputIterator>
1951 time_get<_CharT, _InputIterator>::__get_year4(int& __y,
1952 iter_type& __b, iter_type __e,
1953 ios_base::iostate& __err,
1954 const ctype<char_type>& __ct) const
1956 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);
1957 if (!(__err & ios_base::failbit))
1961 template <class _CharT, class _InputIterator>
1963 time_get<_CharT, _InputIterator>::__get_hour(int& __h,
1964 iter_type& __b, iter_type __e,
1965 ios_base::iostate& __err,
1966 const ctype<char_type>& __ct) const
1968 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1969 if (!(__err & ios_base::failbit) && __t <= 23)
1972 __err |= ios_base::failbit;
1975 template <class _CharT, class _InputIterator>
1977 time_get<_CharT, _InputIterator>::__get_12_hour(int& __h,
1978 iter_type& __b, iter_type __e,
1979 ios_base::iostate& __err,
1980 const ctype<char_type>& __ct) const
1982 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1983 if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12)
1986 __err |= ios_base::failbit;
1989 template <class _CharT, class _InputIterator>
1991 time_get<_CharT, _InputIterator>::__get_minute(int& __m,
1992 iter_type& __b, iter_type __e,
1993 ios_base::iostate& __err,
1994 const ctype<char_type>& __ct) const
1996 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1997 if (!(__err & ios_base::failbit) && __t <= 59)
2000 __err |= ios_base::failbit;
2003 template <class _CharT, class _InputIterator>
2005 time_get<_CharT, _InputIterator>::__get_second(int& __s,
2006 iter_type& __b, iter_type __e,
2007 ios_base::iostate& __err,
2008 const ctype<char_type>& __ct) const
2010 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
2011 if (!(__err & ios_base::failbit) && __t <= 60)
2014 __err |= ios_base::failbit;
2017 template <class _CharT, class _InputIterator>
2019 time_get<_CharT, _InputIterator>::__get_weekday(int& __w,
2020 iter_type& __b, iter_type __e,
2021 ios_base::iostate& __err,
2022 const ctype<char_type>& __ct) const
2024 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 1);
2025 if (!(__err & ios_base::failbit) && __t <= 6)
2028 __err |= ios_base::failbit;
2031 template <class _CharT, class _InputIterator>
2033 time_get<_CharT, _InputIterator>::__get_day_year_num(int& __d,
2034 iter_type& __b, iter_type __e,
2035 ios_base::iostate& __err,
2036 const ctype<char_type>& __ct) const
2038 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 3);
2039 if (!(__err & ios_base::failbit) && __t <= 365)
2042 __err |= ios_base::failbit;
2045 template <class _CharT, class _InputIterator>
2047 time_get<_CharT, _InputIterator>::__get_white_space(iter_type& __b, iter_type __e,
2048 ios_base::iostate& __err,
2049 const ctype<char_type>& __ct) const
2051 for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
2054 __err |= ios_base::eofbit;
2057 template <class _CharT, class _InputIterator>
2059 time_get<_CharT, _InputIterator>::__get_am_pm(int& __h,
2060 iter_type& __b, iter_type __e,
2061 ios_base::iostate& __err,
2062 const ctype<char_type>& __ct) const
2064 const string_type* __ap = this->__am_pm();
2065 if (__ap[0].size() + __ap[1].size() == 0)
2067 __err |= ios_base::failbit;
2070 ptrdiff_t __i = _VSTD::__scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap;
2071 if (__i == 0 && __h == 12)
2073 else if (__i == 1 && __h < 12)
2077 template <class _CharT, class _InputIterator>
2079 time_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e,
2080 ios_base::iostate& __err,
2081 const ctype<char_type>& __ct) const
2085 __err |= ios_base::eofbit | ios_base::failbit;
2088 if (__ct.narrow(*__b, 0) != '%')
2089 __err |= ios_base::failbit;
2090 else if(++__b == __e)
2091 __err |= ios_base::eofbit;
2094 // time_get end primitives
2096 template <class _CharT, class _InputIterator>
2098 time_get<_CharT, _InputIterator>::get(iter_type __b, iter_type __e,
2100 ios_base::iostate& __err, tm* __tm,
2101 const char_type* __fmtb, const char_type* __fmte) const
2103 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
2104 __err = ios_base::goodbit;
2105 while (__fmtb != __fmte && __err == ios_base::goodbit)
2109 __err = ios_base::failbit;
2112 if (__ct.narrow(*__fmtb, 0) == '%')
2114 if (++__fmtb == __fmte)
2116 __err = ios_base::failbit;
2119 char __cmd = __ct.narrow(*__fmtb, 0);
2121 if (__cmd == 'E' || __cmd == '0')
2123 if (++__fmtb == __fmte)
2125 __err = ios_base::failbit;
2129 __cmd = __ct.narrow(*__fmtb, 0);
2131 __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt);
2134 else if (__ct.is(ctype_base::space, *__fmtb))
2136 for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb)
2138 for ( ; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
2141 else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb))
2147 __err = ios_base::failbit;
2150 __err |= ios_base::eofbit;
2154 template <class _CharT, class _InputIterator>
2155 typename time_get<_CharT, _InputIterator>::dateorder
2156 time_get<_CharT, _InputIterator>::do_date_order() const
2161 template <class _CharT, class _InputIterator>
2163 time_get<_CharT, _InputIterator>::do_get_time(iter_type __b, iter_type __e,
2165 ios_base::iostate& __err,
2168 const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
2169 return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
2172 template <class _CharT, class _InputIterator>
2174 time_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e,
2176 ios_base::iostate& __err,
2179 const string_type& __fmt = this->__x();
2180 return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
2183 template <class _CharT, class _InputIterator>
2185 time_get<_CharT, _InputIterator>::do_get_weekday(iter_type __b, iter_type __e,
2187 ios_base::iostate& __err,
2190 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
2191 __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
2195 template <class _CharT, class _InputIterator>
2197 time_get<_CharT, _InputIterator>::do_get_monthname(iter_type __b, iter_type __e,
2199 ios_base::iostate& __err,
2202 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
2203 __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
2207 template <class _CharT, class _InputIterator>
2209 time_get<_CharT, _InputIterator>::do_get_year(iter_type __b, iter_type __e,
2211 ios_base::iostate& __err,
2214 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
2215 __get_year(__tm->tm_year, __b, __e, __err, __ct);
2219 template <class _CharT, class _InputIterator>
2221 time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
2223 ios_base::iostate& __err, tm* __tm,
2224 char __fmt, char) const
2226 __err = ios_base::goodbit;
2227 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
2232 __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
2237 __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
2241 const string_type& __fm = this->__c();
2242 __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
2247 __get_day(__tm->tm_mday, __b, __e, __err, __ct);
2251 const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
2252 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2257 const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
2258 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2262 __get_hour(__tm->tm_hour, __b, __e, __err, __ct);
2265 __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct);
2268 __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct);
2271 __get_month(__tm->tm_mon, __b, __e, __err, __ct);
2274 __get_minute(__tm->tm_min, __b, __e, __err, __ct);
2278 __get_white_space(__b, __e, __err, __ct);
2281 __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct);
2285 const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
2286 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2291 const char_type __fm[] = {'%', 'H', ':', '%', 'M'};
2292 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2296 __get_second(__tm->tm_sec, __b, __e, __err, __ct);
2300 const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
2301 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2305 __get_weekday(__tm->tm_wday, __b, __e, __err, __ct);
2308 return do_get_date(__b, __e, __iob, __err, __tm);
2311 const string_type& __fm = this->__X();
2312 __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
2316 __get_year(__tm->tm_year, __b, __e, __err, __ct);
2319 __get_year4(__tm->tm_year, __b, __e, __err, __ct);
2322 __get_percent(__b, __e, __err, __ct);
2325 __err |= ios_base::failbit;
2330 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>;
2331 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2332 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>;
2335 class _LIBCPP_EXPORTED_FROM_ABI __time_get
2340 __time_get(const char* __nm);
2341 __time_get(const string& __nm);
2345 template <class _CharT>
2346 class _LIBCPP_TEMPLATE_VIS __time_get_storage
2350 typedef basic_string<_CharT> string_type;
2352 string_type __weeks_[14];
2353 string_type __months_[24];
2354 string_type __am_pm_[2];
2360 explicit __time_get_storage(const char* __nm);
2361 explicit __time_get_storage(const string& __nm);
2363 _LIBCPP_INLINE_VISIBILITY ~__time_get_storage() {}
2365 time_base::dateorder __do_date_order() const;
2368 void init(const ctype<_CharT>&);
2369 string_type __analyze(char __fmt, const ctype<_CharT>&);
2372 #define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \
2373 template <> _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
2374 template <> _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
2375 template <> _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
2376 template <> _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
2377 template <> _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \
2378 extern template _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
2379 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
2380 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
2381 extern template _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
2382 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \
2385 _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char)
2386 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2387 _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t)
2389 #undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION
2391 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
2392 class _LIBCPP_TEMPLATE_VIS time_get_byname
2393 : public time_get<_CharT, _InputIterator>,
2394 private __time_get_storage<_CharT>
2397 typedef time_base::dateorder dateorder;
2398 typedef _InputIterator iter_type;
2399 typedef _CharT char_type;
2400 typedef basic_string<char_type> string_type;
2402 _LIBCPP_INLINE_VISIBILITY
2403 explicit time_get_byname(const char* __nm, size_t __refs = 0)
2404 : time_get<_CharT, _InputIterator>(__refs),
2405 __time_get_storage<_CharT>(__nm) {}
2406 _LIBCPP_INLINE_VISIBILITY
2407 explicit time_get_byname(const string& __nm, size_t __refs = 0)
2408 : time_get<_CharT, _InputIterator>(__refs),
2409 __time_get_storage<_CharT>(__nm) {}
2412 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get_byname() override {}
2414 _LIBCPP_HIDE_FROM_ABI_VIRTUAL dateorder do_date_order() const override {return this->__do_date_order();}
2416 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __weeks() const override {return this->__weeks_;}
2417 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __months() const override {return this->__months_;}
2418 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __am_pm() const override {return this->__am_pm_;}
2419 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __c() const override {return this->__c_;}
2420 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __r() const override {return this->__r_;}
2421 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __x() const override {return this->__x_;}
2422 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __X() const override {return this->__X_;}
2425 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>;
2426 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2427 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>;
2430 class _LIBCPP_EXPORTED_FROM_ABI __time_put
2434 _LIBCPP_INLINE_VISIBILITY __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {}
2435 __time_put(const char* __nm);
2436 __time_put(const string& __nm);
2438 void __do_put(char* __nb, char*& __ne, const tm* __tm,
2439 char __fmt, char __mod) const;
2440 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2441 void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
2442 char __fmt, char __mod) const;
2446 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2447 class _LIBCPP_TEMPLATE_VIS time_put
2448 : public locale::facet,
2452 typedef _CharT char_type;
2453 typedef _OutputIterator iter_type;
2455 _LIBCPP_INLINE_VISIBILITY
2456 explicit time_put(size_t __refs = 0)
2457 : locale::facet(__refs) {}
2459 iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm,
2460 const char_type* __pb, const char_type* __pe) const;
2462 _LIBCPP_INLINE_VISIBILITY
2463 iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
2464 const tm* __tm, char __fmt, char __mod = 0) const
2466 return do_put(__s, __iob, __fl, __tm, __fmt, __mod);
2469 static locale::id id;
2472 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put() override {}
2473 virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm,
2474 char __fmt, char __mod) const;
2476 _LIBCPP_INLINE_VISIBILITY
2477 explicit time_put(const char* __nm, size_t __refs)
2478 : locale::facet(__refs),
2480 _LIBCPP_INLINE_VISIBILITY
2481 explicit time_put(const string& __nm, size_t __refs)
2482 : locale::facet(__refs),
2486 template <class _CharT, class _OutputIterator>
2488 time_put<_CharT, _OutputIterator>::id;
2490 template <class _CharT, class _OutputIterator>
2492 time_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob,
2493 char_type __fl, const tm* __tm,
2494 const char_type* __pb,
2495 const char_type* __pe) const
2497 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
2498 for (; __pb != __pe; ++__pb)
2500 if (__ct.narrow(*__pb, 0) == '%')
2508 char __fmt = __ct.narrow(*__pb, 0);
2509 if (__fmt == 'E' || __fmt == 'O')
2518 __fmt = __ct.narrow(*__pb, 0);
2520 __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod);
2528 template <class _CharT, class _OutputIterator>
2530 time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&,
2531 char_type, const tm* __tm,
2532 char __fmt, char __mod) const
2534 char_type __nar[100];
2535 char_type* __nb = __nar;
2536 char_type* __ne = __nb + 100;
2537 __do_put(__nb, __ne, __tm, __fmt, __mod);
2538 return _VSTD::copy(__nb, __ne, __s);
2541 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>;
2542 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2543 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>;
2546 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2547 class _LIBCPP_TEMPLATE_VIS time_put_byname
2548 : public time_put<_CharT, _OutputIterator>
2551 _LIBCPP_INLINE_VISIBILITY
2552 explicit time_put_byname(const char* __nm, size_t __refs = 0)
2553 : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
2555 _LIBCPP_INLINE_VISIBILITY
2556 explicit time_put_byname(const string& __nm, size_t __refs = 0)
2557 : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
2560 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put_byname() override {}
2563 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>;
2564 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2565 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>;
2570 class _LIBCPP_EXPORTED_FROM_ABI money_base
2573 enum part {none, space, symbol, sign, value};
2574 struct pattern {char field[4];};
2576 _LIBCPP_INLINE_VISIBILITY money_base() {}
2581 template <class _CharT, bool _International = false>
2582 class _LIBCPP_TEMPLATE_VIS moneypunct
2583 : public locale::facet,
2587 typedef _CharT char_type;
2588 typedef basic_string<char_type> string_type;
2590 _LIBCPP_INLINE_VISIBILITY
2591 explicit moneypunct(size_t __refs = 0)
2592 : locale::facet(__refs) {}
2594 _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
2595 _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
2596 _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
2597 _LIBCPP_INLINE_VISIBILITY string_type curr_symbol() const {return do_curr_symbol();}
2598 _LIBCPP_INLINE_VISIBILITY string_type positive_sign() const {return do_positive_sign();}
2599 _LIBCPP_INLINE_VISIBILITY string_type negative_sign() const {return do_negative_sign();}
2600 _LIBCPP_INLINE_VISIBILITY int frac_digits() const {return do_frac_digits();}
2601 _LIBCPP_INLINE_VISIBILITY pattern pos_format() const {return do_pos_format();}
2602 _LIBCPP_INLINE_VISIBILITY pattern neg_format() const {return do_neg_format();}
2604 static locale::id id;
2605 static const bool intl = _International;
2608 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct() override {}
2610 virtual char_type do_decimal_point() const {return numeric_limits<char_type>::max();}
2611 virtual char_type do_thousands_sep() const {return numeric_limits<char_type>::max();}
2612 virtual string do_grouping() const {return string();}
2613 virtual string_type do_curr_symbol() const {return string_type();}
2614 virtual string_type do_positive_sign() const {return string_type();}
2615 virtual string_type do_negative_sign() const {return string_type(1, '-');}
2616 virtual int do_frac_digits() const {return 0;}
2617 virtual pattern do_pos_format() const
2618 {pattern __p = {{symbol, sign, none, value}}; return __p;}
2619 virtual pattern do_neg_format() const
2620 {pattern __p = {{symbol, sign, none, value}}; return __p;}
2623 template <class _CharT, bool _International>
2625 moneypunct<_CharT, _International>::id;
2627 template <class _CharT, bool _International>
2629 moneypunct<_CharT, _International>::intl;
2631 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>;
2632 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>;
2633 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2634 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>;
2635 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>;
2638 // moneypunct_byname
2640 template <class _CharT, bool _International = false>
2641 class _LIBCPP_TEMPLATE_VIS moneypunct_byname
2642 : public moneypunct<_CharT, _International>
2645 typedef money_base::pattern pattern;
2646 typedef _CharT char_type;
2647 typedef basic_string<char_type> string_type;
2649 _LIBCPP_INLINE_VISIBILITY
2650 explicit moneypunct_byname(const char* __nm, size_t __refs = 0)
2651 : moneypunct<_CharT, _International>(__refs) {init(__nm);}
2653 _LIBCPP_INLINE_VISIBILITY
2654 explicit moneypunct_byname(const string& __nm, size_t __refs = 0)
2655 : moneypunct<_CharT, _International>(__refs) {init(__nm.c_str());}
2658 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct_byname() override {}
2660 char_type do_decimal_point() const override {return __decimal_point_;}
2661 char_type do_thousands_sep() const override {return __thousands_sep_;}
2662 string do_grouping() const override {return __grouping_;}
2663 string_type do_curr_symbol() const override {return __curr_symbol_;}
2664 string_type do_positive_sign() const override {return __positive_sign_;}
2665 string_type do_negative_sign() const override {return __negative_sign_;}
2666 int do_frac_digits() const override {return __frac_digits_;}
2667 pattern do_pos_format() const override {return __pos_format_;}
2668 pattern do_neg_format() const override {return __neg_format_;}
2671 char_type __decimal_point_;
2672 char_type __thousands_sep_;
2674 string_type __curr_symbol_;
2675 string_type __positive_sign_;
2676 string_type __negative_sign_;
2678 pattern __pos_format_;
2679 pattern __neg_format_;
2681 void init(const char*);
2684 template<> _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, false>::init(const char*);
2685 template<> _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, true>::init(const char*);
2686 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>;
2687 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>;
2689 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2690 template<> _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, false>::init(const char*);
2691 template<> _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, true>::init(const char*);
2692 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>;
2693 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>;
2698 template <class _CharT>
2702 typedef _CharT char_type;
2703 typedef basic_string<char_type> string_type;
2705 _LIBCPP_INLINE_VISIBILITY __money_get() {}
2707 static void __gather_info(bool __intl, const locale& __loc,
2708 money_base::pattern& __pat, char_type& __dp,
2709 char_type& __ts, string& __grp,
2710 string_type& __sym, string_type& __psn,
2711 string_type& __nsn, int& __fd);
2714 template <class _CharT>
2716 __money_get<_CharT>::__gather_info(bool __intl, const locale& __loc,
2717 money_base::pattern& __pat, char_type& __dp,
2718 char_type& __ts, string& __grp,
2719 string_type& __sym, string_type& __psn,
2720 string_type& __nsn, int& __fd)
2724 const moneypunct<char_type, true>& __mp =
2725 std::use_facet<moneypunct<char_type, true> >(__loc);
2726 __pat = __mp.neg_format();
2727 __nsn = __mp.negative_sign();
2728 __psn = __mp.positive_sign();
2729 __dp = __mp.decimal_point();
2730 __ts = __mp.thousands_sep();
2731 __grp = __mp.grouping();
2732 __sym = __mp.curr_symbol();
2733 __fd = __mp.frac_digits();
2737 const moneypunct<char_type, false>& __mp =
2738 std::use_facet<moneypunct<char_type, false> >(__loc);
2739 __pat = __mp.neg_format();
2740 __nsn = __mp.negative_sign();
2741 __psn = __mp.positive_sign();
2742 __dp = __mp.decimal_point();
2743 __ts = __mp.thousands_sep();
2744 __grp = __mp.grouping();
2745 __sym = __mp.curr_symbol();
2746 __fd = __mp.frac_digits();
2750 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>;
2751 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2752 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>;
2755 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
2756 class _LIBCPP_TEMPLATE_VIS money_get
2757 : public locale::facet,
2758 private __money_get<_CharT>
2761 typedef _CharT char_type;
2762 typedef _InputIterator iter_type;
2763 typedef basic_string<char_type> string_type;
2765 _LIBCPP_INLINE_VISIBILITY
2766 explicit money_get(size_t __refs = 0)
2767 : locale::facet(__refs) {}
2769 _LIBCPP_INLINE_VISIBILITY
2770 iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob,
2771 ios_base::iostate& __err, long double& __v) const
2773 return do_get(__b, __e, __intl, __iob, __err, __v);
2776 _LIBCPP_INLINE_VISIBILITY
2777 iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob,
2778 ios_base::iostate& __err, string_type& __v) const
2780 return do_get(__b, __e, __intl, __iob, __err, __v);
2783 static locale::id id;
2786 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_get() override {}
2788 virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl,
2789 ios_base& __iob, ios_base::iostate& __err,
2790 long double& __v) const;
2791 virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl,
2792 ios_base& __iob, ios_base::iostate& __err,
2793 string_type& __v) const;
2796 static bool __do_get(iter_type& __b, iter_type __e,
2797 bool __intl, const locale& __loc,
2798 ios_base::fmtflags __flags, ios_base::iostate& __err,
2799 bool& __neg, const ctype<char_type>& __ct,
2800 unique_ptr<char_type, void(*)(void*)>& __wb,
2801 char_type*& __wn, char_type* __we);
2804 template <class _CharT, class _InputIterator>
2806 money_get<_CharT, _InputIterator>::id;
2808 _LIBCPP_EXPORTED_FROM_ABI void __do_nothing(void*);
2810 template <class _Tp>
2811 _LIBCPP_HIDE_FROM_ABI
2813 __double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e)
2815 bool __owns = __b.get_deleter() != __do_nothing;
2816 size_t __cur_cap = static_cast<size_t>(__e-__b.get()) * sizeof(_Tp);
2817 size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ?
2818 2 * __cur_cap : numeric_limits<size_t>::max();
2820 __new_cap = sizeof(_Tp);
2821 size_t __n_off = static_cast<size_t>(__n - __b.get());
2822 _Tp* __t = (_Tp*)std::realloc(__owns ? __b.get() : 0, __new_cap);
2824 __throw_bad_alloc();
2827 __b = unique_ptr<_Tp, void(*)(void*)>(__t, free);
2828 __new_cap /= sizeof(_Tp);
2829 __n = __b.get() + __n_off;
2830 __e = __b.get() + __new_cap;
2834 template <class _CharT, class _InputIterator>
2836 money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
2837 bool __intl, const locale& __loc,
2838 ios_base::fmtflags __flags,
2839 ios_base::iostate& __err,
2841 const ctype<char_type>& __ct,
2842 unique_ptr<char_type, void(*)(void*)>& __wb,
2843 char_type*& __wn, char_type* __we)
2846 __err |= ios_base::failbit;
2849 const unsigned __bz = 100;
2850 unsigned __gbuf[__bz];
2851 unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing);
2852 unsigned* __gn = __gb.get();
2853 unsigned* __ge = __gn + __bz;
2854 money_base::pattern __pat;
2861 // Capture the spaces read into money_base::{space,none} so they
2862 // can be compared to initial spaces in __sym.
2863 string_type __spaces;
2865 __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp,
2866 __sym, __psn, __nsn, __fd);
2867 const string_type* __trailing_sign = 0;
2869 for (unsigned __p = 0; __p < 4 && __b != __e; ++__p)
2871 switch (__pat.field[__p])
2873 case money_base::space:
2876 if (__ct.is(ctype_base::space, *__b))
2877 __spaces.push_back(*__b++);
2880 __err |= ios_base::failbit;
2884 _LIBCPP_FALLTHROUGH();
2885 case money_base::none:
2888 while (__b != __e && __ct.is(ctype_base::space, *__b))
2889 __spaces.push_back(*__b++);
2892 case money_base::sign:
2893 if (__psn.size() > 0 && *__b == __psn[0])
2897 if (__psn.size() > 1)
2898 __trailing_sign = &__psn;
2901 if (__nsn.size() > 0 && *__b == __nsn[0])
2905 if (__nsn.size() > 1)
2906 __trailing_sign = &__nsn;
2909 if (__psn.size() > 0 && __nsn.size() > 0)
2910 { // sign is required
2911 __err |= ios_base::failbit;
2914 if (__psn.size() == 0 && __nsn.size() == 0)
2915 // locale has no way of specifying a sign. Use the initial value of __neg as a default
2917 __neg = (__nsn.size() == 0);
2919 case money_base::symbol:
2921 bool __more_needed = __trailing_sign ||
2923 (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none));
2924 bool __sb = (__flags & ios_base::showbase) != 0;
2925 if (__sb || __more_needed)
2927 typename string_type::const_iterator __sym_space_end = __sym.begin();
2928 if (__p > 0 && (__pat.field[__p - 1] == money_base::none ||
2929 __pat.field[__p - 1] == money_base::space)) {
2930 // Match spaces we've already read against spaces at
2931 // the beginning of __sym.
2932 while (__sym_space_end != __sym.end() &&
2933 __ct.is(ctype_base::space, *__sym_space_end))
2935 const size_t __num_spaces = __sym_space_end - __sym.begin();
2936 if (__num_spaces > __spaces.size() ||
2937 !std::equal(__spaces.end() - __num_spaces, __spaces.end(),
2939 // No match. Put __sym_space_end back at the
2940 // beginning of __sym, which will prevent a
2941 // match in the next loop.
2942 __sym_space_end = __sym.begin();
2945 typename string_type::const_iterator __sym_curr_char = __sym_space_end;
2946 while (__sym_curr_char != __sym.end() && __b != __e &&
2947 *__b == *__sym_curr_char) {
2951 if (__sb && __sym_curr_char != __sym.end())
2953 __err |= ios_base::failbit;
2959 case money_base::value:
2962 for (; __b != __e; ++__b)
2964 char_type __c = *__b;
2965 if (__ct.is(ctype_base::digit, __c))
2968 std::__double_or_nothing(__wb, __wn, __we);
2972 else if (__grp.size() > 0 && __ng > 0 && __c == __ts)
2975 std::__double_or_nothing(__gb, __gn, __ge);
2982 if (__gb.get() != __gn && __ng > 0)
2985 std::__double_or_nothing(__gb, __gn, __ge);
2990 if (__b == __e || *__b != __dp)
2992 __err |= ios_base::failbit;
2995 for (++__b; __fd > 0; --__fd, ++__b)
2997 if (__b == __e || !__ct.is(ctype_base::digit, *__b))
2999 __err |= ios_base::failbit;
3003 std::__double_or_nothing(__wb, __wn, __we);
3007 if (__wn == __wb.get())
3009 __err |= ios_base::failbit;
3016 if (__trailing_sign)
3018 for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b)
3020 if (__b == __e || *__b != (*__trailing_sign)[__i])
3022 __err |= ios_base::failbit;
3027 if (__gb.get() != __gn)
3029 ios_base::iostate __et = ios_base::goodbit;
3030 __check_grouping(__grp, __gb.get(), __gn, __et);
3033 __err |= ios_base::failbit;
3040 template <class _CharT, class _InputIterator>
3042 money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
3043 bool __intl, ios_base& __iob,
3044 ios_base::iostate& __err,
3045 long double& __v) const
3047 const int __bz = 100;
3048 char_type __wbuf[__bz];
3049 unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
3051 char_type* __we = __wbuf + __bz;
3052 locale __loc = __iob.getloc();
3053 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
3055 if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct,
3058 const char __src[] = "0123456789";
3059 char_type __atoms[sizeof(__src)-1];
3060 __ct.widen(__src, __src + (sizeof(__src)-1), __atoms);
3062 char* __nc = __nbuf;
3063 unique_ptr<char, void(*)(void*)> __h(nullptr, free);
3064 if (__wn - __wb.get() > __bz-2)
3066 __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2)));
3067 if (__h.get() == nullptr)
3068 __throw_bad_alloc();
3073 for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc)
3074 *__nc = __src[std::find(__atoms, _VSTD::end(__atoms), *__w) - __atoms];
3076 if (sscanf(__nbuf, "%Lf", &__v) != 1)
3077 __throw_runtime_error("money_get error");
3080 __err |= ios_base::eofbit;
3084 template <class _CharT, class _InputIterator>
3086 money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
3087 bool __intl, ios_base& __iob,
3088 ios_base::iostate& __err,
3089 string_type& __v) const
3091 const int __bz = 100;
3092 char_type __wbuf[__bz];
3093 unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
3095 char_type* __we = __wbuf + __bz;
3096 locale __loc = __iob.getloc();
3097 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
3099 if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct,
3104 __v.push_back(__ct.widen('-'));
3105 char_type __z = __ct.widen('0');
3107 for (__w = __wb.get(); __w < __wn-1; ++__w)
3110 __v.append(__w, __wn);
3113 __err |= ios_base::eofbit;
3117 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>;
3118 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3119 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>;
3124 template <class _CharT>
3128 typedef _CharT char_type;
3129 typedef basic_string<char_type> string_type;
3131 _LIBCPP_INLINE_VISIBILITY __money_put() {}
3133 static void __gather_info(bool __intl, bool __neg, const locale& __loc,
3134 money_base::pattern& __pat, char_type& __dp,
3135 char_type& __ts, string& __grp,
3136 string_type& __sym, string_type& __sn,
3138 static void __format(char_type* __mb, char_type*& __mi, char_type*& __me,
3139 ios_base::fmtflags __flags,
3140 const char_type* __db, const char_type* __de,
3141 const ctype<char_type>& __ct, bool __neg,
3142 const money_base::pattern& __pat, char_type __dp,
3143 char_type __ts, const string& __grp,
3144 const string_type& __sym, const string_type& __sn,
3148 template <class _CharT>
3150 __money_put<_CharT>::__gather_info(bool __intl, bool __neg, const locale& __loc,
3151 money_base::pattern& __pat, char_type& __dp,
3152 char_type& __ts, string& __grp,
3153 string_type& __sym, string_type& __sn,
3158 const moneypunct<char_type, true>& __mp =
3159 std::use_facet<moneypunct<char_type, true> >(__loc);
3162 __pat = __mp.neg_format();
3163 __sn = __mp.negative_sign();
3167 __pat = __mp.pos_format();
3168 __sn = __mp.positive_sign();
3170 __dp = __mp.decimal_point();
3171 __ts = __mp.thousands_sep();
3172 __grp = __mp.grouping();
3173 __sym = __mp.curr_symbol();
3174 __fd = __mp.frac_digits();
3178 const moneypunct<char_type, false>& __mp =
3179 std::use_facet<moneypunct<char_type, false> >(__loc);
3182 __pat = __mp.neg_format();
3183 __sn = __mp.negative_sign();
3187 __pat = __mp.pos_format();
3188 __sn = __mp.positive_sign();
3190 __dp = __mp.decimal_point();
3191 __ts = __mp.thousands_sep();
3192 __grp = __mp.grouping();
3193 __sym = __mp.curr_symbol();
3194 __fd = __mp.frac_digits();
3198 template <class _CharT>
3200 __money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __me,
3201 ios_base::fmtflags __flags,
3202 const char_type* __db, const char_type* __de,
3203 const ctype<char_type>& __ct, bool __neg,
3204 const money_base::pattern& __pat, char_type __dp,
3205 char_type __ts, const string& __grp,
3206 const string_type& __sym, const string_type& __sn,
3210 for (char __p : __pat.field)
3214 case money_base::none:
3217 case money_base::space:
3219 *__me++ = __ct.widen(' ');
3221 case money_base::sign:
3225 case money_base::symbol:
3226 if (!__sym.empty() && (__flags & ios_base::showbase))
3227 __me = _VSTD::copy(__sym.begin(), __sym.end(), __me);
3229 case money_base::value:
3231 // remember start of value so we can reverse it
3232 char_type* __t = __me;
3233 // find beginning of digits
3236 // find end of digits
3237 const char_type* __d;
3238 for (__d = __db; __d < __de; ++__d)
3239 if (!__ct.is(ctype_base::digit, *__d))
3241 // print fractional part
3245 for (__f = __fd; __d > __db && __f > 0; --__f)
3247 char_type __z = __f > 0 ? __ct.widen('0') : char_type();
3248 for (; __f > 0; --__f)
3255 *__me++ = __ct.widen('0');
3261 unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max()
3262 : static_cast<unsigned>(__grp[__ig]);
3269 if (++__ig < __grp.size())
3270 __gl = __grp[__ig] == numeric_limits<char>::max() ?
3271 numeric_limits<unsigned>::max() :
3272 static_cast<unsigned>(__grp[__ig]);
3279 std::reverse(__t, __me);
3284 // print rest of sign, if any
3285 if (__sn.size() > 1)
3286 __me = _VSTD::copy(__sn.begin()+1, __sn.end(), __me);
3288 if ((__flags & ios_base::adjustfield) == ios_base::left)
3290 else if ((__flags & ios_base::adjustfield) != ios_base::internal)
3294 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>;
3295 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3296 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>;
3299 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
3300 class _LIBCPP_TEMPLATE_VIS money_put
3301 : public locale::facet,
3302 private __money_put<_CharT>
3305 typedef _CharT char_type;
3306 typedef _OutputIterator iter_type;
3307 typedef basic_string<char_type> string_type;
3309 _LIBCPP_INLINE_VISIBILITY
3310 explicit money_put(size_t __refs = 0)
3311 : locale::facet(__refs) {}
3313 _LIBCPP_INLINE_VISIBILITY
3314 iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl,
3315 long double __units) const
3317 return do_put(__s, __intl, __iob, __fl, __units);
3320 _LIBCPP_INLINE_VISIBILITY
3321 iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl,
3322 const string_type& __digits) const
3324 return do_put(__s, __intl, __iob, __fl, __digits);
3327 static locale::id id;
3330 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_put() override {}
3332 virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob,
3333 char_type __fl, long double __units) const;
3334 virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob,
3335 char_type __fl, const string_type& __digits) const;
3338 template <class _CharT, class _OutputIterator>
3340 money_put<_CharT, _OutputIterator>::id;
3342 template <class _CharT, class _OutputIterator>
3344 money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
3345 ios_base& __iob, char_type __fl,
3346 long double __units) const
3349 const size_t __bs = 100;
3352 char_type __digits[__bs];
3353 char_type* __db = __digits;
3354 int __n = snprintf(__bb, __bs, "%.0Lf", __units);
3355 unique_ptr<char, void(*)(void*)> __hn(nullptr, free);
3356 unique_ptr<char_type, void(*)(void*)> __hd(0, free);
3357 // secure memory for digit storage
3358 if (static_cast<size_t>(__n) > __bs-1)
3360 __n = __libcpp_asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units);
3362 __throw_bad_alloc();
3364 __hd.reset((char_type*)malloc(static_cast<size_t>(__n) * sizeof(char_type)));
3365 if (__hd == nullptr)
3366 __throw_bad_alloc();
3370 locale __loc = __iob.getloc();
3371 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
3372 __ct.widen(__bb, __bb + __n, __db);
3373 bool __neg = __n > 0 && __bb[0] == '-';
3374 money_base::pattern __pat;
3381 this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
3382 // secure memory for formatting
3383 char_type __mbuf[__bs];
3384 char_type* __mb = __mbuf;
3385 unique_ptr<char_type, void(*)(void*)> __hw(0, free);
3386 size_t __exn = __n > __fd ?
3387 (static_cast<size_t>(__n) - static_cast<size_t>(__fd)) * 2 +
3388 __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 1
3389 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
3392 __hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
3395 __throw_bad_alloc();
3400 this->__format(__mb, __mi, __me, __iob.flags(),
3401 __db, __db + __n, __ct,
3402 __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
3403 return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
3406 template <class _CharT, class _OutputIterator>
3408 money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
3409 ios_base& __iob, char_type __fl,
3410 const string_type& __digits) const
3413 locale __loc = __iob.getloc();
3414 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
3415 bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-');
3416 money_base::pattern __pat;
3423 this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
3424 // secure memory for formatting
3425 char_type __mbuf[100];
3426 char_type* __mb = __mbuf;
3427 unique_ptr<char_type, void(*)(void*)> __h(0, free);
3428 size_t __exn = static_cast<int>(__digits.size()) > __fd ?
3429 (__digits.size() - static_cast<size_t>(__fd)) * 2 +
3430 __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 1
3431 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
3434 __h.reset((char_type*)malloc(__exn * sizeof(char_type)));
3437 __throw_bad_alloc();
3442 this->__format(__mb, __mi, __me, __iob.flags(),
3443 __digits.data(), __digits.data() + __digits.size(), __ct,
3444 __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
3445 return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
3448 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>;
3449 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3450 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>;
3455 class _LIBCPP_EXPORTED_FROM_ABI messages_base
3458 typedef intptr_t catalog;
3460 _LIBCPP_INLINE_VISIBILITY messages_base() {}
3463 template <class _CharT>
3464 class _LIBCPP_TEMPLATE_VIS messages
3465 : public locale::facet,
3466 public messages_base
3469 typedef _CharT char_type;
3470 typedef basic_string<_CharT> string_type;
3472 _LIBCPP_INLINE_VISIBILITY
3473 explicit messages(size_t __refs = 0)
3474 : locale::facet(__refs) {}
3476 _LIBCPP_INLINE_VISIBILITY
3477 catalog open(const basic_string<char>& __nm, const locale& __loc) const
3479 return do_open(__nm, __loc);
3482 _LIBCPP_INLINE_VISIBILITY
3483 string_type get(catalog __c, int __set, int __msgid,
3484 const string_type& __dflt) const
3486 return do_get(__c, __set, __msgid, __dflt);
3489 _LIBCPP_INLINE_VISIBILITY
3490 void close(catalog __c) const
3495 static locale::id id;
3498 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages() override {}
3500 virtual catalog do_open(const basic_string<char>&, const locale&) const;
3501 virtual string_type do_get(catalog, int __set, int __msgid,
3502 const string_type& __dflt) const;
3503 virtual void do_close(catalog) const;
3506 template <class _CharT>
3508 messages<_CharT>::id;
3510 template <class _CharT>
3511 typename messages<_CharT>::catalog
3512 messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
3514 #ifdef _LIBCPP_HAS_CATOPEN
3515 return (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
3516 #else // !_LIBCPP_HAS_CATOPEN
3519 #endif // _LIBCPP_HAS_CATOPEN
3522 template <class _CharT>
3523 typename messages<_CharT>::string_type
3524 messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
3525 const string_type& __dflt) const
3527 #ifdef _LIBCPP_HAS_CATOPEN
3529 __narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(std::back_inserter(__ndflt),
3531 __dflt.c_str() + __dflt.size());
3532 nl_catd __cat = (nl_catd)__c;
3533 static_assert(sizeof(catalog) >= sizeof(nl_catd), "Unexpected nl_catd type");
3534 char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str());
3536 __widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(std::back_inserter(__w),
3537 __n, __n + _VSTD::strlen(__n));
3539 #else // !_LIBCPP_HAS_CATOPEN
3544 #endif // _LIBCPP_HAS_CATOPEN
3547 template <class _CharT>
3549 messages<_CharT>::do_close(catalog __c) const
3551 #ifdef _LIBCPP_HAS_CATOPEN
3552 catclose((nl_catd)__c);
3553 #else // !_LIBCPP_HAS_CATOPEN
3555 #endif // _LIBCPP_HAS_CATOPEN
3558 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>;
3559 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3560 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>;
3563 template <class _CharT>
3564 class _LIBCPP_TEMPLATE_VIS messages_byname
3565 : public messages<_CharT>
3568 typedef messages_base::catalog catalog;
3569 typedef basic_string<_CharT> string_type;
3571 _LIBCPP_INLINE_VISIBILITY
3572 explicit messages_byname(const char*, size_t __refs = 0)
3573 : messages<_CharT>(__refs) {}
3575 _LIBCPP_INLINE_VISIBILITY
3576 explicit messages_byname(const string&, size_t __refs = 0)
3577 : messages<_CharT>(__refs) {}
3580 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages_byname() override {}
3583 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>;
3584 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3585 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>;
3588 template<class _Codecvt, class _Elem = wchar_t,
3589 class _WideAlloc = allocator<_Elem>,
3590 class _ByteAlloc = allocator<char> >
3591 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 wstring_convert
3594 typedef basic_string<char, char_traits<char>, _ByteAlloc> byte_string;
3595 typedef basic_string<_Elem, char_traits<_Elem>, _WideAlloc> wide_string;
3596 typedef typename _Codecvt::state_type state_type;
3597 typedef typename wide_string::traits_type::int_type int_type;
3600 byte_string __byte_err_string_;
3601 wide_string __wide_err_string_;
3602 _Codecvt* __cvtptr_;
3603 state_type __cvtstate_;
3606 wstring_convert(const wstring_convert& __wc);
3607 wstring_convert& operator=(const wstring_convert& __wc);
3609 #ifndef _LIBCPP_CXX03_LANG
3610 _LIBCPP_INLINE_VISIBILITY
3611 wstring_convert() : wstring_convert(new _Codecvt) {}
3612 _LIBCPP_INLINE_VISIBILITY
3613 explicit wstring_convert(_Codecvt* __pcvt);
3615 _LIBCPP_INLINE_VISIBILITY
3616 _LIBCPP_EXPLICIT_SINCE_CXX14
3617 wstring_convert(_Codecvt* __pcvt = new _Codecvt);
3620 _LIBCPP_INLINE_VISIBILITY
3621 wstring_convert(_Codecvt* __pcvt, state_type __state);
3622 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI wstring_convert(const byte_string& __byte_err,
3623 const wide_string& __wide_err = wide_string());
3624 #ifndef _LIBCPP_CXX03_LANG
3625 _LIBCPP_INLINE_VISIBILITY
3626 wstring_convert(wstring_convert&& __wc);
3628 _LIBCPP_HIDE_FROM_ABI ~wstring_convert();
3630 _LIBCPP_INLINE_VISIBILITY
3631 wide_string from_bytes(char __byte)
3632 {return from_bytes(&__byte, &__byte+1);}
3633 _LIBCPP_INLINE_VISIBILITY
3634 wide_string from_bytes(const char* __ptr)
3635 {return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));}
3636 _LIBCPP_INLINE_VISIBILITY
3637 wide_string from_bytes(const byte_string& __str)
3638 {return from_bytes(__str.data(), __str.data() + __str.size());}
3639 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __first, const char* __last);
3641 _LIBCPP_INLINE_VISIBILITY
3642 byte_string to_bytes(_Elem __wchar)
3643 {return to_bytes(&__wchar, &__wchar+1);}
3644 _LIBCPP_INLINE_VISIBILITY
3645 byte_string to_bytes(const _Elem* __wptr)
3646 {return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));}
3647 _LIBCPP_INLINE_VISIBILITY
3648 byte_string to_bytes(const wide_string& __wstr)
3649 {return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());}
3650 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __first, const _Elem* __last);
3652 _LIBCPP_INLINE_VISIBILITY
3653 size_t converted() const _NOEXCEPT {return __cvtcount_;}
3654 _LIBCPP_INLINE_VISIBILITY
3655 state_type state() const {return __cvtstate_;}
3658 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3659 template<class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3661 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::
3662 wstring_convert(_Codecvt* __pcvt)
3663 : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0)
3666 _LIBCPP_SUPPRESS_DEPRECATED_POP
3668 template<class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3670 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::
3671 wstring_convert(_Codecvt* __pcvt, state_type __state)
3672 : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0)
3676 template<class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3677 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::
3678 wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err)
3679 : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err),
3680 __cvtstate_(), __cvtcount_(0)
3682 __cvtptr_ = new _Codecvt;
3685 #ifndef _LIBCPP_CXX03_LANG
3687 template<class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3689 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::
3690 wstring_convert(wstring_convert&& __wc)
3691 : __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)),
3692 __wide_err_string_(_VSTD::move(__wc.__wide_err_string_)),
3693 __cvtptr_(__wc.__cvtptr_),
3694 __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtcount_)
3696 __wc.__cvtptr_ = nullptr;
3699 #endif // _LIBCPP_CXX03_LANG
3701 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3702 template<class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3703 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::~wstring_convert()
3708 template<class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3709 typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wide_string
3710 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::
3711 from_bytes(const char* __frm, const char* __frm_end)
3713 _LIBCPP_SUPPRESS_DEPRECATED_POP
3715 if (__cvtptr_ != nullptr)
3717 wide_string __ws(2*(__frm_end - __frm), _Elem());
3718 if (__frm != __frm_end)
3719 __ws.resize(__ws.capacity());
3720 codecvt_base::result __r = codecvt_base::ok;
3721 state_type __st = __cvtstate_;
3722 if (__frm != __frm_end)
3724 _Elem* __to = &__ws[0];
3725 _Elem* __to_end = __to + __ws.size();
3726 const char* __frm_nxt;
3730 __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt,
3731 __to, __to_end, __to_nxt);
3732 __cvtcount_ += __frm_nxt - __frm;
3733 if (__frm_nxt == __frm)
3735 __r = codecvt_base::error;
3737 else if (__r == codecvt_base::noconv)
3739 __ws.resize(__to - &__ws[0]);
3740 // This only gets executed if _Elem is char
3741 __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end);
3743 __r = codecvt_base::ok;
3745 else if (__r == codecvt_base::ok)
3747 __ws.resize(__to_nxt - &__ws[0]);
3750 else if (__r == codecvt_base::partial)
3752 ptrdiff_t __s = __to_nxt - &__ws[0];
3753 __ws.resize(2 * __s);
3754 __to = &__ws[0] + __s;
3755 __to_end = &__ws[0] + __ws.size();
3758 } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
3760 if (__r == codecvt_base::ok)
3764 if (__wide_err_string_.empty())
3765 __throw_range_error("wstring_convert: from_bytes error");
3767 return __wide_err_string_;
3770 template<class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3771 typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::byte_string
3772 wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::
3773 to_bytes(const _Elem* __frm, const _Elem* __frm_end)
3776 if (__cvtptr_ != nullptr)
3778 byte_string __bs(2*(__frm_end - __frm), char());
3779 if (__frm != __frm_end)
3780 __bs.resize(__bs.capacity());
3781 codecvt_base::result __r = codecvt_base::ok;
3782 state_type __st = __cvtstate_;
3783 if (__frm != __frm_end)
3785 char* __to = &__bs[0];
3786 char* __to_end = __to + __bs.size();
3787 const _Elem* __frm_nxt;
3791 __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt,
3792 __to, __to_end, __to_nxt);
3793 __cvtcount_ += __frm_nxt - __frm;
3794 if (__frm_nxt == __frm)
3796 __r = codecvt_base::error;
3798 else if (__r == codecvt_base::noconv)
3800 __bs.resize(__to - &__bs[0]);
3801 // This only gets executed if _Elem is char
3802 __bs.append((const char*)__frm, (const char*)__frm_end);
3804 __r = codecvt_base::ok;
3806 else if (__r == codecvt_base::ok)
3808 __bs.resize(__to_nxt - &__bs[0]);
3811 else if (__r == codecvt_base::partial)
3813 ptrdiff_t __s = __to_nxt - &__bs[0];
3814 __bs.resize(2 * __s);
3815 __to = &__bs[0] + __s;
3816 __to_end = &__bs[0] + __bs.size();
3819 } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
3821 if (__r == codecvt_base::ok)
3823 size_t __s = __bs.size();
3824 __bs.resize(__bs.capacity());
3825 char* __to = &__bs[0] + __s;
3826 char* __to_end = __to + __bs.size();
3830 __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt);
3831 if (__r == codecvt_base::noconv)
3833 __bs.resize(__to - &__bs[0]);
3834 __r = codecvt_base::ok;
3836 else if (__r == codecvt_base::ok)
3838 __bs.resize(__to_nxt - &__bs[0]);
3840 else if (__r == codecvt_base::partial)
3842 ptrdiff_t __sp = __to_nxt - &__bs[0];
3843 __bs.resize(2 * __sp);
3844 __to = &__bs[0] + __sp;
3845 __to_end = &__bs[0] + __bs.size();
3847 } while (__r == codecvt_base::partial);
3848 if (__r == codecvt_base::ok)
3853 if (__byte_err_string_.empty())
3854 __throw_range_error("wstring_convert: to_bytes error");
3856 return __byte_err_string_;
3859 template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> >
3860 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 wbuffer_convert
3861 : public basic_streambuf<_Elem, _Tr>
3865 typedef _Elem char_type;
3866 typedef _Tr traits_type;
3867 typedef typename traits_type::int_type int_type;
3868 typedef typename traits_type::pos_type pos_type;
3869 typedef typename traits_type::off_type off_type;
3870 typedef typename _Codecvt::state_type state_type;
3874 const char* __extbufnext_;
3875 const char* __extbufend_;
3876 char __extbuf_min_[8];
3878 char_type* __intbuf_;
3880 streambuf* __bufptr_;
3883 ios_base::openmode __cm_;
3886 bool __always_noconv_;
3888 wbuffer_convert(const wbuffer_convert&);
3889 wbuffer_convert& operator=(const wbuffer_convert&);
3892 #ifndef _LIBCPP_CXX03_LANG
3893 _LIBCPP_HIDE_FROM_ABI wbuffer_convert() : wbuffer_convert(nullptr) {}
3894 explicit _LIBCPP_HIDE_FROM_ABI wbuffer_convert(streambuf* __bytebuf,
3895 _Codecvt* __pcvt = new _Codecvt,
3896 state_type __state = state_type());
3898 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
3899 wbuffer_convert(streambuf* __bytebuf = nullptr,
3900 _Codecvt* __pcvt = new _Codecvt,
3901 state_type __state = state_type());
3904 _LIBCPP_HIDE_FROM_ABI ~wbuffer_convert();
3906 _LIBCPP_INLINE_VISIBILITY
3907 streambuf* rdbuf() const {return __bufptr_;}
3908 _LIBCPP_INLINE_VISIBILITY
3909 streambuf* rdbuf(streambuf* __bytebuf)
3911 streambuf* __r = __bufptr_;
3912 __bufptr_ = __bytebuf;
3916 _LIBCPP_INLINE_VISIBILITY
3917 state_type state() const {return __st_;}
3920 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type underflow();
3921 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type pbackfail(int_type __c = traits_type::eof());
3922 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type overflow (int_type __c = traits_type::eof());
3923 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s,
3925 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
3926 ios_base::openmode __wch = ios_base::in | ios_base::out);
3927 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type seekpos(pos_type __sp,
3928 ios_base::openmode __wch = ios_base::in | ios_base::out);
3929 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int sync();
3932 _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool __read_mode();
3933 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __write_mode();
3934 _LIBCPP_HIDE_FROM_ABI_VIRTUAL wbuffer_convert* __close();
3937 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
3938 template <class _Codecvt, class _Elem, class _Tr>
3939 wbuffer_convert<_Codecvt, _Elem, _Tr>::
3940 wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state)
3941 : __extbuf_(nullptr),
3942 __extbufnext_(nullptr),
3943 __extbufend_(nullptr),
3947 __bufptr_(__bytebuf),
3953 __always_noconv_(__cv_ ? __cv_->always_noconv() : false)
3958 template <class _Codecvt, class _Elem, class _Tr>
3959 wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert()
3964 delete [] __extbuf_;
3966 delete [] __intbuf_;
3969 template <class _Codecvt, class _Elem, class _Tr>
3970 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
3971 wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow()
3973 _LIBCPP_SUPPRESS_DEPRECATED_POP
3974 if (__cv_ == 0 || __bufptr_ == 0)
3975 return traits_type::eof();
3976 bool __initial = __read_mode();
3978 if (this->gptr() == 0)
3979 this->setg(&__1buf, &__1buf+1, &__1buf+1);
3980 const size_t __unget_sz = __initial ? 0 : std::min<size_t>((this->egptr() - this->eback()) / 2, 4);
3981 int_type __c = traits_type::eof();
3982 if (this->gptr() == this->egptr())
3984 _VSTD::memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
3985 if (__always_noconv_)
3987 streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz);
3988 __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb);
3991 this->setg(this->eback(),
3992 this->eback() + __unget_sz,
3993 this->eback() + __unget_sz + __nmemb);
3994 __c = *this->gptr();
3999 if (__extbufend_ != __extbufnext_) {
4000 _LIBCPP_ASSERT_UNCATEGORIZED(__extbufnext_ != nullptr, "underflow moving from nullptr");
4001 _LIBCPP_ASSERT_UNCATEGORIZED(__extbuf_ != nullptr, "underflow moving into nullptr");
4002 _VSTD::memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
4004 __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
4005 __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
4006 streamsize __nmemb = _VSTD::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz),
4007 static_cast<streamsize>(__extbufend_ - __extbufnext_));
4008 codecvt_base::result __r;
4009 // FIXME: Do we ever need to restore the state here?
4010 //state_type __svs = __st_;
4011 streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb);
4014 __extbufend_ = __extbufnext_ + __nr;
4016 __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_,
4017 this->eback() + __unget_sz,
4018 this->egptr(), __inext);
4019 if (__r == codecvt_base::noconv)
4021 this->setg((char_type*)__extbuf_, (char_type*)__extbuf_,
4022 (char_type*) const_cast<char *>(__extbufend_));
4023 __c = *this->gptr();
4025 else if (__inext != this->eback() + __unget_sz)
4027 this->setg(this->eback(), this->eback() + __unget_sz, __inext);
4028 __c = *this->gptr();
4034 __c = *this->gptr();
4035 if (this->eback() == &__1buf)
4036 this->setg(0, 0, 0);
4040 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
4041 template <class _Codecvt, class _Elem, class _Tr>
4042 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
4043 wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c)
4045 _LIBCPP_SUPPRESS_DEPRECATED_POP
4046 if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr())
4048 if (traits_type::eq_int_type(__c, traits_type::eof()))
4051 return traits_type::not_eof(__c);
4053 if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
4056 *this->gptr() = traits_type::to_char_type(__c);
4060 return traits_type::eof();
4063 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
4064 template <class _Codecvt, class _Elem, class _Tr>
4065 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
4066 wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c)
4068 _LIBCPP_SUPPRESS_DEPRECATED_POP
4069 if (__cv_ == 0 || __bufptr_ == 0)
4070 return traits_type::eof();
4073 char_type* __pb_save = this->pbase();
4074 char_type* __epb_save = this->epptr();
4075 if (!traits_type::eq_int_type(__c, traits_type::eof()))
4077 if (this->pptr() == 0)
4078 this->setp(&__1buf, &__1buf+1);
4079 *this->pptr() = traits_type::to_char_type(__c);
4082 if (this->pptr() != this->pbase())
4084 if (__always_noconv_)
4086 streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase());
4087 if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
4088 return traits_type::eof();
4092 char* __extbe = __extbuf_;
4093 codecvt_base::result __r;
4096 const char_type* __e;
4097 __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e,
4098 __extbuf_, __extbuf_ + __ebs_, __extbe);
4099 if (__e == this->pbase())
4100 return traits_type::eof();
4101 if (__r == codecvt_base::noconv)
4103 streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
4104 if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
4105 return traits_type::eof();
4107 else if (__r == codecvt_base::ok || __r == codecvt_base::partial)
4109 streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_);
4110 if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
4111 return traits_type::eof();
4112 if (__r == codecvt_base::partial)
4114 this->setp(const_cast<char_type *>(__e), this->pptr());
4115 this->__pbump(this->epptr() - this->pbase());
4119 return traits_type::eof();
4120 } while (__r == codecvt_base::partial);
4122 this->setp(__pb_save, __epb_save);
4124 return traits_type::not_eof(__c);
4127 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
4128 template <class _Codecvt, class _Elem, class _Tr>
4129 basic_streambuf<_Elem, _Tr>*
4130 wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n)
4132 _LIBCPP_SUPPRESS_DEPRECATED_POP
4133 this->setg(0, 0, 0);
4136 delete [] __extbuf_;
4138 delete [] __intbuf_;
4140 if (__ebs_ > sizeof(__extbuf_min_))
4142 if (__always_noconv_ && __s)
4144 __extbuf_ = (char*)__s;
4149 __extbuf_ = new char[__ebs_];
4155 __extbuf_ = __extbuf_min_;
4156 __ebs_ = sizeof(__extbuf_min_);
4159 if (!__always_noconv_)
4161 __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_));
4162 if (__s && __ibs_ >= sizeof(__extbuf_min_))
4169 __intbuf_ = new char_type[__ibs_];
4182 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
4183 template <class _Codecvt, class _Elem, class _Tr>
4184 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
4185 wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way,
4186 ios_base::openmode __om)
4188 int __width = __cv_->encoding();
4189 if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync())
4190 return pos_type(off_type(-1));
4191 // __width > 0 || __off == 0, now check __way
4192 if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end)
4193 return pos_type(off_type(-1));
4194 pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om);
4199 template <class _Codecvt, class _Elem, class _Tr>
4200 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
4201 wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch)
4203 if (__cv_ == 0 || __bufptr_ == 0 || sync())
4204 return pos_type(off_type(-1));
4205 if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1)))
4206 return pos_type(off_type(-1));
4210 template <class _Codecvt, class _Elem, class _Tr>
4212 wbuffer_convert<_Codecvt, _Elem, _Tr>::sync()
4214 _LIBCPP_SUPPRESS_DEPRECATED_POP
4215 if (__cv_ == 0 || __bufptr_ == 0)
4217 if (__cm_ & ios_base::out)
4219 if (this->pptr() != this->pbase())
4220 if (overflow() == traits_type::eof())
4222 codecvt_base::result __r;
4226 __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
4227 streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_);
4228 if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
4230 } while (__r == codecvt_base::partial);
4231 if (__r == codecvt_base::error)
4233 if (__bufptr_->pubsync())
4236 else if (__cm_ & ios_base::in)
4239 if (__always_noconv_)
4240 __c = this->egptr() - this->gptr();
4243 int __width = __cv_->encoding();
4244 __c = __extbufend_ - __extbufnext_;
4246 __c += __width * (this->egptr() - this->gptr());
4249 if (this->gptr() != this->egptr())
4251 std::reverse(this->gptr(), this->egptr());
4252 codecvt_base::result __r;
4253 const char_type* __e = this->gptr();
4257 __r = __cv_->out(__st_, __e, this->egptr(), __e,
4258 __extbuf_, __extbuf_ + __ebs_, __extbe);
4261 case codecvt_base::noconv:
4262 __c += this->egptr() - this->gptr();
4264 case codecvt_base::ok:
4265 case codecvt_base::partial:
4266 __c += __extbe - __extbuf_;
4271 } while (__r == codecvt_base::partial);
4275 if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1)))
4277 this->setg(0, 0, 0);
4283 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
4284 template <class _Codecvt, class _Elem, class _Tr>
4286 wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode()
4288 if (!(__cm_ & ios_base::in))
4291 if (__always_noconv_)
4292 this->setg((char_type*)__extbuf_,
4293 (char_type*)__extbuf_ + __ebs_,
4294 (char_type*)__extbuf_ + __ebs_);
4296 this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_);
4297 __cm_ = ios_base::in;
4303 template <class _Codecvt, class _Elem, class _Tr>
4305 wbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode()
4307 if (!(__cm_ & ios_base::out))
4309 this->setg(0, 0, 0);
4310 if (__ebs_ > sizeof(__extbuf_min_))
4312 if (__always_noconv_)
4313 this->setp((char_type*)__extbuf_,
4314 (char_type*)__extbuf_ + (__ebs_ - 1));
4316 this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1));
4320 __cm_ = ios_base::out;
4324 template <class _Codecvt, class _Elem, class _Tr>
4325 wbuffer_convert<_Codecvt, _Elem, _Tr>*
4326 wbuffer_convert<_Codecvt, _Elem, _Tr>::__close()
4328 wbuffer_convert* __rt = nullptr;
4329 if (__cv_ != nullptr && __bufptr_ != nullptr)
4332 if ((__cm_ & ios_base::out) && sync())
4338 _LIBCPP_SUPPRESS_DEPRECATED_POP
4340 _LIBCPP_END_NAMESPACE_STD
4344 // NOLINTEND(libcpp-robust-against-adl)
4346 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
4348 # include <concepts>
4350 # include <iterator>
4352 # include <stdexcept>
4353 # include <type_traits>
4354 # include <typeinfo>
4357 #endif // _LIBCPP_LOCALE