xref: /aosp_15_r20/external/libcxx/include/locale (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker// -*- C++ -*-
2*58b9f456SAndroid Build Coastguard Worker//===-------------------------- locale ------------------------------------===//
3*58b9f456SAndroid Build Coastguard Worker//
4*58b9f456SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
5*58b9f456SAndroid Build Coastguard Worker//
6*58b9f456SAndroid Build Coastguard Worker// This file is dual licensed under the MIT and the University of Illinois Open
7*58b9f456SAndroid Build Coastguard Worker// Source Licenses. See LICENSE.TXT for details.
8*58b9f456SAndroid Build Coastguard Worker//
9*58b9f456SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
10*58b9f456SAndroid Build Coastguard Worker
11*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_LOCALE
12*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_LOCALE
13*58b9f456SAndroid Build Coastguard Worker
14*58b9f456SAndroid Build Coastguard Worker/*
15*58b9f456SAndroid Build Coastguard Worker    locale synopsis
16*58b9f456SAndroid Build Coastguard Worker
17*58b9f456SAndroid Build Coastguard Workernamespace std
18*58b9f456SAndroid Build Coastguard Worker{
19*58b9f456SAndroid Build Coastguard Worker
20*58b9f456SAndroid Build Coastguard Workerclass locale
21*58b9f456SAndroid Build Coastguard Worker{
22*58b9f456SAndroid Build Coastguard Workerpublic:
23*58b9f456SAndroid Build Coastguard Worker    // types:
24*58b9f456SAndroid Build Coastguard Worker    class facet;
25*58b9f456SAndroid Build Coastguard Worker    class id;
26*58b9f456SAndroid Build Coastguard Worker
27*58b9f456SAndroid Build Coastguard Worker    typedef int category;
28*58b9f456SAndroid Build Coastguard Worker    static const category // values assigned here are for exposition only
29*58b9f456SAndroid Build Coastguard Worker        none     = 0x000,
30*58b9f456SAndroid Build Coastguard Worker        collate  = 0x010,
31*58b9f456SAndroid Build Coastguard Worker        ctype    = 0x020,
32*58b9f456SAndroid Build Coastguard Worker        monetary = 0x040,
33*58b9f456SAndroid Build Coastguard Worker        numeric  = 0x080,
34*58b9f456SAndroid Build Coastguard Worker        time     = 0x100,
35*58b9f456SAndroid Build Coastguard Worker        messages = 0x200,
36*58b9f456SAndroid Build Coastguard Worker        all = collate | ctype | monetary | numeric | time | messages;
37*58b9f456SAndroid Build Coastguard Worker
38*58b9f456SAndroid Build Coastguard Worker    // construct/copy/destroy:
39*58b9f456SAndroid Build Coastguard Worker    locale() noexcept;
40*58b9f456SAndroid Build Coastguard Worker    locale(const locale& other) noexcept;
41*58b9f456SAndroid Build Coastguard Worker    explicit locale(const char* std_name);
42*58b9f456SAndroid Build Coastguard Worker    explicit locale(const string& std_name);
43*58b9f456SAndroid Build Coastguard Worker    locale(const locale& other, const char* std_name, category);
44*58b9f456SAndroid Build Coastguard Worker    locale(const locale& other, const string& std_name, category);
45*58b9f456SAndroid Build Coastguard Worker    template <class Facet> locale(const locale& other, Facet* f);
46*58b9f456SAndroid Build Coastguard Worker    locale(const locale& other, const locale& one, category);
47*58b9f456SAndroid Build Coastguard Worker
48*58b9f456SAndroid Build Coastguard Worker    ~locale(); // not virtual
49*58b9f456SAndroid Build Coastguard Worker
50*58b9f456SAndroid Build Coastguard Worker    const locale& operator=(const locale& other) noexcept;
51*58b9f456SAndroid Build Coastguard Worker
52*58b9f456SAndroid Build Coastguard Worker    template <class Facet> locale combine(const locale& other) const;
53*58b9f456SAndroid Build Coastguard Worker
54*58b9f456SAndroid Build Coastguard Worker    // locale operations:
55*58b9f456SAndroid Build Coastguard Worker    basic_string<char> name() const;
56*58b9f456SAndroid Build Coastguard Worker    bool operator==(const locale& other) const;
57*58b9f456SAndroid Build Coastguard Worker    bool operator!=(const locale& other) const;
58*58b9f456SAndroid Build Coastguard Worker    template <class charT, class Traits, class Allocator>
59*58b9f456SAndroid Build Coastguard Worker      bool operator()(const basic_string<charT,Traits,Allocator>& s1,
60*58b9f456SAndroid Build Coastguard Worker                      const basic_string<charT,Traits,Allocator>& s2) const;
61*58b9f456SAndroid Build Coastguard Worker
62*58b9f456SAndroid Build Coastguard Worker    // global locale objects:
63*58b9f456SAndroid Build Coastguard Worker    static locale global(const locale&);
64*58b9f456SAndroid Build Coastguard Worker    static const locale& classic();
65*58b9f456SAndroid Build Coastguard Worker};
66*58b9f456SAndroid Build Coastguard Worker
67*58b9f456SAndroid Build Coastguard Workertemplate <class Facet> const Facet& use_facet(const locale&);
68*58b9f456SAndroid Build Coastguard Workertemplate <class Facet> bool has_facet(const locale&) noexcept;
69*58b9f456SAndroid Build Coastguard Worker
70*58b9f456SAndroid Build Coastguard Worker// 22.3.3, convenience interfaces:
71*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool isspace (charT c, const locale& loc);
72*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool isprint (charT c, const locale& loc);
73*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool iscntrl (charT c, const locale& loc);
74*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool isupper (charT c, const locale& loc);
75*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool islower (charT c, const locale& loc);
76*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool isalpha (charT c, const locale& loc);
77*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool isdigit (charT c, const locale& loc);
78*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool ispunct (charT c, const locale& loc);
79*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool isxdigit(charT c, const locale& loc);
80*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool isalnum (charT c, const locale& loc);
81*58b9f456SAndroid Build Coastguard Workertemplate <class charT> bool isgraph (charT c, const locale& loc);
82*58b9f456SAndroid Build Coastguard Workertemplate <class charT> charT toupper(charT c, const locale& loc);
83*58b9f456SAndroid Build Coastguard Workertemplate <class charT> charT tolower(charT c, const locale& loc);
84*58b9f456SAndroid Build Coastguard Worker
85*58b9f456SAndroid Build Coastguard Workertemplate<class Codecvt, class Elem = wchar_t,
86*58b9f456SAndroid Build Coastguard Worker         class Wide_alloc = allocator<Elem>,
87*58b9f456SAndroid Build Coastguard Worker         class Byte_alloc = allocator<char>>
88*58b9f456SAndroid Build Coastguard Workerclass wstring_convert
89*58b9f456SAndroid Build Coastguard Worker{
90*58b9f456SAndroid Build Coastguard Workerpublic:
91*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char, char_traits<char>, Byte_alloc> byte_string;
92*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
93*58b9f456SAndroid Build Coastguard Worker    typedef typename Codecvt::state_type                      state_type;
94*58b9f456SAndroid Build Coastguard Worker    typedef typename wide_string::traits_type::int_type       int_type;
95*58b9f456SAndroid Build Coastguard Worker
96*58b9f456SAndroid Build Coastguard Worker    explicit wstring_convert(Codecvt* pcvt = new Codecvt);          // explicit in C++14
97*58b9f456SAndroid Build Coastguard Worker    wstring_convert(Codecvt* pcvt, state_type state);
98*58b9f456SAndroid Build Coastguard Worker    explicit wstring_convert(const byte_string& byte_err,           // explicit in C++14
99*58b9f456SAndroid Build Coastguard Worker                    const wide_string& wide_err = wide_string());
100*58b9f456SAndroid Build Coastguard Worker    wstring_convert(const wstring_convert&) = delete;               // C++14
101*58b9f456SAndroid Build Coastguard Worker    wstring_convert & operator=(const wstring_convert &) = delete;  // C++14
102*58b9f456SAndroid Build Coastguard Worker    ~wstring_convert();
103*58b9f456SAndroid Build Coastguard Worker
104*58b9f456SAndroid Build Coastguard Worker    wide_string from_bytes(char byte);
105*58b9f456SAndroid Build Coastguard Worker    wide_string from_bytes(const char* ptr);
106*58b9f456SAndroid Build Coastguard Worker    wide_string from_bytes(const byte_string& str);
107*58b9f456SAndroid Build Coastguard Worker    wide_string from_bytes(const char* first, const char* last);
108*58b9f456SAndroid Build Coastguard Worker
109*58b9f456SAndroid Build Coastguard Worker    byte_string to_bytes(Elem wchar);
110*58b9f456SAndroid Build Coastguard Worker    byte_string to_bytes(const Elem* wptr);
111*58b9f456SAndroid Build Coastguard Worker    byte_string to_bytes(const wide_string& wstr);
112*58b9f456SAndroid Build Coastguard Worker    byte_string to_bytes(const Elem* first, const Elem* last);
113*58b9f456SAndroid Build Coastguard Worker
114*58b9f456SAndroid Build Coastguard Worker    size_t converted() const; // noexcept in C++14
115*58b9f456SAndroid Build Coastguard Worker    state_type state() const;
116*58b9f456SAndroid Build Coastguard Worker};
117*58b9f456SAndroid Build Coastguard Worker
118*58b9f456SAndroid Build Coastguard Workertemplate <class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem>>
119*58b9f456SAndroid Build Coastguard Workerclass wbuffer_convert
120*58b9f456SAndroid Build Coastguard Worker    : public basic_streambuf<Elem, Tr>
121*58b9f456SAndroid Build Coastguard Worker{
122*58b9f456SAndroid Build Coastguard Workerpublic:
123*58b9f456SAndroid Build Coastguard Worker    typedef typename Tr::state_type state_type;
124*58b9f456SAndroid Build Coastguard Worker
125*58b9f456SAndroid Build Coastguard Worker    explicit wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt,
126*58b9f456SAndroid Build Coastguard Worker                    state_type state = state_type());       // explicit in C++14
127*58b9f456SAndroid Build Coastguard Worker    wbuffer_convert(const wbuffer_convert&) = delete;               // C++14
128*58b9f456SAndroid Build Coastguard Worker    wbuffer_convert & operator=(const wbuffer_convert &) = delete;  // C++14
129*58b9f456SAndroid Build Coastguard Worker    ~wbuffer_convert();                                             // C++14
130*58b9f456SAndroid Build Coastguard Worker
131*58b9f456SAndroid Build Coastguard Worker    streambuf* rdbuf() const;
132*58b9f456SAndroid Build Coastguard Worker    streambuf* rdbuf(streambuf* bytebuf);
133*58b9f456SAndroid Build Coastguard Worker
134*58b9f456SAndroid Build Coastguard Worker    state_type state() const;
135*58b9f456SAndroid Build Coastguard Worker};
136*58b9f456SAndroid Build Coastguard Worker
137*58b9f456SAndroid Build Coastguard Worker// 22.4.1 and 22.4.1.3, ctype:
138*58b9f456SAndroid Build Coastguard Workerclass ctype_base;
139*58b9f456SAndroid Build Coastguard Workertemplate <class charT> class ctype;
140*58b9f456SAndroid Build Coastguard Workertemplate <> class ctype<char>; // specialization
141*58b9f456SAndroid Build Coastguard Workertemplate <class charT> class ctype_byname;
142*58b9f456SAndroid Build Coastguard Workertemplate <> class ctype_byname<char>; // specialization
143*58b9f456SAndroid Build Coastguard Worker
144*58b9f456SAndroid Build Coastguard Workerclass codecvt_base;
145*58b9f456SAndroid Build Coastguard Workertemplate <class internT, class externT, class stateT> class codecvt;
146*58b9f456SAndroid Build Coastguard Workertemplate <class internT, class externT, class stateT> class codecvt_byname;
147*58b9f456SAndroid Build Coastguard Worker
148*58b9f456SAndroid Build Coastguard Worker// 22.4.2 and 22.4.3, numeric:
149*58b9f456SAndroid Build Coastguard Workertemplate <class charT, class InputIterator> class num_get;
150*58b9f456SAndroid Build Coastguard Workertemplate <class charT, class OutputIterator> class num_put;
151*58b9f456SAndroid Build Coastguard Workertemplate <class charT> class numpunct;
152*58b9f456SAndroid Build Coastguard Workertemplate <class charT> class numpunct_byname;
153*58b9f456SAndroid Build Coastguard Worker
154*58b9f456SAndroid Build Coastguard Worker// 22.4.4, col lation:
155*58b9f456SAndroid Build Coastguard Workertemplate <class charT> class collate;
156*58b9f456SAndroid Build Coastguard Workertemplate <class charT> class collate_byname;
157*58b9f456SAndroid Build Coastguard Worker
158*58b9f456SAndroid Build Coastguard Worker// 22.4.5, date and time:
159*58b9f456SAndroid Build Coastguard Workerclass time_base;
160*58b9f456SAndroid Build Coastguard Workertemplate <class charT, class InputIterator> class time_get;
161*58b9f456SAndroid Build Coastguard Workertemplate <class charT, class InputIterator> class time_get_byname;
162*58b9f456SAndroid Build Coastguard Workertemplate <class charT, class OutputIterator> class time_put;
163*58b9f456SAndroid Build Coastguard Workertemplate <class charT, class OutputIterator> class time_put_byname;
164*58b9f456SAndroid Build Coastguard Worker
165*58b9f456SAndroid Build Coastguard Worker// 22.4.6, money:
166*58b9f456SAndroid Build Coastguard Workerclass money_base;
167*58b9f456SAndroid Build Coastguard Workertemplate <class charT, class InputIterator> class money_get;
168*58b9f456SAndroid Build Coastguard Workertemplate <class charT, class OutputIterator> class money_put;
169*58b9f456SAndroid Build Coastguard Workertemplate <class charT, bool Intl> class moneypunct;
170*58b9f456SAndroid Build Coastguard Workertemplate <class charT, bool Intl> class moneypunct_byname;
171*58b9f456SAndroid Build Coastguard Worker
172*58b9f456SAndroid Build Coastguard Worker// 22.4.7, message retrieval:
173*58b9f456SAndroid Build Coastguard Workerclass messages_base;
174*58b9f456SAndroid Build Coastguard Workertemplate <class charT> class messages;
175*58b9f456SAndroid Build Coastguard Workertemplate <class charT> class messages_byname;
176*58b9f456SAndroid Build Coastguard Worker
177*58b9f456SAndroid Build Coastguard Worker}  // std
178*58b9f456SAndroid Build Coastguard Worker
179*58b9f456SAndroid Build Coastguard Worker*/
180*58b9f456SAndroid Build Coastguard Worker
181*58b9f456SAndroid Build Coastguard Worker#include <__config>
182*58b9f456SAndroid Build Coastguard Worker#include <__locale>
183*58b9f456SAndroid Build Coastguard Worker#include <__debug>
184*58b9f456SAndroid Build Coastguard Worker#include <algorithm>
185*58b9f456SAndroid Build Coastguard Worker#include <memory>
186*58b9f456SAndroid Build Coastguard Worker#include <ios>
187*58b9f456SAndroid Build Coastguard Worker#include <streambuf>
188*58b9f456SAndroid Build Coastguard Worker#include <iterator>
189*58b9f456SAndroid Build Coastguard Worker#include <limits>
190*58b9f456SAndroid Build Coastguard Worker#include <version>
191*58b9f456SAndroid Build Coastguard Worker#ifndef __APPLE__
192*58b9f456SAndroid Build Coastguard Worker#include <cstdarg>
193*58b9f456SAndroid Build Coastguard Worker#endif
194*58b9f456SAndroid Build Coastguard Worker#include <cstdlib>
195*58b9f456SAndroid Build Coastguard Worker#include <ctime>
196*58b9f456SAndroid Build Coastguard Worker#include <cstdio>
197*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_HAS_CATOPEN
198*58b9f456SAndroid Build Coastguard Worker#include <nl_types.h>
199*58b9f456SAndroid Build Coastguard Worker#endif
200*58b9f456SAndroid Build Coastguard Worker
201*58b9f456SAndroid Build Coastguard Worker#ifdef __APPLE__
202*58b9f456SAndroid Build Coastguard Worker#include <Availability.h>
203*58b9f456SAndroid Build Coastguard Worker#endif
204*58b9f456SAndroid Build Coastguard Worker
205*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
206*58b9f456SAndroid Build Coastguard Worker#include <__bsd_locale_defaults.h>
207*58b9f456SAndroid Build Coastguard Worker#else
208*58b9f456SAndroid Build Coastguard Worker#include <__bsd_locale_fallbacks.h>
209*58b9f456SAndroid Build Coastguard Worker#endif
210*58b9f456SAndroid Build Coastguard Worker
211*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
212*58b9f456SAndroid Build Coastguard Worker#pragma GCC system_header
213*58b9f456SAndroid Build Coastguard Worker#endif
214*58b9f456SAndroid Build Coastguard Worker
215*58b9f456SAndroid Build Coastguard Worker_LIBCPP_PUSH_MACROS
216*58b9f456SAndroid Build Coastguard Worker#include <__undef_macros>
217*58b9f456SAndroid Build Coastguard Worker
218*58b9f456SAndroid Build Coastguard Worker
219*58b9f456SAndroid Build Coastguard Worker_LIBCPP_BEGIN_NAMESPACE_STD
220*58b9f456SAndroid Build Coastguard Worker
221*58b9f456SAndroid Build Coastguard Worker#if defined(__APPLE__) || defined(__FreeBSD__)
222*58b9f456SAndroid Build Coastguard Worker#  define _LIBCPP_GET_C_LOCALE 0
223*58b9f456SAndroid Build Coastguard Worker#elif defined(__CloudABI__) || defined(__NetBSD__)
224*58b9f456SAndroid Build Coastguard Worker#  define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
225*58b9f456SAndroid Build Coastguard Worker#else
226*58b9f456SAndroid Build Coastguard Worker#  define _LIBCPP_GET_C_LOCALE __cloc()
227*58b9f456SAndroid Build Coastguard Worker   // Get the C locale object
228*58b9f456SAndroid Build Coastguard Worker   _LIBCPP_FUNC_VIS locale_t __cloc();
229*58b9f456SAndroid Build Coastguard Worker#define __cloc_defined
230*58b9f456SAndroid Build Coastguard Worker#endif
231*58b9f456SAndroid Build Coastguard Worker
232*58b9f456SAndroid Build Coastguard Worker// __scan_keyword
233*58b9f456SAndroid Build Coastguard Worker// Scans [__b, __e) until a match is found in the basic_strings range
234*58b9f456SAndroid Build Coastguard Worker//  [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke).
235*58b9f456SAndroid Build Coastguard Worker//  __b will be incremented (visibly), consuming CharT until a match is found
236*58b9f456SAndroid Build Coastguard Worker//  or proved to not exist.  A keyword may be "", in which will match anything.
237*58b9f456SAndroid Build Coastguard Worker//  If one keyword is a prefix of another, and the next CharT in the input
238*58b9f456SAndroid Build Coastguard Worker//  might match another keyword, the algorithm will attempt to find the longest
239*58b9f456SAndroid Build Coastguard Worker//  matching keyword.  If the longer matching keyword ends up not matching, then
240*58b9f456SAndroid Build Coastguard Worker//  no keyword match is found.  If no keyword match is found, __ke is returned
241*58b9f456SAndroid Build Coastguard Worker//  and failbit is set in __err.
242*58b9f456SAndroid Build Coastguard Worker//  Else an iterator pointing to the matching keyword is found.  If more than
243*58b9f456SAndroid Build Coastguard Worker//  one keyword matches, an iterator to the first matching keyword is returned.
244*58b9f456SAndroid Build Coastguard Worker//  If on exit __b == __e, eofbit is set in __err.  If __case_sensitive is false,
245*58b9f456SAndroid Build Coastguard Worker//  __ct is used to force to lower case before comparing characters.
246*58b9f456SAndroid Build Coastguard Worker//  Examples:
247*58b9f456SAndroid Build Coastguard Worker//  Keywords:  "a", "abb"
248*58b9f456SAndroid Build Coastguard Worker//  If the input is "a", the first keyword matches and eofbit is set.
249*58b9f456SAndroid Build Coastguard Worker//  If the input is "abc", no match is found and "ab" are consumed.
250*58b9f456SAndroid Build Coastguard Workertemplate <class _InputIterator, class _ForwardIterator, class _Ctype>
251*58b9f456SAndroid Build Coastguard Worker_LIBCPP_HIDDEN
252*58b9f456SAndroid Build Coastguard Worker_ForwardIterator
253*58b9f456SAndroid Build Coastguard Worker__scan_keyword(_InputIterator& __b, _InputIterator __e,
254*58b9f456SAndroid Build Coastguard Worker               _ForwardIterator __kb, _ForwardIterator __ke,
255*58b9f456SAndroid Build Coastguard Worker               const _Ctype& __ct, ios_base::iostate& __err,
256*58b9f456SAndroid Build Coastguard Worker               bool __case_sensitive = true)
257*58b9f456SAndroid Build Coastguard Worker{
258*58b9f456SAndroid Build Coastguard Worker    typedef typename iterator_traits<_InputIterator>::value_type _CharT;
259*58b9f456SAndroid Build Coastguard Worker    size_t __nkw = static_cast<size_t>(_VSTD::distance(__kb, __ke));
260*58b9f456SAndroid Build Coastguard Worker    const unsigned char __doesnt_match = '\0';
261*58b9f456SAndroid Build Coastguard Worker    const unsigned char __might_match = '\1';
262*58b9f456SAndroid Build Coastguard Worker    const unsigned char __does_match = '\2';
263*58b9f456SAndroid Build Coastguard Worker    unsigned char __statbuf[100];
264*58b9f456SAndroid Build Coastguard Worker    unsigned char* __status = __statbuf;
265*58b9f456SAndroid Build Coastguard Worker    unique_ptr<unsigned char, void(*)(void*)> __stat_hold(0, free);
266*58b9f456SAndroid Build Coastguard Worker    if (__nkw > sizeof(__statbuf))
267*58b9f456SAndroid Build Coastguard Worker    {
268*58b9f456SAndroid Build Coastguard Worker        __status = (unsigned char*)malloc(__nkw);
269*58b9f456SAndroid Build Coastguard Worker        if (__status == 0)
270*58b9f456SAndroid Build Coastguard Worker            __throw_bad_alloc();
271*58b9f456SAndroid Build Coastguard Worker        __stat_hold.reset(__status);
272*58b9f456SAndroid Build Coastguard Worker    }
273*58b9f456SAndroid Build Coastguard Worker    size_t __n_might_match = __nkw;  // At this point, any keyword might match
274*58b9f456SAndroid Build Coastguard Worker    size_t __n_does_match = 0;       // but none of them definitely do
275*58b9f456SAndroid Build Coastguard Worker    // Initialize all statuses to __might_match, except for "" keywords are __does_match
276*58b9f456SAndroid Build Coastguard Worker    unsigned char* __st = __status;
277*58b9f456SAndroid Build Coastguard Worker    for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
278*58b9f456SAndroid Build Coastguard Worker    {
279*58b9f456SAndroid Build Coastguard Worker        if (!__ky->empty())
280*58b9f456SAndroid Build Coastguard Worker            *__st = __might_match;
281*58b9f456SAndroid Build Coastguard Worker        else
282*58b9f456SAndroid Build Coastguard Worker        {
283*58b9f456SAndroid Build Coastguard Worker            *__st = __does_match;
284*58b9f456SAndroid Build Coastguard Worker            --__n_might_match;
285*58b9f456SAndroid Build Coastguard Worker            ++__n_does_match;
286*58b9f456SAndroid Build Coastguard Worker        }
287*58b9f456SAndroid Build Coastguard Worker    }
288*58b9f456SAndroid Build Coastguard Worker    // While there might be a match, test keywords against the next CharT
289*58b9f456SAndroid Build Coastguard Worker    for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx)
290*58b9f456SAndroid Build Coastguard Worker    {
291*58b9f456SAndroid Build Coastguard Worker        // Peek at the next CharT but don't consume it
292*58b9f456SAndroid Build Coastguard Worker        _CharT __c = *__b;
293*58b9f456SAndroid Build Coastguard Worker        if (!__case_sensitive)
294*58b9f456SAndroid Build Coastguard Worker            __c = __ct.toupper(__c);
295*58b9f456SAndroid Build Coastguard Worker        bool __consume = false;
296*58b9f456SAndroid Build Coastguard Worker        // For each keyword which might match, see if the __indx character is __c
297*58b9f456SAndroid Build Coastguard Worker        // If a match if found, consume __c
298*58b9f456SAndroid Build Coastguard Worker        // If a match is found, and that is the last character in the keyword,
299*58b9f456SAndroid Build Coastguard Worker        //    then that keyword matches.
300*58b9f456SAndroid Build Coastguard Worker        // If the keyword doesn't match this character, then change the keyword
301*58b9f456SAndroid Build Coastguard Worker        //    to doesn't match
302*58b9f456SAndroid Build Coastguard Worker        __st = __status;
303*58b9f456SAndroid Build Coastguard Worker        for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
304*58b9f456SAndroid Build Coastguard Worker        {
305*58b9f456SAndroid Build Coastguard Worker            if (*__st == __might_match)
306*58b9f456SAndroid Build Coastguard Worker            {
307*58b9f456SAndroid Build Coastguard Worker                _CharT __kc = (*__ky)[__indx];
308*58b9f456SAndroid Build Coastguard Worker                if (!__case_sensitive)
309*58b9f456SAndroid Build Coastguard Worker                    __kc = __ct.toupper(__kc);
310*58b9f456SAndroid Build Coastguard Worker                if (__c == __kc)
311*58b9f456SAndroid Build Coastguard Worker                {
312*58b9f456SAndroid Build Coastguard Worker                    __consume = true;
313*58b9f456SAndroid Build Coastguard Worker                    if (__ky->size() == __indx+1)
314*58b9f456SAndroid Build Coastguard Worker                    {
315*58b9f456SAndroid Build Coastguard Worker                        *__st = __does_match;
316*58b9f456SAndroid Build Coastguard Worker                        --__n_might_match;
317*58b9f456SAndroid Build Coastguard Worker                        ++__n_does_match;
318*58b9f456SAndroid Build Coastguard Worker                    }
319*58b9f456SAndroid Build Coastguard Worker                }
320*58b9f456SAndroid Build Coastguard Worker                else
321*58b9f456SAndroid Build Coastguard Worker                {
322*58b9f456SAndroid Build Coastguard Worker                    *__st = __doesnt_match;
323*58b9f456SAndroid Build Coastguard Worker                    --__n_might_match;
324*58b9f456SAndroid Build Coastguard Worker                }
325*58b9f456SAndroid Build Coastguard Worker            }
326*58b9f456SAndroid Build Coastguard Worker        }
327*58b9f456SAndroid Build Coastguard Worker        // consume if we matched a character
328*58b9f456SAndroid Build Coastguard Worker        if (__consume)
329*58b9f456SAndroid Build Coastguard Worker        {
330*58b9f456SAndroid Build Coastguard Worker            ++__b;
331*58b9f456SAndroid Build Coastguard Worker            // If we consumed a character and there might be a matched keyword that
332*58b9f456SAndroid Build Coastguard Worker            //   was marked matched on a previous iteration, then such keywords
333*58b9f456SAndroid Build Coastguard Worker            //   which are now marked as not matching.
334*58b9f456SAndroid Build Coastguard Worker            if (__n_might_match + __n_does_match > 1)
335*58b9f456SAndroid Build Coastguard Worker            {
336*58b9f456SAndroid Build Coastguard Worker                __st = __status;
337*58b9f456SAndroid Build Coastguard Worker                for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
338*58b9f456SAndroid Build Coastguard Worker                {
339*58b9f456SAndroid Build Coastguard Worker                    if (*__st == __does_match && __ky->size() != __indx+1)
340*58b9f456SAndroid Build Coastguard Worker                    {
341*58b9f456SAndroid Build Coastguard Worker                        *__st = __doesnt_match;
342*58b9f456SAndroid Build Coastguard Worker                        --__n_does_match;
343*58b9f456SAndroid Build Coastguard Worker                    }
344*58b9f456SAndroid Build Coastguard Worker                }
345*58b9f456SAndroid Build Coastguard Worker            }
346*58b9f456SAndroid Build Coastguard Worker        }
347*58b9f456SAndroid Build Coastguard Worker    }
348*58b9f456SAndroid Build Coastguard Worker    // We've exited the loop because we hit eof and/or we have no more "might matches".
349*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
350*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
351*58b9f456SAndroid Build Coastguard Worker    // Return the first matching result
352*58b9f456SAndroid Build Coastguard Worker    for (__st = __status; __kb != __ke; ++__kb, (void) ++__st)
353*58b9f456SAndroid Build Coastguard Worker        if (*__st == __does_match)
354*58b9f456SAndroid Build Coastguard Worker            break;
355*58b9f456SAndroid Build Coastguard Worker    if (__kb == __ke)
356*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
357*58b9f456SAndroid Build Coastguard Worker    return __kb;
358*58b9f456SAndroid Build Coastguard Worker}
359*58b9f456SAndroid Build Coastguard Worker
360*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TYPE_VIS __num_get_base
361*58b9f456SAndroid Build Coastguard Worker{
362*58b9f456SAndroid Build Coastguard Worker    static const int __num_get_buf_sz = 40;
363*58b9f456SAndroid Build Coastguard Worker
364*58b9f456SAndroid Build Coastguard Worker    static int __get_base(ios_base&);
365*58b9f456SAndroid Build Coastguard Worker    static const char __src[33];
366*58b9f456SAndroid Build Coastguard Worker};
367*58b9f456SAndroid Build Coastguard Worker
368*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS
369*58b9f456SAndroid Build Coastguard Workervoid __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
370*58b9f456SAndroid Build Coastguard Worker                      ios_base::iostate& __err);
371*58b9f456SAndroid Build Coastguard Worker
372*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
373*58b9f456SAndroid Build Coastguard Workerstruct __num_get
374*58b9f456SAndroid Build Coastguard Worker    : protected __num_get_base
375*58b9f456SAndroid Build Coastguard Worker{
376*58b9f456SAndroid Build Coastguard Worker    static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
377*58b9f456SAndroid Build Coastguard Worker                                      _CharT& __thousands_sep);
378*58b9f456SAndroid Build Coastguard Worker
379*58b9f456SAndroid Build Coastguard Worker    static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp,
380*58b9f456SAndroid Build Coastguard Worker                                   char* __a, char*& __a_end,
381*58b9f456SAndroid Build Coastguard Worker                                   _CharT __decimal_point, _CharT __thousands_sep,
382*58b9f456SAndroid Build Coastguard Worker                                   const string& __grouping, unsigned* __g,
383*58b9f456SAndroid Build Coastguard Worker                                   unsigned*& __g_end, unsigned& __dc, _CharT* __atoms);
384*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
385*58b9f456SAndroid Build Coastguard Worker    static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
386*58b9f456SAndroid Build Coastguard Worker    static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
387*58b9f456SAndroid Build Coastguard Worker                  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
388*58b9f456SAndroid Build Coastguard Worker                  unsigned* __g, unsigned*& __g_end, _CharT* __atoms);
389*58b9f456SAndroid Build Coastguard Worker
390*58b9f456SAndroid Build Coastguard Worker#else
391*58b9f456SAndroid Build Coastguard Worker    static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep)
392*58b9f456SAndroid Build Coastguard Worker    {
393*58b9f456SAndroid Build Coastguard Worker        locale __loc = __iob.getloc();
394*58b9f456SAndroid Build Coastguard Worker        const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
395*58b9f456SAndroid Build Coastguard Worker        __thousands_sep = __np.thousands_sep();
396*58b9f456SAndroid Build Coastguard Worker        return __np.grouping();
397*58b9f456SAndroid Build Coastguard Worker    }
398*58b9f456SAndroid Build Coastguard Worker
399*58b9f456SAndroid Build Coastguard Worker    const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const
400*58b9f456SAndroid Build Coastguard Worker    {
401*58b9f456SAndroid Build Coastguard Worker      return __do_widen_p(__iob, __atoms);
402*58b9f456SAndroid Build Coastguard Worker    }
403*58b9f456SAndroid Build Coastguard Worker
404*58b9f456SAndroid Build Coastguard Worker
405*58b9f456SAndroid Build Coastguard Worker    static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
406*58b9f456SAndroid Build Coastguard Worker                  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
407*58b9f456SAndroid Build Coastguard Worker                  unsigned* __g, unsigned*& __g_end, const _CharT* __atoms);
408*58b9f456SAndroid Build Coastguard Workerprivate:
409*58b9f456SAndroid Build Coastguard Worker    template<typename T>
410*58b9f456SAndroid Build Coastguard Worker    const T* __do_widen_p(ios_base& __iob, T* __atoms) const
411*58b9f456SAndroid Build Coastguard Worker    {
412*58b9f456SAndroid Build Coastguard Worker      locale __loc = __iob.getloc();
413*58b9f456SAndroid Build Coastguard Worker      use_facet<ctype<T> >(__loc).widen(__src, __src + 26, __atoms);
414*58b9f456SAndroid Build Coastguard Worker      return __atoms;
415*58b9f456SAndroid Build Coastguard Worker    }
416*58b9f456SAndroid Build Coastguard Worker
417*58b9f456SAndroid Build Coastguard Worker    const char* __do_widen_p(ios_base& __iob, char* __atoms) const
418*58b9f456SAndroid Build Coastguard Worker    {
419*58b9f456SAndroid Build Coastguard Worker      (void)__iob;
420*58b9f456SAndroid Build Coastguard Worker      (void)__atoms;
421*58b9f456SAndroid Build Coastguard Worker      return __src;
422*58b9f456SAndroid Build Coastguard Worker    }
423*58b9f456SAndroid Build Coastguard Worker#endif
424*58b9f456SAndroid Build Coastguard Worker};
425*58b9f456SAndroid Build Coastguard Worker
426*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
427*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
428*58b9f456SAndroid Build Coastguard Workerstring
429*58b9f456SAndroid Build Coastguard Worker__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep)
430*58b9f456SAndroid Build Coastguard Worker{
431*58b9f456SAndroid Build Coastguard Worker    locale __loc = __iob.getloc();
432*58b9f456SAndroid Build Coastguard Worker    use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 26, __atoms);
433*58b9f456SAndroid Build Coastguard Worker    const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
434*58b9f456SAndroid Build Coastguard Worker    __thousands_sep = __np.thousands_sep();
435*58b9f456SAndroid Build Coastguard Worker    return __np.grouping();
436*58b9f456SAndroid Build Coastguard Worker}
437*58b9f456SAndroid Build Coastguard Worker#endif
438*58b9f456SAndroid Build Coastguard Worker
439*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
440*58b9f456SAndroid Build Coastguard Workerstring
441*58b9f456SAndroid Build Coastguard Worker__num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
442*58b9f456SAndroid Build Coastguard Worker                    _CharT& __thousands_sep)
443*58b9f456SAndroid Build Coastguard Worker{
444*58b9f456SAndroid Build Coastguard Worker    locale __loc = __iob.getloc();
445*58b9f456SAndroid Build Coastguard Worker    use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 32, __atoms);
446*58b9f456SAndroid Build Coastguard Worker    const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
447*58b9f456SAndroid Build Coastguard Worker    __decimal_point = __np.decimal_point();
448*58b9f456SAndroid Build Coastguard Worker    __thousands_sep = __np.thousands_sep();
449*58b9f456SAndroid Build Coastguard Worker    return __np.grouping();
450*58b9f456SAndroid Build Coastguard Worker}
451*58b9f456SAndroid Build Coastguard Worker
452*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
453*58b9f456SAndroid Build Coastguard Workerint
454*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
455*58b9f456SAndroid Build Coastguard Worker__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
456*58b9f456SAndroid Build Coastguard Worker                  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
457*58b9f456SAndroid Build Coastguard Worker                  unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
458*58b9f456SAndroid Build Coastguard Worker#else
459*58b9f456SAndroid Build Coastguard Worker__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
460*58b9f456SAndroid Build Coastguard Worker                  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
461*58b9f456SAndroid Build Coastguard Worker                  unsigned* __g, unsigned*& __g_end, const _CharT* __atoms)
462*58b9f456SAndroid Build Coastguard Worker
463*58b9f456SAndroid Build Coastguard Worker#endif
464*58b9f456SAndroid Build Coastguard Worker{
465*58b9f456SAndroid Build Coastguard Worker    if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25]))
466*58b9f456SAndroid Build Coastguard Worker    {
467*58b9f456SAndroid Build Coastguard Worker        *__a_end++ = __ct == __atoms[24] ? '+' : '-';
468*58b9f456SAndroid Build Coastguard Worker        __dc = 0;
469*58b9f456SAndroid Build Coastguard Worker        return 0;
470*58b9f456SAndroid Build Coastguard Worker    }
471*58b9f456SAndroid Build Coastguard Worker    if (__grouping.size() != 0 && __ct == __thousands_sep)
472*58b9f456SAndroid Build Coastguard Worker    {
473*58b9f456SAndroid Build Coastguard Worker        if (__g_end-__g < __num_get_buf_sz)
474*58b9f456SAndroid Build Coastguard Worker        {
475*58b9f456SAndroid Build Coastguard Worker            *__g_end++ = __dc;
476*58b9f456SAndroid Build Coastguard Worker            __dc = 0;
477*58b9f456SAndroid Build Coastguard Worker        }
478*58b9f456SAndroid Build Coastguard Worker        return 0;
479*58b9f456SAndroid Build Coastguard Worker    }
480*58b9f456SAndroid Build Coastguard Worker    ptrdiff_t __f = find(__atoms, __atoms + 26, __ct) - __atoms;
481*58b9f456SAndroid Build Coastguard Worker    if (__f >= 24)
482*58b9f456SAndroid Build Coastguard Worker        return -1;
483*58b9f456SAndroid Build Coastguard Worker    switch (__base)
484*58b9f456SAndroid Build Coastguard Worker    {
485*58b9f456SAndroid Build Coastguard Worker    case 8:
486*58b9f456SAndroid Build Coastguard Worker    case 10:
487*58b9f456SAndroid Build Coastguard Worker        if (__f >= __base)
488*58b9f456SAndroid Build Coastguard Worker            return -1;
489*58b9f456SAndroid Build Coastguard Worker        break;
490*58b9f456SAndroid Build Coastguard Worker    case 16:
491*58b9f456SAndroid Build Coastguard Worker        if (__f < 22)
492*58b9f456SAndroid Build Coastguard Worker            break;
493*58b9f456SAndroid Build Coastguard Worker        if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0')
494*58b9f456SAndroid Build Coastguard Worker        {
495*58b9f456SAndroid Build Coastguard Worker            __dc = 0;
496*58b9f456SAndroid Build Coastguard Worker            *__a_end++ = __src[__f];
497*58b9f456SAndroid Build Coastguard Worker            return 0;
498*58b9f456SAndroid Build Coastguard Worker        }
499*58b9f456SAndroid Build Coastguard Worker        return -1;
500*58b9f456SAndroid Build Coastguard Worker    }
501*58b9f456SAndroid Build Coastguard Worker    *__a_end++ = __src[__f];
502*58b9f456SAndroid Build Coastguard Worker    ++__dc;
503*58b9f456SAndroid Build Coastguard Worker    return 0;
504*58b9f456SAndroid Build Coastguard Worker}
505*58b9f456SAndroid Build Coastguard Worker
506*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
507*58b9f456SAndroid Build Coastguard Workerint
508*58b9f456SAndroid Build Coastguard Worker__num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end,
509*58b9f456SAndroid Build Coastguard Worker                    _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping,
510*58b9f456SAndroid Build Coastguard Worker                    unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms)
511*58b9f456SAndroid Build Coastguard Worker{
512*58b9f456SAndroid Build Coastguard Worker    if (__ct == __decimal_point)
513*58b9f456SAndroid Build Coastguard Worker    {
514*58b9f456SAndroid Build Coastguard Worker        if (!__in_units)
515*58b9f456SAndroid Build Coastguard Worker            return -1;
516*58b9f456SAndroid Build Coastguard Worker        __in_units = false;
517*58b9f456SAndroid Build Coastguard Worker        *__a_end++ = '.';
518*58b9f456SAndroid Build Coastguard Worker        if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
519*58b9f456SAndroid Build Coastguard Worker            *__g_end++ = __dc;
520*58b9f456SAndroid Build Coastguard Worker        return 0;
521*58b9f456SAndroid Build Coastguard Worker    }
522*58b9f456SAndroid Build Coastguard Worker    if (__ct == __thousands_sep && __grouping.size() != 0)
523*58b9f456SAndroid Build Coastguard Worker    {
524*58b9f456SAndroid Build Coastguard Worker        if (!__in_units)
525*58b9f456SAndroid Build Coastguard Worker            return -1;
526*58b9f456SAndroid Build Coastguard Worker        if (__g_end-__g < __num_get_buf_sz)
527*58b9f456SAndroid Build Coastguard Worker        {
528*58b9f456SAndroid Build Coastguard Worker            *__g_end++ = __dc;
529*58b9f456SAndroid Build Coastguard Worker            __dc = 0;
530*58b9f456SAndroid Build Coastguard Worker        }
531*58b9f456SAndroid Build Coastguard Worker        return 0;
532*58b9f456SAndroid Build Coastguard Worker    }
533*58b9f456SAndroid Build Coastguard Worker    ptrdiff_t __f = find(__atoms, __atoms + 32, __ct) - __atoms;
534*58b9f456SAndroid Build Coastguard Worker    if (__f >= 32)
535*58b9f456SAndroid Build Coastguard Worker        return -1;
536*58b9f456SAndroid Build Coastguard Worker    char __x = __src[__f];
537*58b9f456SAndroid Build Coastguard Worker    if (__x == '-' || __x == '+')
538*58b9f456SAndroid Build Coastguard Worker    {
539*58b9f456SAndroid Build Coastguard Worker        if (__a_end == __a || (__a_end[-1] & 0x5F) == (__exp & 0x7F))
540*58b9f456SAndroid Build Coastguard Worker        {
541*58b9f456SAndroid Build Coastguard Worker            *__a_end++ = __x;
542*58b9f456SAndroid Build Coastguard Worker            return 0;
543*58b9f456SAndroid Build Coastguard Worker        }
544*58b9f456SAndroid Build Coastguard Worker        return -1;
545*58b9f456SAndroid Build Coastguard Worker    }
546*58b9f456SAndroid Build Coastguard Worker    if (__x == 'x' || __x == 'X')
547*58b9f456SAndroid Build Coastguard Worker        __exp = 'P';
548*58b9f456SAndroid Build Coastguard Worker    else if ((__x & 0x5F) == __exp)
549*58b9f456SAndroid Build Coastguard Worker    {
550*58b9f456SAndroid Build Coastguard Worker        __exp |= 0x80;
551*58b9f456SAndroid Build Coastguard Worker        if (__in_units)
552*58b9f456SAndroid Build Coastguard Worker        {
553*58b9f456SAndroid Build Coastguard Worker            __in_units = false;
554*58b9f456SAndroid Build Coastguard Worker            if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
555*58b9f456SAndroid Build Coastguard Worker                *__g_end++ = __dc;
556*58b9f456SAndroid Build Coastguard Worker        }
557*58b9f456SAndroid Build Coastguard Worker    }
558*58b9f456SAndroid Build Coastguard Worker    *__a_end++ = __x;
559*58b9f456SAndroid Build Coastguard Worker    if (__f >= 22)
560*58b9f456SAndroid Build Coastguard Worker        return 0;
561*58b9f456SAndroid Build Coastguard Worker    ++__dc;
562*58b9f456SAndroid Build Coastguard Worker    return 0;
563*58b9f456SAndroid Build Coastguard Worker}
564*58b9f456SAndroid Build Coastguard Worker
565*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>)
566*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>)
567*58b9f456SAndroid Build Coastguard Worker
568*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
569*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS num_get
570*58b9f456SAndroid Build Coastguard Worker    : public locale::facet,
571*58b9f456SAndroid Build Coastguard Worker      private __num_get<_CharT>
572*58b9f456SAndroid Build Coastguard Worker{
573*58b9f456SAndroid Build Coastguard Workerpublic:
574*58b9f456SAndroid Build Coastguard Worker    typedef _CharT char_type;
575*58b9f456SAndroid Build Coastguard Worker    typedef _InputIterator iter_type;
576*58b9f456SAndroid Build Coastguard Worker
577*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
578*58b9f456SAndroid Build Coastguard Worker    explicit num_get(size_t __refs = 0)
579*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs) {}
580*58b9f456SAndroid Build Coastguard Worker
581*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
582*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
583*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, bool& __v) const
584*58b9f456SAndroid Build Coastguard Worker    {
585*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
586*58b9f456SAndroid Build Coastguard Worker    }
587*58b9f456SAndroid Build Coastguard Worker
588*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
589*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
590*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, long& __v) const
591*58b9f456SAndroid Build Coastguard Worker    {
592*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
593*58b9f456SAndroid Build Coastguard Worker    }
594*58b9f456SAndroid Build Coastguard Worker
595*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
596*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
597*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, long long& __v) const
598*58b9f456SAndroid Build Coastguard Worker    {
599*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
600*58b9f456SAndroid Build Coastguard Worker    }
601*58b9f456SAndroid Build Coastguard Worker
602*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
603*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
604*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, unsigned short& __v) const
605*58b9f456SAndroid Build Coastguard Worker    {
606*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
607*58b9f456SAndroid Build Coastguard Worker    }
608*58b9f456SAndroid Build Coastguard Worker
609*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
610*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
611*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, unsigned int& __v) const
612*58b9f456SAndroid Build Coastguard Worker    {
613*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
614*58b9f456SAndroid Build Coastguard Worker    }
615*58b9f456SAndroid Build Coastguard Worker
616*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
617*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
618*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, unsigned long& __v) const
619*58b9f456SAndroid Build Coastguard Worker    {
620*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
621*58b9f456SAndroid Build Coastguard Worker    }
622*58b9f456SAndroid Build Coastguard Worker
623*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
624*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
625*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, unsigned long long& __v) const
626*58b9f456SAndroid Build Coastguard Worker    {
627*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
628*58b9f456SAndroid Build Coastguard Worker    }
629*58b9f456SAndroid Build Coastguard Worker
630*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
631*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
632*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, float& __v) const
633*58b9f456SAndroid Build Coastguard Worker    {
634*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
635*58b9f456SAndroid Build Coastguard Worker    }
636*58b9f456SAndroid Build Coastguard Worker
637*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
638*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
639*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, double& __v) const
640*58b9f456SAndroid Build Coastguard Worker    {
641*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
642*58b9f456SAndroid Build Coastguard Worker    }
643*58b9f456SAndroid Build Coastguard Worker
644*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
645*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
646*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, long double& __v) const
647*58b9f456SAndroid Build Coastguard Worker    {
648*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
649*58b9f456SAndroid Build Coastguard Worker    }
650*58b9f456SAndroid Build Coastguard Worker
651*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
652*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
653*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, void*& __v) const
654*58b9f456SAndroid Build Coastguard Worker    {
655*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __v);
656*58b9f456SAndroid Build Coastguard Worker    }
657*58b9f456SAndroid Build Coastguard Worker
658*58b9f456SAndroid Build Coastguard Worker    static locale::id id;
659*58b9f456SAndroid Build Coastguard Worker
660*58b9f456SAndroid Build Coastguard Workerprotected:
661*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
662*58b9f456SAndroid Build Coastguard Worker    ~num_get() {}
663*58b9f456SAndroid Build Coastguard Worker
664*58b9f456SAndroid Build Coastguard Worker    template <class _Fp>
665*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
666*58b9f456SAndroid Build Coastguard Worker    iter_type __do_get_floating_point
667*58b9f456SAndroid Build Coastguard Worker                            (iter_type __b, iter_type __e, ios_base& __iob,
668*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, _Fp& __v) const;
669*58b9f456SAndroid Build Coastguard Worker
670*58b9f456SAndroid Build Coastguard Worker    template <class _Signed>
671*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
672*58b9f456SAndroid Build Coastguard Worker    iter_type __do_get_signed
673*58b9f456SAndroid Build Coastguard Worker                            (iter_type __b, iter_type __e, ios_base& __iob,
674*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, _Signed& __v) const;
675*58b9f456SAndroid Build Coastguard Worker
676*58b9f456SAndroid Build Coastguard Worker    template <class _Unsigned>
677*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
678*58b9f456SAndroid Build Coastguard Worker    iter_type __do_get_unsigned
679*58b9f456SAndroid Build Coastguard Worker                            (iter_type __b, iter_type __e, ios_base& __iob,
680*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, _Unsigned& __v) const;
681*58b9f456SAndroid Build Coastguard Worker
682*58b9f456SAndroid Build Coastguard Worker
683*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
684*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, bool& __v) const;
685*58b9f456SAndroid Build Coastguard Worker
686*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
687*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, long& __v) const
688*58b9f456SAndroid Build Coastguard Worker    { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); }
689*58b9f456SAndroid Build Coastguard Worker
690*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
691*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, long long& __v) const
692*58b9f456SAndroid Build Coastguard Worker    { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); }
693*58b9f456SAndroid Build Coastguard Worker
694*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
695*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, unsigned short& __v) const
696*58b9f456SAndroid Build Coastguard Worker    { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
697*58b9f456SAndroid Build Coastguard Worker
698*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
699*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, unsigned int& __v) const
700*58b9f456SAndroid Build Coastguard Worker    { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
701*58b9f456SAndroid Build Coastguard Worker
702*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
703*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, unsigned long& __v) const
704*58b9f456SAndroid Build Coastguard Worker    { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
705*58b9f456SAndroid Build Coastguard Worker
706*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
707*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, unsigned long long& __v) const
708*58b9f456SAndroid Build Coastguard Worker    { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
709*58b9f456SAndroid Build Coastguard Worker
710*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
711*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, float& __v) const
712*58b9f456SAndroid Build Coastguard Worker    { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); }
713*58b9f456SAndroid Build Coastguard Worker
714*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
715*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, double& __v) const
716*58b9f456SAndroid Build Coastguard Worker    { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); }
717*58b9f456SAndroid Build Coastguard Worker
718*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
719*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, long double& __v) const
720*58b9f456SAndroid Build Coastguard Worker    { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); }
721*58b9f456SAndroid Build Coastguard Worker
722*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
723*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, void*& __v) const;
724*58b9f456SAndroid Build Coastguard Worker};
725*58b9f456SAndroid Build Coastguard Worker
726*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
727*58b9f456SAndroid Build Coastguard Workerlocale::id
728*58b9f456SAndroid Build Coastguard Workernum_get<_CharT, _InputIterator>::id;
729*58b9f456SAndroid Build Coastguard Worker
730*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
731*58b9f456SAndroid Build Coastguard Worker_LIBCPP_HIDDEN _Tp
732*58b9f456SAndroid Build Coastguard Worker__num_get_signed_integral(const char* __a, const char* __a_end,
733*58b9f456SAndroid Build Coastguard Worker                          ios_base::iostate& __err, int __base)
734*58b9f456SAndroid Build Coastguard Worker{
735*58b9f456SAndroid Build Coastguard Worker    if (__a != __a_end)
736*58b9f456SAndroid Build Coastguard Worker    {
737*58b9f456SAndroid Build Coastguard Worker        typename remove_reference<decltype(errno)>::type __save_errno = errno;
738*58b9f456SAndroid Build Coastguard Worker        errno = 0;
739*58b9f456SAndroid Build Coastguard Worker        char *__p2;
740*58b9f456SAndroid Build Coastguard Worker        long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
741*58b9f456SAndroid Build Coastguard Worker        typename remove_reference<decltype(errno)>::type __current_errno = errno;
742*58b9f456SAndroid Build Coastguard Worker        if (__current_errno == 0)
743*58b9f456SAndroid Build Coastguard Worker            errno = __save_errno;
744*58b9f456SAndroid Build Coastguard Worker        if (__p2 != __a_end)
745*58b9f456SAndroid Build Coastguard Worker        {
746*58b9f456SAndroid Build Coastguard Worker            __err = ios_base::failbit;
747*58b9f456SAndroid Build Coastguard Worker            return 0;
748*58b9f456SAndroid Build Coastguard Worker        }
749*58b9f456SAndroid Build Coastguard Worker        else if (__current_errno == ERANGE         ||
750*58b9f456SAndroid Build Coastguard Worker                 __ll < numeric_limits<_Tp>::min() ||
751*58b9f456SAndroid Build Coastguard Worker                 numeric_limits<_Tp>::max() < __ll)
752*58b9f456SAndroid Build Coastguard Worker        {
753*58b9f456SAndroid Build Coastguard Worker            __err = ios_base::failbit;
754*58b9f456SAndroid Build Coastguard Worker            if (__ll > 0)
755*58b9f456SAndroid Build Coastguard Worker                return numeric_limits<_Tp>::max();
756*58b9f456SAndroid Build Coastguard Worker            else
757*58b9f456SAndroid Build Coastguard Worker                return numeric_limits<_Tp>::min();
758*58b9f456SAndroid Build Coastguard Worker        }
759*58b9f456SAndroid Build Coastguard Worker        return static_cast<_Tp>(__ll);
760*58b9f456SAndroid Build Coastguard Worker    }
761*58b9f456SAndroid Build Coastguard Worker    __err = ios_base::failbit;
762*58b9f456SAndroid Build Coastguard Worker    return 0;
763*58b9f456SAndroid Build Coastguard Worker}
764*58b9f456SAndroid Build Coastguard Worker
765*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
766*58b9f456SAndroid Build Coastguard Worker_LIBCPP_HIDDEN _Tp
767*58b9f456SAndroid Build Coastguard Worker__num_get_unsigned_integral(const char* __a, const char* __a_end,
768*58b9f456SAndroid Build Coastguard Worker                            ios_base::iostate& __err, int __base)
769*58b9f456SAndroid Build Coastguard Worker{
770*58b9f456SAndroid Build Coastguard Worker    if (__a != __a_end)
771*58b9f456SAndroid Build Coastguard Worker    {
772*58b9f456SAndroid Build Coastguard Worker        const bool __negate = *__a == '-';
773*58b9f456SAndroid Build Coastguard Worker        if (__negate && ++__a == __a_end) {
774*58b9f456SAndroid Build Coastguard Worker          __err = ios_base::failbit;
775*58b9f456SAndroid Build Coastguard Worker          return 0;
776*58b9f456SAndroid Build Coastguard Worker        }
777*58b9f456SAndroid Build Coastguard Worker        typename remove_reference<decltype(errno)>::type __save_errno = errno;
778*58b9f456SAndroid Build Coastguard Worker        errno = 0;
779*58b9f456SAndroid Build Coastguard Worker        char *__p2;
780*58b9f456SAndroid Build Coastguard Worker        unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
781*58b9f456SAndroid Build Coastguard Worker        typename remove_reference<decltype(errno)>::type __current_errno = errno;
782*58b9f456SAndroid Build Coastguard Worker        if (__current_errno == 0)
783*58b9f456SAndroid Build Coastguard Worker            errno = __save_errno;
784*58b9f456SAndroid Build Coastguard Worker        if (__p2 != __a_end)
785*58b9f456SAndroid Build Coastguard Worker        {
786*58b9f456SAndroid Build Coastguard Worker            __err = ios_base::failbit;
787*58b9f456SAndroid Build Coastguard Worker            return 0;
788*58b9f456SAndroid Build Coastguard Worker        }
789*58b9f456SAndroid Build Coastguard Worker        else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll)
790*58b9f456SAndroid Build Coastguard Worker        {
791*58b9f456SAndroid Build Coastguard Worker            __err = ios_base::failbit;
792*58b9f456SAndroid Build Coastguard Worker            return numeric_limits<_Tp>::max();
793*58b9f456SAndroid Build Coastguard Worker        }
794*58b9f456SAndroid Build Coastguard Worker        _Tp __res = static_cast<_Tp>(__ll);
795*58b9f456SAndroid Build Coastguard Worker        if (__negate) __res = -__res;
796*58b9f456SAndroid Build Coastguard Worker        return __res;
797*58b9f456SAndroid Build Coastguard Worker    }
798*58b9f456SAndroid Build Coastguard Worker    __err = ios_base::failbit;
799*58b9f456SAndroid Build Coastguard Worker    return 0;
800*58b9f456SAndroid Build Coastguard Worker}
801*58b9f456SAndroid Build Coastguard Worker
802*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
803*58b9f456SAndroid Build Coastguard Worker_LIBCPP_INLINE_VISIBILITY
804*58b9f456SAndroid Build Coastguard Worker_Tp __do_strtod(const char* __a, char** __p2);
805*58b9f456SAndroid Build Coastguard Worker
806*58b9f456SAndroid Build Coastguard Workertemplate <>
807*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
808*58b9f456SAndroid Build Coastguard Workerfloat __do_strtod<float>(const char* __a, char** __p2) {
809*58b9f456SAndroid Build Coastguard Worker    return strtof_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
810*58b9f456SAndroid Build Coastguard Worker}
811*58b9f456SAndroid Build Coastguard Worker
812*58b9f456SAndroid Build Coastguard Workertemplate <>
813*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
814*58b9f456SAndroid Build Coastguard Workerdouble __do_strtod<double>(const char* __a, char** __p2) {
815*58b9f456SAndroid Build Coastguard Worker    return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
816*58b9f456SAndroid Build Coastguard Worker}
817*58b9f456SAndroid Build Coastguard Worker
818*58b9f456SAndroid Build Coastguard Workertemplate <>
819*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
820*58b9f456SAndroid Build Coastguard Workerlong double __do_strtod<long double>(const char* __a, char** __p2) {
821*58b9f456SAndroid Build Coastguard Worker    return strtold_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
822*58b9f456SAndroid Build Coastguard Worker}
823*58b9f456SAndroid Build Coastguard Worker
824*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
825*58b9f456SAndroid Build Coastguard Worker_LIBCPP_HIDDEN
826*58b9f456SAndroid Build Coastguard Worker_Tp
827*58b9f456SAndroid Build Coastguard Worker__num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err)
828*58b9f456SAndroid Build Coastguard Worker{
829*58b9f456SAndroid Build Coastguard Worker    if (__a != __a_end)
830*58b9f456SAndroid Build Coastguard Worker    {
831*58b9f456SAndroid Build Coastguard Worker        typename remove_reference<decltype(errno)>::type __save_errno = errno;
832*58b9f456SAndroid Build Coastguard Worker        errno = 0;
833*58b9f456SAndroid Build Coastguard Worker        char *__p2;
834*58b9f456SAndroid Build Coastguard Worker        _Tp __ld = __do_strtod<_Tp>(__a, &__p2);
835*58b9f456SAndroid Build Coastguard Worker        typename remove_reference<decltype(errno)>::type __current_errno = errno;
836*58b9f456SAndroid Build Coastguard Worker        if (__current_errno == 0)
837*58b9f456SAndroid Build Coastguard Worker            errno = __save_errno;
838*58b9f456SAndroid Build Coastguard Worker        if (__p2 != __a_end)
839*58b9f456SAndroid Build Coastguard Worker        {
840*58b9f456SAndroid Build Coastguard Worker            __err = ios_base::failbit;
841*58b9f456SAndroid Build Coastguard Worker            return 0;
842*58b9f456SAndroid Build Coastguard Worker        }
843*58b9f456SAndroid Build Coastguard Worker        else if (__current_errno == ERANGE)
844*58b9f456SAndroid Build Coastguard Worker            __err = ios_base::failbit;
845*58b9f456SAndroid Build Coastguard Worker        return __ld;
846*58b9f456SAndroid Build Coastguard Worker    }
847*58b9f456SAndroid Build Coastguard Worker    __err = ios_base::failbit;
848*58b9f456SAndroid Build Coastguard Worker    return 0;
849*58b9f456SAndroid Build Coastguard Worker}
850*58b9f456SAndroid Build Coastguard Worker
851*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
852*58b9f456SAndroid Build Coastguard Worker_InputIterator
853*58b9f456SAndroid Build Coastguard Workernum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
854*58b9f456SAndroid Build Coastguard Worker                                        ios_base& __iob,
855*58b9f456SAndroid Build Coastguard Worker                                        ios_base::iostate& __err,
856*58b9f456SAndroid Build Coastguard Worker                                        bool& __v) const
857*58b9f456SAndroid Build Coastguard Worker{
858*58b9f456SAndroid Build Coastguard Worker    if ((__iob.flags() & ios_base::boolalpha) == 0)
859*58b9f456SAndroid Build Coastguard Worker    {
860*58b9f456SAndroid Build Coastguard Worker        long __lv = -1;
861*58b9f456SAndroid Build Coastguard Worker        __b = do_get(__b, __e, __iob, __err, __lv);
862*58b9f456SAndroid Build Coastguard Worker        switch (__lv)
863*58b9f456SAndroid Build Coastguard Worker        {
864*58b9f456SAndroid Build Coastguard Worker        case 0:
865*58b9f456SAndroid Build Coastguard Worker            __v = false;
866*58b9f456SAndroid Build Coastguard Worker            break;
867*58b9f456SAndroid Build Coastguard Worker        case 1:
868*58b9f456SAndroid Build Coastguard Worker            __v = true;
869*58b9f456SAndroid Build Coastguard Worker            break;
870*58b9f456SAndroid Build Coastguard Worker        default:
871*58b9f456SAndroid Build Coastguard Worker            __v = true;
872*58b9f456SAndroid Build Coastguard Worker            __err = ios_base::failbit;
873*58b9f456SAndroid Build Coastguard Worker            break;
874*58b9f456SAndroid Build Coastguard Worker        }
875*58b9f456SAndroid Build Coastguard Worker        return __b;
876*58b9f456SAndroid Build Coastguard Worker    }
877*58b9f456SAndroid Build Coastguard Worker    const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__iob.getloc());
878*58b9f456SAndroid Build Coastguard Worker    const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__iob.getloc());
879*58b9f456SAndroid Build Coastguard Worker    typedef typename numpunct<_CharT>::string_type string_type;
880*58b9f456SAndroid Build Coastguard Worker    const string_type __names[2] = {__np.truename(), __np.falsename()};
881*58b9f456SAndroid Build Coastguard Worker    const string_type* __i = __scan_keyword(__b, __e, __names, __names+2,
882*58b9f456SAndroid Build Coastguard Worker                                            __ct, __err);
883*58b9f456SAndroid Build Coastguard Worker    __v = __i == __names;
884*58b9f456SAndroid Build Coastguard Worker    return __b;
885*58b9f456SAndroid Build Coastguard Worker}
886*58b9f456SAndroid Build Coastguard Worker
887*58b9f456SAndroid Build Coastguard Worker// signed
888*58b9f456SAndroid Build Coastguard Worker
889*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
890*58b9f456SAndroid Build Coastguard Workertemplate <class _Signed>
891*58b9f456SAndroid Build Coastguard Worker_InputIterator
892*58b9f456SAndroid Build Coastguard Workernum_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e,
893*58b9f456SAndroid Build Coastguard Worker                                        ios_base& __iob,
894*58b9f456SAndroid Build Coastguard Worker                                        ios_base::iostate& __err,
895*58b9f456SAndroid Build Coastguard Worker                                        _Signed& __v) const
896*58b9f456SAndroid Build Coastguard Worker{
897*58b9f456SAndroid Build Coastguard Worker    // Stage 1
898*58b9f456SAndroid Build Coastguard Worker    int __base = this->__get_base(__iob);
899*58b9f456SAndroid Build Coastguard Worker    // Stage 2
900*58b9f456SAndroid Build Coastguard Worker    char_type __thousands_sep;
901*58b9f456SAndroid Build Coastguard Worker    const int __atoms_size = 26;
902*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
903*58b9f456SAndroid Build Coastguard Worker    char_type __atoms1[__atoms_size];
904*58b9f456SAndroid Build Coastguard Worker    const char_type *__atoms = this->__do_widen(__iob, __atoms1);
905*58b9f456SAndroid Build Coastguard Worker    string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
906*58b9f456SAndroid Build Coastguard Worker#else
907*58b9f456SAndroid Build Coastguard Worker    char_type __atoms[__atoms_size];
908*58b9f456SAndroid Build Coastguard Worker    string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
909*58b9f456SAndroid Build Coastguard Worker#endif
910*58b9f456SAndroid Build Coastguard Worker    string __buf;
911*58b9f456SAndroid Build Coastguard Worker    __buf.resize(__buf.capacity());
912*58b9f456SAndroid Build Coastguard Worker    char* __a = &__buf[0];
913*58b9f456SAndroid Build Coastguard Worker    char* __a_end = __a;
914*58b9f456SAndroid Build Coastguard Worker    unsigned __g[__num_get_base::__num_get_buf_sz];
915*58b9f456SAndroid Build Coastguard Worker    unsigned* __g_end = __g;
916*58b9f456SAndroid Build Coastguard Worker    unsigned __dc = 0;
917*58b9f456SAndroid Build Coastguard Worker    for (; __b != __e; ++__b)
918*58b9f456SAndroid Build Coastguard Worker    {
919*58b9f456SAndroid Build Coastguard Worker        if (__a_end == __a + __buf.size())
920*58b9f456SAndroid Build Coastguard Worker        {
921*58b9f456SAndroid Build Coastguard Worker            size_t __tmp = __buf.size();
922*58b9f456SAndroid Build Coastguard Worker            __buf.resize(2*__buf.size());
923*58b9f456SAndroid Build Coastguard Worker            __buf.resize(__buf.capacity());
924*58b9f456SAndroid Build Coastguard Worker            __a = &__buf[0];
925*58b9f456SAndroid Build Coastguard Worker            __a_end = __a + __tmp;
926*58b9f456SAndroid Build Coastguard Worker        }
927*58b9f456SAndroid Build Coastguard Worker        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
928*58b9f456SAndroid Build Coastguard Worker                                    __thousands_sep, __grouping, __g, __g_end,
929*58b9f456SAndroid Build Coastguard Worker                                    __atoms))
930*58b9f456SAndroid Build Coastguard Worker            break;
931*58b9f456SAndroid Build Coastguard Worker    }
932*58b9f456SAndroid Build Coastguard Worker    if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
933*58b9f456SAndroid Build Coastguard Worker        *__g_end++ = __dc;
934*58b9f456SAndroid Build Coastguard Worker    // Stage 3
935*58b9f456SAndroid Build Coastguard Worker    __v = __num_get_signed_integral<_Signed>(__a, __a_end, __err, __base);
936*58b9f456SAndroid Build Coastguard Worker    // Digit grouping checked
937*58b9f456SAndroid Build Coastguard Worker    __check_grouping(__grouping, __g, __g_end, __err);
938*58b9f456SAndroid Build Coastguard Worker    // EOF checked
939*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
940*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
941*58b9f456SAndroid Build Coastguard Worker    return __b;
942*58b9f456SAndroid Build Coastguard Worker}
943*58b9f456SAndroid Build Coastguard Worker
944*58b9f456SAndroid Build Coastguard Worker// unsigned
945*58b9f456SAndroid Build Coastguard Worker
946*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
947*58b9f456SAndroid Build Coastguard Workertemplate <class _Unsigned>
948*58b9f456SAndroid Build Coastguard Worker_InputIterator
949*58b9f456SAndroid Build Coastguard Workernum_get<_CharT, _InputIterator>::__do_get_unsigned(iter_type __b, iter_type __e,
950*58b9f456SAndroid Build Coastguard Worker                                        ios_base& __iob,
951*58b9f456SAndroid Build Coastguard Worker                                        ios_base::iostate& __err,
952*58b9f456SAndroid Build Coastguard Worker                                        _Unsigned& __v) const
953*58b9f456SAndroid Build Coastguard Worker{
954*58b9f456SAndroid Build Coastguard Worker    // Stage 1
955*58b9f456SAndroid Build Coastguard Worker    int __base = this->__get_base(__iob);
956*58b9f456SAndroid Build Coastguard Worker    // Stage 2
957*58b9f456SAndroid Build Coastguard Worker    char_type __thousands_sep;
958*58b9f456SAndroid Build Coastguard Worker    const int __atoms_size = 26;
959*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
960*58b9f456SAndroid Build Coastguard Worker    char_type __atoms1[__atoms_size];
961*58b9f456SAndroid Build Coastguard Worker    const char_type *__atoms = this->__do_widen(__iob, __atoms1);
962*58b9f456SAndroid Build Coastguard Worker    string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
963*58b9f456SAndroid Build Coastguard Worker#else
964*58b9f456SAndroid Build Coastguard Worker    char_type __atoms[__atoms_size];
965*58b9f456SAndroid Build Coastguard Worker    string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
966*58b9f456SAndroid Build Coastguard Worker#endif
967*58b9f456SAndroid Build Coastguard Worker    string __buf;
968*58b9f456SAndroid Build Coastguard Worker    __buf.resize(__buf.capacity());
969*58b9f456SAndroid Build Coastguard Worker    char* __a = &__buf[0];
970*58b9f456SAndroid Build Coastguard Worker    char* __a_end = __a;
971*58b9f456SAndroid Build Coastguard Worker    unsigned __g[__num_get_base::__num_get_buf_sz];
972*58b9f456SAndroid Build Coastguard Worker    unsigned* __g_end = __g;
973*58b9f456SAndroid Build Coastguard Worker    unsigned __dc = 0;
974*58b9f456SAndroid Build Coastguard Worker    for (; __b != __e; ++__b)
975*58b9f456SAndroid Build Coastguard Worker    {
976*58b9f456SAndroid Build Coastguard Worker        if (__a_end == __a + __buf.size())
977*58b9f456SAndroid Build Coastguard Worker        {
978*58b9f456SAndroid Build Coastguard Worker            size_t __tmp = __buf.size();
979*58b9f456SAndroid Build Coastguard Worker            __buf.resize(2*__buf.size());
980*58b9f456SAndroid Build Coastguard Worker            __buf.resize(__buf.capacity());
981*58b9f456SAndroid Build Coastguard Worker            __a = &__buf[0];
982*58b9f456SAndroid Build Coastguard Worker            __a_end = __a + __tmp;
983*58b9f456SAndroid Build Coastguard Worker        }
984*58b9f456SAndroid Build Coastguard Worker        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
985*58b9f456SAndroid Build Coastguard Worker                                    __thousands_sep, __grouping, __g, __g_end,
986*58b9f456SAndroid Build Coastguard Worker                                    __atoms))
987*58b9f456SAndroid Build Coastguard Worker            break;
988*58b9f456SAndroid Build Coastguard Worker    }
989*58b9f456SAndroid Build Coastguard Worker    if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
990*58b9f456SAndroid Build Coastguard Worker        *__g_end++ = __dc;
991*58b9f456SAndroid Build Coastguard Worker    // Stage 3
992*58b9f456SAndroid Build Coastguard Worker    __v = __num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base);
993*58b9f456SAndroid Build Coastguard Worker    // Digit grouping checked
994*58b9f456SAndroid Build Coastguard Worker    __check_grouping(__grouping, __g, __g_end, __err);
995*58b9f456SAndroid Build Coastguard Worker    // EOF checked
996*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
997*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
998*58b9f456SAndroid Build Coastguard Worker    return __b;
999*58b9f456SAndroid Build Coastguard Worker}
1000*58b9f456SAndroid Build Coastguard Worker
1001*58b9f456SAndroid Build Coastguard Worker// floating point
1002*58b9f456SAndroid Build Coastguard Worker
1003*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1004*58b9f456SAndroid Build Coastguard Workertemplate <class _Fp>
1005*58b9f456SAndroid Build Coastguard Worker_InputIterator
1006*58b9f456SAndroid Build Coastguard Workernum_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_type __e,
1007*58b9f456SAndroid Build Coastguard Worker                                        ios_base& __iob,
1008*58b9f456SAndroid Build Coastguard Worker                                        ios_base::iostate& __err,
1009*58b9f456SAndroid Build Coastguard Worker                                        _Fp& __v) const
1010*58b9f456SAndroid Build Coastguard Worker{
1011*58b9f456SAndroid Build Coastguard Worker    // Stage 1, nothing to do
1012*58b9f456SAndroid Build Coastguard Worker    // Stage 2
1013*58b9f456SAndroid Build Coastguard Worker    char_type __atoms[32];
1014*58b9f456SAndroid Build Coastguard Worker    char_type __decimal_point;
1015*58b9f456SAndroid Build Coastguard Worker    char_type __thousands_sep;
1016*58b9f456SAndroid Build Coastguard Worker    string __grouping = this->__stage2_float_prep(__iob, __atoms,
1017*58b9f456SAndroid Build Coastguard Worker                                                  __decimal_point,
1018*58b9f456SAndroid Build Coastguard Worker                                                  __thousands_sep);
1019*58b9f456SAndroid Build Coastguard Worker    string __buf;
1020*58b9f456SAndroid Build Coastguard Worker    __buf.resize(__buf.capacity());
1021*58b9f456SAndroid Build Coastguard Worker    char* __a = &__buf[0];
1022*58b9f456SAndroid Build Coastguard Worker    char* __a_end = __a;
1023*58b9f456SAndroid Build Coastguard Worker    unsigned __g[__num_get_base::__num_get_buf_sz];
1024*58b9f456SAndroid Build Coastguard Worker    unsigned* __g_end = __g;
1025*58b9f456SAndroid Build Coastguard Worker    unsigned __dc = 0;
1026*58b9f456SAndroid Build Coastguard Worker    bool __in_units = true;
1027*58b9f456SAndroid Build Coastguard Worker    char __exp = 'E';
1028*58b9f456SAndroid Build Coastguard Worker    for (; __b != __e; ++__b)
1029*58b9f456SAndroid Build Coastguard Worker    {
1030*58b9f456SAndroid Build Coastguard Worker        if (__a_end == __a + __buf.size())
1031*58b9f456SAndroid Build Coastguard Worker        {
1032*58b9f456SAndroid Build Coastguard Worker            size_t __tmp = __buf.size();
1033*58b9f456SAndroid Build Coastguard Worker            __buf.resize(2*__buf.size());
1034*58b9f456SAndroid Build Coastguard Worker            __buf.resize(__buf.capacity());
1035*58b9f456SAndroid Build Coastguard Worker            __a = &__buf[0];
1036*58b9f456SAndroid Build Coastguard Worker            __a_end = __a + __tmp;
1037*58b9f456SAndroid Build Coastguard Worker        }
1038*58b9f456SAndroid Build Coastguard Worker        if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
1039*58b9f456SAndroid Build Coastguard Worker                                      __decimal_point, __thousands_sep,
1040*58b9f456SAndroid Build Coastguard Worker                                      __grouping, __g, __g_end,
1041*58b9f456SAndroid Build Coastguard Worker                                      __dc, __atoms))
1042*58b9f456SAndroid Build Coastguard Worker            break;
1043*58b9f456SAndroid Build Coastguard Worker    }
1044*58b9f456SAndroid Build Coastguard Worker    if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
1045*58b9f456SAndroid Build Coastguard Worker        *__g_end++ = __dc;
1046*58b9f456SAndroid Build Coastguard Worker    // Stage 3
1047*58b9f456SAndroid Build Coastguard Worker    __v = __num_get_float<_Fp>(__a, __a_end, __err);
1048*58b9f456SAndroid Build Coastguard Worker    // Digit grouping checked
1049*58b9f456SAndroid Build Coastguard Worker    __check_grouping(__grouping, __g, __g_end, __err);
1050*58b9f456SAndroid Build Coastguard Worker    // EOF checked
1051*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
1052*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
1053*58b9f456SAndroid Build Coastguard Worker    return __b;
1054*58b9f456SAndroid Build Coastguard Worker}
1055*58b9f456SAndroid Build Coastguard Worker
1056*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1057*58b9f456SAndroid Build Coastguard Worker_InputIterator
1058*58b9f456SAndroid Build Coastguard Workernum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
1059*58b9f456SAndroid Build Coastguard Worker                                        ios_base& __iob,
1060*58b9f456SAndroid Build Coastguard Worker                                        ios_base::iostate& __err,
1061*58b9f456SAndroid Build Coastguard Worker                                        void*& __v) const
1062*58b9f456SAndroid Build Coastguard Worker{
1063*58b9f456SAndroid Build Coastguard Worker    // Stage 1
1064*58b9f456SAndroid Build Coastguard Worker    int __base = 16;
1065*58b9f456SAndroid Build Coastguard Worker    // Stage 2
1066*58b9f456SAndroid Build Coastguard Worker    char_type __atoms[26];
1067*58b9f456SAndroid Build Coastguard Worker    char_type __thousands_sep = 0;
1068*58b9f456SAndroid Build Coastguard Worker    string __grouping;
1069*58b9f456SAndroid Build Coastguard Worker    use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src,
1070*58b9f456SAndroid Build Coastguard Worker                                                    __num_get_base::__src + 26, __atoms);
1071*58b9f456SAndroid Build Coastguard Worker    string __buf;
1072*58b9f456SAndroid Build Coastguard Worker    __buf.resize(__buf.capacity());
1073*58b9f456SAndroid Build Coastguard Worker    char* __a = &__buf[0];
1074*58b9f456SAndroid Build Coastguard Worker    char* __a_end = __a;
1075*58b9f456SAndroid Build Coastguard Worker    unsigned __g[__num_get_base::__num_get_buf_sz];
1076*58b9f456SAndroid Build Coastguard Worker    unsigned* __g_end = __g;
1077*58b9f456SAndroid Build Coastguard Worker    unsigned __dc = 0;
1078*58b9f456SAndroid Build Coastguard Worker    for (; __b != __e; ++__b)
1079*58b9f456SAndroid Build Coastguard Worker    {
1080*58b9f456SAndroid Build Coastguard Worker        if (__a_end == __a + __buf.size())
1081*58b9f456SAndroid Build Coastguard Worker        {
1082*58b9f456SAndroid Build Coastguard Worker            size_t __tmp = __buf.size();
1083*58b9f456SAndroid Build Coastguard Worker            __buf.resize(2*__buf.size());
1084*58b9f456SAndroid Build Coastguard Worker            __buf.resize(__buf.capacity());
1085*58b9f456SAndroid Build Coastguard Worker            __a = &__buf[0];
1086*58b9f456SAndroid Build Coastguard Worker            __a_end = __a + __tmp;
1087*58b9f456SAndroid Build Coastguard Worker        }
1088*58b9f456SAndroid Build Coastguard Worker        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
1089*58b9f456SAndroid Build Coastguard Worker                                    __thousands_sep, __grouping,
1090*58b9f456SAndroid Build Coastguard Worker                                    __g, __g_end, __atoms))
1091*58b9f456SAndroid Build Coastguard Worker            break;
1092*58b9f456SAndroid Build Coastguard Worker    }
1093*58b9f456SAndroid Build Coastguard Worker    // Stage 3
1094*58b9f456SAndroid Build Coastguard Worker    __buf.resize(__a_end - __a);
1095*58b9f456SAndroid Build Coastguard Worker    if (__libcpp_sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
1096*58b9f456SAndroid Build Coastguard Worker        __err = ios_base::failbit;
1097*58b9f456SAndroid Build Coastguard Worker    // EOF checked
1098*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
1099*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
1100*58b9f456SAndroid Build Coastguard Worker    return __b;
1101*58b9f456SAndroid Build Coastguard Worker}
1102*58b9f456SAndroid Build Coastguard Worker
1103*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>)
1104*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>)
1105*58b9f456SAndroid Build Coastguard Worker
1106*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TYPE_VIS __num_put_base
1107*58b9f456SAndroid Build Coastguard Worker{
1108*58b9f456SAndroid Build Coastguard Workerprotected:
1109*58b9f456SAndroid Build Coastguard Worker    static void __format_int(char* __fmt, const char* __len, bool __signd,
1110*58b9f456SAndroid Build Coastguard Worker                             ios_base::fmtflags __flags);
1111*58b9f456SAndroid Build Coastguard Worker    static bool __format_float(char* __fmt, const char* __len,
1112*58b9f456SAndroid Build Coastguard Worker                               ios_base::fmtflags __flags);
1113*58b9f456SAndroid Build Coastguard Worker    static char* __identify_padding(char* __nb, char* __ne,
1114*58b9f456SAndroid Build Coastguard Worker                                    const ios_base& __iob);
1115*58b9f456SAndroid Build Coastguard Worker};
1116*58b9f456SAndroid Build Coastguard Worker
1117*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
1118*58b9f456SAndroid Build Coastguard Workerstruct __num_put
1119*58b9f456SAndroid Build Coastguard Worker    : protected __num_put_base
1120*58b9f456SAndroid Build Coastguard Worker{
1121*58b9f456SAndroid Build Coastguard Worker    static void __widen_and_group_int(char* __nb, char* __np, char* __ne,
1122*58b9f456SAndroid Build Coastguard Worker                                      _CharT* __ob, _CharT*& __op, _CharT*& __oe,
1123*58b9f456SAndroid Build Coastguard Worker                                      const locale& __loc);
1124*58b9f456SAndroid Build Coastguard Worker    static void __widen_and_group_float(char* __nb, char* __np, char* __ne,
1125*58b9f456SAndroid Build Coastguard Worker                                        _CharT* __ob, _CharT*& __op, _CharT*& __oe,
1126*58b9f456SAndroid Build Coastguard Worker                                        const locale& __loc);
1127*58b9f456SAndroid Build Coastguard Worker};
1128*58b9f456SAndroid Build Coastguard Worker
1129*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
1130*58b9f456SAndroid Build Coastguard Workervoid
1131*58b9f456SAndroid Build Coastguard Worker__num_put<_CharT>::__widen_and_group_int(char* __nb, char* __np, char* __ne,
1132*58b9f456SAndroid Build Coastguard Worker                                         _CharT* __ob, _CharT*& __op, _CharT*& __oe,
1133*58b9f456SAndroid Build Coastguard Worker                                         const locale& __loc)
1134*58b9f456SAndroid Build Coastguard Worker{
1135*58b9f456SAndroid Build Coastguard Worker    const ctype<_CharT>&    __ct = use_facet<ctype<_CharT> >   (__loc);
1136*58b9f456SAndroid Build Coastguard Worker    const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc);
1137*58b9f456SAndroid Build Coastguard Worker    string __grouping = __npt.grouping();
1138*58b9f456SAndroid Build Coastguard Worker    if (__grouping.empty())
1139*58b9f456SAndroid Build Coastguard Worker    {
1140*58b9f456SAndroid Build Coastguard Worker        __ct.widen(__nb, __ne, __ob);
1141*58b9f456SAndroid Build Coastguard Worker        __oe = __ob + (__ne - __nb);
1142*58b9f456SAndroid Build Coastguard Worker    }
1143*58b9f456SAndroid Build Coastguard Worker    else
1144*58b9f456SAndroid Build Coastguard Worker    {
1145*58b9f456SAndroid Build Coastguard Worker        __oe = __ob;
1146*58b9f456SAndroid Build Coastguard Worker        char* __nf = __nb;
1147*58b9f456SAndroid Build Coastguard Worker        if (*__nf == '-' || *__nf == '+')
1148*58b9f456SAndroid Build Coastguard Worker            *__oe++ = __ct.widen(*__nf++);
1149*58b9f456SAndroid Build Coastguard Worker        if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' ||
1150*58b9f456SAndroid Build Coastguard Worker                                                   __nf[1] == 'X'))
1151*58b9f456SAndroid Build Coastguard Worker        {
1152*58b9f456SAndroid Build Coastguard Worker            *__oe++ = __ct.widen(*__nf++);
1153*58b9f456SAndroid Build Coastguard Worker            *__oe++ = __ct.widen(*__nf++);
1154*58b9f456SAndroid Build Coastguard Worker        }
1155*58b9f456SAndroid Build Coastguard Worker        reverse(__nf, __ne);
1156*58b9f456SAndroid Build Coastguard Worker        _CharT __thousands_sep = __npt.thousands_sep();
1157*58b9f456SAndroid Build Coastguard Worker        unsigned __dc = 0;
1158*58b9f456SAndroid Build Coastguard Worker        unsigned __dg = 0;
1159*58b9f456SAndroid Build Coastguard Worker        for (char* __p = __nf; __p < __ne; ++__p)
1160*58b9f456SAndroid Build Coastguard Worker        {
1161*58b9f456SAndroid Build Coastguard Worker            if (static_cast<unsigned>(__grouping[__dg]) > 0 &&
1162*58b9f456SAndroid Build Coastguard Worker                __dc == static_cast<unsigned>(__grouping[__dg]))
1163*58b9f456SAndroid Build Coastguard Worker            {
1164*58b9f456SAndroid Build Coastguard Worker                *__oe++ = __thousands_sep;
1165*58b9f456SAndroid Build Coastguard Worker                __dc = 0;
1166*58b9f456SAndroid Build Coastguard Worker                if (__dg < __grouping.size()-1)
1167*58b9f456SAndroid Build Coastguard Worker                    ++__dg;
1168*58b9f456SAndroid Build Coastguard Worker            }
1169*58b9f456SAndroid Build Coastguard Worker            *__oe++ = __ct.widen(*__p);
1170*58b9f456SAndroid Build Coastguard Worker            ++__dc;
1171*58b9f456SAndroid Build Coastguard Worker        }
1172*58b9f456SAndroid Build Coastguard Worker        reverse(__ob + (__nf - __nb), __oe);
1173*58b9f456SAndroid Build Coastguard Worker    }
1174*58b9f456SAndroid Build Coastguard Worker    if (__np == __ne)
1175*58b9f456SAndroid Build Coastguard Worker        __op = __oe;
1176*58b9f456SAndroid Build Coastguard Worker    else
1177*58b9f456SAndroid Build Coastguard Worker        __op = __ob + (__np - __nb);
1178*58b9f456SAndroid Build Coastguard Worker}
1179*58b9f456SAndroid Build Coastguard Worker
1180*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
1181*58b9f456SAndroid Build Coastguard Workervoid
1182*58b9f456SAndroid Build Coastguard Worker__num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne,
1183*58b9f456SAndroid Build Coastguard Worker                                           _CharT* __ob, _CharT*& __op, _CharT*& __oe,
1184*58b9f456SAndroid Build Coastguard Worker                                           const locale& __loc)
1185*58b9f456SAndroid Build Coastguard Worker{
1186*58b9f456SAndroid Build Coastguard Worker    const ctype<_CharT>&    __ct = use_facet<ctype<_CharT> >   (__loc);
1187*58b9f456SAndroid Build Coastguard Worker    const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc);
1188*58b9f456SAndroid Build Coastguard Worker    string __grouping = __npt.grouping();
1189*58b9f456SAndroid Build Coastguard Worker    __oe = __ob;
1190*58b9f456SAndroid Build Coastguard Worker    char* __nf = __nb;
1191*58b9f456SAndroid Build Coastguard Worker    if (*__nf == '-' || *__nf == '+')
1192*58b9f456SAndroid Build Coastguard Worker        *__oe++ = __ct.widen(*__nf++);
1193*58b9f456SAndroid Build Coastguard Worker    char* __ns;
1194*58b9f456SAndroid Build Coastguard Worker    if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' ||
1195*58b9f456SAndroid Build Coastguard Worker                                               __nf[1] == 'X'))
1196*58b9f456SAndroid Build Coastguard Worker    {
1197*58b9f456SAndroid Build Coastguard Worker        *__oe++ = __ct.widen(*__nf++);
1198*58b9f456SAndroid Build Coastguard Worker        *__oe++ = __ct.widen(*__nf++);
1199*58b9f456SAndroid Build Coastguard Worker        for (__ns = __nf; __ns < __ne; ++__ns)
1200*58b9f456SAndroid Build Coastguard Worker            if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE))
1201*58b9f456SAndroid Build Coastguard Worker                break;
1202*58b9f456SAndroid Build Coastguard Worker    }
1203*58b9f456SAndroid Build Coastguard Worker    else
1204*58b9f456SAndroid Build Coastguard Worker    {
1205*58b9f456SAndroid Build Coastguard Worker        for (__ns = __nf; __ns < __ne; ++__ns)
1206*58b9f456SAndroid Build Coastguard Worker            if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE))
1207*58b9f456SAndroid Build Coastguard Worker                break;
1208*58b9f456SAndroid Build Coastguard Worker    }
1209*58b9f456SAndroid Build Coastguard Worker    if (__grouping.empty())
1210*58b9f456SAndroid Build Coastguard Worker    {
1211*58b9f456SAndroid Build Coastguard Worker        __ct.widen(__nf, __ns, __oe);
1212*58b9f456SAndroid Build Coastguard Worker        __oe += __ns - __nf;
1213*58b9f456SAndroid Build Coastguard Worker    }
1214*58b9f456SAndroid Build Coastguard Worker    else
1215*58b9f456SAndroid Build Coastguard Worker    {
1216*58b9f456SAndroid Build Coastguard Worker        reverse(__nf, __ns);
1217*58b9f456SAndroid Build Coastguard Worker        _CharT __thousands_sep = __npt.thousands_sep();
1218*58b9f456SAndroid Build Coastguard Worker        unsigned __dc = 0;
1219*58b9f456SAndroid Build Coastguard Worker        unsigned __dg = 0;
1220*58b9f456SAndroid Build Coastguard Worker        for (char* __p = __nf; __p < __ns; ++__p)
1221*58b9f456SAndroid Build Coastguard Worker        {
1222*58b9f456SAndroid Build Coastguard Worker            if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg]))
1223*58b9f456SAndroid Build Coastguard Worker            {
1224*58b9f456SAndroid Build Coastguard Worker                *__oe++ = __thousands_sep;
1225*58b9f456SAndroid Build Coastguard Worker                __dc = 0;
1226*58b9f456SAndroid Build Coastguard Worker                if (__dg < __grouping.size()-1)
1227*58b9f456SAndroid Build Coastguard Worker                    ++__dg;
1228*58b9f456SAndroid Build Coastguard Worker            }
1229*58b9f456SAndroid Build Coastguard Worker            *__oe++ = __ct.widen(*__p);
1230*58b9f456SAndroid Build Coastguard Worker            ++__dc;
1231*58b9f456SAndroid Build Coastguard Worker        }
1232*58b9f456SAndroid Build Coastguard Worker        reverse(__ob + (__nf - __nb), __oe);
1233*58b9f456SAndroid Build Coastguard Worker    }
1234*58b9f456SAndroid Build Coastguard Worker    for (__nf = __ns; __nf < __ne; ++__nf)
1235*58b9f456SAndroid Build Coastguard Worker    {
1236*58b9f456SAndroid Build Coastguard Worker        if (*__nf == '.')
1237*58b9f456SAndroid Build Coastguard Worker        {
1238*58b9f456SAndroid Build Coastguard Worker            *__oe++ = __npt.decimal_point();
1239*58b9f456SAndroid Build Coastguard Worker            ++__nf;
1240*58b9f456SAndroid Build Coastguard Worker            break;
1241*58b9f456SAndroid Build Coastguard Worker        }
1242*58b9f456SAndroid Build Coastguard Worker        else
1243*58b9f456SAndroid Build Coastguard Worker            *__oe++ = __ct.widen(*__nf);
1244*58b9f456SAndroid Build Coastguard Worker    }
1245*58b9f456SAndroid Build Coastguard Worker    __ct.widen(__nf, __ne, __oe);
1246*58b9f456SAndroid Build Coastguard Worker    __oe += __ne - __nf;
1247*58b9f456SAndroid Build Coastguard Worker    if (__np == __ne)
1248*58b9f456SAndroid Build Coastguard Worker        __op = __oe;
1249*58b9f456SAndroid Build Coastguard Worker    else
1250*58b9f456SAndroid Build Coastguard Worker        __op = __ob + (__np - __nb);
1251*58b9f456SAndroid Build Coastguard Worker}
1252*58b9f456SAndroid Build Coastguard Worker
1253*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>)
1254*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>)
1255*58b9f456SAndroid Build Coastguard Worker
1256*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
1257*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS num_put
1258*58b9f456SAndroid Build Coastguard Worker    : public locale::facet,
1259*58b9f456SAndroid Build Coastguard Worker      private __num_put<_CharT>
1260*58b9f456SAndroid Build Coastguard Worker{
1261*58b9f456SAndroid Build Coastguard Workerpublic:
1262*58b9f456SAndroid Build Coastguard Worker    typedef _CharT char_type;
1263*58b9f456SAndroid Build Coastguard Worker    typedef _OutputIterator iter_type;
1264*58b9f456SAndroid Build Coastguard Worker
1265*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1266*58b9f456SAndroid Build Coastguard Worker    explicit num_put(size_t __refs = 0)
1267*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs) {}
1268*58b9f456SAndroid Build Coastguard Worker
1269*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1270*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1271*58b9f456SAndroid Build Coastguard Worker                  bool __v) const
1272*58b9f456SAndroid Build Coastguard Worker    {
1273*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, __v);
1274*58b9f456SAndroid Build Coastguard Worker    }
1275*58b9f456SAndroid Build Coastguard Worker
1276*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1277*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1278*58b9f456SAndroid Build Coastguard Worker                  long __v) const
1279*58b9f456SAndroid Build Coastguard Worker    {
1280*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, __v);
1281*58b9f456SAndroid Build Coastguard Worker    }
1282*58b9f456SAndroid Build Coastguard Worker
1283*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1284*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1285*58b9f456SAndroid Build Coastguard Worker                  long long __v) const
1286*58b9f456SAndroid Build Coastguard Worker    {
1287*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, __v);
1288*58b9f456SAndroid Build Coastguard Worker    }
1289*58b9f456SAndroid Build Coastguard Worker
1290*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1291*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1292*58b9f456SAndroid Build Coastguard Worker                  unsigned long __v) const
1293*58b9f456SAndroid Build Coastguard Worker    {
1294*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, __v);
1295*58b9f456SAndroid Build Coastguard Worker    }
1296*58b9f456SAndroid Build Coastguard Worker
1297*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1298*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1299*58b9f456SAndroid Build Coastguard Worker                  unsigned long long __v) const
1300*58b9f456SAndroid Build Coastguard Worker    {
1301*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, __v);
1302*58b9f456SAndroid Build Coastguard Worker    }
1303*58b9f456SAndroid Build Coastguard Worker
1304*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1305*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1306*58b9f456SAndroid Build Coastguard Worker                  double __v) const
1307*58b9f456SAndroid Build Coastguard Worker    {
1308*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, __v);
1309*58b9f456SAndroid Build Coastguard Worker    }
1310*58b9f456SAndroid Build Coastguard Worker
1311*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1312*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1313*58b9f456SAndroid Build Coastguard Worker                  long double __v) const
1314*58b9f456SAndroid Build Coastguard Worker    {
1315*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, __v);
1316*58b9f456SAndroid Build Coastguard Worker    }
1317*58b9f456SAndroid Build Coastguard Worker
1318*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1319*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
1320*58b9f456SAndroid Build Coastguard Worker                  const void* __v) const
1321*58b9f456SAndroid Build Coastguard Worker    {
1322*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, __v);
1323*58b9f456SAndroid Build Coastguard Worker    }
1324*58b9f456SAndroid Build Coastguard Worker
1325*58b9f456SAndroid Build Coastguard Worker    static locale::id id;
1326*58b9f456SAndroid Build Coastguard Worker
1327*58b9f456SAndroid Build Coastguard Workerprotected:
1328*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1329*58b9f456SAndroid Build Coastguard Worker    ~num_put() {}
1330*58b9f456SAndroid Build Coastguard Worker
1331*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1332*58b9f456SAndroid Build Coastguard Worker                             bool __v) const;
1333*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1334*58b9f456SAndroid Build Coastguard Worker                             long __v) const;
1335*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1336*58b9f456SAndroid Build Coastguard Worker                             long long __v) const;
1337*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1338*58b9f456SAndroid Build Coastguard Worker                             unsigned long) const;
1339*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1340*58b9f456SAndroid Build Coastguard Worker                             unsigned long long) const;
1341*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1342*58b9f456SAndroid Build Coastguard Worker                             double __v) const;
1343*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1344*58b9f456SAndroid Build Coastguard Worker                             long double __v) const;
1345*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
1346*58b9f456SAndroid Build Coastguard Worker                             const void* __v) const;
1347*58b9f456SAndroid Build Coastguard Worker};
1348*58b9f456SAndroid Build Coastguard Worker
1349*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1350*58b9f456SAndroid Build Coastguard Workerlocale::id
1351*58b9f456SAndroid Build Coastguard Workernum_put<_CharT, _OutputIterator>::id;
1352*58b9f456SAndroid Build Coastguard Worker
1353*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1354*58b9f456SAndroid Build Coastguard Worker_LIBCPP_HIDDEN
1355*58b9f456SAndroid Build Coastguard Worker_OutputIterator
1356*58b9f456SAndroid Build Coastguard Worker__pad_and_output(_OutputIterator __s,
1357*58b9f456SAndroid Build Coastguard Worker                 const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
1358*58b9f456SAndroid Build Coastguard Worker                 ios_base& __iob, _CharT __fl)
1359*58b9f456SAndroid Build Coastguard Worker{
1360*58b9f456SAndroid Build Coastguard Worker    streamsize __sz = __oe - __ob;
1361*58b9f456SAndroid Build Coastguard Worker    streamsize __ns = __iob.width();
1362*58b9f456SAndroid Build Coastguard Worker    if (__ns > __sz)
1363*58b9f456SAndroid Build Coastguard Worker        __ns -= __sz;
1364*58b9f456SAndroid Build Coastguard Worker    else
1365*58b9f456SAndroid Build Coastguard Worker        __ns = 0;
1366*58b9f456SAndroid Build Coastguard Worker    for (;__ob < __op; ++__ob, ++__s)
1367*58b9f456SAndroid Build Coastguard Worker        *__s = *__ob;
1368*58b9f456SAndroid Build Coastguard Worker    for (; __ns; --__ns, ++__s)
1369*58b9f456SAndroid Build Coastguard Worker        *__s = __fl;
1370*58b9f456SAndroid Build Coastguard Worker    for (; __ob < __oe; ++__ob, ++__s)
1371*58b9f456SAndroid Build Coastguard Worker        *__s = *__ob;
1372*58b9f456SAndroid Build Coastguard Worker    __iob.width(0);
1373*58b9f456SAndroid Build Coastguard Worker    return __s;
1374*58b9f456SAndroid Build Coastguard Worker}
1375*58b9f456SAndroid Build Coastguard Worker
1376*58b9f456SAndroid Build Coastguard Worker#if !defined(__APPLE__) || \
1377*58b9f456SAndroid Build Coastguard Worker    (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1378*58b9f456SAndroid Build Coastguard Worker    (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1379*58b9f456SAndroid Build Coastguard Worker
1380*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _Traits>
1381*58b9f456SAndroid Build Coastguard Worker_LIBCPP_HIDDEN
1382*58b9f456SAndroid Build Coastguard Workerostreambuf_iterator<_CharT, _Traits>
1383*58b9f456SAndroid Build Coastguard Worker__pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s,
1384*58b9f456SAndroid Build Coastguard Worker                 const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
1385*58b9f456SAndroid Build Coastguard Worker                 ios_base& __iob, _CharT __fl)
1386*58b9f456SAndroid Build Coastguard Worker{
1387*58b9f456SAndroid Build Coastguard Worker    if (__s.__sbuf_ == nullptr)
1388*58b9f456SAndroid Build Coastguard Worker        return __s;
1389*58b9f456SAndroid Build Coastguard Worker    streamsize __sz = __oe - __ob;
1390*58b9f456SAndroid Build Coastguard Worker    streamsize __ns = __iob.width();
1391*58b9f456SAndroid Build Coastguard Worker    if (__ns > __sz)
1392*58b9f456SAndroid Build Coastguard Worker        __ns -= __sz;
1393*58b9f456SAndroid Build Coastguard Worker    else
1394*58b9f456SAndroid Build Coastguard Worker        __ns = 0;
1395*58b9f456SAndroid Build Coastguard Worker    streamsize __np = __op - __ob;
1396*58b9f456SAndroid Build Coastguard Worker    if (__np > 0)
1397*58b9f456SAndroid Build Coastguard Worker    {
1398*58b9f456SAndroid Build Coastguard Worker        if (__s.__sbuf_->sputn(__ob, __np) != __np)
1399*58b9f456SAndroid Build Coastguard Worker        {
1400*58b9f456SAndroid Build Coastguard Worker            __s.__sbuf_ = nullptr;
1401*58b9f456SAndroid Build Coastguard Worker            return __s;
1402*58b9f456SAndroid Build Coastguard Worker        }
1403*58b9f456SAndroid Build Coastguard Worker    }
1404*58b9f456SAndroid Build Coastguard Worker    if (__ns > 0)
1405*58b9f456SAndroid Build Coastguard Worker    {
1406*58b9f456SAndroid Build Coastguard Worker        basic_string<_CharT, _Traits> __sp(__ns, __fl);
1407*58b9f456SAndroid Build Coastguard Worker        if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns)
1408*58b9f456SAndroid Build Coastguard Worker        {
1409*58b9f456SAndroid Build Coastguard Worker            __s.__sbuf_ = nullptr;
1410*58b9f456SAndroid Build Coastguard Worker            return __s;
1411*58b9f456SAndroid Build Coastguard Worker        }
1412*58b9f456SAndroid Build Coastguard Worker    }
1413*58b9f456SAndroid Build Coastguard Worker    __np = __oe - __op;
1414*58b9f456SAndroid Build Coastguard Worker    if (__np > 0)
1415*58b9f456SAndroid Build Coastguard Worker    {
1416*58b9f456SAndroid Build Coastguard Worker        if (__s.__sbuf_->sputn(__op, __np) != __np)
1417*58b9f456SAndroid Build Coastguard Worker        {
1418*58b9f456SAndroid Build Coastguard Worker            __s.__sbuf_ = nullptr;
1419*58b9f456SAndroid Build Coastguard Worker            return __s;
1420*58b9f456SAndroid Build Coastguard Worker        }
1421*58b9f456SAndroid Build Coastguard Worker    }
1422*58b9f456SAndroid Build Coastguard Worker    __iob.width(0);
1423*58b9f456SAndroid Build Coastguard Worker    return __s;
1424*58b9f456SAndroid Build Coastguard Worker}
1425*58b9f456SAndroid Build Coastguard Worker
1426*58b9f456SAndroid Build Coastguard Worker#endif
1427*58b9f456SAndroid Build Coastguard Worker
1428*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1429*58b9f456SAndroid Build Coastguard Worker_OutputIterator
1430*58b9f456SAndroid Build Coastguard Workernum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1431*58b9f456SAndroid Build Coastguard Worker                                         char_type __fl, bool __v) const
1432*58b9f456SAndroid Build Coastguard Worker{
1433*58b9f456SAndroid Build Coastguard Worker    if ((__iob.flags() & ios_base::boolalpha) == 0)
1434*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, (unsigned long)__v);
1435*58b9f456SAndroid Build Coastguard Worker    const numpunct<char_type>& __np = use_facet<numpunct<char_type> >(__iob.getloc());
1436*58b9f456SAndroid Build Coastguard Worker    typedef typename numpunct<char_type>::string_type string_type;
1437*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_DEBUG_LEVEL >= 2
1438*58b9f456SAndroid Build Coastguard Worker    string_type __tmp(__v ? __np.truename() : __np.falsename());
1439*58b9f456SAndroid Build Coastguard Worker    string_type __nm = _VSTD::move(__tmp);
1440*58b9f456SAndroid Build Coastguard Worker#else
1441*58b9f456SAndroid Build Coastguard Worker    string_type __nm = __v ? __np.truename() : __np.falsename();
1442*58b9f456SAndroid Build Coastguard Worker#endif
1443*58b9f456SAndroid Build Coastguard Worker    for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s)
1444*58b9f456SAndroid Build Coastguard Worker        *__s = *__i;
1445*58b9f456SAndroid Build Coastguard Worker    return __s;
1446*58b9f456SAndroid Build Coastguard Worker}
1447*58b9f456SAndroid Build Coastguard Worker
1448*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1449*58b9f456SAndroid Build Coastguard Worker_OutputIterator
1450*58b9f456SAndroid Build Coastguard Workernum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1451*58b9f456SAndroid Build Coastguard Worker                                         char_type __fl, long __v) const
1452*58b9f456SAndroid Build Coastguard Worker{
1453*58b9f456SAndroid Build Coastguard Worker    // Stage 1 - Get number in narrow char
1454*58b9f456SAndroid Build Coastguard Worker    char __fmt[6] = {'%', 0};
1455*58b9f456SAndroid Build Coastguard Worker    const char* __len = "l";
1456*58b9f456SAndroid Build Coastguard Worker    this->__format_int(__fmt+1, __len, true, __iob.flags());
1457*58b9f456SAndroid Build Coastguard Worker    const unsigned __nbuf = (numeric_limits<long>::digits / 3)
1458*58b9f456SAndroid Build Coastguard Worker                          + ((numeric_limits<long>::digits % 3) != 0)
1459*58b9f456SAndroid Build Coastguard Worker                          + ((__iob.flags() & ios_base::showbase) != 0)
1460*58b9f456SAndroid Build Coastguard Worker                          + 2;
1461*58b9f456SAndroid Build Coastguard Worker    char __nar[__nbuf];
1462*58b9f456SAndroid Build Coastguard Worker    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1463*58b9f456SAndroid Build Coastguard Worker    char* __ne = __nar + __nc;
1464*58b9f456SAndroid Build Coastguard Worker    char* __np = this->__identify_padding(__nar, __ne, __iob);
1465*58b9f456SAndroid Build Coastguard Worker    // Stage 2 - Widen __nar while adding thousands separators
1466*58b9f456SAndroid Build Coastguard Worker    char_type __o[2*(__nbuf-1) - 1];
1467*58b9f456SAndroid Build Coastguard Worker    char_type* __op;  // pad here
1468*58b9f456SAndroid Build Coastguard Worker    char_type* __oe;  // end of output
1469*58b9f456SAndroid Build Coastguard Worker    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1470*58b9f456SAndroid Build Coastguard Worker    // [__o, __oe) contains thousands_sep'd wide number
1471*58b9f456SAndroid Build Coastguard Worker    // Stage 3 & 4
1472*58b9f456SAndroid Build Coastguard Worker    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1473*58b9f456SAndroid Build Coastguard Worker}
1474*58b9f456SAndroid Build Coastguard Worker
1475*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1476*58b9f456SAndroid Build Coastguard Worker_OutputIterator
1477*58b9f456SAndroid Build Coastguard Workernum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1478*58b9f456SAndroid Build Coastguard Worker                                         char_type __fl, long long __v) const
1479*58b9f456SAndroid Build Coastguard Worker{
1480*58b9f456SAndroid Build Coastguard Worker    // Stage 1 - Get number in narrow char
1481*58b9f456SAndroid Build Coastguard Worker    char __fmt[8] = {'%', 0};
1482*58b9f456SAndroid Build Coastguard Worker    const char* __len = "ll";
1483*58b9f456SAndroid Build Coastguard Worker    this->__format_int(__fmt+1, __len, true, __iob.flags());
1484*58b9f456SAndroid Build Coastguard Worker    const unsigned __nbuf = (numeric_limits<long long>::digits / 3)
1485*58b9f456SAndroid Build Coastguard Worker                          + ((numeric_limits<long long>::digits % 3) != 0)
1486*58b9f456SAndroid Build Coastguard Worker                          + ((__iob.flags() & ios_base::showbase) != 0)
1487*58b9f456SAndroid Build Coastguard Worker                          + 2;
1488*58b9f456SAndroid Build Coastguard Worker    char __nar[__nbuf];
1489*58b9f456SAndroid Build Coastguard Worker    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1490*58b9f456SAndroid Build Coastguard Worker    char* __ne = __nar + __nc;
1491*58b9f456SAndroid Build Coastguard Worker    char* __np = this->__identify_padding(__nar, __ne, __iob);
1492*58b9f456SAndroid Build Coastguard Worker    // Stage 2 - Widen __nar while adding thousands separators
1493*58b9f456SAndroid Build Coastguard Worker    char_type __o[2*(__nbuf-1) - 1];
1494*58b9f456SAndroid Build Coastguard Worker    char_type* __op;  // pad here
1495*58b9f456SAndroid Build Coastguard Worker    char_type* __oe;  // end of output
1496*58b9f456SAndroid Build Coastguard Worker    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1497*58b9f456SAndroid Build Coastguard Worker    // [__o, __oe) contains thousands_sep'd wide number
1498*58b9f456SAndroid Build Coastguard Worker    // Stage 3 & 4
1499*58b9f456SAndroid Build Coastguard Worker    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1500*58b9f456SAndroid Build Coastguard Worker}
1501*58b9f456SAndroid Build Coastguard Worker
1502*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1503*58b9f456SAndroid Build Coastguard Worker_OutputIterator
1504*58b9f456SAndroid Build Coastguard Workernum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1505*58b9f456SAndroid Build Coastguard Worker                                         char_type __fl, unsigned long __v) const
1506*58b9f456SAndroid Build Coastguard Worker{
1507*58b9f456SAndroid Build Coastguard Worker    // Stage 1 - Get number in narrow char
1508*58b9f456SAndroid Build Coastguard Worker    char __fmt[6] = {'%', 0};
1509*58b9f456SAndroid Build Coastguard Worker    const char* __len = "l";
1510*58b9f456SAndroid Build Coastguard Worker    this->__format_int(__fmt+1, __len, false, __iob.flags());
1511*58b9f456SAndroid Build Coastguard Worker    const unsigned __nbuf = (numeric_limits<unsigned long>::digits / 3)
1512*58b9f456SAndroid Build Coastguard Worker                          + ((numeric_limits<unsigned long>::digits % 3) != 0)
1513*58b9f456SAndroid Build Coastguard Worker                          + ((__iob.flags() & ios_base::showbase) != 0)
1514*58b9f456SAndroid Build Coastguard Worker                          + 1;
1515*58b9f456SAndroid Build Coastguard Worker    char __nar[__nbuf];
1516*58b9f456SAndroid Build Coastguard Worker    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1517*58b9f456SAndroid Build Coastguard Worker    char* __ne = __nar + __nc;
1518*58b9f456SAndroid Build Coastguard Worker    char* __np = this->__identify_padding(__nar, __ne, __iob);
1519*58b9f456SAndroid Build Coastguard Worker    // Stage 2 - Widen __nar while adding thousands separators
1520*58b9f456SAndroid Build Coastguard Worker    char_type __o[2*(__nbuf-1) - 1];
1521*58b9f456SAndroid Build Coastguard Worker    char_type* __op;  // pad here
1522*58b9f456SAndroid Build Coastguard Worker    char_type* __oe;  // end of output
1523*58b9f456SAndroid Build Coastguard Worker    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1524*58b9f456SAndroid Build Coastguard Worker    // [__o, __oe) contains thousands_sep'd wide number
1525*58b9f456SAndroid Build Coastguard Worker    // Stage 3 & 4
1526*58b9f456SAndroid Build Coastguard Worker    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1527*58b9f456SAndroid Build Coastguard Worker}
1528*58b9f456SAndroid Build Coastguard Worker
1529*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1530*58b9f456SAndroid Build Coastguard Worker_OutputIterator
1531*58b9f456SAndroid Build Coastguard Workernum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1532*58b9f456SAndroid Build Coastguard Worker                                         char_type __fl, unsigned long long __v) const
1533*58b9f456SAndroid Build Coastguard Worker{
1534*58b9f456SAndroid Build Coastguard Worker    // Stage 1 - Get number in narrow char
1535*58b9f456SAndroid Build Coastguard Worker    char __fmt[8] = {'%', 0};
1536*58b9f456SAndroid Build Coastguard Worker    const char* __len = "ll";
1537*58b9f456SAndroid Build Coastguard Worker    this->__format_int(__fmt+1, __len, false, __iob.flags());
1538*58b9f456SAndroid Build Coastguard Worker    const unsigned __nbuf = (numeric_limits<unsigned long long>::digits / 3)
1539*58b9f456SAndroid Build Coastguard Worker                          + ((numeric_limits<unsigned long long>::digits % 3) != 0)
1540*58b9f456SAndroid Build Coastguard Worker                          + ((__iob.flags() & ios_base::showbase) != 0)
1541*58b9f456SAndroid Build Coastguard Worker                          + 1;
1542*58b9f456SAndroid Build Coastguard Worker    char __nar[__nbuf];
1543*58b9f456SAndroid Build Coastguard Worker    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1544*58b9f456SAndroid Build Coastguard Worker    char* __ne = __nar + __nc;
1545*58b9f456SAndroid Build Coastguard Worker    char* __np = this->__identify_padding(__nar, __ne, __iob);
1546*58b9f456SAndroid Build Coastguard Worker    // Stage 2 - Widen __nar while adding thousands separators
1547*58b9f456SAndroid Build Coastguard Worker    char_type __o[2*(__nbuf-1) - 1];
1548*58b9f456SAndroid Build Coastguard Worker    char_type* __op;  // pad here
1549*58b9f456SAndroid Build Coastguard Worker    char_type* __oe;  // end of output
1550*58b9f456SAndroid Build Coastguard Worker    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1551*58b9f456SAndroid Build Coastguard Worker    // [__o, __oe) contains thousands_sep'd wide number
1552*58b9f456SAndroid Build Coastguard Worker    // Stage 3 & 4
1553*58b9f456SAndroid Build Coastguard Worker    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1554*58b9f456SAndroid Build Coastguard Worker}
1555*58b9f456SAndroid Build Coastguard Worker
1556*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1557*58b9f456SAndroid Build Coastguard Worker_OutputIterator
1558*58b9f456SAndroid Build Coastguard Workernum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1559*58b9f456SAndroid Build Coastguard Worker                                         char_type __fl, double __v) const
1560*58b9f456SAndroid Build Coastguard Worker{
1561*58b9f456SAndroid Build Coastguard Worker    // Stage 1 - Get number in narrow char
1562*58b9f456SAndroid Build Coastguard Worker    char __fmt[8] = {'%', 0};
1563*58b9f456SAndroid Build Coastguard Worker    const char* __len = "";
1564*58b9f456SAndroid Build Coastguard Worker    bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
1565*58b9f456SAndroid Build Coastguard Worker    const unsigned __nbuf = 30;
1566*58b9f456SAndroid Build Coastguard Worker    char __nar[__nbuf];
1567*58b9f456SAndroid Build Coastguard Worker    char* __nb = __nar;
1568*58b9f456SAndroid Build Coastguard Worker    int __nc;
1569*58b9f456SAndroid Build Coastguard Worker    if (__specify_precision)
1570*58b9f456SAndroid Build Coastguard Worker        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
1571*58b9f456SAndroid Build Coastguard Worker                                   (int)__iob.precision(), __v);
1572*58b9f456SAndroid Build Coastguard Worker    else
1573*58b9f456SAndroid Build Coastguard Worker        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1574*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char, void(*)(void*)> __nbh(0, free);
1575*58b9f456SAndroid Build Coastguard Worker    if (__nc > static_cast<int>(__nbuf-1))
1576*58b9f456SAndroid Build Coastguard Worker    {
1577*58b9f456SAndroid Build Coastguard Worker        if (__specify_precision)
1578*58b9f456SAndroid Build Coastguard Worker            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1579*58b9f456SAndroid Build Coastguard Worker        else
1580*58b9f456SAndroid Build Coastguard Worker            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1581*58b9f456SAndroid Build Coastguard Worker        if (__nb == 0)
1582*58b9f456SAndroid Build Coastguard Worker            __throw_bad_alloc();
1583*58b9f456SAndroid Build Coastguard Worker        __nbh.reset(__nb);
1584*58b9f456SAndroid Build Coastguard Worker    }
1585*58b9f456SAndroid Build Coastguard Worker    char* __ne = __nb + __nc;
1586*58b9f456SAndroid Build Coastguard Worker    char* __np = this->__identify_padding(__nb, __ne, __iob);
1587*58b9f456SAndroid Build Coastguard Worker    // Stage 2 - Widen __nar while adding thousands separators
1588*58b9f456SAndroid Build Coastguard Worker    char_type __o[2*(__nbuf-1) - 1];
1589*58b9f456SAndroid Build Coastguard Worker    char_type* __ob = __o;
1590*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char_type, void(*)(void*)> __obh(0, free);
1591*58b9f456SAndroid Build Coastguard Worker    if (__nb != __nar)
1592*58b9f456SAndroid Build Coastguard Worker    {
1593*58b9f456SAndroid Build Coastguard Worker        __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
1594*58b9f456SAndroid Build Coastguard Worker        if (__ob == 0)
1595*58b9f456SAndroid Build Coastguard Worker            __throw_bad_alloc();
1596*58b9f456SAndroid Build Coastguard Worker        __obh.reset(__ob);
1597*58b9f456SAndroid Build Coastguard Worker    }
1598*58b9f456SAndroid Build Coastguard Worker    char_type* __op;  // pad here
1599*58b9f456SAndroid Build Coastguard Worker    char_type* __oe;  // end of output
1600*58b9f456SAndroid Build Coastguard Worker    this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
1601*58b9f456SAndroid Build Coastguard Worker    // [__o, __oe) contains thousands_sep'd wide number
1602*58b9f456SAndroid Build Coastguard Worker    // Stage 3 & 4
1603*58b9f456SAndroid Build Coastguard Worker    __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
1604*58b9f456SAndroid Build Coastguard Worker    return __s;
1605*58b9f456SAndroid Build Coastguard Worker}
1606*58b9f456SAndroid Build Coastguard Worker
1607*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1608*58b9f456SAndroid Build Coastguard Worker_OutputIterator
1609*58b9f456SAndroid Build Coastguard Workernum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1610*58b9f456SAndroid Build Coastguard Worker                                         char_type __fl, long double __v) const
1611*58b9f456SAndroid Build Coastguard Worker{
1612*58b9f456SAndroid Build Coastguard Worker    // Stage 1 - Get number in narrow char
1613*58b9f456SAndroid Build Coastguard Worker    char __fmt[8] = {'%', 0};
1614*58b9f456SAndroid Build Coastguard Worker    const char* __len = "L";
1615*58b9f456SAndroid Build Coastguard Worker    bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
1616*58b9f456SAndroid Build Coastguard Worker    const unsigned __nbuf = 30;
1617*58b9f456SAndroid Build Coastguard Worker    char __nar[__nbuf];
1618*58b9f456SAndroid Build Coastguard Worker    char* __nb = __nar;
1619*58b9f456SAndroid Build Coastguard Worker    int __nc;
1620*58b9f456SAndroid Build Coastguard Worker    if (__specify_precision)
1621*58b9f456SAndroid Build Coastguard Worker        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
1622*58b9f456SAndroid Build Coastguard Worker                                   (int)__iob.precision(), __v);
1623*58b9f456SAndroid Build Coastguard Worker    else
1624*58b9f456SAndroid Build Coastguard Worker        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1625*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char, void(*)(void*)> __nbh(0, free);
1626*58b9f456SAndroid Build Coastguard Worker    if (__nc > static_cast<int>(__nbuf-1))
1627*58b9f456SAndroid Build Coastguard Worker    {
1628*58b9f456SAndroid Build Coastguard Worker        if (__specify_precision)
1629*58b9f456SAndroid Build Coastguard Worker            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1630*58b9f456SAndroid Build Coastguard Worker        else
1631*58b9f456SAndroid Build Coastguard Worker            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1632*58b9f456SAndroid Build Coastguard Worker        if (__nb == 0)
1633*58b9f456SAndroid Build Coastguard Worker            __throw_bad_alloc();
1634*58b9f456SAndroid Build Coastguard Worker        __nbh.reset(__nb);
1635*58b9f456SAndroid Build Coastguard Worker    }
1636*58b9f456SAndroid Build Coastguard Worker    char* __ne = __nb + __nc;
1637*58b9f456SAndroid Build Coastguard Worker    char* __np = this->__identify_padding(__nb, __ne, __iob);
1638*58b9f456SAndroid Build Coastguard Worker    // Stage 2 - Widen __nar while adding thousands separators
1639*58b9f456SAndroid Build Coastguard Worker    char_type __o[2*(__nbuf-1) - 1];
1640*58b9f456SAndroid Build Coastguard Worker    char_type* __ob = __o;
1641*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char_type, void(*)(void*)> __obh(0, free);
1642*58b9f456SAndroid Build Coastguard Worker    if (__nb != __nar)
1643*58b9f456SAndroid Build Coastguard Worker    {
1644*58b9f456SAndroid Build Coastguard Worker        __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
1645*58b9f456SAndroid Build Coastguard Worker        if (__ob == 0)
1646*58b9f456SAndroid Build Coastguard Worker            __throw_bad_alloc();
1647*58b9f456SAndroid Build Coastguard Worker        __obh.reset(__ob);
1648*58b9f456SAndroid Build Coastguard Worker    }
1649*58b9f456SAndroid Build Coastguard Worker    char_type* __op;  // pad here
1650*58b9f456SAndroid Build Coastguard Worker    char_type* __oe;  // end of output
1651*58b9f456SAndroid Build Coastguard Worker    this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
1652*58b9f456SAndroid Build Coastguard Worker    // [__o, __oe) contains thousands_sep'd wide number
1653*58b9f456SAndroid Build Coastguard Worker    // Stage 3 & 4
1654*58b9f456SAndroid Build Coastguard Worker    __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
1655*58b9f456SAndroid Build Coastguard Worker    return __s;
1656*58b9f456SAndroid Build Coastguard Worker}
1657*58b9f456SAndroid Build Coastguard Worker
1658*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
1659*58b9f456SAndroid Build Coastguard Worker_OutputIterator
1660*58b9f456SAndroid Build Coastguard Workernum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1661*58b9f456SAndroid Build Coastguard Worker                                         char_type __fl, const void* __v) const
1662*58b9f456SAndroid Build Coastguard Worker{
1663*58b9f456SAndroid Build Coastguard Worker    // Stage 1 - Get pointer in narrow char
1664*58b9f456SAndroid Build Coastguard Worker    char __fmt[6] = "%p";
1665*58b9f456SAndroid Build Coastguard Worker    const unsigned __nbuf = 20;
1666*58b9f456SAndroid Build Coastguard Worker    char __nar[__nbuf];
1667*58b9f456SAndroid Build Coastguard Worker    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1668*58b9f456SAndroid Build Coastguard Worker    char* __ne = __nar + __nc;
1669*58b9f456SAndroid Build Coastguard Worker    char* __np = this->__identify_padding(__nar, __ne, __iob);
1670*58b9f456SAndroid Build Coastguard Worker    // Stage 2 - Widen __nar
1671*58b9f456SAndroid Build Coastguard Worker    char_type __o[2*(__nbuf-1) - 1];
1672*58b9f456SAndroid Build Coastguard Worker    char_type* __op;  // pad here
1673*58b9f456SAndroid Build Coastguard Worker    char_type* __oe;  // end of output
1674*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
1675*58b9f456SAndroid Build Coastguard Worker    __ct.widen(__nar, __ne, __o);
1676*58b9f456SAndroid Build Coastguard Worker    __oe = __o + (__ne - __nar);
1677*58b9f456SAndroid Build Coastguard Worker    if (__np == __ne)
1678*58b9f456SAndroid Build Coastguard Worker        __op = __oe;
1679*58b9f456SAndroid Build Coastguard Worker    else
1680*58b9f456SAndroid Build Coastguard Worker        __op = __o + (__np - __nar);
1681*58b9f456SAndroid Build Coastguard Worker    // [__o, __oe) contains wide number
1682*58b9f456SAndroid Build Coastguard Worker    // Stage 3 & 4
1683*58b9f456SAndroid Build Coastguard Worker    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1684*58b9f456SAndroid Build Coastguard Worker}
1685*58b9f456SAndroid Build Coastguard Worker
1686*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>)
1687*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>)
1688*58b9f456SAndroid Build Coastguard Worker
1689*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1690*58b9f456SAndroid Build Coastguard Worker_LIBCPP_HIDDEN
1691*58b9f456SAndroid Build Coastguard Workerint
1692*58b9f456SAndroid Build Coastguard Worker__get_up_to_n_digits(_InputIterator& __b, _InputIterator __e,
1693*58b9f456SAndroid Build Coastguard Worker                     ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n)
1694*58b9f456SAndroid Build Coastguard Worker{
1695*58b9f456SAndroid Build Coastguard Worker    // Precondition:  __n >= 1
1696*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
1697*58b9f456SAndroid Build Coastguard Worker    {
1698*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit | ios_base::failbit;
1699*58b9f456SAndroid Build Coastguard Worker        return 0;
1700*58b9f456SAndroid Build Coastguard Worker    }
1701*58b9f456SAndroid Build Coastguard Worker    // get first digit
1702*58b9f456SAndroid Build Coastguard Worker    _CharT __c = *__b;
1703*58b9f456SAndroid Build Coastguard Worker    if (!__ct.is(ctype_base::digit, __c))
1704*58b9f456SAndroid Build Coastguard Worker    {
1705*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
1706*58b9f456SAndroid Build Coastguard Worker        return 0;
1707*58b9f456SAndroid Build Coastguard Worker    }
1708*58b9f456SAndroid Build Coastguard Worker    int __r = __ct.narrow(__c, 0) - '0';
1709*58b9f456SAndroid Build Coastguard Worker    for (++__b, (void) --__n; __b != __e && __n > 0; ++__b, (void) --__n)
1710*58b9f456SAndroid Build Coastguard Worker    {
1711*58b9f456SAndroid Build Coastguard Worker        // get next digit
1712*58b9f456SAndroid Build Coastguard Worker        __c = *__b;
1713*58b9f456SAndroid Build Coastguard Worker        if (!__ct.is(ctype_base::digit, __c))
1714*58b9f456SAndroid Build Coastguard Worker            return __r;
1715*58b9f456SAndroid Build Coastguard Worker        __r = __r * 10 + __ct.narrow(__c, 0) - '0';
1716*58b9f456SAndroid Build Coastguard Worker    }
1717*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
1718*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
1719*58b9f456SAndroid Build Coastguard Worker    return __r;
1720*58b9f456SAndroid Build Coastguard Worker}
1721*58b9f456SAndroid Build Coastguard Worker
1722*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS time_base
1723*58b9f456SAndroid Build Coastguard Worker{
1724*58b9f456SAndroid Build Coastguard Workerpublic:
1725*58b9f456SAndroid Build Coastguard Worker    enum dateorder {no_order, dmy, mdy, ymd, ydm};
1726*58b9f456SAndroid Build Coastguard Worker};
1727*58b9f456SAndroid Build Coastguard Worker
1728*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
1729*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __time_get_c_storage
1730*58b9f456SAndroid Build Coastguard Worker{
1731*58b9f456SAndroid Build Coastguard Workerprotected:
1732*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<_CharT> string_type;
1733*58b9f456SAndroid Build Coastguard Worker
1734*58b9f456SAndroid Build Coastguard Worker    virtual const string_type* __weeks() const;
1735*58b9f456SAndroid Build Coastguard Worker    virtual const string_type* __months() const;
1736*58b9f456SAndroid Build Coastguard Worker    virtual const string_type* __am_pm() const;
1737*58b9f456SAndroid Build Coastguard Worker    virtual const string_type& __c() const;
1738*58b9f456SAndroid Build Coastguard Worker    virtual const string_type& __r() const;
1739*58b9f456SAndroid Build Coastguard Worker    virtual const string_type& __x() const;
1740*58b9f456SAndroid Build Coastguard Worker    virtual const string_type& __X() const;
1741*58b9f456SAndroid Build Coastguard Worker
1742*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1743*58b9f456SAndroid Build Coastguard Worker    ~__time_get_c_storage() {}
1744*58b9f456SAndroid Build Coastguard Worker};
1745*58b9f456SAndroid Build Coastguard Worker
1746*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__weeks() const;
1747*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__months() const;
1748*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__am_pm() const;
1749*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__c() const;
1750*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__r() const;
1751*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__x() const;
1752*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__X() const;
1753*58b9f456SAndroid Build Coastguard Worker
1754*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__weeks() const;
1755*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__months() const;
1756*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__am_pm() const;
1757*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__c() const;
1758*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__r() const;
1759*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__x() const;
1760*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__X() const;
1761*58b9f456SAndroid Build Coastguard Worker
1762*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
1763*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS time_get
1764*58b9f456SAndroid Build Coastguard Worker    : public locale::facet,
1765*58b9f456SAndroid Build Coastguard Worker      public time_base,
1766*58b9f456SAndroid Build Coastguard Worker      private __time_get_c_storage<_CharT>
1767*58b9f456SAndroid Build Coastguard Worker{
1768*58b9f456SAndroid Build Coastguard Workerpublic:
1769*58b9f456SAndroid Build Coastguard Worker    typedef _CharT                  char_type;
1770*58b9f456SAndroid Build Coastguard Worker    typedef _InputIterator          iter_type;
1771*58b9f456SAndroid Build Coastguard Worker    typedef time_base::dateorder    dateorder;
1772*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char_type> string_type;
1773*58b9f456SAndroid Build Coastguard Worker
1774*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1775*58b9f456SAndroid Build Coastguard Worker    explicit time_get(size_t __refs = 0)
1776*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs) {}
1777*58b9f456SAndroid Build Coastguard Worker
1778*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1779*58b9f456SAndroid Build Coastguard Worker    dateorder date_order() const
1780*58b9f456SAndroid Build Coastguard Worker    {
1781*58b9f456SAndroid Build Coastguard Worker        return this->do_date_order();
1782*58b9f456SAndroid Build Coastguard Worker    }
1783*58b9f456SAndroid Build Coastguard Worker
1784*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1785*58b9f456SAndroid Build Coastguard Worker    iter_type get_time(iter_type __b, iter_type __e, ios_base& __iob,
1786*58b9f456SAndroid Build Coastguard Worker                       ios_base::iostate& __err, tm* __tm) const
1787*58b9f456SAndroid Build Coastguard Worker    {
1788*58b9f456SAndroid Build Coastguard Worker        return do_get_time(__b, __e, __iob, __err, __tm);
1789*58b9f456SAndroid Build Coastguard Worker    }
1790*58b9f456SAndroid Build Coastguard Worker
1791*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1792*58b9f456SAndroid Build Coastguard Worker    iter_type get_date(iter_type __b, iter_type __e, ios_base& __iob,
1793*58b9f456SAndroid Build Coastguard Worker                       ios_base::iostate& __err, tm* __tm) const
1794*58b9f456SAndroid Build Coastguard Worker    {
1795*58b9f456SAndroid Build Coastguard Worker        return do_get_date(__b, __e, __iob, __err, __tm);
1796*58b9f456SAndroid Build Coastguard Worker    }
1797*58b9f456SAndroid Build Coastguard Worker
1798*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1799*58b9f456SAndroid Build Coastguard Worker    iter_type get_weekday(iter_type __b, iter_type __e, ios_base& __iob,
1800*58b9f456SAndroid Build Coastguard Worker                          ios_base::iostate& __err, tm* __tm) const
1801*58b9f456SAndroid Build Coastguard Worker    {
1802*58b9f456SAndroid Build Coastguard Worker        return do_get_weekday(__b, __e, __iob, __err, __tm);
1803*58b9f456SAndroid Build Coastguard Worker    }
1804*58b9f456SAndroid Build Coastguard Worker
1805*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1806*58b9f456SAndroid Build Coastguard Worker    iter_type get_monthname(iter_type __b, iter_type __e, ios_base& __iob,
1807*58b9f456SAndroid Build Coastguard Worker                            ios_base::iostate& __err, tm* __tm) const
1808*58b9f456SAndroid Build Coastguard Worker    {
1809*58b9f456SAndroid Build Coastguard Worker        return do_get_monthname(__b, __e, __iob, __err, __tm);
1810*58b9f456SAndroid Build Coastguard Worker    }
1811*58b9f456SAndroid Build Coastguard Worker
1812*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1813*58b9f456SAndroid Build Coastguard Worker    iter_type get_year(iter_type __b, iter_type __e, ios_base& __iob,
1814*58b9f456SAndroid Build Coastguard Worker                       ios_base::iostate& __err, tm* __tm) const
1815*58b9f456SAndroid Build Coastguard Worker    {
1816*58b9f456SAndroid Build Coastguard Worker        return do_get_year(__b, __e, __iob, __err, __tm);
1817*58b9f456SAndroid Build Coastguard Worker    }
1818*58b9f456SAndroid Build Coastguard Worker
1819*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1820*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
1821*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, tm *__tm,
1822*58b9f456SAndroid Build Coastguard Worker                  char __fmt, char __mod = 0) const
1823*58b9f456SAndroid Build Coastguard Worker    {
1824*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod);
1825*58b9f456SAndroid Build Coastguard Worker    }
1826*58b9f456SAndroid Build Coastguard Worker
1827*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
1828*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, tm* __tm,
1829*58b9f456SAndroid Build Coastguard Worker                  const char_type* __fmtb, const char_type* __fmte) const;
1830*58b9f456SAndroid Build Coastguard Worker
1831*58b9f456SAndroid Build Coastguard Worker    static locale::id id;
1832*58b9f456SAndroid Build Coastguard Worker
1833*58b9f456SAndroid Build Coastguard Workerprotected:
1834*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1835*58b9f456SAndroid Build Coastguard Worker    ~time_get() {}
1836*58b9f456SAndroid Build Coastguard Worker
1837*58b9f456SAndroid Build Coastguard Worker    virtual dateorder do_date_order() const;
1838*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get_time(iter_type __b, iter_type __e, ios_base& __iob,
1839*58b9f456SAndroid Build Coastguard Worker                                  ios_base::iostate& __err, tm* __tm) const;
1840*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get_date(iter_type __b, iter_type __e, ios_base& __iob,
1841*58b9f456SAndroid Build Coastguard Worker                                  ios_base::iostate& __err, tm* __tm) const;
1842*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob,
1843*58b9f456SAndroid Build Coastguard Worker                                     ios_base::iostate& __err, tm* __tm) const;
1844*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob,
1845*58b9f456SAndroid Build Coastguard Worker                                       ios_base::iostate& __err, tm* __tm) const;
1846*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get_year(iter_type __b, iter_type __e, ios_base& __iob,
1847*58b9f456SAndroid Build Coastguard Worker                                  ios_base::iostate& __err, tm* __tm) const;
1848*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
1849*58b9f456SAndroid Build Coastguard Worker                             ios_base::iostate& __err, tm* __tm,
1850*58b9f456SAndroid Build Coastguard Worker                             char __fmt, char __mod) const;
1851*58b9f456SAndroid Build Coastguard Workerprivate:
1852*58b9f456SAndroid Build Coastguard Worker    void __get_white_space(iter_type& __b, iter_type __e,
1853*58b9f456SAndroid Build Coastguard Worker                           ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1854*58b9f456SAndroid Build Coastguard Worker    void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err,
1855*58b9f456SAndroid Build Coastguard Worker                       const ctype<char_type>& __ct) const;
1856*58b9f456SAndroid Build Coastguard Worker
1857*58b9f456SAndroid Build Coastguard Worker    void __get_weekdayname(int& __m,
1858*58b9f456SAndroid Build Coastguard Worker                           iter_type& __b, iter_type __e,
1859*58b9f456SAndroid Build Coastguard Worker                           ios_base::iostate& __err,
1860*58b9f456SAndroid Build Coastguard Worker                           const ctype<char_type>& __ct) const;
1861*58b9f456SAndroid Build Coastguard Worker    void __get_monthname(int& __m,
1862*58b9f456SAndroid Build Coastguard Worker                         iter_type& __b, iter_type __e,
1863*58b9f456SAndroid Build Coastguard Worker                         ios_base::iostate& __err,
1864*58b9f456SAndroid Build Coastguard Worker                         const ctype<char_type>& __ct) const;
1865*58b9f456SAndroid Build Coastguard Worker    void __get_day(int& __d,
1866*58b9f456SAndroid Build Coastguard Worker                   iter_type& __b, iter_type __e,
1867*58b9f456SAndroid Build Coastguard Worker                   ios_base::iostate& __err,
1868*58b9f456SAndroid Build Coastguard Worker                   const ctype<char_type>& __ct) const;
1869*58b9f456SAndroid Build Coastguard Worker    void __get_month(int& __m,
1870*58b9f456SAndroid Build Coastguard Worker                     iter_type& __b, iter_type __e,
1871*58b9f456SAndroid Build Coastguard Worker                     ios_base::iostate& __err,
1872*58b9f456SAndroid Build Coastguard Worker                     const ctype<char_type>& __ct) const;
1873*58b9f456SAndroid Build Coastguard Worker    void __get_year(int& __y,
1874*58b9f456SAndroid Build Coastguard Worker                   iter_type& __b, iter_type __e,
1875*58b9f456SAndroid Build Coastguard Worker                   ios_base::iostate& __err,
1876*58b9f456SAndroid Build Coastguard Worker                   const ctype<char_type>& __ct) const;
1877*58b9f456SAndroid Build Coastguard Worker    void __get_year4(int& __y,
1878*58b9f456SAndroid Build Coastguard Worker                    iter_type& __b, iter_type __e,
1879*58b9f456SAndroid Build Coastguard Worker                    ios_base::iostate& __err,
1880*58b9f456SAndroid Build Coastguard Worker                    const ctype<char_type>& __ct) const;
1881*58b9f456SAndroid Build Coastguard Worker    void __get_hour(int& __d,
1882*58b9f456SAndroid Build Coastguard Worker                    iter_type& __b, iter_type __e,
1883*58b9f456SAndroid Build Coastguard Worker                    ios_base::iostate& __err,
1884*58b9f456SAndroid Build Coastguard Worker                    const ctype<char_type>& __ct) const;
1885*58b9f456SAndroid Build Coastguard Worker    void __get_12_hour(int& __h,
1886*58b9f456SAndroid Build Coastguard Worker                       iter_type& __b, iter_type __e,
1887*58b9f456SAndroid Build Coastguard Worker                       ios_base::iostate& __err,
1888*58b9f456SAndroid Build Coastguard Worker                       const ctype<char_type>& __ct) const;
1889*58b9f456SAndroid Build Coastguard Worker    void __get_am_pm(int& __h,
1890*58b9f456SAndroid Build Coastguard Worker                     iter_type& __b, iter_type __e,
1891*58b9f456SAndroid Build Coastguard Worker                     ios_base::iostate& __err,
1892*58b9f456SAndroid Build Coastguard Worker                     const ctype<char_type>& __ct) const;
1893*58b9f456SAndroid Build Coastguard Worker    void __get_minute(int& __m,
1894*58b9f456SAndroid Build Coastguard Worker                      iter_type& __b, iter_type __e,
1895*58b9f456SAndroid Build Coastguard Worker                      ios_base::iostate& __err,
1896*58b9f456SAndroid Build Coastguard Worker                      const ctype<char_type>& __ct) const;
1897*58b9f456SAndroid Build Coastguard Worker    void __get_second(int& __s,
1898*58b9f456SAndroid Build Coastguard Worker                      iter_type& __b, iter_type __e,
1899*58b9f456SAndroid Build Coastguard Worker                      ios_base::iostate& __err,
1900*58b9f456SAndroid Build Coastguard Worker                      const ctype<char_type>& __ct) const;
1901*58b9f456SAndroid Build Coastguard Worker    void __get_weekday(int& __w,
1902*58b9f456SAndroid Build Coastguard Worker                       iter_type& __b, iter_type __e,
1903*58b9f456SAndroid Build Coastguard Worker                       ios_base::iostate& __err,
1904*58b9f456SAndroid Build Coastguard Worker                       const ctype<char_type>& __ct) const;
1905*58b9f456SAndroid Build Coastguard Worker    void __get_day_year_num(int& __w,
1906*58b9f456SAndroid Build Coastguard Worker                            iter_type& __b, iter_type __e,
1907*58b9f456SAndroid Build Coastguard Worker                            ios_base::iostate& __err,
1908*58b9f456SAndroid Build Coastguard Worker                            const ctype<char_type>& __ct) const;
1909*58b9f456SAndroid Build Coastguard Worker};
1910*58b9f456SAndroid Build Coastguard Worker
1911*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1912*58b9f456SAndroid Build Coastguard Workerlocale::id
1913*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::id;
1914*58b9f456SAndroid Build Coastguard Worker
1915*58b9f456SAndroid Build Coastguard Worker// time_get primitives
1916*58b9f456SAndroid Build Coastguard Worker
1917*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1918*58b9f456SAndroid Build Coastguard Workervoid
1919*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_weekdayname(int& __w,
1920*58b9f456SAndroid Build Coastguard Worker                                                    iter_type& __b, iter_type __e,
1921*58b9f456SAndroid Build Coastguard Worker                                                    ios_base::iostate& __err,
1922*58b9f456SAndroid Build Coastguard Worker                                                    const ctype<char_type>& __ct) const
1923*58b9f456SAndroid Build Coastguard Worker{
1924*58b9f456SAndroid Build Coastguard Worker    // Note:  ignoring case comes from the POSIX strptime spec
1925*58b9f456SAndroid Build Coastguard Worker    const string_type* __wk = this->__weeks();
1926*58b9f456SAndroid Build Coastguard Worker    ptrdiff_t __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk;
1927*58b9f456SAndroid Build Coastguard Worker    if (__i < 14)
1928*58b9f456SAndroid Build Coastguard Worker        __w = __i % 7;
1929*58b9f456SAndroid Build Coastguard Worker}
1930*58b9f456SAndroid Build Coastguard Worker
1931*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1932*58b9f456SAndroid Build Coastguard Workervoid
1933*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_monthname(int& __m,
1934*58b9f456SAndroid Build Coastguard Worker                                                  iter_type& __b, iter_type __e,
1935*58b9f456SAndroid Build Coastguard Worker                                                  ios_base::iostate& __err,
1936*58b9f456SAndroid Build Coastguard Worker                                                  const ctype<char_type>& __ct) const
1937*58b9f456SAndroid Build Coastguard Worker{
1938*58b9f456SAndroid Build Coastguard Worker    // Note:  ignoring case comes from the POSIX strptime spec
1939*58b9f456SAndroid Build Coastguard Worker    const string_type* __month = this->__months();
1940*58b9f456SAndroid Build Coastguard Worker    ptrdiff_t __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month;
1941*58b9f456SAndroid Build Coastguard Worker    if (__i < 24)
1942*58b9f456SAndroid Build Coastguard Worker        __m = __i % 12;
1943*58b9f456SAndroid Build Coastguard Worker}
1944*58b9f456SAndroid Build Coastguard Worker
1945*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1946*58b9f456SAndroid Build Coastguard Workervoid
1947*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_day(int& __d,
1948*58b9f456SAndroid Build Coastguard Worker                                            iter_type& __b, iter_type __e,
1949*58b9f456SAndroid Build Coastguard Worker                                            ios_base::iostate& __err,
1950*58b9f456SAndroid Build Coastguard Worker                                            const ctype<char_type>& __ct) const
1951*58b9f456SAndroid Build Coastguard Worker{
1952*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
1953*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31)
1954*58b9f456SAndroid Build Coastguard Worker        __d = __t;
1955*58b9f456SAndroid Build Coastguard Worker    else
1956*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
1957*58b9f456SAndroid Build Coastguard Worker}
1958*58b9f456SAndroid Build Coastguard Worker
1959*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1960*58b9f456SAndroid Build Coastguard Workervoid
1961*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_month(int& __m,
1962*58b9f456SAndroid Build Coastguard Worker                                              iter_type& __b, iter_type __e,
1963*58b9f456SAndroid Build Coastguard Worker                                              ios_base::iostate& __err,
1964*58b9f456SAndroid Build Coastguard Worker                                              const ctype<char_type>& __ct) const
1965*58b9f456SAndroid Build Coastguard Worker{
1966*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1;
1967*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit) && __t <= 11)
1968*58b9f456SAndroid Build Coastguard Worker        __m = __t;
1969*58b9f456SAndroid Build Coastguard Worker    else
1970*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
1971*58b9f456SAndroid Build Coastguard Worker}
1972*58b9f456SAndroid Build Coastguard Worker
1973*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1974*58b9f456SAndroid Build Coastguard Workervoid
1975*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_year(int& __y,
1976*58b9f456SAndroid Build Coastguard Worker                                             iter_type& __b, iter_type __e,
1977*58b9f456SAndroid Build Coastguard Worker                                             ios_base::iostate& __err,
1978*58b9f456SAndroid Build Coastguard Worker                                             const ctype<char_type>& __ct) const
1979*58b9f456SAndroid Build Coastguard Worker{
1980*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4);
1981*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit))
1982*58b9f456SAndroid Build Coastguard Worker    {
1983*58b9f456SAndroid Build Coastguard Worker        if (__t < 69)
1984*58b9f456SAndroid Build Coastguard Worker            __t += 2000;
1985*58b9f456SAndroid Build Coastguard Worker        else if (69 <= __t && __t <= 99)
1986*58b9f456SAndroid Build Coastguard Worker            __t += 1900;
1987*58b9f456SAndroid Build Coastguard Worker        __y = __t - 1900;
1988*58b9f456SAndroid Build Coastguard Worker    }
1989*58b9f456SAndroid Build Coastguard Worker}
1990*58b9f456SAndroid Build Coastguard Worker
1991*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
1992*58b9f456SAndroid Build Coastguard Workervoid
1993*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_year4(int& __y,
1994*58b9f456SAndroid Build Coastguard Worker                                              iter_type& __b, iter_type __e,
1995*58b9f456SAndroid Build Coastguard Worker                                              ios_base::iostate& __err,
1996*58b9f456SAndroid Build Coastguard Worker                                              const ctype<char_type>& __ct) const
1997*58b9f456SAndroid Build Coastguard Worker{
1998*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4);
1999*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit))
2000*58b9f456SAndroid Build Coastguard Worker        __y = __t - 1900;
2001*58b9f456SAndroid Build Coastguard Worker}
2002*58b9f456SAndroid Build Coastguard Worker
2003*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2004*58b9f456SAndroid Build Coastguard Workervoid
2005*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_hour(int& __h,
2006*58b9f456SAndroid Build Coastguard Worker                                             iter_type& __b, iter_type __e,
2007*58b9f456SAndroid Build Coastguard Worker                                             ios_base::iostate& __err,
2008*58b9f456SAndroid Build Coastguard Worker                                             const ctype<char_type>& __ct) const
2009*58b9f456SAndroid Build Coastguard Worker{
2010*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
2011*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit) && __t <= 23)
2012*58b9f456SAndroid Build Coastguard Worker        __h = __t;
2013*58b9f456SAndroid Build Coastguard Worker    else
2014*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
2015*58b9f456SAndroid Build Coastguard Worker}
2016*58b9f456SAndroid Build Coastguard Worker
2017*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2018*58b9f456SAndroid Build Coastguard Workervoid
2019*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_12_hour(int& __h,
2020*58b9f456SAndroid Build Coastguard Worker                                                iter_type& __b, iter_type __e,
2021*58b9f456SAndroid Build Coastguard Worker                                                ios_base::iostate& __err,
2022*58b9f456SAndroid Build Coastguard Worker                                                const ctype<char_type>& __ct) const
2023*58b9f456SAndroid Build Coastguard Worker{
2024*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
2025*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12)
2026*58b9f456SAndroid Build Coastguard Worker        __h = __t;
2027*58b9f456SAndroid Build Coastguard Worker    else
2028*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
2029*58b9f456SAndroid Build Coastguard Worker}
2030*58b9f456SAndroid Build Coastguard Worker
2031*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2032*58b9f456SAndroid Build Coastguard Workervoid
2033*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_minute(int& __m,
2034*58b9f456SAndroid Build Coastguard Worker                                               iter_type& __b, iter_type __e,
2035*58b9f456SAndroid Build Coastguard Worker                                               ios_base::iostate& __err,
2036*58b9f456SAndroid Build Coastguard Worker                                               const ctype<char_type>& __ct) const
2037*58b9f456SAndroid Build Coastguard Worker{
2038*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
2039*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit) && __t <= 59)
2040*58b9f456SAndroid Build Coastguard Worker        __m = __t;
2041*58b9f456SAndroid Build Coastguard Worker    else
2042*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
2043*58b9f456SAndroid Build Coastguard Worker}
2044*58b9f456SAndroid Build Coastguard Worker
2045*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2046*58b9f456SAndroid Build Coastguard Workervoid
2047*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_second(int& __s,
2048*58b9f456SAndroid Build Coastguard Worker                                               iter_type& __b, iter_type __e,
2049*58b9f456SAndroid Build Coastguard Worker                                               ios_base::iostate& __err,
2050*58b9f456SAndroid Build Coastguard Worker                                               const ctype<char_type>& __ct) const
2051*58b9f456SAndroid Build Coastguard Worker{
2052*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
2053*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit) && __t <= 60)
2054*58b9f456SAndroid Build Coastguard Worker        __s = __t;
2055*58b9f456SAndroid Build Coastguard Worker    else
2056*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
2057*58b9f456SAndroid Build Coastguard Worker}
2058*58b9f456SAndroid Build Coastguard Worker
2059*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2060*58b9f456SAndroid Build Coastguard Workervoid
2061*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_weekday(int& __w,
2062*58b9f456SAndroid Build Coastguard Worker                                                iter_type& __b, iter_type __e,
2063*58b9f456SAndroid Build Coastguard Worker                                                ios_base::iostate& __err,
2064*58b9f456SAndroid Build Coastguard Worker                                                const ctype<char_type>& __ct) const
2065*58b9f456SAndroid Build Coastguard Worker{
2066*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 1);
2067*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit) && __t <= 6)
2068*58b9f456SAndroid Build Coastguard Worker        __w = __t;
2069*58b9f456SAndroid Build Coastguard Worker    else
2070*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
2071*58b9f456SAndroid Build Coastguard Worker}
2072*58b9f456SAndroid Build Coastguard Worker
2073*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2074*58b9f456SAndroid Build Coastguard Workervoid
2075*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_day_year_num(int& __d,
2076*58b9f456SAndroid Build Coastguard Worker                                                     iter_type& __b, iter_type __e,
2077*58b9f456SAndroid Build Coastguard Worker                                                     ios_base::iostate& __err,
2078*58b9f456SAndroid Build Coastguard Worker                                                     const ctype<char_type>& __ct) const
2079*58b9f456SAndroid Build Coastguard Worker{
2080*58b9f456SAndroid Build Coastguard Worker    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 3);
2081*58b9f456SAndroid Build Coastguard Worker    if (!(__err & ios_base::failbit) && __t <= 365)
2082*58b9f456SAndroid Build Coastguard Worker        __d = __t;
2083*58b9f456SAndroid Build Coastguard Worker    else
2084*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
2085*58b9f456SAndroid Build Coastguard Worker}
2086*58b9f456SAndroid Build Coastguard Worker
2087*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2088*58b9f456SAndroid Build Coastguard Workervoid
2089*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_white_space(iter_type& __b, iter_type __e,
2090*58b9f456SAndroid Build Coastguard Worker                                                    ios_base::iostate& __err,
2091*58b9f456SAndroid Build Coastguard Worker                                                    const ctype<char_type>& __ct) const
2092*58b9f456SAndroid Build Coastguard Worker{
2093*58b9f456SAndroid Build Coastguard Worker    for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
2094*58b9f456SAndroid Build Coastguard Worker        ;
2095*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
2096*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
2097*58b9f456SAndroid Build Coastguard Worker}
2098*58b9f456SAndroid Build Coastguard Worker
2099*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2100*58b9f456SAndroid Build Coastguard Workervoid
2101*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_am_pm(int& __h,
2102*58b9f456SAndroid Build Coastguard Worker                                              iter_type& __b, iter_type __e,
2103*58b9f456SAndroid Build Coastguard Worker                                              ios_base::iostate& __err,
2104*58b9f456SAndroid Build Coastguard Worker                                              const ctype<char_type>& __ct) const
2105*58b9f456SAndroid Build Coastguard Worker{
2106*58b9f456SAndroid Build Coastguard Worker    const string_type* __ap = this->__am_pm();
2107*58b9f456SAndroid Build Coastguard Worker    if (__ap[0].size() + __ap[1].size() == 0)
2108*58b9f456SAndroid Build Coastguard Worker    {
2109*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
2110*58b9f456SAndroid Build Coastguard Worker        return;
2111*58b9f456SAndroid Build Coastguard Worker    }
2112*58b9f456SAndroid Build Coastguard Worker    ptrdiff_t __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap;
2113*58b9f456SAndroid Build Coastguard Worker    if (__i == 0 && __h == 12)
2114*58b9f456SAndroid Build Coastguard Worker        __h = 0;
2115*58b9f456SAndroid Build Coastguard Worker    else if (__i == 1 && __h < 12)
2116*58b9f456SAndroid Build Coastguard Worker        __h += 12;
2117*58b9f456SAndroid Build Coastguard Worker}
2118*58b9f456SAndroid Build Coastguard Worker
2119*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2120*58b9f456SAndroid Build Coastguard Workervoid
2121*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e,
2122*58b9f456SAndroid Build Coastguard Worker                                                ios_base::iostate& __err,
2123*58b9f456SAndroid Build Coastguard Worker                                                const ctype<char_type>& __ct) const
2124*58b9f456SAndroid Build Coastguard Worker{
2125*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
2126*58b9f456SAndroid Build Coastguard Worker    {
2127*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit | ios_base::failbit;
2128*58b9f456SAndroid Build Coastguard Worker        return;
2129*58b9f456SAndroid Build Coastguard Worker    }
2130*58b9f456SAndroid Build Coastguard Worker    if (__ct.narrow(*__b, 0) != '%')
2131*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
2132*58b9f456SAndroid Build Coastguard Worker    else if(++__b == __e)
2133*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
2134*58b9f456SAndroid Build Coastguard Worker}
2135*58b9f456SAndroid Build Coastguard Worker
2136*58b9f456SAndroid Build Coastguard Worker// time_get end primitives
2137*58b9f456SAndroid Build Coastguard Worker
2138*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2139*58b9f456SAndroid Build Coastguard Worker_InputIterator
2140*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::get(iter_type __b, iter_type __e,
2141*58b9f456SAndroid Build Coastguard Worker                                      ios_base& __iob,
2142*58b9f456SAndroid Build Coastguard Worker                                      ios_base::iostate& __err, tm* __tm,
2143*58b9f456SAndroid Build Coastguard Worker                                      const char_type* __fmtb, const char_type* __fmte) const
2144*58b9f456SAndroid Build Coastguard Worker{
2145*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
2146*58b9f456SAndroid Build Coastguard Worker    __err = ios_base::goodbit;
2147*58b9f456SAndroid Build Coastguard Worker    while (__fmtb != __fmte && __err == ios_base::goodbit)
2148*58b9f456SAndroid Build Coastguard Worker    {
2149*58b9f456SAndroid Build Coastguard Worker        if (__b == __e)
2150*58b9f456SAndroid Build Coastguard Worker        {
2151*58b9f456SAndroid Build Coastguard Worker            __err = ios_base::failbit;
2152*58b9f456SAndroid Build Coastguard Worker            break;
2153*58b9f456SAndroid Build Coastguard Worker        }
2154*58b9f456SAndroid Build Coastguard Worker        if (__ct.narrow(*__fmtb, 0) == '%')
2155*58b9f456SAndroid Build Coastguard Worker        {
2156*58b9f456SAndroid Build Coastguard Worker            if (++__fmtb == __fmte)
2157*58b9f456SAndroid Build Coastguard Worker            {
2158*58b9f456SAndroid Build Coastguard Worker                __err = ios_base::failbit;
2159*58b9f456SAndroid Build Coastguard Worker                break;
2160*58b9f456SAndroid Build Coastguard Worker            }
2161*58b9f456SAndroid Build Coastguard Worker            char __cmd = __ct.narrow(*__fmtb, 0);
2162*58b9f456SAndroid Build Coastguard Worker            char __opt = '\0';
2163*58b9f456SAndroid Build Coastguard Worker            if (__cmd == 'E' || __cmd == '0')
2164*58b9f456SAndroid Build Coastguard Worker            {
2165*58b9f456SAndroid Build Coastguard Worker                if (++__fmtb == __fmte)
2166*58b9f456SAndroid Build Coastguard Worker                {
2167*58b9f456SAndroid Build Coastguard Worker                    __err = ios_base::failbit;
2168*58b9f456SAndroid Build Coastguard Worker                    break;
2169*58b9f456SAndroid Build Coastguard Worker                }
2170*58b9f456SAndroid Build Coastguard Worker                __opt = __cmd;
2171*58b9f456SAndroid Build Coastguard Worker                __cmd = __ct.narrow(*__fmtb, 0);
2172*58b9f456SAndroid Build Coastguard Worker            }
2173*58b9f456SAndroid Build Coastguard Worker            __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt);
2174*58b9f456SAndroid Build Coastguard Worker            ++__fmtb;
2175*58b9f456SAndroid Build Coastguard Worker        }
2176*58b9f456SAndroid Build Coastguard Worker        else if (__ct.is(ctype_base::space, *__fmtb))
2177*58b9f456SAndroid Build Coastguard Worker        {
2178*58b9f456SAndroid Build Coastguard Worker            for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb)
2179*58b9f456SAndroid Build Coastguard Worker                ;
2180*58b9f456SAndroid Build Coastguard Worker            for (        ;    __b != __e    && __ct.is(ctype_base::space, *__b);    ++__b)
2181*58b9f456SAndroid Build Coastguard Worker                ;
2182*58b9f456SAndroid Build Coastguard Worker        }
2183*58b9f456SAndroid Build Coastguard Worker        else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb))
2184*58b9f456SAndroid Build Coastguard Worker        {
2185*58b9f456SAndroid Build Coastguard Worker            ++__b;
2186*58b9f456SAndroid Build Coastguard Worker            ++__fmtb;
2187*58b9f456SAndroid Build Coastguard Worker        }
2188*58b9f456SAndroid Build Coastguard Worker        else
2189*58b9f456SAndroid Build Coastguard Worker            __err = ios_base::failbit;
2190*58b9f456SAndroid Build Coastguard Worker    }
2191*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
2192*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
2193*58b9f456SAndroid Build Coastguard Worker    return __b;
2194*58b9f456SAndroid Build Coastguard Worker}
2195*58b9f456SAndroid Build Coastguard Worker
2196*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2197*58b9f456SAndroid Build Coastguard Workertypename time_get<_CharT, _InputIterator>::dateorder
2198*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::do_date_order() const
2199*58b9f456SAndroid Build Coastguard Worker{
2200*58b9f456SAndroid Build Coastguard Worker    return mdy;
2201*58b9f456SAndroid Build Coastguard Worker}
2202*58b9f456SAndroid Build Coastguard Worker
2203*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2204*58b9f456SAndroid Build Coastguard Worker_InputIterator
2205*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::do_get_time(iter_type __b, iter_type __e,
2206*58b9f456SAndroid Build Coastguard Worker                                              ios_base& __iob,
2207*58b9f456SAndroid Build Coastguard Worker                                              ios_base::iostate& __err,
2208*58b9f456SAndroid Build Coastguard Worker                                              tm* __tm) const
2209*58b9f456SAndroid Build Coastguard Worker{
2210*58b9f456SAndroid Build Coastguard Worker    const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
2211*58b9f456SAndroid Build Coastguard Worker    return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
2212*58b9f456SAndroid Build Coastguard Worker}
2213*58b9f456SAndroid Build Coastguard Worker
2214*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2215*58b9f456SAndroid Build Coastguard Worker_InputIterator
2216*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e,
2217*58b9f456SAndroid Build Coastguard Worker                                              ios_base& __iob,
2218*58b9f456SAndroid Build Coastguard Worker                                              ios_base::iostate& __err,
2219*58b9f456SAndroid Build Coastguard Worker                                              tm* __tm) const
2220*58b9f456SAndroid Build Coastguard Worker{
2221*58b9f456SAndroid Build Coastguard Worker    const string_type& __fmt = this->__x();
2222*58b9f456SAndroid Build Coastguard Worker    return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
2223*58b9f456SAndroid Build Coastguard Worker}
2224*58b9f456SAndroid Build Coastguard Worker
2225*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2226*58b9f456SAndroid Build Coastguard Worker_InputIterator
2227*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::do_get_weekday(iter_type __b, iter_type __e,
2228*58b9f456SAndroid Build Coastguard Worker                                                 ios_base& __iob,
2229*58b9f456SAndroid Build Coastguard Worker                                                 ios_base::iostate& __err,
2230*58b9f456SAndroid Build Coastguard Worker                                                 tm* __tm) const
2231*58b9f456SAndroid Build Coastguard Worker{
2232*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
2233*58b9f456SAndroid Build Coastguard Worker    __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
2234*58b9f456SAndroid Build Coastguard Worker    return __b;
2235*58b9f456SAndroid Build Coastguard Worker}
2236*58b9f456SAndroid Build Coastguard Worker
2237*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2238*58b9f456SAndroid Build Coastguard Worker_InputIterator
2239*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::do_get_monthname(iter_type __b, iter_type __e,
2240*58b9f456SAndroid Build Coastguard Worker                                                   ios_base& __iob,
2241*58b9f456SAndroid Build Coastguard Worker                                                   ios_base::iostate& __err,
2242*58b9f456SAndroid Build Coastguard Worker                                                   tm* __tm) const
2243*58b9f456SAndroid Build Coastguard Worker{
2244*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
2245*58b9f456SAndroid Build Coastguard Worker    __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
2246*58b9f456SAndroid Build Coastguard Worker    return __b;
2247*58b9f456SAndroid Build Coastguard Worker}
2248*58b9f456SAndroid Build Coastguard Worker
2249*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2250*58b9f456SAndroid Build Coastguard Worker_InputIterator
2251*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::do_get_year(iter_type __b, iter_type __e,
2252*58b9f456SAndroid Build Coastguard Worker                                              ios_base& __iob,
2253*58b9f456SAndroid Build Coastguard Worker                                              ios_base::iostate& __err,
2254*58b9f456SAndroid Build Coastguard Worker                                              tm* __tm) const
2255*58b9f456SAndroid Build Coastguard Worker{
2256*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
2257*58b9f456SAndroid Build Coastguard Worker    __get_year(__tm->tm_year, __b, __e, __err, __ct);
2258*58b9f456SAndroid Build Coastguard Worker    return __b;
2259*58b9f456SAndroid Build Coastguard Worker}
2260*58b9f456SAndroid Build Coastguard Worker
2261*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2262*58b9f456SAndroid Build Coastguard Worker_InputIterator
2263*58b9f456SAndroid Build Coastguard Workertime_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
2264*58b9f456SAndroid Build Coastguard Worker                                         ios_base& __iob,
2265*58b9f456SAndroid Build Coastguard Worker                                         ios_base::iostate& __err, tm* __tm,
2266*58b9f456SAndroid Build Coastguard Worker                                         char __fmt, char) const
2267*58b9f456SAndroid Build Coastguard Worker{
2268*58b9f456SAndroid Build Coastguard Worker    __err = ios_base::goodbit;
2269*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
2270*58b9f456SAndroid Build Coastguard Worker    switch (__fmt)
2271*58b9f456SAndroid Build Coastguard Worker    {
2272*58b9f456SAndroid Build Coastguard Worker    case 'a':
2273*58b9f456SAndroid Build Coastguard Worker    case 'A':
2274*58b9f456SAndroid Build Coastguard Worker        __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
2275*58b9f456SAndroid Build Coastguard Worker        break;
2276*58b9f456SAndroid Build Coastguard Worker    case 'b':
2277*58b9f456SAndroid Build Coastguard Worker    case 'B':
2278*58b9f456SAndroid Build Coastguard Worker    case 'h':
2279*58b9f456SAndroid Build Coastguard Worker        __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
2280*58b9f456SAndroid Build Coastguard Worker        break;
2281*58b9f456SAndroid Build Coastguard Worker    case 'c':
2282*58b9f456SAndroid Build Coastguard Worker        {
2283*58b9f456SAndroid Build Coastguard Worker        const string_type& __fm = this->__c();
2284*58b9f456SAndroid Build Coastguard Worker        __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
2285*58b9f456SAndroid Build Coastguard Worker        }
2286*58b9f456SAndroid Build Coastguard Worker        break;
2287*58b9f456SAndroid Build Coastguard Worker    case 'd':
2288*58b9f456SAndroid Build Coastguard Worker    case 'e':
2289*58b9f456SAndroid Build Coastguard Worker        __get_day(__tm->tm_mday, __b, __e, __err, __ct);
2290*58b9f456SAndroid Build Coastguard Worker        break;
2291*58b9f456SAndroid Build Coastguard Worker    case 'D':
2292*58b9f456SAndroid Build Coastguard Worker        {
2293*58b9f456SAndroid Build Coastguard Worker        const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
2294*58b9f456SAndroid Build Coastguard Worker        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2295*58b9f456SAndroid Build Coastguard Worker        }
2296*58b9f456SAndroid Build Coastguard Worker        break;
2297*58b9f456SAndroid Build Coastguard Worker    case 'F':
2298*58b9f456SAndroid Build Coastguard Worker        {
2299*58b9f456SAndroid Build Coastguard Worker        const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
2300*58b9f456SAndroid Build Coastguard Worker        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2301*58b9f456SAndroid Build Coastguard Worker        }
2302*58b9f456SAndroid Build Coastguard Worker        break;
2303*58b9f456SAndroid Build Coastguard Worker    case 'H':
2304*58b9f456SAndroid Build Coastguard Worker        __get_hour(__tm->tm_hour, __b, __e, __err, __ct);
2305*58b9f456SAndroid Build Coastguard Worker        break;
2306*58b9f456SAndroid Build Coastguard Worker    case 'I':
2307*58b9f456SAndroid Build Coastguard Worker        __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct);
2308*58b9f456SAndroid Build Coastguard Worker        break;
2309*58b9f456SAndroid Build Coastguard Worker    case 'j':
2310*58b9f456SAndroid Build Coastguard Worker        __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct);
2311*58b9f456SAndroid Build Coastguard Worker        break;
2312*58b9f456SAndroid Build Coastguard Worker    case 'm':
2313*58b9f456SAndroid Build Coastguard Worker        __get_month(__tm->tm_mon, __b, __e, __err, __ct);
2314*58b9f456SAndroid Build Coastguard Worker        break;
2315*58b9f456SAndroid Build Coastguard Worker    case 'M':
2316*58b9f456SAndroid Build Coastguard Worker        __get_minute(__tm->tm_min, __b, __e, __err, __ct);
2317*58b9f456SAndroid Build Coastguard Worker        break;
2318*58b9f456SAndroid Build Coastguard Worker    case 'n':
2319*58b9f456SAndroid Build Coastguard Worker    case 't':
2320*58b9f456SAndroid Build Coastguard Worker        __get_white_space(__b, __e, __err, __ct);
2321*58b9f456SAndroid Build Coastguard Worker        break;
2322*58b9f456SAndroid Build Coastguard Worker    case 'p':
2323*58b9f456SAndroid Build Coastguard Worker        __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct);
2324*58b9f456SAndroid Build Coastguard Worker        break;
2325*58b9f456SAndroid Build Coastguard Worker    case 'r':
2326*58b9f456SAndroid Build Coastguard Worker        {
2327*58b9f456SAndroid Build Coastguard Worker        const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
2328*58b9f456SAndroid Build Coastguard Worker        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2329*58b9f456SAndroid Build Coastguard Worker        }
2330*58b9f456SAndroid Build Coastguard Worker        break;
2331*58b9f456SAndroid Build Coastguard Worker    case 'R':
2332*58b9f456SAndroid Build Coastguard Worker        {
2333*58b9f456SAndroid Build Coastguard Worker        const char_type __fm[] = {'%', 'H', ':', '%', 'M'};
2334*58b9f456SAndroid Build Coastguard Worker        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2335*58b9f456SAndroid Build Coastguard Worker        }
2336*58b9f456SAndroid Build Coastguard Worker        break;
2337*58b9f456SAndroid Build Coastguard Worker    case 'S':
2338*58b9f456SAndroid Build Coastguard Worker        __get_second(__tm->tm_sec, __b, __e, __err, __ct);
2339*58b9f456SAndroid Build Coastguard Worker        break;
2340*58b9f456SAndroid Build Coastguard Worker    case 'T':
2341*58b9f456SAndroid Build Coastguard Worker        {
2342*58b9f456SAndroid Build Coastguard Worker        const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
2343*58b9f456SAndroid Build Coastguard Worker        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
2344*58b9f456SAndroid Build Coastguard Worker        }
2345*58b9f456SAndroid Build Coastguard Worker        break;
2346*58b9f456SAndroid Build Coastguard Worker    case 'w':
2347*58b9f456SAndroid Build Coastguard Worker        __get_weekday(__tm->tm_wday, __b, __e, __err, __ct);
2348*58b9f456SAndroid Build Coastguard Worker        break;
2349*58b9f456SAndroid Build Coastguard Worker    case 'x':
2350*58b9f456SAndroid Build Coastguard Worker        return do_get_date(__b, __e, __iob, __err, __tm);
2351*58b9f456SAndroid Build Coastguard Worker    case 'X':
2352*58b9f456SAndroid Build Coastguard Worker        {
2353*58b9f456SAndroid Build Coastguard Worker        const string_type& __fm = this->__X();
2354*58b9f456SAndroid Build Coastguard Worker        __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
2355*58b9f456SAndroid Build Coastguard Worker        }
2356*58b9f456SAndroid Build Coastguard Worker        break;
2357*58b9f456SAndroid Build Coastguard Worker    case 'y':
2358*58b9f456SAndroid Build Coastguard Worker        __get_year(__tm->tm_year, __b, __e, __err, __ct);
2359*58b9f456SAndroid Build Coastguard Worker        break;
2360*58b9f456SAndroid Build Coastguard Worker    case 'Y':
2361*58b9f456SAndroid Build Coastguard Worker        __get_year4(__tm->tm_year, __b, __e, __err, __ct);
2362*58b9f456SAndroid Build Coastguard Worker        break;
2363*58b9f456SAndroid Build Coastguard Worker    case '%':
2364*58b9f456SAndroid Build Coastguard Worker        __get_percent(__b, __e, __err, __ct);
2365*58b9f456SAndroid Build Coastguard Worker        break;
2366*58b9f456SAndroid Build Coastguard Worker    default:
2367*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::failbit;
2368*58b9f456SAndroid Build Coastguard Worker    }
2369*58b9f456SAndroid Build Coastguard Worker    return __b;
2370*58b9f456SAndroid Build Coastguard Worker}
2371*58b9f456SAndroid Build Coastguard Worker
2372*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>)
2373*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>)
2374*58b9f456SAndroid Build Coastguard Worker
2375*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS __time_get
2376*58b9f456SAndroid Build Coastguard Worker{
2377*58b9f456SAndroid Build Coastguard Workerprotected:
2378*58b9f456SAndroid Build Coastguard Worker    locale_t __loc_;
2379*58b9f456SAndroid Build Coastguard Worker
2380*58b9f456SAndroid Build Coastguard Worker    __time_get(const char* __nm);
2381*58b9f456SAndroid Build Coastguard Worker    __time_get(const string& __nm);
2382*58b9f456SAndroid Build Coastguard Worker    ~__time_get();
2383*58b9f456SAndroid Build Coastguard Worker};
2384*58b9f456SAndroid Build Coastguard Worker
2385*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
2386*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __time_get_storage
2387*58b9f456SAndroid Build Coastguard Worker    : public __time_get
2388*58b9f456SAndroid Build Coastguard Worker{
2389*58b9f456SAndroid Build Coastguard Workerprotected:
2390*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<_CharT> string_type;
2391*58b9f456SAndroid Build Coastguard Worker
2392*58b9f456SAndroid Build Coastguard Worker    string_type __weeks_[14];
2393*58b9f456SAndroid Build Coastguard Worker    string_type __months_[24];
2394*58b9f456SAndroid Build Coastguard Worker    string_type __am_pm_[2];
2395*58b9f456SAndroid Build Coastguard Worker    string_type __c_;
2396*58b9f456SAndroid Build Coastguard Worker    string_type __r_;
2397*58b9f456SAndroid Build Coastguard Worker    string_type __x_;
2398*58b9f456SAndroid Build Coastguard Worker    string_type __X_;
2399*58b9f456SAndroid Build Coastguard Worker
2400*58b9f456SAndroid Build Coastguard Worker    explicit __time_get_storage(const char* __nm);
2401*58b9f456SAndroid Build Coastguard Worker    explicit __time_get_storage(const string& __nm);
2402*58b9f456SAndroid Build Coastguard Worker
2403*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY ~__time_get_storage() {}
2404*58b9f456SAndroid Build Coastguard Worker
2405*58b9f456SAndroid Build Coastguard Worker    time_base::dateorder __do_date_order() const;
2406*58b9f456SAndroid Build Coastguard Worker
2407*58b9f456SAndroid Build Coastguard Workerprivate:
2408*58b9f456SAndroid Build Coastguard Worker    void init(const ctype<_CharT>&);
2409*58b9f456SAndroid Build Coastguard Worker    string_type __analyze(char __fmt, const ctype<_CharT>&);
2410*58b9f456SAndroid Build Coastguard Worker};
2411*58b9f456SAndroid Build Coastguard Worker
2412*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \
2413*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
2414*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const char*); \
2415*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const string&); \
2416*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
2417*58b9f456SAndroid Build Coastguard Workertemplate <> _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \
2418*58b9f456SAndroid Build Coastguard Workerextern template _LIBCPP_FUNC_VIS time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
2419*58b9f456SAndroid Build Coastguard Workerextern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const char*); \
2420*58b9f456SAndroid Build Coastguard Workerextern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const string&); \
2421*58b9f456SAndroid Build Coastguard Workerextern template _LIBCPP_FUNC_VIS void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
2422*58b9f456SAndroid Build Coastguard Workerextern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \
2423*58b9f456SAndroid Build Coastguard Worker/**/
2424*58b9f456SAndroid Build Coastguard Worker
2425*58b9f456SAndroid Build Coastguard Worker_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char)
2426*58b9f456SAndroid Build Coastguard Worker_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t)
2427*58b9f456SAndroid Build Coastguard Worker#undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION
2428*58b9f456SAndroid Build Coastguard Worker
2429*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
2430*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS time_get_byname
2431*58b9f456SAndroid Build Coastguard Worker    : public time_get<_CharT, _InputIterator>,
2432*58b9f456SAndroid Build Coastguard Worker      private __time_get_storage<_CharT>
2433*58b9f456SAndroid Build Coastguard Worker{
2434*58b9f456SAndroid Build Coastguard Workerpublic:
2435*58b9f456SAndroid Build Coastguard Worker    typedef time_base::dateorder    dateorder;
2436*58b9f456SAndroid Build Coastguard Worker    typedef _InputIterator          iter_type;
2437*58b9f456SAndroid Build Coastguard Worker    typedef _CharT                  char_type;
2438*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char_type> string_type;
2439*58b9f456SAndroid Build Coastguard Worker
2440*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2441*58b9f456SAndroid Build Coastguard Worker    explicit time_get_byname(const char* __nm, size_t __refs = 0)
2442*58b9f456SAndroid Build Coastguard Worker        : time_get<_CharT, _InputIterator>(__refs),
2443*58b9f456SAndroid Build Coastguard Worker          __time_get_storage<_CharT>(__nm) {}
2444*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2445*58b9f456SAndroid Build Coastguard Worker    explicit time_get_byname(const string& __nm, size_t __refs = 0)
2446*58b9f456SAndroid Build Coastguard Worker        : time_get<_CharT, _InputIterator>(__refs),
2447*58b9f456SAndroid Build Coastguard Worker          __time_get_storage<_CharT>(__nm) {}
2448*58b9f456SAndroid Build Coastguard Worker
2449*58b9f456SAndroid Build Coastguard Workerprotected:
2450*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2451*58b9f456SAndroid Build Coastguard Worker    ~time_get_byname() {}
2452*58b9f456SAndroid Build Coastguard Worker
2453*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2454*58b9f456SAndroid Build Coastguard Worker    virtual dateorder do_date_order() const {return this->__do_date_order();}
2455*58b9f456SAndroid Build Coastguard Workerprivate:
2456*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2457*58b9f456SAndroid Build Coastguard Worker    virtual const string_type* __weeks() const  {return this->__weeks_;}
2458*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2459*58b9f456SAndroid Build Coastguard Worker    virtual const string_type* __months() const {return this->__months_;}
2460*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2461*58b9f456SAndroid Build Coastguard Worker    virtual const string_type* __am_pm() const  {return this->__am_pm_;}
2462*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2463*58b9f456SAndroid Build Coastguard Worker    virtual const string_type& __c() const      {return this->__c_;}
2464*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2465*58b9f456SAndroid Build Coastguard Worker    virtual const string_type& __r() const      {return this->__r_;}
2466*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2467*58b9f456SAndroid Build Coastguard Worker    virtual const string_type& __x() const      {return this->__x_;}
2468*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2469*58b9f456SAndroid Build Coastguard Worker    virtual const string_type& __X() const      {return this->__X_;}
2470*58b9f456SAndroid Build Coastguard Worker};
2471*58b9f456SAndroid Build Coastguard Worker
2472*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>)
2473*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>)
2474*58b9f456SAndroid Build Coastguard Worker
2475*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS __time_put
2476*58b9f456SAndroid Build Coastguard Worker{
2477*58b9f456SAndroid Build Coastguard Worker    locale_t __loc_;
2478*58b9f456SAndroid Build Coastguard Workerprotected:
2479*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {}
2480*58b9f456SAndroid Build Coastguard Worker    __time_put(const char* __nm);
2481*58b9f456SAndroid Build Coastguard Worker    __time_put(const string& __nm);
2482*58b9f456SAndroid Build Coastguard Worker    ~__time_put();
2483*58b9f456SAndroid Build Coastguard Worker    void __do_put(char* __nb, char*& __ne, const tm* __tm,
2484*58b9f456SAndroid Build Coastguard Worker                  char __fmt, char __mod) const;
2485*58b9f456SAndroid Build Coastguard Worker    void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
2486*58b9f456SAndroid Build Coastguard Worker                  char __fmt, char __mod) const;
2487*58b9f456SAndroid Build Coastguard Worker};
2488*58b9f456SAndroid Build Coastguard Worker
2489*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2490*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS time_put
2491*58b9f456SAndroid Build Coastguard Worker    : public locale::facet,
2492*58b9f456SAndroid Build Coastguard Worker      private __time_put
2493*58b9f456SAndroid Build Coastguard Worker{
2494*58b9f456SAndroid Build Coastguard Workerpublic:
2495*58b9f456SAndroid Build Coastguard Worker    typedef _CharT char_type;
2496*58b9f456SAndroid Build Coastguard Worker    typedef _OutputIterator iter_type;
2497*58b9f456SAndroid Build Coastguard Worker
2498*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2499*58b9f456SAndroid Build Coastguard Worker    explicit time_put(size_t __refs = 0)
2500*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs) {}
2501*58b9f456SAndroid Build Coastguard Worker
2502*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm,
2503*58b9f456SAndroid Build Coastguard Worker                  const char_type* __pb, const char_type* __pe) const;
2504*58b9f456SAndroid Build Coastguard Worker
2505*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2506*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
2507*58b9f456SAndroid Build Coastguard Worker                  const tm* __tm, char __fmt, char __mod = 0) const
2508*58b9f456SAndroid Build Coastguard Worker    {
2509*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __iob, __fl, __tm, __fmt, __mod);
2510*58b9f456SAndroid Build Coastguard Worker    }
2511*58b9f456SAndroid Build Coastguard Worker
2512*58b9f456SAndroid Build Coastguard Worker    static locale::id id;
2513*58b9f456SAndroid Build Coastguard Worker
2514*58b9f456SAndroid Build Coastguard Workerprotected:
2515*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2516*58b9f456SAndroid Build Coastguard Worker    ~time_put() {}
2517*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm,
2518*58b9f456SAndroid Build Coastguard Worker                             char __fmt, char __mod) const;
2519*58b9f456SAndroid Build Coastguard Worker
2520*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2521*58b9f456SAndroid Build Coastguard Worker    explicit time_put(const char* __nm, size_t __refs)
2522*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs),
2523*58b9f456SAndroid Build Coastguard Worker          __time_put(__nm) {}
2524*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2525*58b9f456SAndroid Build Coastguard Worker    explicit time_put(const string& __nm, size_t __refs)
2526*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs),
2527*58b9f456SAndroid Build Coastguard Worker          __time_put(__nm) {}
2528*58b9f456SAndroid Build Coastguard Worker};
2529*58b9f456SAndroid Build Coastguard Worker
2530*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
2531*58b9f456SAndroid Build Coastguard Workerlocale::id
2532*58b9f456SAndroid Build Coastguard Workertime_put<_CharT, _OutputIterator>::id;
2533*58b9f456SAndroid Build Coastguard Worker
2534*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
2535*58b9f456SAndroid Build Coastguard Worker_OutputIterator
2536*58b9f456SAndroid Build Coastguard Workertime_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob,
2537*58b9f456SAndroid Build Coastguard Worker                                       char_type __fl, const tm* __tm,
2538*58b9f456SAndroid Build Coastguard Worker                                       const char_type* __pb,
2539*58b9f456SAndroid Build Coastguard Worker                                       const char_type* __pe) const
2540*58b9f456SAndroid Build Coastguard Worker{
2541*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
2542*58b9f456SAndroid Build Coastguard Worker    for (; __pb != __pe; ++__pb)
2543*58b9f456SAndroid Build Coastguard Worker    {
2544*58b9f456SAndroid Build Coastguard Worker        if (__ct.narrow(*__pb, 0) == '%')
2545*58b9f456SAndroid Build Coastguard Worker        {
2546*58b9f456SAndroid Build Coastguard Worker            if (++__pb == __pe)
2547*58b9f456SAndroid Build Coastguard Worker            {
2548*58b9f456SAndroid Build Coastguard Worker                *__s++ = __pb[-1];
2549*58b9f456SAndroid Build Coastguard Worker                break;
2550*58b9f456SAndroid Build Coastguard Worker            }
2551*58b9f456SAndroid Build Coastguard Worker            char __mod = 0;
2552*58b9f456SAndroid Build Coastguard Worker            char __fmt = __ct.narrow(*__pb, 0);
2553*58b9f456SAndroid Build Coastguard Worker            if (__fmt == 'E' || __fmt == 'O')
2554*58b9f456SAndroid Build Coastguard Worker            {
2555*58b9f456SAndroid Build Coastguard Worker                if (++__pb == __pe)
2556*58b9f456SAndroid Build Coastguard Worker                {
2557*58b9f456SAndroid Build Coastguard Worker                    *__s++ = __pb[-2];
2558*58b9f456SAndroid Build Coastguard Worker                    *__s++ = __pb[-1];
2559*58b9f456SAndroid Build Coastguard Worker                    break;
2560*58b9f456SAndroid Build Coastguard Worker                }
2561*58b9f456SAndroid Build Coastguard Worker                __mod = __fmt;
2562*58b9f456SAndroid Build Coastguard Worker                __fmt = __ct.narrow(*__pb, 0);
2563*58b9f456SAndroid Build Coastguard Worker            }
2564*58b9f456SAndroid Build Coastguard Worker            __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod);
2565*58b9f456SAndroid Build Coastguard Worker        }
2566*58b9f456SAndroid Build Coastguard Worker        else
2567*58b9f456SAndroid Build Coastguard Worker            *__s++ = *__pb;
2568*58b9f456SAndroid Build Coastguard Worker    }
2569*58b9f456SAndroid Build Coastguard Worker    return __s;
2570*58b9f456SAndroid Build Coastguard Worker}
2571*58b9f456SAndroid Build Coastguard Worker
2572*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
2573*58b9f456SAndroid Build Coastguard Worker_OutputIterator
2574*58b9f456SAndroid Build Coastguard Workertime_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&,
2575*58b9f456SAndroid Build Coastguard Worker                                          char_type, const tm* __tm,
2576*58b9f456SAndroid Build Coastguard Worker                                          char __fmt, char __mod) const
2577*58b9f456SAndroid Build Coastguard Worker{
2578*58b9f456SAndroid Build Coastguard Worker    char_type __nar[100];
2579*58b9f456SAndroid Build Coastguard Worker    char_type* __nb = __nar;
2580*58b9f456SAndroid Build Coastguard Worker    char_type* __ne = __nb + 100;
2581*58b9f456SAndroid Build Coastguard Worker    __do_put(__nb, __ne, __tm, __fmt, __mod);
2582*58b9f456SAndroid Build Coastguard Worker    return _VSTD::copy(__nb, __ne, __s);
2583*58b9f456SAndroid Build Coastguard Worker}
2584*58b9f456SAndroid Build Coastguard Worker
2585*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>)
2586*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>)
2587*58b9f456SAndroid Build Coastguard Worker
2588*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2589*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS time_put_byname
2590*58b9f456SAndroid Build Coastguard Worker    : public time_put<_CharT, _OutputIterator>
2591*58b9f456SAndroid Build Coastguard Worker{
2592*58b9f456SAndroid Build Coastguard Workerpublic:
2593*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2594*58b9f456SAndroid Build Coastguard Worker    explicit time_put_byname(const char* __nm, size_t __refs = 0)
2595*58b9f456SAndroid Build Coastguard Worker        : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
2596*58b9f456SAndroid Build Coastguard Worker
2597*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2598*58b9f456SAndroid Build Coastguard Worker    explicit time_put_byname(const string& __nm, size_t __refs = 0)
2599*58b9f456SAndroid Build Coastguard Worker        : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
2600*58b9f456SAndroid Build Coastguard Worker
2601*58b9f456SAndroid Build Coastguard Workerprotected:
2602*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2603*58b9f456SAndroid Build Coastguard Worker    ~time_put_byname() {}
2604*58b9f456SAndroid Build Coastguard Worker};
2605*58b9f456SAndroid Build Coastguard Worker
2606*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>)
2607*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>)
2608*58b9f456SAndroid Build Coastguard Worker
2609*58b9f456SAndroid Build Coastguard Worker// money_base
2610*58b9f456SAndroid Build Coastguard Worker
2611*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS money_base
2612*58b9f456SAndroid Build Coastguard Worker{
2613*58b9f456SAndroid Build Coastguard Workerpublic:
2614*58b9f456SAndroid Build Coastguard Worker    enum part {none, space, symbol, sign, value};
2615*58b9f456SAndroid Build Coastguard Worker    struct pattern {char field[4];};
2616*58b9f456SAndroid Build Coastguard Worker
2617*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY money_base() {}
2618*58b9f456SAndroid Build Coastguard Worker};
2619*58b9f456SAndroid Build Coastguard Worker
2620*58b9f456SAndroid Build Coastguard Worker// moneypunct
2621*58b9f456SAndroid Build Coastguard Worker
2622*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, bool _International = false>
2623*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS moneypunct
2624*58b9f456SAndroid Build Coastguard Worker    : public locale::facet,
2625*58b9f456SAndroid Build Coastguard Worker      public money_base
2626*58b9f456SAndroid Build Coastguard Worker{
2627*58b9f456SAndroid Build Coastguard Workerpublic:
2628*58b9f456SAndroid Build Coastguard Worker    typedef _CharT                  char_type;
2629*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char_type> string_type;
2630*58b9f456SAndroid Build Coastguard Worker
2631*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2632*58b9f456SAndroid Build Coastguard Worker    explicit moneypunct(size_t __refs = 0)
2633*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs) {}
2634*58b9f456SAndroid Build Coastguard Worker
2635*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY char_type   decimal_point() const {return do_decimal_point();}
2636*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY char_type   thousands_sep() const {return do_thousands_sep();}
2637*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY string      grouping()      const {return do_grouping();}
2638*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY string_type curr_symbol()   const {return do_curr_symbol();}
2639*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY string_type positive_sign() const {return do_positive_sign();}
2640*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY string_type negative_sign() const {return do_negative_sign();}
2641*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY int         frac_digits()   const {return do_frac_digits();}
2642*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY pattern     pos_format()    const {return do_pos_format();}
2643*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY pattern     neg_format()    const {return do_neg_format();}
2644*58b9f456SAndroid Build Coastguard Worker
2645*58b9f456SAndroid Build Coastguard Worker    static locale::id id;
2646*58b9f456SAndroid Build Coastguard Worker    static const bool intl = _International;
2647*58b9f456SAndroid Build Coastguard Worker
2648*58b9f456SAndroid Build Coastguard Workerprotected:
2649*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2650*58b9f456SAndroid Build Coastguard Worker    ~moneypunct() {}
2651*58b9f456SAndroid Build Coastguard Worker
2652*58b9f456SAndroid Build Coastguard Worker    virtual char_type   do_decimal_point() const {return numeric_limits<char_type>::max();}
2653*58b9f456SAndroid Build Coastguard Worker    virtual char_type   do_thousands_sep() const {return numeric_limits<char_type>::max();}
2654*58b9f456SAndroid Build Coastguard Worker    virtual string      do_grouping()      const {return string();}
2655*58b9f456SAndroid Build Coastguard Worker    virtual string_type do_curr_symbol()   const {return string_type();}
2656*58b9f456SAndroid Build Coastguard Worker    virtual string_type do_positive_sign() const {return string_type();}
2657*58b9f456SAndroid Build Coastguard Worker    virtual string_type do_negative_sign() const {return string_type(1, '-');}
2658*58b9f456SAndroid Build Coastguard Worker    virtual int         do_frac_digits()   const {return 0;}
2659*58b9f456SAndroid Build Coastguard Worker    virtual pattern     do_pos_format()    const
2660*58b9f456SAndroid Build Coastguard Worker        {pattern __p = {{symbol, sign, none, value}}; return __p;}
2661*58b9f456SAndroid Build Coastguard Worker    virtual pattern     do_neg_format()    const
2662*58b9f456SAndroid Build Coastguard Worker        {pattern __p = {{symbol, sign, none, value}}; return __p;}
2663*58b9f456SAndroid Build Coastguard Worker};
2664*58b9f456SAndroid Build Coastguard Worker
2665*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, bool _International>
2666*58b9f456SAndroid Build Coastguard Workerlocale::id
2667*58b9f456SAndroid Build Coastguard Workermoneypunct<_CharT, _International>::id;
2668*58b9f456SAndroid Build Coastguard Worker
2669*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, bool _International>
2670*58b9f456SAndroid Build Coastguard Workerconst bool
2671*58b9f456SAndroid Build Coastguard Workermoneypunct<_CharT, _International>::intl;
2672*58b9f456SAndroid Build Coastguard Worker
2673*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>)
2674*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>)
2675*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>)
2676*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>)
2677*58b9f456SAndroid Build Coastguard Worker
2678*58b9f456SAndroid Build Coastguard Worker// moneypunct_byname
2679*58b9f456SAndroid Build Coastguard Worker
2680*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, bool _International = false>
2681*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS moneypunct_byname
2682*58b9f456SAndroid Build Coastguard Worker    : public moneypunct<_CharT, _International>
2683*58b9f456SAndroid Build Coastguard Worker{
2684*58b9f456SAndroid Build Coastguard Workerpublic:
2685*58b9f456SAndroid Build Coastguard Worker    typedef money_base::pattern  pattern;
2686*58b9f456SAndroid Build Coastguard Worker    typedef _CharT                  char_type;
2687*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char_type> string_type;
2688*58b9f456SAndroid Build Coastguard Worker
2689*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2690*58b9f456SAndroid Build Coastguard Worker    explicit moneypunct_byname(const char* __nm, size_t __refs = 0)
2691*58b9f456SAndroid Build Coastguard Worker        : moneypunct<_CharT, _International>(__refs) {init(__nm);}
2692*58b9f456SAndroid Build Coastguard Worker
2693*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2694*58b9f456SAndroid Build Coastguard Worker    explicit moneypunct_byname(const string& __nm, size_t __refs = 0)
2695*58b9f456SAndroid Build Coastguard Worker        : moneypunct<_CharT, _International>(__refs) {init(__nm.c_str());}
2696*58b9f456SAndroid Build Coastguard Worker
2697*58b9f456SAndroid Build Coastguard Workerprotected:
2698*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2699*58b9f456SAndroid Build Coastguard Worker    ~moneypunct_byname() {}
2700*58b9f456SAndroid Build Coastguard Worker
2701*58b9f456SAndroid Build Coastguard Worker    virtual char_type   do_decimal_point() const {return __decimal_point_;}
2702*58b9f456SAndroid Build Coastguard Worker    virtual char_type   do_thousands_sep() const {return __thousands_sep_;}
2703*58b9f456SAndroid Build Coastguard Worker    virtual string      do_grouping()      const {return __grouping_;}
2704*58b9f456SAndroid Build Coastguard Worker    virtual string_type do_curr_symbol()   const {return __curr_symbol_;}
2705*58b9f456SAndroid Build Coastguard Worker    virtual string_type do_positive_sign() const {return __positive_sign_;}
2706*58b9f456SAndroid Build Coastguard Worker    virtual string_type do_negative_sign() const {return __negative_sign_;}
2707*58b9f456SAndroid Build Coastguard Worker    virtual int         do_frac_digits()   const {return __frac_digits_;}
2708*58b9f456SAndroid Build Coastguard Worker    virtual pattern     do_pos_format()    const {return __pos_format_;}
2709*58b9f456SAndroid Build Coastguard Worker    virtual pattern     do_neg_format()    const {return __neg_format_;}
2710*58b9f456SAndroid Build Coastguard Worker
2711*58b9f456SAndroid Build Coastguard Workerprivate:
2712*58b9f456SAndroid Build Coastguard Worker    char_type   __decimal_point_;
2713*58b9f456SAndroid Build Coastguard Worker    char_type   __thousands_sep_;
2714*58b9f456SAndroid Build Coastguard Worker    string      __grouping_;
2715*58b9f456SAndroid Build Coastguard Worker    string_type __curr_symbol_;
2716*58b9f456SAndroid Build Coastguard Worker    string_type __positive_sign_;
2717*58b9f456SAndroid Build Coastguard Worker    string_type __negative_sign_;
2718*58b9f456SAndroid Build Coastguard Worker    int         __frac_digits_;
2719*58b9f456SAndroid Build Coastguard Worker    pattern     __pos_format_;
2720*58b9f456SAndroid Build Coastguard Worker    pattern     __neg_format_;
2721*58b9f456SAndroid Build Coastguard Worker
2722*58b9f456SAndroid Build Coastguard Worker    void init(const char*);
2723*58b9f456SAndroid Build Coastguard Worker};
2724*58b9f456SAndroid Build Coastguard Worker
2725*58b9f456SAndroid Build Coastguard Workertemplate<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, false>::init(const char*);
2726*58b9f456SAndroid Build Coastguard Workertemplate<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, true>::init(const char*);
2727*58b9f456SAndroid Build Coastguard Workertemplate<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, false>::init(const char*);
2728*58b9f456SAndroid Build Coastguard Workertemplate<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, true>::init(const char*);
2729*58b9f456SAndroid Build Coastguard Worker
2730*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>)
2731*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>)
2732*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>)
2733*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>)
2734*58b9f456SAndroid Build Coastguard Worker
2735*58b9f456SAndroid Build Coastguard Worker// money_get
2736*58b9f456SAndroid Build Coastguard Worker
2737*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
2738*58b9f456SAndroid Build Coastguard Workerclass __money_get
2739*58b9f456SAndroid Build Coastguard Worker{
2740*58b9f456SAndroid Build Coastguard Workerprotected:
2741*58b9f456SAndroid Build Coastguard Worker    typedef _CharT                  char_type;
2742*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char_type> string_type;
2743*58b9f456SAndroid Build Coastguard Worker
2744*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY __money_get() {}
2745*58b9f456SAndroid Build Coastguard Worker
2746*58b9f456SAndroid Build Coastguard Worker    static void __gather_info(bool __intl, const locale& __loc,
2747*58b9f456SAndroid Build Coastguard Worker                              money_base::pattern& __pat, char_type& __dp,
2748*58b9f456SAndroid Build Coastguard Worker                              char_type& __ts, string& __grp,
2749*58b9f456SAndroid Build Coastguard Worker                              string_type& __sym, string_type& __psn,
2750*58b9f456SAndroid Build Coastguard Worker                              string_type& __nsn, int& __fd);
2751*58b9f456SAndroid Build Coastguard Worker};
2752*58b9f456SAndroid Build Coastguard Worker
2753*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
2754*58b9f456SAndroid Build Coastguard Workervoid
2755*58b9f456SAndroid Build Coastguard Worker__money_get<_CharT>::__gather_info(bool __intl, const locale& __loc,
2756*58b9f456SAndroid Build Coastguard Worker                                   money_base::pattern& __pat, char_type& __dp,
2757*58b9f456SAndroid Build Coastguard Worker                                   char_type& __ts, string& __grp,
2758*58b9f456SAndroid Build Coastguard Worker                                   string_type& __sym, string_type& __psn,
2759*58b9f456SAndroid Build Coastguard Worker                                   string_type& __nsn, int& __fd)
2760*58b9f456SAndroid Build Coastguard Worker{
2761*58b9f456SAndroid Build Coastguard Worker    if (__intl)
2762*58b9f456SAndroid Build Coastguard Worker    {
2763*58b9f456SAndroid Build Coastguard Worker        const moneypunct<char_type, true>& __mp =
2764*58b9f456SAndroid Build Coastguard Worker            use_facet<moneypunct<char_type, true> >(__loc);
2765*58b9f456SAndroid Build Coastguard Worker        __pat = __mp.neg_format();
2766*58b9f456SAndroid Build Coastguard Worker        __nsn = __mp.negative_sign();
2767*58b9f456SAndroid Build Coastguard Worker        __psn = __mp.positive_sign();
2768*58b9f456SAndroid Build Coastguard Worker        __dp = __mp.decimal_point();
2769*58b9f456SAndroid Build Coastguard Worker        __ts = __mp.thousands_sep();
2770*58b9f456SAndroid Build Coastguard Worker        __grp = __mp.grouping();
2771*58b9f456SAndroid Build Coastguard Worker        __sym = __mp.curr_symbol();
2772*58b9f456SAndroid Build Coastguard Worker        __fd = __mp.frac_digits();
2773*58b9f456SAndroid Build Coastguard Worker    }
2774*58b9f456SAndroid Build Coastguard Worker    else
2775*58b9f456SAndroid Build Coastguard Worker    {
2776*58b9f456SAndroid Build Coastguard Worker        const moneypunct<char_type, false>& __mp =
2777*58b9f456SAndroid Build Coastguard Worker            use_facet<moneypunct<char_type, false> >(__loc);
2778*58b9f456SAndroid Build Coastguard Worker        __pat = __mp.neg_format();
2779*58b9f456SAndroid Build Coastguard Worker        __nsn = __mp.negative_sign();
2780*58b9f456SAndroid Build Coastguard Worker        __psn = __mp.positive_sign();
2781*58b9f456SAndroid Build Coastguard Worker        __dp = __mp.decimal_point();
2782*58b9f456SAndroid Build Coastguard Worker        __ts = __mp.thousands_sep();
2783*58b9f456SAndroid Build Coastguard Worker        __grp = __mp.grouping();
2784*58b9f456SAndroid Build Coastguard Worker        __sym = __mp.curr_symbol();
2785*58b9f456SAndroid Build Coastguard Worker        __fd = __mp.frac_digits();
2786*58b9f456SAndroid Build Coastguard Worker    }
2787*58b9f456SAndroid Build Coastguard Worker}
2788*58b9f456SAndroid Build Coastguard Worker
2789*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>)
2790*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>)
2791*58b9f456SAndroid Build Coastguard Worker
2792*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
2793*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS money_get
2794*58b9f456SAndroid Build Coastguard Worker    : public locale::facet,
2795*58b9f456SAndroid Build Coastguard Worker      private __money_get<_CharT>
2796*58b9f456SAndroid Build Coastguard Worker{
2797*58b9f456SAndroid Build Coastguard Workerpublic:
2798*58b9f456SAndroid Build Coastguard Worker    typedef _CharT                  char_type;
2799*58b9f456SAndroid Build Coastguard Worker    typedef _InputIterator          iter_type;
2800*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char_type> string_type;
2801*58b9f456SAndroid Build Coastguard Worker
2802*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2803*58b9f456SAndroid Build Coastguard Worker    explicit money_get(size_t __refs = 0)
2804*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs) {}
2805*58b9f456SAndroid Build Coastguard Worker
2806*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2807*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob,
2808*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, long double& __v) const
2809*58b9f456SAndroid Build Coastguard Worker    {
2810*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __intl, __iob, __err, __v);
2811*58b9f456SAndroid Build Coastguard Worker    }
2812*58b9f456SAndroid Build Coastguard Worker
2813*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2814*58b9f456SAndroid Build Coastguard Worker    iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob,
2815*58b9f456SAndroid Build Coastguard Worker                  ios_base::iostate& __err, string_type& __v) const
2816*58b9f456SAndroid Build Coastguard Worker    {
2817*58b9f456SAndroid Build Coastguard Worker        return do_get(__b, __e, __intl, __iob, __err, __v);
2818*58b9f456SAndroid Build Coastguard Worker    }
2819*58b9f456SAndroid Build Coastguard Worker
2820*58b9f456SAndroid Build Coastguard Worker    static locale::id id;
2821*58b9f456SAndroid Build Coastguard Worker
2822*58b9f456SAndroid Build Coastguard Workerprotected:
2823*58b9f456SAndroid Build Coastguard Worker
2824*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
2825*58b9f456SAndroid Build Coastguard Worker    ~money_get() {}
2826*58b9f456SAndroid Build Coastguard Worker
2827*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl,
2828*58b9f456SAndroid Build Coastguard Worker                             ios_base& __iob, ios_base::iostate& __err,
2829*58b9f456SAndroid Build Coastguard Worker                             long double& __v) const;
2830*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl,
2831*58b9f456SAndroid Build Coastguard Worker                             ios_base& __iob, ios_base::iostate& __err,
2832*58b9f456SAndroid Build Coastguard Worker                             string_type& __v) const;
2833*58b9f456SAndroid Build Coastguard Worker
2834*58b9f456SAndroid Build Coastguard Workerprivate:
2835*58b9f456SAndroid Build Coastguard Worker    static bool __do_get(iter_type& __b, iter_type __e,
2836*58b9f456SAndroid Build Coastguard Worker                         bool __intl, const locale& __loc,
2837*58b9f456SAndroid Build Coastguard Worker                         ios_base::fmtflags __flags, ios_base::iostate& __err,
2838*58b9f456SAndroid Build Coastguard Worker                         bool& __neg, const ctype<char_type>& __ct,
2839*58b9f456SAndroid Build Coastguard Worker                         unique_ptr<char_type, void(*)(void*)>& __wb,
2840*58b9f456SAndroid Build Coastguard Worker                         char_type*& __wn, char_type* __we);
2841*58b9f456SAndroid Build Coastguard Worker};
2842*58b9f456SAndroid Build Coastguard Worker
2843*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2844*58b9f456SAndroid Build Coastguard Workerlocale::id
2845*58b9f456SAndroid Build Coastguard Workermoney_get<_CharT, _InputIterator>::id;
2846*58b9f456SAndroid Build Coastguard Worker
2847*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS void __do_nothing(void*);
2848*58b9f456SAndroid Build Coastguard Worker
2849*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
2850*58b9f456SAndroid Build Coastguard Worker_LIBCPP_HIDDEN
2851*58b9f456SAndroid Build Coastguard Workervoid
2852*58b9f456SAndroid Build Coastguard Worker__double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e)
2853*58b9f456SAndroid Build Coastguard Worker{
2854*58b9f456SAndroid Build Coastguard Worker    bool __owns = __b.get_deleter() != __do_nothing;
2855*58b9f456SAndroid Build Coastguard Worker    size_t __cur_cap = static_cast<size_t>(__e-__b.get()) * sizeof(_Tp);
2856*58b9f456SAndroid Build Coastguard Worker    size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ?
2857*58b9f456SAndroid Build Coastguard Worker                       2 * __cur_cap : numeric_limits<size_t>::max();
2858*58b9f456SAndroid Build Coastguard Worker    if (__new_cap == 0)
2859*58b9f456SAndroid Build Coastguard Worker        __new_cap = sizeof(_Tp);
2860*58b9f456SAndroid Build Coastguard Worker    size_t __n_off = static_cast<size_t>(__n - __b.get());
2861*58b9f456SAndroid Build Coastguard Worker    _Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap);
2862*58b9f456SAndroid Build Coastguard Worker    if (__t == 0)
2863*58b9f456SAndroid Build Coastguard Worker        __throw_bad_alloc();
2864*58b9f456SAndroid Build Coastguard Worker    if (__owns)
2865*58b9f456SAndroid Build Coastguard Worker        __b.release();
2866*58b9f456SAndroid Build Coastguard Worker    __b = unique_ptr<_Tp, void(*)(void*)>(__t, free);
2867*58b9f456SAndroid Build Coastguard Worker    __new_cap /= sizeof(_Tp);
2868*58b9f456SAndroid Build Coastguard Worker    __n = __b.get() + __n_off;
2869*58b9f456SAndroid Build Coastguard Worker    __e = __b.get() + __new_cap;
2870*58b9f456SAndroid Build Coastguard Worker}
2871*58b9f456SAndroid Build Coastguard Worker
2872*58b9f456SAndroid Build Coastguard Worker// true == success
2873*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
2874*58b9f456SAndroid Build Coastguard Workerbool
2875*58b9f456SAndroid Build Coastguard Workermoney_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
2876*58b9f456SAndroid Build Coastguard Worker                                            bool __intl, const locale& __loc,
2877*58b9f456SAndroid Build Coastguard Worker                                            ios_base::fmtflags __flags,
2878*58b9f456SAndroid Build Coastguard Worker                                            ios_base::iostate& __err,
2879*58b9f456SAndroid Build Coastguard Worker                                            bool& __neg,
2880*58b9f456SAndroid Build Coastguard Worker                                            const ctype<char_type>& __ct,
2881*58b9f456SAndroid Build Coastguard Worker                                            unique_ptr<char_type, void(*)(void*)>& __wb,
2882*58b9f456SAndroid Build Coastguard Worker                                            char_type*& __wn, char_type* __we)
2883*58b9f456SAndroid Build Coastguard Worker{
2884*58b9f456SAndroid Build Coastguard Worker    const unsigned __bz = 100;
2885*58b9f456SAndroid Build Coastguard Worker    unsigned __gbuf[__bz];
2886*58b9f456SAndroid Build Coastguard Worker    unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing);
2887*58b9f456SAndroid Build Coastguard Worker    unsigned* __gn = __gb.get();
2888*58b9f456SAndroid Build Coastguard Worker    unsigned* __ge = __gn + __bz;
2889*58b9f456SAndroid Build Coastguard Worker    money_base::pattern __pat;
2890*58b9f456SAndroid Build Coastguard Worker    char_type __dp;
2891*58b9f456SAndroid Build Coastguard Worker    char_type __ts;
2892*58b9f456SAndroid Build Coastguard Worker    string __grp;
2893*58b9f456SAndroid Build Coastguard Worker    string_type __sym;
2894*58b9f456SAndroid Build Coastguard Worker    string_type __psn;
2895*58b9f456SAndroid Build Coastguard Worker    string_type __nsn;
2896*58b9f456SAndroid Build Coastguard Worker    // Capture the spaces read into money_base::{space,none} so they
2897*58b9f456SAndroid Build Coastguard Worker    // can be compared to initial spaces in __sym.
2898*58b9f456SAndroid Build Coastguard Worker    string_type __spaces;
2899*58b9f456SAndroid Build Coastguard Worker    int __fd;
2900*58b9f456SAndroid Build Coastguard Worker    __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp,
2901*58b9f456SAndroid Build Coastguard Worker                                       __sym, __psn, __nsn, __fd);
2902*58b9f456SAndroid Build Coastguard Worker    const string_type* __trailing_sign = 0;
2903*58b9f456SAndroid Build Coastguard Worker    __wn = __wb.get();
2904*58b9f456SAndroid Build Coastguard Worker    for (unsigned __p = 0; __p < 4 && __b != __e; ++__p)
2905*58b9f456SAndroid Build Coastguard Worker    {
2906*58b9f456SAndroid Build Coastguard Worker        switch (__pat.field[__p])
2907*58b9f456SAndroid Build Coastguard Worker        {
2908*58b9f456SAndroid Build Coastguard Worker        case money_base::space:
2909*58b9f456SAndroid Build Coastguard Worker            if (__p != 3)
2910*58b9f456SAndroid Build Coastguard Worker            {
2911*58b9f456SAndroid Build Coastguard Worker                if (__ct.is(ctype_base::space, *__b))
2912*58b9f456SAndroid Build Coastguard Worker                    __spaces.push_back(*__b++);
2913*58b9f456SAndroid Build Coastguard Worker                else
2914*58b9f456SAndroid Build Coastguard Worker                {
2915*58b9f456SAndroid Build Coastguard Worker                    __err |= ios_base::failbit;
2916*58b9f456SAndroid Build Coastguard Worker                    return false;
2917*58b9f456SAndroid Build Coastguard Worker                }
2918*58b9f456SAndroid Build Coastguard Worker            }
2919*58b9f456SAndroid Build Coastguard Worker            _LIBCPP_FALLTHROUGH();
2920*58b9f456SAndroid Build Coastguard Worker        case money_base::none:
2921*58b9f456SAndroid Build Coastguard Worker            if (__p != 3)
2922*58b9f456SAndroid Build Coastguard Worker            {
2923*58b9f456SAndroid Build Coastguard Worker                while (__b != __e && __ct.is(ctype_base::space, *__b))
2924*58b9f456SAndroid Build Coastguard Worker                    __spaces.push_back(*__b++);
2925*58b9f456SAndroid Build Coastguard Worker            }
2926*58b9f456SAndroid Build Coastguard Worker            break;
2927*58b9f456SAndroid Build Coastguard Worker        case money_base::sign:
2928*58b9f456SAndroid Build Coastguard Worker            if (__psn.size() + __nsn.size() > 0)
2929*58b9f456SAndroid Build Coastguard Worker            {
2930*58b9f456SAndroid Build Coastguard Worker                if (__psn.size() == 0 || __nsn.size() == 0)
2931*58b9f456SAndroid Build Coastguard Worker                {   // sign is optional
2932*58b9f456SAndroid Build Coastguard Worker                    if (__psn.size() > 0)
2933*58b9f456SAndroid Build Coastguard Worker                    {   // __nsn.size() == 0
2934*58b9f456SAndroid Build Coastguard Worker                        if (*__b == __psn[0])
2935*58b9f456SAndroid Build Coastguard Worker                        {
2936*58b9f456SAndroid Build Coastguard Worker                            ++__b;
2937*58b9f456SAndroid Build Coastguard Worker                            if (__psn.size() > 1)
2938*58b9f456SAndroid Build Coastguard Worker                                __trailing_sign = &__psn;
2939*58b9f456SAndroid Build Coastguard Worker                        }
2940*58b9f456SAndroid Build Coastguard Worker                        else
2941*58b9f456SAndroid Build Coastguard Worker                            __neg = true;
2942*58b9f456SAndroid Build Coastguard Worker                    }
2943*58b9f456SAndroid Build Coastguard Worker                    else if (*__b == __nsn[0])  // __nsn.size() > 0 &&  __psn.size() == 0
2944*58b9f456SAndroid Build Coastguard Worker                    {
2945*58b9f456SAndroid Build Coastguard Worker                        ++__b;
2946*58b9f456SAndroid Build Coastguard Worker                        __neg = true;
2947*58b9f456SAndroid Build Coastguard Worker                        if (__nsn.size() > 1)
2948*58b9f456SAndroid Build Coastguard Worker                            __trailing_sign = &__nsn;
2949*58b9f456SAndroid Build Coastguard Worker                    }
2950*58b9f456SAndroid Build Coastguard Worker                }
2951*58b9f456SAndroid Build Coastguard Worker                else  // sign is required
2952*58b9f456SAndroid Build Coastguard Worker                {
2953*58b9f456SAndroid Build Coastguard Worker                    if (*__b == __psn[0])
2954*58b9f456SAndroid Build Coastguard Worker                    {
2955*58b9f456SAndroid Build Coastguard Worker                        ++__b;
2956*58b9f456SAndroid Build Coastguard Worker                        if (__psn.size() > 1)
2957*58b9f456SAndroid Build Coastguard Worker                            __trailing_sign = &__psn;
2958*58b9f456SAndroid Build Coastguard Worker                    }
2959*58b9f456SAndroid Build Coastguard Worker                    else if (*__b == __nsn[0])
2960*58b9f456SAndroid Build Coastguard Worker                    {
2961*58b9f456SAndroid Build Coastguard Worker                        ++__b;
2962*58b9f456SAndroid Build Coastguard Worker                        __neg = true;
2963*58b9f456SAndroid Build Coastguard Worker                        if (__nsn.size() > 1)
2964*58b9f456SAndroid Build Coastguard Worker                            __trailing_sign = &__nsn;
2965*58b9f456SAndroid Build Coastguard Worker                    }
2966*58b9f456SAndroid Build Coastguard Worker                    else
2967*58b9f456SAndroid Build Coastguard Worker                    {
2968*58b9f456SAndroid Build Coastguard Worker                        __err |= ios_base::failbit;
2969*58b9f456SAndroid Build Coastguard Worker                        return false;
2970*58b9f456SAndroid Build Coastguard Worker                    }
2971*58b9f456SAndroid Build Coastguard Worker                }
2972*58b9f456SAndroid Build Coastguard Worker            }
2973*58b9f456SAndroid Build Coastguard Worker            break;
2974*58b9f456SAndroid Build Coastguard Worker        case money_base::symbol:
2975*58b9f456SAndroid Build Coastguard Worker            {
2976*58b9f456SAndroid Build Coastguard Worker            bool __more_needed = __trailing_sign ||
2977*58b9f456SAndroid Build Coastguard Worker                                 (__p < 2)       ||
2978*58b9f456SAndroid Build Coastguard Worker                                 (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none));
2979*58b9f456SAndroid Build Coastguard Worker            bool __sb = (__flags & ios_base::showbase) != 0;
2980*58b9f456SAndroid Build Coastguard Worker            if (__sb || __more_needed)
2981*58b9f456SAndroid Build Coastguard Worker            {
2982*58b9f456SAndroid Build Coastguard Worker                typename string_type::const_iterator __sym_space_end = __sym.begin();
2983*58b9f456SAndroid Build Coastguard Worker                if (__p > 0 && (__pat.field[__p - 1] == money_base::none ||
2984*58b9f456SAndroid Build Coastguard Worker                                __pat.field[__p - 1] == money_base::space)) {
2985*58b9f456SAndroid Build Coastguard Worker                    // Match spaces we've already read against spaces at
2986*58b9f456SAndroid Build Coastguard Worker                    // the beginning of __sym.
2987*58b9f456SAndroid Build Coastguard Worker                    while (__sym_space_end != __sym.end() &&
2988*58b9f456SAndroid Build Coastguard Worker                           __ct.is(ctype_base::space, *__sym_space_end))
2989*58b9f456SAndroid Build Coastguard Worker                        ++__sym_space_end;
2990*58b9f456SAndroid Build Coastguard Worker                    const size_t __num_spaces = __sym_space_end - __sym.begin();
2991*58b9f456SAndroid Build Coastguard Worker                    if (__num_spaces > __spaces.size() ||
2992*58b9f456SAndroid Build Coastguard Worker                        !equal(__spaces.end() - __num_spaces, __spaces.end(),
2993*58b9f456SAndroid Build Coastguard Worker                               __sym.begin())) {
2994*58b9f456SAndroid Build Coastguard Worker                        // No match. Put __sym_space_end back at the
2995*58b9f456SAndroid Build Coastguard Worker                        // beginning of __sym, which will prevent a
2996*58b9f456SAndroid Build Coastguard Worker                        // match in the next loop.
2997*58b9f456SAndroid Build Coastguard Worker                        __sym_space_end = __sym.begin();
2998*58b9f456SAndroid Build Coastguard Worker                    }
2999*58b9f456SAndroid Build Coastguard Worker                }
3000*58b9f456SAndroid Build Coastguard Worker                typename string_type::const_iterator __sym_curr_char = __sym_space_end;
3001*58b9f456SAndroid Build Coastguard Worker                while (__sym_curr_char != __sym.end() && __b != __e &&
3002*58b9f456SAndroid Build Coastguard Worker                       *__b == *__sym_curr_char) {
3003*58b9f456SAndroid Build Coastguard Worker                    ++__b;
3004*58b9f456SAndroid Build Coastguard Worker                    ++__sym_curr_char;
3005*58b9f456SAndroid Build Coastguard Worker                }
3006*58b9f456SAndroid Build Coastguard Worker                if (__sb && __sym_curr_char != __sym.end())
3007*58b9f456SAndroid Build Coastguard Worker                {
3008*58b9f456SAndroid Build Coastguard Worker                    __err |= ios_base::failbit;
3009*58b9f456SAndroid Build Coastguard Worker                    return false;
3010*58b9f456SAndroid Build Coastguard Worker                }
3011*58b9f456SAndroid Build Coastguard Worker            }
3012*58b9f456SAndroid Build Coastguard Worker            }
3013*58b9f456SAndroid Build Coastguard Worker            break;
3014*58b9f456SAndroid Build Coastguard Worker        case money_base::value:
3015*58b9f456SAndroid Build Coastguard Worker            {
3016*58b9f456SAndroid Build Coastguard Worker            unsigned __ng = 0;
3017*58b9f456SAndroid Build Coastguard Worker            for (; __b != __e; ++__b)
3018*58b9f456SAndroid Build Coastguard Worker            {
3019*58b9f456SAndroid Build Coastguard Worker                char_type __c = *__b;
3020*58b9f456SAndroid Build Coastguard Worker                if (__ct.is(ctype_base::digit, __c))
3021*58b9f456SAndroid Build Coastguard Worker                {
3022*58b9f456SAndroid Build Coastguard Worker                    if (__wn == __we)
3023*58b9f456SAndroid Build Coastguard Worker                        __double_or_nothing(__wb, __wn, __we);
3024*58b9f456SAndroid Build Coastguard Worker                    *__wn++ = __c;
3025*58b9f456SAndroid Build Coastguard Worker                    ++__ng;
3026*58b9f456SAndroid Build Coastguard Worker                }
3027*58b9f456SAndroid Build Coastguard Worker                else if (__grp.size() > 0 && __ng > 0 && __c == __ts)
3028*58b9f456SAndroid Build Coastguard Worker                {
3029*58b9f456SAndroid Build Coastguard Worker                    if (__gn == __ge)
3030*58b9f456SAndroid Build Coastguard Worker                        __double_or_nothing(__gb, __gn, __ge);
3031*58b9f456SAndroid Build Coastguard Worker                    *__gn++ = __ng;
3032*58b9f456SAndroid Build Coastguard Worker                    __ng = 0;
3033*58b9f456SAndroid Build Coastguard Worker                }
3034*58b9f456SAndroid Build Coastguard Worker                else
3035*58b9f456SAndroid Build Coastguard Worker                    break;
3036*58b9f456SAndroid Build Coastguard Worker            }
3037*58b9f456SAndroid Build Coastguard Worker            if (__gb.get() != __gn && __ng > 0)
3038*58b9f456SAndroid Build Coastguard Worker            {
3039*58b9f456SAndroid Build Coastguard Worker                if (__gn == __ge)
3040*58b9f456SAndroid Build Coastguard Worker                    __double_or_nothing(__gb, __gn, __ge);
3041*58b9f456SAndroid Build Coastguard Worker                *__gn++ = __ng;
3042*58b9f456SAndroid Build Coastguard Worker            }
3043*58b9f456SAndroid Build Coastguard Worker            if (__fd > 0)
3044*58b9f456SAndroid Build Coastguard Worker            {
3045*58b9f456SAndroid Build Coastguard Worker                if (__b == __e || *__b != __dp)
3046*58b9f456SAndroid Build Coastguard Worker                {
3047*58b9f456SAndroid Build Coastguard Worker                    __err |= ios_base::failbit;
3048*58b9f456SAndroid Build Coastguard Worker                    return false;
3049*58b9f456SAndroid Build Coastguard Worker                }
3050*58b9f456SAndroid Build Coastguard Worker                for (++__b; __fd > 0; --__fd, ++__b)
3051*58b9f456SAndroid Build Coastguard Worker                {
3052*58b9f456SAndroid Build Coastguard Worker                    if (__b == __e || !__ct.is(ctype_base::digit, *__b))
3053*58b9f456SAndroid Build Coastguard Worker                    {
3054*58b9f456SAndroid Build Coastguard Worker                        __err |= ios_base::failbit;
3055*58b9f456SAndroid Build Coastguard Worker                        return false;
3056*58b9f456SAndroid Build Coastguard Worker                    }
3057*58b9f456SAndroid Build Coastguard Worker                    if (__wn == __we)
3058*58b9f456SAndroid Build Coastguard Worker                        __double_or_nothing(__wb, __wn, __we);
3059*58b9f456SAndroid Build Coastguard Worker                    *__wn++ = *__b;
3060*58b9f456SAndroid Build Coastguard Worker                }
3061*58b9f456SAndroid Build Coastguard Worker            }
3062*58b9f456SAndroid Build Coastguard Worker            if (__wn == __wb.get())
3063*58b9f456SAndroid Build Coastguard Worker            {
3064*58b9f456SAndroid Build Coastguard Worker                __err |= ios_base::failbit;
3065*58b9f456SAndroid Build Coastguard Worker                return false;
3066*58b9f456SAndroid Build Coastguard Worker            }
3067*58b9f456SAndroid Build Coastguard Worker            }
3068*58b9f456SAndroid Build Coastguard Worker            break;
3069*58b9f456SAndroid Build Coastguard Worker        }
3070*58b9f456SAndroid Build Coastguard Worker    }
3071*58b9f456SAndroid Build Coastguard Worker    if (__trailing_sign)
3072*58b9f456SAndroid Build Coastguard Worker    {
3073*58b9f456SAndroid Build Coastguard Worker        for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b)
3074*58b9f456SAndroid Build Coastguard Worker        {
3075*58b9f456SAndroid Build Coastguard Worker            if (__b == __e || *__b != (*__trailing_sign)[__i])
3076*58b9f456SAndroid Build Coastguard Worker            {
3077*58b9f456SAndroid Build Coastguard Worker                __err |= ios_base::failbit;
3078*58b9f456SAndroid Build Coastguard Worker                return false;
3079*58b9f456SAndroid Build Coastguard Worker            }
3080*58b9f456SAndroid Build Coastguard Worker        }
3081*58b9f456SAndroid Build Coastguard Worker    }
3082*58b9f456SAndroid Build Coastguard Worker    if (__gb.get() != __gn)
3083*58b9f456SAndroid Build Coastguard Worker    {
3084*58b9f456SAndroid Build Coastguard Worker        ios_base::iostate __et = ios_base::goodbit;
3085*58b9f456SAndroid Build Coastguard Worker        __check_grouping(__grp, __gb.get(), __gn, __et);
3086*58b9f456SAndroid Build Coastguard Worker        if (__et)
3087*58b9f456SAndroid Build Coastguard Worker        {
3088*58b9f456SAndroid Build Coastguard Worker            __err |= ios_base::failbit;
3089*58b9f456SAndroid Build Coastguard Worker            return false;
3090*58b9f456SAndroid Build Coastguard Worker        }
3091*58b9f456SAndroid Build Coastguard Worker    }
3092*58b9f456SAndroid Build Coastguard Worker    return true;
3093*58b9f456SAndroid Build Coastguard Worker}
3094*58b9f456SAndroid Build Coastguard Worker
3095*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
3096*58b9f456SAndroid Build Coastguard Worker_InputIterator
3097*58b9f456SAndroid Build Coastguard Workermoney_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
3098*58b9f456SAndroid Build Coastguard Worker                                          bool __intl, ios_base& __iob,
3099*58b9f456SAndroid Build Coastguard Worker                                          ios_base::iostate& __err,
3100*58b9f456SAndroid Build Coastguard Worker                                          long double& __v) const
3101*58b9f456SAndroid Build Coastguard Worker{
3102*58b9f456SAndroid Build Coastguard Worker    const int __bz = 100;
3103*58b9f456SAndroid Build Coastguard Worker    char_type __wbuf[__bz];
3104*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
3105*58b9f456SAndroid Build Coastguard Worker    char_type* __wn;
3106*58b9f456SAndroid Build Coastguard Worker    char_type* __we = __wbuf + __bz;
3107*58b9f456SAndroid Build Coastguard Worker    locale __loc = __iob.getloc();
3108*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
3109*58b9f456SAndroid Build Coastguard Worker    bool __neg = false;
3110*58b9f456SAndroid Build Coastguard Worker    if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct,
3111*58b9f456SAndroid Build Coastguard Worker                 __wb, __wn, __we))
3112*58b9f456SAndroid Build Coastguard Worker    {
3113*58b9f456SAndroid Build Coastguard Worker        const char __src[] = "0123456789";
3114*58b9f456SAndroid Build Coastguard Worker        char_type __atoms[sizeof(__src)-1];
3115*58b9f456SAndroid Build Coastguard Worker        __ct.widen(__src, __src + (sizeof(__src)-1), __atoms);
3116*58b9f456SAndroid Build Coastguard Worker        char __nbuf[__bz];
3117*58b9f456SAndroid Build Coastguard Worker        char* __nc = __nbuf;
3118*58b9f456SAndroid Build Coastguard Worker        unique_ptr<char, void(*)(void*)> __h(0, free);
3119*58b9f456SAndroid Build Coastguard Worker        if (__wn - __wb.get() > __bz-2)
3120*58b9f456SAndroid Build Coastguard Worker        {
3121*58b9f456SAndroid Build Coastguard Worker            __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2)));
3122*58b9f456SAndroid Build Coastguard Worker            if (__h.get() == 0)
3123*58b9f456SAndroid Build Coastguard Worker                __throw_bad_alloc();
3124*58b9f456SAndroid Build Coastguard Worker            __nc = __h.get();
3125*58b9f456SAndroid Build Coastguard Worker        }
3126*58b9f456SAndroid Build Coastguard Worker        if (__neg)
3127*58b9f456SAndroid Build Coastguard Worker            *__nc++ = '-';
3128*58b9f456SAndroid Build Coastguard Worker        for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc)
3129*58b9f456SAndroid Build Coastguard Worker            *__nc = __src[find(__atoms, _VSTD::end(__atoms), *__w) - __atoms];
3130*58b9f456SAndroid Build Coastguard Worker        *__nc = char();
3131*58b9f456SAndroid Build Coastguard Worker        if (sscanf(__nbuf, "%Lf", &__v) != 1)
3132*58b9f456SAndroid Build Coastguard Worker            __throw_runtime_error("money_get error");
3133*58b9f456SAndroid Build Coastguard Worker    }
3134*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
3135*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
3136*58b9f456SAndroid Build Coastguard Worker    return __b;
3137*58b9f456SAndroid Build Coastguard Worker}
3138*58b9f456SAndroid Build Coastguard Worker
3139*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _InputIterator>
3140*58b9f456SAndroid Build Coastguard Worker_InputIterator
3141*58b9f456SAndroid Build Coastguard Workermoney_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
3142*58b9f456SAndroid Build Coastguard Worker                                          bool __intl, ios_base& __iob,
3143*58b9f456SAndroid Build Coastguard Worker                                          ios_base::iostate& __err,
3144*58b9f456SAndroid Build Coastguard Worker                                          string_type& __v) const
3145*58b9f456SAndroid Build Coastguard Worker{
3146*58b9f456SAndroid Build Coastguard Worker    const int __bz = 100;
3147*58b9f456SAndroid Build Coastguard Worker    char_type __wbuf[__bz];
3148*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
3149*58b9f456SAndroid Build Coastguard Worker    char_type* __wn;
3150*58b9f456SAndroid Build Coastguard Worker    char_type* __we = __wbuf + __bz;
3151*58b9f456SAndroid Build Coastguard Worker    locale __loc = __iob.getloc();
3152*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
3153*58b9f456SAndroid Build Coastguard Worker    bool __neg = false;
3154*58b9f456SAndroid Build Coastguard Worker    if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct,
3155*58b9f456SAndroid Build Coastguard Worker                 __wb, __wn, __we))
3156*58b9f456SAndroid Build Coastguard Worker    {
3157*58b9f456SAndroid Build Coastguard Worker        __v.clear();
3158*58b9f456SAndroid Build Coastguard Worker        if (__neg)
3159*58b9f456SAndroid Build Coastguard Worker            __v.push_back(__ct.widen('-'));
3160*58b9f456SAndroid Build Coastguard Worker        char_type __z = __ct.widen('0');
3161*58b9f456SAndroid Build Coastguard Worker        char_type* __w;
3162*58b9f456SAndroid Build Coastguard Worker        for (__w = __wb.get(); __w < __wn-1; ++__w)
3163*58b9f456SAndroid Build Coastguard Worker            if (*__w != __z)
3164*58b9f456SAndroid Build Coastguard Worker                break;
3165*58b9f456SAndroid Build Coastguard Worker        __v.append(__w, __wn);
3166*58b9f456SAndroid Build Coastguard Worker    }
3167*58b9f456SAndroid Build Coastguard Worker    if (__b == __e)
3168*58b9f456SAndroid Build Coastguard Worker        __err |= ios_base::eofbit;
3169*58b9f456SAndroid Build Coastguard Worker    return __b;
3170*58b9f456SAndroid Build Coastguard Worker}
3171*58b9f456SAndroid Build Coastguard Worker
3172*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>)
3173*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>)
3174*58b9f456SAndroid Build Coastguard Worker
3175*58b9f456SAndroid Build Coastguard Worker// money_put
3176*58b9f456SAndroid Build Coastguard Worker
3177*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
3178*58b9f456SAndroid Build Coastguard Workerclass __money_put
3179*58b9f456SAndroid Build Coastguard Worker{
3180*58b9f456SAndroid Build Coastguard Workerprotected:
3181*58b9f456SAndroid Build Coastguard Worker    typedef _CharT                  char_type;
3182*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char_type> string_type;
3183*58b9f456SAndroid Build Coastguard Worker
3184*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY __money_put() {}
3185*58b9f456SAndroid Build Coastguard Worker
3186*58b9f456SAndroid Build Coastguard Worker    static void __gather_info(bool __intl, bool __neg, const locale& __loc,
3187*58b9f456SAndroid Build Coastguard Worker                              money_base::pattern& __pat, char_type& __dp,
3188*58b9f456SAndroid Build Coastguard Worker                              char_type& __ts, string& __grp,
3189*58b9f456SAndroid Build Coastguard Worker                              string_type& __sym, string_type& __sn,
3190*58b9f456SAndroid Build Coastguard Worker                              int& __fd);
3191*58b9f456SAndroid Build Coastguard Worker    static void __format(char_type* __mb, char_type*& __mi, char_type*& __me,
3192*58b9f456SAndroid Build Coastguard Worker                         ios_base::fmtflags __flags,
3193*58b9f456SAndroid Build Coastguard Worker                         const char_type* __db, const char_type* __de,
3194*58b9f456SAndroid Build Coastguard Worker                         const ctype<char_type>& __ct, bool __neg,
3195*58b9f456SAndroid Build Coastguard Worker                         const money_base::pattern& __pat, char_type __dp,
3196*58b9f456SAndroid Build Coastguard Worker                         char_type __ts, const string& __grp,
3197*58b9f456SAndroid Build Coastguard Worker                         const string_type& __sym, const string_type& __sn,
3198*58b9f456SAndroid Build Coastguard Worker                         int __fd);
3199*58b9f456SAndroid Build Coastguard Worker};
3200*58b9f456SAndroid Build Coastguard Worker
3201*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
3202*58b9f456SAndroid Build Coastguard Workervoid
3203*58b9f456SAndroid Build Coastguard Worker__money_put<_CharT>::__gather_info(bool __intl, bool __neg, const locale& __loc,
3204*58b9f456SAndroid Build Coastguard Worker                                   money_base::pattern& __pat, char_type& __dp,
3205*58b9f456SAndroid Build Coastguard Worker                                   char_type& __ts, string& __grp,
3206*58b9f456SAndroid Build Coastguard Worker                                   string_type& __sym, string_type& __sn,
3207*58b9f456SAndroid Build Coastguard Worker                                   int& __fd)
3208*58b9f456SAndroid Build Coastguard Worker{
3209*58b9f456SAndroid Build Coastguard Worker    if (__intl)
3210*58b9f456SAndroid Build Coastguard Worker    {
3211*58b9f456SAndroid Build Coastguard Worker        const moneypunct<char_type, true>& __mp =
3212*58b9f456SAndroid Build Coastguard Worker            use_facet<moneypunct<char_type, true> >(__loc);
3213*58b9f456SAndroid Build Coastguard Worker        if (__neg)
3214*58b9f456SAndroid Build Coastguard Worker        {
3215*58b9f456SAndroid Build Coastguard Worker            __pat = __mp.neg_format();
3216*58b9f456SAndroid Build Coastguard Worker            __sn = __mp.negative_sign();
3217*58b9f456SAndroid Build Coastguard Worker        }
3218*58b9f456SAndroid Build Coastguard Worker        else
3219*58b9f456SAndroid Build Coastguard Worker        {
3220*58b9f456SAndroid Build Coastguard Worker            __pat = __mp.pos_format();
3221*58b9f456SAndroid Build Coastguard Worker            __sn = __mp.positive_sign();
3222*58b9f456SAndroid Build Coastguard Worker        }
3223*58b9f456SAndroid Build Coastguard Worker        __dp = __mp.decimal_point();
3224*58b9f456SAndroid Build Coastguard Worker        __ts = __mp.thousands_sep();
3225*58b9f456SAndroid Build Coastguard Worker        __grp = __mp.grouping();
3226*58b9f456SAndroid Build Coastguard Worker        __sym = __mp.curr_symbol();
3227*58b9f456SAndroid Build Coastguard Worker        __fd = __mp.frac_digits();
3228*58b9f456SAndroid Build Coastguard Worker    }
3229*58b9f456SAndroid Build Coastguard Worker    else
3230*58b9f456SAndroid Build Coastguard Worker    {
3231*58b9f456SAndroid Build Coastguard Worker        const moneypunct<char_type, false>& __mp =
3232*58b9f456SAndroid Build Coastguard Worker            use_facet<moneypunct<char_type, false> >(__loc);
3233*58b9f456SAndroid Build Coastguard Worker        if (__neg)
3234*58b9f456SAndroid Build Coastguard Worker        {
3235*58b9f456SAndroid Build Coastguard Worker            __pat = __mp.neg_format();
3236*58b9f456SAndroid Build Coastguard Worker            __sn = __mp.negative_sign();
3237*58b9f456SAndroid Build Coastguard Worker        }
3238*58b9f456SAndroid Build Coastguard Worker        else
3239*58b9f456SAndroid Build Coastguard Worker        {
3240*58b9f456SAndroid Build Coastguard Worker            __pat = __mp.pos_format();
3241*58b9f456SAndroid Build Coastguard Worker            __sn = __mp.positive_sign();
3242*58b9f456SAndroid Build Coastguard Worker        }
3243*58b9f456SAndroid Build Coastguard Worker        __dp = __mp.decimal_point();
3244*58b9f456SAndroid Build Coastguard Worker        __ts = __mp.thousands_sep();
3245*58b9f456SAndroid Build Coastguard Worker        __grp = __mp.grouping();
3246*58b9f456SAndroid Build Coastguard Worker        __sym = __mp.curr_symbol();
3247*58b9f456SAndroid Build Coastguard Worker        __fd = __mp.frac_digits();
3248*58b9f456SAndroid Build Coastguard Worker    }
3249*58b9f456SAndroid Build Coastguard Worker}
3250*58b9f456SAndroid Build Coastguard Worker
3251*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
3252*58b9f456SAndroid Build Coastguard Workervoid
3253*58b9f456SAndroid Build Coastguard Worker__money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __me,
3254*58b9f456SAndroid Build Coastguard Worker                              ios_base::fmtflags __flags,
3255*58b9f456SAndroid Build Coastguard Worker                              const char_type* __db, const char_type* __de,
3256*58b9f456SAndroid Build Coastguard Worker                              const ctype<char_type>& __ct, bool __neg,
3257*58b9f456SAndroid Build Coastguard Worker                              const money_base::pattern& __pat, char_type __dp,
3258*58b9f456SAndroid Build Coastguard Worker                              char_type __ts, const string& __grp,
3259*58b9f456SAndroid Build Coastguard Worker                              const string_type& __sym, const string_type& __sn,
3260*58b9f456SAndroid Build Coastguard Worker                              int __fd)
3261*58b9f456SAndroid Build Coastguard Worker{
3262*58b9f456SAndroid Build Coastguard Worker    __me = __mb;
3263*58b9f456SAndroid Build Coastguard Worker    for (unsigned __p = 0; __p < 4; ++__p)
3264*58b9f456SAndroid Build Coastguard Worker    {
3265*58b9f456SAndroid Build Coastguard Worker        switch (__pat.field[__p])
3266*58b9f456SAndroid Build Coastguard Worker        {
3267*58b9f456SAndroid Build Coastguard Worker        case money_base::none:
3268*58b9f456SAndroid Build Coastguard Worker            __mi = __me;
3269*58b9f456SAndroid Build Coastguard Worker            break;
3270*58b9f456SAndroid Build Coastguard Worker        case money_base::space:
3271*58b9f456SAndroid Build Coastguard Worker            __mi = __me;
3272*58b9f456SAndroid Build Coastguard Worker            *__me++ = __ct.widen(' ');
3273*58b9f456SAndroid Build Coastguard Worker            break;
3274*58b9f456SAndroid Build Coastguard Worker        case money_base::sign:
3275*58b9f456SAndroid Build Coastguard Worker            if (!__sn.empty())
3276*58b9f456SAndroid Build Coastguard Worker                *__me++ = __sn[0];
3277*58b9f456SAndroid Build Coastguard Worker            break;
3278*58b9f456SAndroid Build Coastguard Worker        case money_base::symbol:
3279*58b9f456SAndroid Build Coastguard Worker            if (!__sym.empty() && (__flags & ios_base::showbase))
3280*58b9f456SAndroid Build Coastguard Worker                __me = _VSTD::copy(__sym.begin(), __sym.end(), __me);
3281*58b9f456SAndroid Build Coastguard Worker            break;
3282*58b9f456SAndroid Build Coastguard Worker        case money_base::value:
3283*58b9f456SAndroid Build Coastguard Worker            {
3284*58b9f456SAndroid Build Coastguard Worker            // remember start of value so we can reverse it
3285*58b9f456SAndroid Build Coastguard Worker            char_type* __t = __me;
3286*58b9f456SAndroid Build Coastguard Worker            // find beginning of digits
3287*58b9f456SAndroid Build Coastguard Worker            if (__neg)
3288*58b9f456SAndroid Build Coastguard Worker                ++__db;
3289*58b9f456SAndroid Build Coastguard Worker            // find end of digits
3290*58b9f456SAndroid Build Coastguard Worker            const char_type* __d;
3291*58b9f456SAndroid Build Coastguard Worker            for (__d = __db; __d < __de; ++__d)
3292*58b9f456SAndroid Build Coastguard Worker                if (!__ct.is(ctype_base::digit, *__d))
3293*58b9f456SAndroid Build Coastguard Worker                    break;
3294*58b9f456SAndroid Build Coastguard Worker            // print fractional part
3295*58b9f456SAndroid Build Coastguard Worker            if (__fd > 0)
3296*58b9f456SAndroid Build Coastguard Worker            {
3297*58b9f456SAndroid Build Coastguard Worker                int __f;
3298*58b9f456SAndroid Build Coastguard Worker                for (__f = __fd; __d > __db && __f > 0; --__f)
3299*58b9f456SAndroid Build Coastguard Worker                    *__me++ = *--__d;
3300*58b9f456SAndroid Build Coastguard Worker                char_type __z = __f > 0 ? __ct.widen('0') : char_type();
3301*58b9f456SAndroid Build Coastguard Worker                for (; __f > 0; --__f)
3302*58b9f456SAndroid Build Coastguard Worker                    *__me++ = __z;
3303*58b9f456SAndroid Build Coastguard Worker                *__me++ = __dp;
3304*58b9f456SAndroid Build Coastguard Worker            }
3305*58b9f456SAndroid Build Coastguard Worker            // print units part
3306*58b9f456SAndroid Build Coastguard Worker            if (__d == __db)
3307*58b9f456SAndroid Build Coastguard Worker            {
3308*58b9f456SAndroid Build Coastguard Worker                *__me++ = __ct.widen('0');
3309*58b9f456SAndroid Build Coastguard Worker            }
3310*58b9f456SAndroid Build Coastguard Worker            else
3311*58b9f456SAndroid Build Coastguard Worker            {
3312*58b9f456SAndroid Build Coastguard Worker                unsigned __ng = 0;
3313*58b9f456SAndroid Build Coastguard Worker                unsigned __ig = 0;
3314*58b9f456SAndroid Build Coastguard Worker                unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max()
3315*58b9f456SAndroid Build Coastguard Worker                                              : static_cast<unsigned>(__grp[__ig]);
3316*58b9f456SAndroid Build Coastguard Worker                while (__d != __db)
3317*58b9f456SAndroid Build Coastguard Worker                {
3318*58b9f456SAndroid Build Coastguard Worker                    if (__ng == __gl)
3319*58b9f456SAndroid Build Coastguard Worker                    {
3320*58b9f456SAndroid Build Coastguard Worker                        *__me++ = __ts;
3321*58b9f456SAndroid Build Coastguard Worker                        __ng = 0;
3322*58b9f456SAndroid Build Coastguard Worker                        if (++__ig < __grp.size())
3323*58b9f456SAndroid Build Coastguard Worker                            __gl = __grp[__ig] == numeric_limits<char>::max() ?
3324*58b9f456SAndroid Build Coastguard Worker                                        numeric_limits<unsigned>::max() :
3325*58b9f456SAndroid Build Coastguard Worker                                        static_cast<unsigned>(__grp[__ig]);
3326*58b9f456SAndroid Build Coastguard Worker                    }
3327*58b9f456SAndroid Build Coastguard Worker                    *__me++ = *--__d;
3328*58b9f456SAndroid Build Coastguard Worker                    ++__ng;
3329*58b9f456SAndroid Build Coastguard Worker                }
3330*58b9f456SAndroid Build Coastguard Worker            }
3331*58b9f456SAndroid Build Coastguard Worker            // reverse it
3332*58b9f456SAndroid Build Coastguard Worker            reverse(__t, __me);
3333*58b9f456SAndroid Build Coastguard Worker            }
3334*58b9f456SAndroid Build Coastguard Worker            break;
3335*58b9f456SAndroid Build Coastguard Worker        }
3336*58b9f456SAndroid Build Coastguard Worker    }
3337*58b9f456SAndroid Build Coastguard Worker    // print rest of sign, if any
3338*58b9f456SAndroid Build Coastguard Worker    if (__sn.size() > 1)
3339*58b9f456SAndroid Build Coastguard Worker        __me = _VSTD::copy(__sn.begin()+1, __sn.end(), __me);
3340*58b9f456SAndroid Build Coastguard Worker    // set alignment
3341*58b9f456SAndroid Build Coastguard Worker    if ((__flags & ios_base::adjustfield) == ios_base::left)
3342*58b9f456SAndroid Build Coastguard Worker        __mi = __me;
3343*58b9f456SAndroid Build Coastguard Worker    else if ((__flags & ios_base::adjustfield) != ios_base::internal)
3344*58b9f456SAndroid Build Coastguard Worker        __mi = __mb;
3345*58b9f456SAndroid Build Coastguard Worker}
3346*58b9f456SAndroid Build Coastguard Worker
3347*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>)
3348*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>)
3349*58b9f456SAndroid Build Coastguard Worker
3350*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
3351*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS money_put
3352*58b9f456SAndroid Build Coastguard Worker    : public locale::facet,
3353*58b9f456SAndroid Build Coastguard Worker      private __money_put<_CharT>
3354*58b9f456SAndroid Build Coastguard Worker{
3355*58b9f456SAndroid Build Coastguard Workerpublic:
3356*58b9f456SAndroid Build Coastguard Worker    typedef _CharT                  char_type;
3357*58b9f456SAndroid Build Coastguard Worker    typedef _OutputIterator         iter_type;
3358*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char_type> string_type;
3359*58b9f456SAndroid Build Coastguard Worker
3360*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3361*58b9f456SAndroid Build Coastguard Worker    explicit money_put(size_t __refs = 0)
3362*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs) {}
3363*58b9f456SAndroid Build Coastguard Worker
3364*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3365*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl,
3366*58b9f456SAndroid Build Coastguard Worker                  long double __units) const
3367*58b9f456SAndroid Build Coastguard Worker    {
3368*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __intl, __iob, __fl, __units);
3369*58b9f456SAndroid Build Coastguard Worker    }
3370*58b9f456SAndroid Build Coastguard Worker
3371*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3372*58b9f456SAndroid Build Coastguard Worker    iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl,
3373*58b9f456SAndroid Build Coastguard Worker                  const string_type& __digits) const
3374*58b9f456SAndroid Build Coastguard Worker    {
3375*58b9f456SAndroid Build Coastguard Worker        return do_put(__s, __intl, __iob, __fl, __digits);
3376*58b9f456SAndroid Build Coastguard Worker    }
3377*58b9f456SAndroid Build Coastguard Worker
3378*58b9f456SAndroid Build Coastguard Worker    static locale::id id;
3379*58b9f456SAndroid Build Coastguard Worker
3380*58b9f456SAndroid Build Coastguard Workerprotected:
3381*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3382*58b9f456SAndroid Build Coastguard Worker    ~money_put() {}
3383*58b9f456SAndroid Build Coastguard Worker
3384*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob,
3385*58b9f456SAndroid Build Coastguard Worker                             char_type __fl, long double __units) const;
3386*58b9f456SAndroid Build Coastguard Worker    virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob,
3387*58b9f456SAndroid Build Coastguard Worker                             char_type __fl, const string_type& __digits) const;
3388*58b9f456SAndroid Build Coastguard Worker};
3389*58b9f456SAndroid Build Coastguard Worker
3390*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
3391*58b9f456SAndroid Build Coastguard Workerlocale::id
3392*58b9f456SAndroid Build Coastguard Workermoney_put<_CharT, _OutputIterator>::id;
3393*58b9f456SAndroid Build Coastguard Worker
3394*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
3395*58b9f456SAndroid Build Coastguard Worker_OutputIterator
3396*58b9f456SAndroid Build Coastguard Workermoney_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
3397*58b9f456SAndroid Build Coastguard Worker                                           ios_base& __iob, char_type __fl,
3398*58b9f456SAndroid Build Coastguard Worker                                           long double __units) const
3399*58b9f456SAndroid Build Coastguard Worker{
3400*58b9f456SAndroid Build Coastguard Worker    // convert to char
3401*58b9f456SAndroid Build Coastguard Worker    const size_t __bs = 100;
3402*58b9f456SAndroid Build Coastguard Worker    char __buf[__bs];
3403*58b9f456SAndroid Build Coastguard Worker    char* __bb = __buf;
3404*58b9f456SAndroid Build Coastguard Worker    char_type __digits[__bs];
3405*58b9f456SAndroid Build Coastguard Worker    char_type* __db = __digits;
3406*58b9f456SAndroid Build Coastguard Worker    size_t __n = static_cast<size_t>(snprintf(__bb, __bs, "%.0Lf", __units));
3407*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char, void(*)(void*)> __hn(0, free);
3408*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char_type, void(*)(void*)> __hd(0, free);
3409*58b9f456SAndroid Build Coastguard Worker    // secure memory for digit storage
3410*58b9f456SAndroid Build Coastguard Worker    if (__n > __bs-1)
3411*58b9f456SAndroid Build Coastguard Worker    {
3412*58b9f456SAndroid Build Coastguard Worker        __n = static_cast<size_t>(__libcpp_asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units));
3413*58b9f456SAndroid Build Coastguard Worker        if (__bb == 0)
3414*58b9f456SAndroid Build Coastguard Worker            __throw_bad_alloc();
3415*58b9f456SAndroid Build Coastguard Worker        __hn.reset(__bb);
3416*58b9f456SAndroid Build Coastguard Worker        __hd.reset((char_type*)malloc(__n * sizeof(char_type)));
3417*58b9f456SAndroid Build Coastguard Worker        if (__hd == nullptr)
3418*58b9f456SAndroid Build Coastguard Worker            __throw_bad_alloc();
3419*58b9f456SAndroid Build Coastguard Worker        __db = __hd.get();
3420*58b9f456SAndroid Build Coastguard Worker    }
3421*58b9f456SAndroid Build Coastguard Worker    // gather info
3422*58b9f456SAndroid Build Coastguard Worker    locale __loc = __iob.getloc();
3423*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
3424*58b9f456SAndroid Build Coastguard Worker    __ct.widen(__bb, __bb + __n, __db);
3425*58b9f456SAndroid Build Coastguard Worker    bool __neg = __n > 0 && __bb[0] == '-';
3426*58b9f456SAndroid Build Coastguard Worker    money_base::pattern __pat;
3427*58b9f456SAndroid Build Coastguard Worker    char_type __dp;
3428*58b9f456SAndroid Build Coastguard Worker    char_type __ts;
3429*58b9f456SAndroid Build Coastguard Worker    string __grp;
3430*58b9f456SAndroid Build Coastguard Worker    string_type __sym;
3431*58b9f456SAndroid Build Coastguard Worker    string_type __sn;
3432*58b9f456SAndroid Build Coastguard Worker    int __fd;
3433*58b9f456SAndroid Build Coastguard Worker    this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
3434*58b9f456SAndroid Build Coastguard Worker    // secure memory for formatting
3435*58b9f456SAndroid Build Coastguard Worker    char_type __mbuf[__bs];
3436*58b9f456SAndroid Build Coastguard Worker    char_type* __mb = __mbuf;
3437*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char_type, void(*)(void*)> __hw(0, free);
3438*58b9f456SAndroid Build Coastguard Worker    size_t __exn = static_cast<int>(__n) > __fd ?
3439*58b9f456SAndroid Build Coastguard Worker                   (__n - static_cast<size_t>(__fd)) * 2 + __sn.size() +
3440*58b9f456SAndroid Build Coastguard Worker                    __sym.size() + static_cast<size_t>(__fd) + 1
3441*58b9f456SAndroid Build Coastguard Worker                 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
3442*58b9f456SAndroid Build Coastguard Worker    if (__exn > __bs)
3443*58b9f456SAndroid Build Coastguard Worker    {
3444*58b9f456SAndroid Build Coastguard Worker        __hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
3445*58b9f456SAndroid Build Coastguard Worker        __mb = __hw.get();
3446*58b9f456SAndroid Build Coastguard Worker        if (__mb == 0)
3447*58b9f456SAndroid Build Coastguard Worker            __throw_bad_alloc();
3448*58b9f456SAndroid Build Coastguard Worker    }
3449*58b9f456SAndroid Build Coastguard Worker    // format
3450*58b9f456SAndroid Build Coastguard Worker    char_type* __mi;
3451*58b9f456SAndroid Build Coastguard Worker    char_type* __me;
3452*58b9f456SAndroid Build Coastguard Worker    this->__format(__mb, __mi, __me, __iob.flags(),
3453*58b9f456SAndroid Build Coastguard Worker                   __db, __db + __n, __ct,
3454*58b9f456SAndroid Build Coastguard Worker                   __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
3455*58b9f456SAndroid Build Coastguard Worker    return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
3456*58b9f456SAndroid Build Coastguard Worker}
3457*58b9f456SAndroid Build Coastguard Worker
3458*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _OutputIterator>
3459*58b9f456SAndroid Build Coastguard Worker_OutputIterator
3460*58b9f456SAndroid Build Coastguard Workermoney_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
3461*58b9f456SAndroid Build Coastguard Worker                                           ios_base& __iob, char_type __fl,
3462*58b9f456SAndroid Build Coastguard Worker                                           const string_type& __digits) const
3463*58b9f456SAndroid Build Coastguard Worker{
3464*58b9f456SAndroid Build Coastguard Worker    // gather info
3465*58b9f456SAndroid Build Coastguard Worker    locale __loc = __iob.getloc();
3466*58b9f456SAndroid Build Coastguard Worker    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
3467*58b9f456SAndroid Build Coastguard Worker    bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-');
3468*58b9f456SAndroid Build Coastguard Worker    money_base::pattern __pat;
3469*58b9f456SAndroid Build Coastguard Worker    char_type __dp;
3470*58b9f456SAndroid Build Coastguard Worker    char_type __ts;
3471*58b9f456SAndroid Build Coastguard Worker    string __grp;
3472*58b9f456SAndroid Build Coastguard Worker    string_type __sym;
3473*58b9f456SAndroid Build Coastguard Worker    string_type __sn;
3474*58b9f456SAndroid Build Coastguard Worker    int __fd;
3475*58b9f456SAndroid Build Coastguard Worker    this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
3476*58b9f456SAndroid Build Coastguard Worker    // secure memory for formatting
3477*58b9f456SAndroid Build Coastguard Worker    char_type __mbuf[100];
3478*58b9f456SAndroid Build Coastguard Worker    char_type* __mb = __mbuf;
3479*58b9f456SAndroid Build Coastguard Worker    unique_ptr<char_type, void(*)(void*)> __h(0, free);
3480*58b9f456SAndroid Build Coastguard Worker    size_t __exn = static_cast<int>(__digits.size()) > __fd ?
3481*58b9f456SAndroid Build Coastguard Worker                   (__digits.size() - static_cast<size_t>(__fd)) * 2 +
3482*58b9f456SAndroid Build Coastguard Worker                    __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 1
3483*58b9f456SAndroid Build Coastguard Worker                 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
3484*58b9f456SAndroid Build Coastguard Worker    if (__exn > 100)
3485*58b9f456SAndroid Build Coastguard Worker    {
3486*58b9f456SAndroid Build Coastguard Worker        __h.reset((char_type*)malloc(__exn * sizeof(char_type)));
3487*58b9f456SAndroid Build Coastguard Worker        __mb = __h.get();
3488*58b9f456SAndroid Build Coastguard Worker        if (__mb == 0)
3489*58b9f456SAndroid Build Coastguard Worker            __throw_bad_alloc();
3490*58b9f456SAndroid Build Coastguard Worker    }
3491*58b9f456SAndroid Build Coastguard Worker    // format
3492*58b9f456SAndroid Build Coastguard Worker    char_type* __mi;
3493*58b9f456SAndroid Build Coastguard Worker    char_type* __me;
3494*58b9f456SAndroid Build Coastguard Worker    this->__format(__mb, __mi, __me, __iob.flags(),
3495*58b9f456SAndroid Build Coastguard Worker                   __digits.data(), __digits.data() + __digits.size(), __ct,
3496*58b9f456SAndroid Build Coastguard Worker                   __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
3497*58b9f456SAndroid Build Coastguard Worker    return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
3498*58b9f456SAndroid Build Coastguard Worker}
3499*58b9f456SAndroid Build Coastguard Worker
3500*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>)
3501*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>)
3502*58b9f456SAndroid Build Coastguard Worker
3503*58b9f456SAndroid Build Coastguard Worker// messages
3504*58b9f456SAndroid Build Coastguard Worker
3505*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS messages_base
3506*58b9f456SAndroid Build Coastguard Worker{
3507*58b9f456SAndroid Build Coastguard Workerpublic:
3508*58b9f456SAndroid Build Coastguard Worker    typedef ptrdiff_t catalog;
3509*58b9f456SAndroid Build Coastguard Worker
3510*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY messages_base() {}
3511*58b9f456SAndroid Build Coastguard Worker};
3512*58b9f456SAndroid Build Coastguard Worker
3513*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
3514*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS messages
3515*58b9f456SAndroid Build Coastguard Worker    : public locale::facet,
3516*58b9f456SAndroid Build Coastguard Worker      public messages_base
3517*58b9f456SAndroid Build Coastguard Worker{
3518*58b9f456SAndroid Build Coastguard Workerpublic:
3519*58b9f456SAndroid Build Coastguard Worker    typedef _CharT               char_type;
3520*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<_CharT> string_type;
3521*58b9f456SAndroid Build Coastguard Worker
3522*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3523*58b9f456SAndroid Build Coastguard Worker    explicit messages(size_t __refs = 0)
3524*58b9f456SAndroid Build Coastguard Worker        : locale::facet(__refs) {}
3525*58b9f456SAndroid Build Coastguard Worker
3526*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3527*58b9f456SAndroid Build Coastguard Worker    catalog open(const basic_string<char>& __nm, const locale& __loc) const
3528*58b9f456SAndroid Build Coastguard Worker    {
3529*58b9f456SAndroid Build Coastguard Worker        return do_open(__nm, __loc);
3530*58b9f456SAndroid Build Coastguard Worker    }
3531*58b9f456SAndroid Build Coastguard Worker
3532*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3533*58b9f456SAndroid Build Coastguard Worker    string_type get(catalog __c, int __set, int __msgid,
3534*58b9f456SAndroid Build Coastguard Worker                    const string_type& __dflt) const
3535*58b9f456SAndroid Build Coastguard Worker    {
3536*58b9f456SAndroid Build Coastguard Worker        return do_get(__c, __set, __msgid, __dflt);
3537*58b9f456SAndroid Build Coastguard Worker    }
3538*58b9f456SAndroid Build Coastguard Worker
3539*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3540*58b9f456SAndroid Build Coastguard Worker    void close(catalog __c) const
3541*58b9f456SAndroid Build Coastguard Worker    {
3542*58b9f456SAndroid Build Coastguard Worker        do_close(__c);
3543*58b9f456SAndroid Build Coastguard Worker    }
3544*58b9f456SAndroid Build Coastguard Worker
3545*58b9f456SAndroid Build Coastguard Worker    static locale::id id;
3546*58b9f456SAndroid Build Coastguard Worker
3547*58b9f456SAndroid Build Coastguard Workerprotected:
3548*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3549*58b9f456SAndroid Build Coastguard Worker    ~messages() {}
3550*58b9f456SAndroid Build Coastguard Worker
3551*58b9f456SAndroid Build Coastguard Worker    virtual catalog do_open(const basic_string<char>&, const locale&) const;
3552*58b9f456SAndroid Build Coastguard Worker    virtual string_type do_get(catalog, int __set, int __msgid,
3553*58b9f456SAndroid Build Coastguard Worker                               const string_type& __dflt) const;
3554*58b9f456SAndroid Build Coastguard Worker    virtual void do_close(catalog) const;
3555*58b9f456SAndroid Build Coastguard Worker};
3556*58b9f456SAndroid Build Coastguard Worker
3557*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
3558*58b9f456SAndroid Build Coastguard Workerlocale::id
3559*58b9f456SAndroid Build Coastguard Workermessages<_CharT>::id;
3560*58b9f456SAndroid Build Coastguard Worker
3561*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
3562*58b9f456SAndroid Build Coastguard Workertypename messages<_CharT>::catalog
3563*58b9f456SAndroid Build Coastguard Workermessages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
3564*58b9f456SAndroid Build Coastguard Worker{
3565*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_HAS_CATOPEN
3566*58b9f456SAndroid Build Coastguard Worker    catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
3567*58b9f456SAndroid Build Coastguard Worker    if (__cat != -1)
3568*58b9f456SAndroid Build Coastguard Worker        __cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1));
3569*58b9f456SAndroid Build Coastguard Worker    return __cat;
3570*58b9f456SAndroid Build Coastguard Worker#else // !_LIBCPP_HAS_CATOPEN
3571*58b9f456SAndroid Build Coastguard Worker    return -1;
3572*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_HAS_CATOPEN
3573*58b9f456SAndroid Build Coastguard Worker}
3574*58b9f456SAndroid Build Coastguard Worker
3575*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
3576*58b9f456SAndroid Build Coastguard Workertypename messages<_CharT>::string_type
3577*58b9f456SAndroid Build Coastguard Workermessages<_CharT>::do_get(catalog __c, int __set, int __msgid,
3578*58b9f456SAndroid Build Coastguard Worker                         const string_type& __dflt) const
3579*58b9f456SAndroid Build Coastguard Worker{
3580*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_HAS_CATOPEN
3581*58b9f456SAndroid Build Coastguard Worker    string __ndflt;
3582*58b9f456SAndroid Build Coastguard Worker    __narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt),
3583*58b9f456SAndroid Build Coastguard Worker                                                       __dflt.c_str(),
3584*58b9f456SAndroid Build Coastguard Worker                                                       __dflt.c_str() + __dflt.size());
3585*58b9f456SAndroid Build Coastguard Worker    if (__c != -1)
3586*58b9f456SAndroid Build Coastguard Worker        __c <<= 1;
3587*58b9f456SAndroid Build Coastguard Worker    nl_catd __cat = (nl_catd)__c;
3588*58b9f456SAndroid Build Coastguard Worker    char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str());
3589*58b9f456SAndroid Build Coastguard Worker    string_type __w;
3590*58b9f456SAndroid Build Coastguard Worker    __widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w),
3591*58b9f456SAndroid Build Coastguard Worker                                                        __n, __n + strlen(__n));
3592*58b9f456SAndroid Build Coastguard Worker    return __w;
3593*58b9f456SAndroid Build Coastguard Worker#else // !_LIBCPP_HAS_CATOPEN
3594*58b9f456SAndroid Build Coastguard Worker    return __dflt;
3595*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_HAS_CATOPEN
3596*58b9f456SAndroid Build Coastguard Worker}
3597*58b9f456SAndroid Build Coastguard Worker
3598*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
3599*58b9f456SAndroid Build Coastguard Workervoid
3600*58b9f456SAndroid Build Coastguard Workermessages<_CharT>::do_close(catalog __c) const
3601*58b9f456SAndroid Build Coastguard Worker{
3602*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_HAS_CATOPEN
3603*58b9f456SAndroid Build Coastguard Worker    if (__c != -1)
3604*58b9f456SAndroid Build Coastguard Worker        __c <<= 1;
3605*58b9f456SAndroid Build Coastguard Worker    nl_catd __cat = (nl_catd)__c;
3606*58b9f456SAndroid Build Coastguard Worker    catclose(__cat);
3607*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_HAS_CATOPEN
3608*58b9f456SAndroid Build Coastguard Worker}
3609*58b9f456SAndroid Build Coastguard Worker
3610*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>)
3611*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>)
3612*58b9f456SAndroid Build Coastguard Worker
3613*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
3614*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS messages_byname
3615*58b9f456SAndroid Build Coastguard Worker    : public messages<_CharT>
3616*58b9f456SAndroid Build Coastguard Worker{
3617*58b9f456SAndroid Build Coastguard Workerpublic:
3618*58b9f456SAndroid Build Coastguard Worker    typedef messages_base::catalog catalog;
3619*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<_CharT> string_type;
3620*58b9f456SAndroid Build Coastguard Worker
3621*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3622*58b9f456SAndroid Build Coastguard Worker    explicit messages_byname(const char*, size_t __refs = 0)
3623*58b9f456SAndroid Build Coastguard Worker        : messages<_CharT>(__refs) {}
3624*58b9f456SAndroid Build Coastguard Worker
3625*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3626*58b9f456SAndroid Build Coastguard Worker    explicit messages_byname(const string&, size_t __refs = 0)
3627*58b9f456SAndroid Build Coastguard Worker        : messages<_CharT>(__refs) {}
3628*58b9f456SAndroid Build Coastguard Worker
3629*58b9f456SAndroid Build Coastguard Workerprotected:
3630*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3631*58b9f456SAndroid Build Coastguard Worker    ~messages_byname() {}
3632*58b9f456SAndroid Build Coastguard Worker};
3633*58b9f456SAndroid Build Coastguard Worker
3634*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>)
3635*58b9f456SAndroid Build Coastguard Worker_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>)
3636*58b9f456SAndroid Build Coastguard Worker
3637*58b9f456SAndroid Build Coastguard Workertemplate<class _Codecvt, class _Elem = wchar_t,
3638*58b9f456SAndroid Build Coastguard Worker         class _Wide_alloc = allocator<_Elem>,
3639*58b9f456SAndroid Build Coastguard Worker         class _Byte_alloc = allocator<char> >
3640*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS wstring_convert
3641*58b9f456SAndroid Build Coastguard Worker{
3642*58b9f456SAndroid Build Coastguard Workerpublic:
3643*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<char, char_traits<char>, _Byte_alloc>   byte_string;
3644*58b9f456SAndroid Build Coastguard Worker    typedef basic_string<_Elem, char_traits<_Elem>, _Wide_alloc> wide_string;
3645*58b9f456SAndroid Build Coastguard Worker    typedef typename _Codecvt::state_type                        state_type;
3646*58b9f456SAndroid Build Coastguard Worker    typedef typename wide_string::traits_type::int_type          int_type;
3647*58b9f456SAndroid Build Coastguard Worker
3648*58b9f456SAndroid Build Coastguard Workerprivate:
3649*58b9f456SAndroid Build Coastguard Worker    byte_string __byte_err_string_;
3650*58b9f456SAndroid Build Coastguard Worker    wide_string __wide_err_string_;
3651*58b9f456SAndroid Build Coastguard Worker    _Codecvt* __cvtptr_;
3652*58b9f456SAndroid Build Coastguard Worker    state_type __cvtstate_;
3653*58b9f456SAndroid Build Coastguard Worker    size_t __cvtcount_;
3654*58b9f456SAndroid Build Coastguard Worker
3655*58b9f456SAndroid Build Coastguard Worker    wstring_convert(const wstring_convert& __wc);
3656*58b9f456SAndroid Build Coastguard Worker    wstring_convert& operator=(const wstring_convert& __wc);
3657*58b9f456SAndroid Build Coastguard Workerpublic:
3658*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3659*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(_Codecvt* __pcvt = new _Codecvt);
3660*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3661*58b9f456SAndroid Build Coastguard Worker    wstring_convert(_Codecvt* __pcvt, state_type __state);
3662*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(const byte_string& __byte_err,
3663*58b9f456SAndroid Build Coastguard Worker                    const wide_string& __wide_err = wide_string());
3664*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
3665*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3666*58b9f456SAndroid Build Coastguard Worker    wstring_convert(wstring_convert&& __wc);
3667*58b9f456SAndroid Build Coastguard Worker#endif
3668*58b9f456SAndroid Build Coastguard Worker    ~wstring_convert();
3669*58b9f456SAndroid Build Coastguard Worker
3670*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3671*58b9f456SAndroid Build Coastguard Worker    wide_string from_bytes(char __byte)
3672*58b9f456SAndroid Build Coastguard Worker        {return from_bytes(&__byte, &__byte+1);}
3673*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3674*58b9f456SAndroid Build Coastguard Worker    wide_string from_bytes(const char* __ptr)
3675*58b9f456SAndroid Build Coastguard Worker        {return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));}
3676*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3677*58b9f456SAndroid Build Coastguard Worker    wide_string from_bytes(const byte_string& __str)
3678*58b9f456SAndroid Build Coastguard Worker        {return from_bytes(__str.data(), __str.data() + __str.size());}
3679*58b9f456SAndroid Build Coastguard Worker    wide_string from_bytes(const char* __first, const char* __last);
3680*58b9f456SAndroid Build Coastguard Worker
3681*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3682*58b9f456SAndroid Build Coastguard Worker    byte_string to_bytes(_Elem __wchar)
3683*58b9f456SAndroid Build Coastguard Worker        {return to_bytes(&__wchar, &__wchar+1);}
3684*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3685*58b9f456SAndroid Build Coastguard Worker    byte_string to_bytes(const _Elem* __wptr)
3686*58b9f456SAndroid Build Coastguard Worker        {return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));}
3687*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3688*58b9f456SAndroid Build Coastguard Worker    byte_string to_bytes(const wide_string& __wstr)
3689*58b9f456SAndroid Build Coastguard Worker        {return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());}
3690*58b9f456SAndroid Build Coastguard Worker    byte_string to_bytes(const _Elem* __first, const _Elem* __last);
3691*58b9f456SAndroid Build Coastguard Worker
3692*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3693*58b9f456SAndroid Build Coastguard Worker    size_t converted() const _NOEXCEPT {return __cvtcount_;}
3694*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3695*58b9f456SAndroid Build Coastguard Worker    state_type state() const {return __cvtstate_;}
3696*58b9f456SAndroid Build Coastguard Worker};
3697*58b9f456SAndroid Build Coastguard Worker
3698*58b9f456SAndroid Build Coastguard Workertemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
3699*58b9f456SAndroid Build Coastguard Workerinline
3700*58b9f456SAndroid Build Coastguard Workerwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
3701*58b9f456SAndroid Build Coastguard Worker    wstring_convert(_Codecvt* __pcvt)
3702*58b9f456SAndroid Build Coastguard Worker        : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0)
3703*58b9f456SAndroid Build Coastguard Worker{
3704*58b9f456SAndroid Build Coastguard Worker}
3705*58b9f456SAndroid Build Coastguard Worker
3706*58b9f456SAndroid Build Coastguard Workertemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
3707*58b9f456SAndroid Build Coastguard Workerinline
3708*58b9f456SAndroid Build Coastguard Workerwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
3709*58b9f456SAndroid Build Coastguard Worker    wstring_convert(_Codecvt* __pcvt, state_type __state)
3710*58b9f456SAndroid Build Coastguard Worker        : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0)
3711*58b9f456SAndroid Build Coastguard Worker{
3712*58b9f456SAndroid Build Coastguard Worker}
3713*58b9f456SAndroid Build Coastguard Worker
3714*58b9f456SAndroid Build Coastguard Workertemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
3715*58b9f456SAndroid Build Coastguard Workerwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
3716*58b9f456SAndroid Build Coastguard Worker    wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err)
3717*58b9f456SAndroid Build Coastguard Worker        : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err),
3718*58b9f456SAndroid Build Coastguard Worker          __cvtstate_(), __cvtcount_(0)
3719*58b9f456SAndroid Build Coastguard Worker{
3720*58b9f456SAndroid Build Coastguard Worker    __cvtptr_ = new _Codecvt;
3721*58b9f456SAndroid Build Coastguard Worker}
3722*58b9f456SAndroid Build Coastguard Worker
3723*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
3724*58b9f456SAndroid Build Coastguard Worker
3725*58b9f456SAndroid Build Coastguard Workertemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
3726*58b9f456SAndroid Build Coastguard Workerinline
3727*58b9f456SAndroid Build Coastguard Workerwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
3728*58b9f456SAndroid Build Coastguard Worker    wstring_convert(wstring_convert&& __wc)
3729*58b9f456SAndroid Build Coastguard Worker        : __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)),
3730*58b9f456SAndroid Build Coastguard Worker          __wide_err_string_(_VSTD::move(__wc.__wide_err_string_)),
3731*58b9f456SAndroid Build Coastguard Worker          __cvtptr_(__wc.__cvtptr_),
3732*58b9f456SAndroid Build Coastguard Worker          __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtcount_)
3733*58b9f456SAndroid Build Coastguard Worker{
3734*58b9f456SAndroid Build Coastguard Worker    __wc.__cvtptr_ = nullptr;
3735*58b9f456SAndroid Build Coastguard Worker}
3736*58b9f456SAndroid Build Coastguard Worker
3737*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_CXX03_LANG
3738*58b9f456SAndroid Build Coastguard Worker
3739*58b9f456SAndroid Build Coastguard Workertemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
3740*58b9f456SAndroid Build Coastguard Workerwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::~wstring_convert()
3741*58b9f456SAndroid Build Coastguard Worker{
3742*58b9f456SAndroid Build Coastguard Worker    delete __cvtptr_;
3743*58b9f456SAndroid Build Coastguard Worker}
3744*58b9f456SAndroid Build Coastguard Worker
3745*58b9f456SAndroid Build Coastguard Workertemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
3746*58b9f456SAndroid Build Coastguard Workertypename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::wide_string
3747*58b9f456SAndroid Build Coastguard Workerwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
3748*58b9f456SAndroid Build Coastguard Worker    from_bytes(const char* __frm, const char* __frm_end)
3749*58b9f456SAndroid Build Coastguard Worker{
3750*58b9f456SAndroid Build Coastguard Worker    __cvtcount_ = 0;
3751*58b9f456SAndroid Build Coastguard Worker    if (__cvtptr_ != nullptr)
3752*58b9f456SAndroid Build Coastguard Worker    {
3753*58b9f456SAndroid Build Coastguard Worker        wide_string __ws(2*(__frm_end - __frm), _Elem());
3754*58b9f456SAndroid Build Coastguard Worker        if (__frm != __frm_end)
3755*58b9f456SAndroid Build Coastguard Worker            __ws.resize(__ws.capacity());
3756*58b9f456SAndroid Build Coastguard Worker        codecvt_base::result __r = codecvt_base::ok;
3757*58b9f456SAndroid Build Coastguard Worker        state_type __st = __cvtstate_;
3758*58b9f456SAndroid Build Coastguard Worker        if (__frm != __frm_end)
3759*58b9f456SAndroid Build Coastguard Worker        {
3760*58b9f456SAndroid Build Coastguard Worker            _Elem* __to = &__ws[0];
3761*58b9f456SAndroid Build Coastguard Worker            _Elem* __to_end = __to + __ws.size();
3762*58b9f456SAndroid Build Coastguard Worker            const char* __frm_nxt;
3763*58b9f456SAndroid Build Coastguard Worker            do
3764*58b9f456SAndroid Build Coastguard Worker            {
3765*58b9f456SAndroid Build Coastguard Worker                _Elem* __to_nxt;
3766*58b9f456SAndroid Build Coastguard Worker                __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt,
3767*58b9f456SAndroid Build Coastguard Worker                                          __to, __to_end, __to_nxt);
3768*58b9f456SAndroid Build Coastguard Worker                __cvtcount_ += __frm_nxt - __frm;
3769*58b9f456SAndroid Build Coastguard Worker                if (__frm_nxt == __frm)
3770*58b9f456SAndroid Build Coastguard Worker                {
3771*58b9f456SAndroid Build Coastguard Worker                    __r = codecvt_base::error;
3772*58b9f456SAndroid Build Coastguard Worker                }
3773*58b9f456SAndroid Build Coastguard Worker                else if (__r == codecvt_base::noconv)
3774*58b9f456SAndroid Build Coastguard Worker                {
3775*58b9f456SAndroid Build Coastguard Worker                    __ws.resize(__to - &__ws[0]);
3776*58b9f456SAndroid Build Coastguard Worker                    // This only gets executed if _Elem is char
3777*58b9f456SAndroid Build Coastguard Worker                    __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end);
3778*58b9f456SAndroid Build Coastguard Worker                    __frm = __frm_nxt;
3779*58b9f456SAndroid Build Coastguard Worker                    __r = codecvt_base::ok;
3780*58b9f456SAndroid Build Coastguard Worker                }
3781*58b9f456SAndroid Build Coastguard Worker                else if (__r == codecvt_base::ok)
3782*58b9f456SAndroid Build Coastguard Worker                {
3783*58b9f456SAndroid Build Coastguard Worker                    __ws.resize(__to_nxt - &__ws[0]);
3784*58b9f456SAndroid Build Coastguard Worker                    __frm = __frm_nxt;
3785*58b9f456SAndroid Build Coastguard Worker                }
3786*58b9f456SAndroid Build Coastguard Worker                else if (__r == codecvt_base::partial)
3787*58b9f456SAndroid Build Coastguard Worker                {
3788*58b9f456SAndroid Build Coastguard Worker                    ptrdiff_t __s = __to_nxt - &__ws[0];
3789*58b9f456SAndroid Build Coastguard Worker                    __ws.resize(2 * __s);
3790*58b9f456SAndroid Build Coastguard Worker                    __to = &__ws[0] + __s;
3791*58b9f456SAndroid Build Coastguard Worker                    __to_end = &__ws[0] + __ws.size();
3792*58b9f456SAndroid Build Coastguard Worker                    __frm = __frm_nxt;
3793*58b9f456SAndroid Build Coastguard Worker                }
3794*58b9f456SAndroid Build Coastguard Worker            } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
3795*58b9f456SAndroid Build Coastguard Worker        }
3796*58b9f456SAndroid Build Coastguard Worker        if (__r == codecvt_base::ok)
3797*58b9f456SAndroid Build Coastguard Worker            return __ws;
3798*58b9f456SAndroid Build Coastguard Worker    }
3799*58b9f456SAndroid Build Coastguard Worker
3800*58b9f456SAndroid Build Coastguard Worker    if (__wide_err_string_.empty())
3801*58b9f456SAndroid Build Coastguard Worker        __throw_range_error("wstring_convert: from_bytes error");
3802*58b9f456SAndroid Build Coastguard Worker
3803*58b9f456SAndroid Build Coastguard Worker    return __wide_err_string_;
3804*58b9f456SAndroid Build Coastguard Worker}
3805*58b9f456SAndroid Build Coastguard Worker
3806*58b9f456SAndroid Build Coastguard Workertemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
3807*58b9f456SAndroid Build Coastguard Workertypename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::byte_string
3808*58b9f456SAndroid Build Coastguard Workerwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
3809*58b9f456SAndroid Build Coastguard Worker    to_bytes(const _Elem* __frm, const _Elem* __frm_end)
3810*58b9f456SAndroid Build Coastguard Worker{
3811*58b9f456SAndroid Build Coastguard Worker    __cvtcount_ = 0;
3812*58b9f456SAndroid Build Coastguard Worker    if (__cvtptr_ != nullptr)
3813*58b9f456SAndroid Build Coastguard Worker    {
3814*58b9f456SAndroid Build Coastguard Worker        byte_string __bs(2*(__frm_end - __frm), char());
3815*58b9f456SAndroid Build Coastguard Worker        if (__frm != __frm_end)
3816*58b9f456SAndroid Build Coastguard Worker            __bs.resize(__bs.capacity());
3817*58b9f456SAndroid Build Coastguard Worker        codecvt_base::result __r = codecvt_base::ok;
3818*58b9f456SAndroid Build Coastguard Worker        state_type __st = __cvtstate_;
3819*58b9f456SAndroid Build Coastguard Worker        if (__frm != __frm_end)
3820*58b9f456SAndroid Build Coastguard Worker        {
3821*58b9f456SAndroid Build Coastguard Worker            char* __to = &__bs[0];
3822*58b9f456SAndroid Build Coastguard Worker            char* __to_end = __to + __bs.size();
3823*58b9f456SAndroid Build Coastguard Worker            const _Elem* __frm_nxt;
3824*58b9f456SAndroid Build Coastguard Worker            do
3825*58b9f456SAndroid Build Coastguard Worker            {
3826*58b9f456SAndroid Build Coastguard Worker                char* __to_nxt;
3827*58b9f456SAndroid Build Coastguard Worker                __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt,
3828*58b9f456SAndroid Build Coastguard Worker                                           __to, __to_end, __to_nxt);
3829*58b9f456SAndroid Build Coastguard Worker                __cvtcount_ += __frm_nxt - __frm;
3830*58b9f456SAndroid Build Coastguard Worker                if (__frm_nxt == __frm)
3831*58b9f456SAndroid Build Coastguard Worker                {
3832*58b9f456SAndroid Build Coastguard Worker                    __r = codecvt_base::error;
3833*58b9f456SAndroid Build Coastguard Worker                }
3834*58b9f456SAndroid Build Coastguard Worker                else if (__r == codecvt_base::noconv)
3835*58b9f456SAndroid Build Coastguard Worker                {
3836*58b9f456SAndroid Build Coastguard Worker                    __bs.resize(__to - &__bs[0]);
3837*58b9f456SAndroid Build Coastguard Worker                    // This only gets executed if _Elem is char
3838*58b9f456SAndroid Build Coastguard Worker                    __bs.append((const char*)__frm, (const char*)__frm_end);
3839*58b9f456SAndroid Build Coastguard Worker                    __frm = __frm_nxt;
3840*58b9f456SAndroid Build Coastguard Worker                    __r = codecvt_base::ok;
3841*58b9f456SAndroid Build Coastguard Worker                }
3842*58b9f456SAndroid Build Coastguard Worker                else if (__r == codecvt_base::ok)
3843*58b9f456SAndroid Build Coastguard Worker                {
3844*58b9f456SAndroid Build Coastguard Worker                    __bs.resize(__to_nxt - &__bs[0]);
3845*58b9f456SAndroid Build Coastguard Worker                    __frm = __frm_nxt;
3846*58b9f456SAndroid Build Coastguard Worker                }
3847*58b9f456SAndroid Build Coastguard Worker                else if (__r == codecvt_base::partial)
3848*58b9f456SAndroid Build Coastguard Worker                {
3849*58b9f456SAndroid Build Coastguard Worker                    ptrdiff_t __s = __to_nxt - &__bs[0];
3850*58b9f456SAndroid Build Coastguard Worker                    __bs.resize(2 * __s);
3851*58b9f456SAndroid Build Coastguard Worker                    __to = &__bs[0] + __s;
3852*58b9f456SAndroid Build Coastguard Worker                    __to_end = &__bs[0] + __bs.size();
3853*58b9f456SAndroid Build Coastguard Worker                    __frm = __frm_nxt;
3854*58b9f456SAndroid Build Coastguard Worker                }
3855*58b9f456SAndroid Build Coastguard Worker            } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
3856*58b9f456SAndroid Build Coastguard Worker        }
3857*58b9f456SAndroid Build Coastguard Worker        if (__r == codecvt_base::ok)
3858*58b9f456SAndroid Build Coastguard Worker        {
3859*58b9f456SAndroid Build Coastguard Worker            size_t __s = __bs.size();
3860*58b9f456SAndroid Build Coastguard Worker            __bs.resize(__bs.capacity());
3861*58b9f456SAndroid Build Coastguard Worker            char* __to = &__bs[0] + __s;
3862*58b9f456SAndroid Build Coastguard Worker            char* __to_end = __to + __bs.size();
3863*58b9f456SAndroid Build Coastguard Worker            do
3864*58b9f456SAndroid Build Coastguard Worker            {
3865*58b9f456SAndroid Build Coastguard Worker                char* __to_nxt;
3866*58b9f456SAndroid Build Coastguard Worker                __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt);
3867*58b9f456SAndroid Build Coastguard Worker                if (__r == codecvt_base::noconv)
3868*58b9f456SAndroid Build Coastguard Worker                {
3869*58b9f456SAndroid Build Coastguard Worker                    __bs.resize(__to - &__bs[0]);
3870*58b9f456SAndroid Build Coastguard Worker                    __r = codecvt_base::ok;
3871*58b9f456SAndroid Build Coastguard Worker                }
3872*58b9f456SAndroid Build Coastguard Worker                else if (__r == codecvt_base::ok)
3873*58b9f456SAndroid Build Coastguard Worker                {
3874*58b9f456SAndroid Build Coastguard Worker                    __bs.resize(__to_nxt - &__bs[0]);
3875*58b9f456SAndroid Build Coastguard Worker                }
3876*58b9f456SAndroid Build Coastguard Worker                else if (__r == codecvt_base::partial)
3877*58b9f456SAndroid Build Coastguard Worker                {
3878*58b9f456SAndroid Build Coastguard Worker                    ptrdiff_t __sp = __to_nxt - &__bs[0];
3879*58b9f456SAndroid Build Coastguard Worker                    __bs.resize(2 * __sp);
3880*58b9f456SAndroid Build Coastguard Worker                    __to = &__bs[0] + __sp;
3881*58b9f456SAndroid Build Coastguard Worker                    __to_end = &__bs[0] + __bs.size();
3882*58b9f456SAndroid Build Coastguard Worker                }
3883*58b9f456SAndroid Build Coastguard Worker            } while (__r == codecvt_base::partial);
3884*58b9f456SAndroid Build Coastguard Worker            if (__r == codecvt_base::ok)
3885*58b9f456SAndroid Build Coastguard Worker                return __bs;
3886*58b9f456SAndroid Build Coastguard Worker        }
3887*58b9f456SAndroid Build Coastguard Worker    }
3888*58b9f456SAndroid Build Coastguard Worker
3889*58b9f456SAndroid Build Coastguard Worker    if (__byte_err_string_.empty())
3890*58b9f456SAndroid Build Coastguard Worker        __throw_range_error("wstring_convert: to_bytes error");
3891*58b9f456SAndroid Build Coastguard Worker
3892*58b9f456SAndroid Build Coastguard Worker    return __byte_err_string_;
3893*58b9f456SAndroid Build Coastguard Worker}
3894*58b9f456SAndroid Build Coastguard Worker
3895*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> >
3896*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS wbuffer_convert
3897*58b9f456SAndroid Build Coastguard Worker    : public basic_streambuf<_Elem, _Tr>
3898*58b9f456SAndroid Build Coastguard Worker{
3899*58b9f456SAndroid Build Coastguard Workerpublic:
3900*58b9f456SAndroid Build Coastguard Worker    // types:
3901*58b9f456SAndroid Build Coastguard Worker    typedef _Elem                          char_type;
3902*58b9f456SAndroid Build Coastguard Worker    typedef _Tr                            traits_type;
3903*58b9f456SAndroid Build Coastguard Worker    typedef typename traits_type::int_type int_type;
3904*58b9f456SAndroid Build Coastguard Worker    typedef typename traits_type::pos_type pos_type;
3905*58b9f456SAndroid Build Coastguard Worker    typedef typename traits_type::off_type off_type;
3906*58b9f456SAndroid Build Coastguard Worker    typedef typename _Codecvt::state_type  state_type;
3907*58b9f456SAndroid Build Coastguard Worker
3908*58b9f456SAndroid Build Coastguard Workerprivate:
3909*58b9f456SAndroid Build Coastguard Worker    char*       __extbuf_;
3910*58b9f456SAndroid Build Coastguard Worker    const char* __extbufnext_;
3911*58b9f456SAndroid Build Coastguard Worker    const char* __extbufend_;
3912*58b9f456SAndroid Build Coastguard Worker    char __extbuf_min_[8];
3913*58b9f456SAndroid Build Coastguard Worker    size_t __ebs_;
3914*58b9f456SAndroid Build Coastguard Worker    char_type* __intbuf_;
3915*58b9f456SAndroid Build Coastguard Worker    size_t __ibs_;
3916*58b9f456SAndroid Build Coastguard Worker    streambuf* __bufptr_;
3917*58b9f456SAndroid Build Coastguard Worker    _Codecvt* __cv_;
3918*58b9f456SAndroid Build Coastguard Worker    state_type __st_;
3919*58b9f456SAndroid Build Coastguard Worker    ios_base::openmode __cm_;
3920*58b9f456SAndroid Build Coastguard Worker    bool __owns_eb_;
3921*58b9f456SAndroid Build Coastguard Worker    bool __owns_ib_;
3922*58b9f456SAndroid Build Coastguard Worker    bool __always_noconv_;
3923*58b9f456SAndroid Build Coastguard Worker
3924*58b9f456SAndroid Build Coastguard Worker    wbuffer_convert(const wbuffer_convert&);
3925*58b9f456SAndroid Build Coastguard Worker    wbuffer_convert& operator=(const wbuffer_convert&);
3926*58b9f456SAndroid Build Coastguard Workerpublic:
3927*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_EXPLICIT_AFTER_CXX11 wbuffer_convert(streambuf* __bytebuf = 0,
3928*58b9f456SAndroid Build Coastguard Worker            _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
3929*58b9f456SAndroid Build Coastguard Worker    ~wbuffer_convert();
3930*58b9f456SAndroid Build Coastguard Worker
3931*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3932*58b9f456SAndroid Build Coastguard Worker    streambuf* rdbuf() const {return __bufptr_;}
3933*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3934*58b9f456SAndroid Build Coastguard Worker    streambuf* rdbuf(streambuf* __bytebuf)
3935*58b9f456SAndroid Build Coastguard Worker    {
3936*58b9f456SAndroid Build Coastguard Worker        streambuf* __r = __bufptr_;
3937*58b9f456SAndroid Build Coastguard Worker        __bufptr_ = __bytebuf;
3938*58b9f456SAndroid Build Coastguard Worker        return __r;
3939*58b9f456SAndroid Build Coastguard Worker    }
3940*58b9f456SAndroid Build Coastguard Worker
3941*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3942*58b9f456SAndroid Build Coastguard Worker    state_type state() const {return __st_;}
3943*58b9f456SAndroid Build Coastguard Worker
3944*58b9f456SAndroid Build Coastguard Workerprotected:
3945*58b9f456SAndroid Build Coastguard Worker    virtual int_type underflow();
3946*58b9f456SAndroid Build Coastguard Worker    virtual int_type pbackfail(int_type __c = traits_type::eof());
3947*58b9f456SAndroid Build Coastguard Worker    virtual int_type overflow (int_type __c = traits_type::eof());
3948*58b9f456SAndroid Build Coastguard Worker    virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s,
3949*58b9f456SAndroid Build Coastguard Worker                                                            streamsize __n);
3950*58b9f456SAndroid Build Coastguard Worker    virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
3951*58b9f456SAndroid Build Coastguard Worker                             ios_base::openmode __wch = ios_base::in | ios_base::out);
3952*58b9f456SAndroid Build Coastguard Worker    virtual pos_type seekpos(pos_type __sp,
3953*58b9f456SAndroid Build Coastguard Worker                             ios_base::openmode __wch = ios_base::in | ios_base::out);
3954*58b9f456SAndroid Build Coastguard Worker    virtual int sync();
3955*58b9f456SAndroid Build Coastguard Worker
3956*58b9f456SAndroid Build Coastguard Workerprivate:
3957*58b9f456SAndroid Build Coastguard Worker    bool __read_mode();
3958*58b9f456SAndroid Build Coastguard Worker    void __write_mode();
3959*58b9f456SAndroid Build Coastguard Worker    wbuffer_convert* __close();
3960*58b9f456SAndroid Build Coastguard Worker};
3961*58b9f456SAndroid Build Coastguard Worker
3962*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
3963*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::
3964*58b9f456SAndroid Build Coastguard Worker    wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state)
3965*58b9f456SAndroid Build Coastguard Worker    : __extbuf_(0),
3966*58b9f456SAndroid Build Coastguard Worker      __extbufnext_(0),
3967*58b9f456SAndroid Build Coastguard Worker      __extbufend_(0),
3968*58b9f456SAndroid Build Coastguard Worker      __ebs_(0),
3969*58b9f456SAndroid Build Coastguard Worker      __intbuf_(0),
3970*58b9f456SAndroid Build Coastguard Worker      __ibs_(0),
3971*58b9f456SAndroid Build Coastguard Worker      __bufptr_(__bytebuf),
3972*58b9f456SAndroid Build Coastguard Worker      __cv_(__pcvt),
3973*58b9f456SAndroid Build Coastguard Worker      __st_(__state),
3974*58b9f456SAndroid Build Coastguard Worker      __cm_(0),
3975*58b9f456SAndroid Build Coastguard Worker      __owns_eb_(false),
3976*58b9f456SAndroid Build Coastguard Worker      __owns_ib_(false),
3977*58b9f456SAndroid Build Coastguard Worker      __always_noconv_(__cv_ ? __cv_->always_noconv() : false)
3978*58b9f456SAndroid Build Coastguard Worker{
3979*58b9f456SAndroid Build Coastguard Worker    setbuf(0, 4096);
3980*58b9f456SAndroid Build Coastguard Worker}
3981*58b9f456SAndroid Build Coastguard Worker
3982*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
3983*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert()
3984*58b9f456SAndroid Build Coastguard Worker{
3985*58b9f456SAndroid Build Coastguard Worker    __close();
3986*58b9f456SAndroid Build Coastguard Worker    delete __cv_;
3987*58b9f456SAndroid Build Coastguard Worker    if (__owns_eb_)
3988*58b9f456SAndroid Build Coastguard Worker        delete [] __extbuf_;
3989*58b9f456SAndroid Build Coastguard Worker    if (__owns_ib_)
3990*58b9f456SAndroid Build Coastguard Worker        delete [] __intbuf_;
3991*58b9f456SAndroid Build Coastguard Worker}
3992*58b9f456SAndroid Build Coastguard Worker
3993*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
3994*58b9f456SAndroid Build Coastguard Workertypename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
3995*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::underflow()
3996*58b9f456SAndroid Build Coastguard Worker{
3997*58b9f456SAndroid Build Coastguard Worker    if (__cv_ == 0 || __bufptr_ == 0)
3998*58b9f456SAndroid Build Coastguard Worker        return traits_type::eof();
3999*58b9f456SAndroid Build Coastguard Worker    bool __initial = __read_mode();
4000*58b9f456SAndroid Build Coastguard Worker    char_type __1buf;
4001*58b9f456SAndroid Build Coastguard Worker    if (this->gptr() == 0)
4002*58b9f456SAndroid Build Coastguard Worker        this->setg(&__1buf, &__1buf+1, &__1buf+1);
4003*58b9f456SAndroid Build Coastguard Worker    const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4);
4004*58b9f456SAndroid Build Coastguard Worker    int_type __c = traits_type::eof();
4005*58b9f456SAndroid Build Coastguard Worker    if (this->gptr() == this->egptr())
4006*58b9f456SAndroid Build Coastguard Worker    {
4007*58b9f456SAndroid Build Coastguard Worker        memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
4008*58b9f456SAndroid Build Coastguard Worker        if (__always_noconv_)
4009*58b9f456SAndroid Build Coastguard Worker        {
4010*58b9f456SAndroid Build Coastguard Worker            streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz);
4011*58b9f456SAndroid Build Coastguard Worker            __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb);
4012*58b9f456SAndroid Build Coastguard Worker            if (__nmemb != 0)
4013*58b9f456SAndroid Build Coastguard Worker            {
4014*58b9f456SAndroid Build Coastguard Worker                this->setg(this->eback(),
4015*58b9f456SAndroid Build Coastguard Worker                           this->eback() + __unget_sz,
4016*58b9f456SAndroid Build Coastguard Worker                           this->eback() + __unget_sz + __nmemb);
4017*58b9f456SAndroid Build Coastguard Worker                __c = *this->gptr();
4018*58b9f456SAndroid Build Coastguard Worker            }
4019*58b9f456SAndroid Build Coastguard Worker        }
4020*58b9f456SAndroid Build Coastguard Worker        else
4021*58b9f456SAndroid Build Coastguard Worker        {
4022*58b9f456SAndroid Build Coastguard Worker             _LIBCPP_ASSERT(!(__extbufnext_ == NULL && (__extbufend_ != __extbufnext_)), "underflow moving from NULL" );
4023*58b9f456SAndroid Build Coastguard Worker             if (__extbufend_ != __extbufnext_)
4024*58b9f456SAndroid Build Coastguard Worker                memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
4025*58b9f456SAndroid Build Coastguard Worker            __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
4026*58b9f456SAndroid Build Coastguard Worker            __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
4027*58b9f456SAndroid Build Coastguard Worker            streamsize __nmemb = _VSTD::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz),
4028*58b9f456SAndroid Build Coastguard Worker                                 static_cast<streamsize>(__extbufend_ - __extbufnext_));
4029*58b9f456SAndroid Build Coastguard Worker            codecvt_base::result __r;
4030*58b9f456SAndroid Build Coastguard Worker            // FIXME: Do we ever need to restore the state here?
4031*58b9f456SAndroid Build Coastguard Worker            //state_type __svs = __st_;
4032*58b9f456SAndroid Build Coastguard Worker            streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb);
4033*58b9f456SAndroid Build Coastguard Worker            if (__nr != 0)
4034*58b9f456SAndroid Build Coastguard Worker            {
4035*58b9f456SAndroid Build Coastguard Worker                __extbufend_ = __extbufnext_ + __nr;
4036*58b9f456SAndroid Build Coastguard Worker                char_type*  __inext;
4037*58b9f456SAndroid Build Coastguard Worker                __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_,
4038*58b9f456SAndroid Build Coastguard Worker                                       this->eback() + __unget_sz,
4039*58b9f456SAndroid Build Coastguard Worker                                       this->egptr(), __inext);
4040*58b9f456SAndroid Build Coastguard Worker                if (__r == codecvt_base::noconv)
4041*58b9f456SAndroid Build Coastguard Worker                {
4042*58b9f456SAndroid Build Coastguard Worker                    this->setg((char_type*)__extbuf_, (char_type*)__extbuf_,
4043*58b9f456SAndroid Build Coastguard Worker                               (char_type*) const_cast<char *>(__extbufend_));
4044*58b9f456SAndroid Build Coastguard Worker                    __c = *this->gptr();
4045*58b9f456SAndroid Build Coastguard Worker                }
4046*58b9f456SAndroid Build Coastguard Worker                else if (__inext != this->eback() + __unget_sz)
4047*58b9f456SAndroid Build Coastguard Worker                {
4048*58b9f456SAndroid Build Coastguard Worker                    this->setg(this->eback(), this->eback() + __unget_sz, __inext);
4049*58b9f456SAndroid Build Coastguard Worker                    __c = *this->gptr();
4050*58b9f456SAndroid Build Coastguard Worker                }
4051*58b9f456SAndroid Build Coastguard Worker            }
4052*58b9f456SAndroid Build Coastguard Worker        }
4053*58b9f456SAndroid Build Coastguard Worker    }
4054*58b9f456SAndroid Build Coastguard Worker    else
4055*58b9f456SAndroid Build Coastguard Worker        __c = *this->gptr();
4056*58b9f456SAndroid Build Coastguard Worker    if (this->eback() == &__1buf)
4057*58b9f456SAndroid Build Coastguard Worker        this->setg(0, 0, 0);
4058*58b9f456SAndroid Build Coastguard Worker    return __c;
4059*58b9f456SAndroid Build Coastguard Worker}
4060*58b9f456SAndroid Build Coastguard Worker
4061*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
4062*58b9f456SAndroid Build Coastguard Workertypename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
4063*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c)
4064*58b9f456SAndroid Build Coastguard Worker{
4065*58b9f456SAndroid Build Coastguard Worker    if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr())
4066*58b9f456SAndroid Build Coastguard Worker    {
4067*58b9f456SAndroid Build Coastguard Worker        if (traits_type::eq_int_type(__c, traits_type::eof()))
4068*58b9f456SAndroid Build Coastguard Worker        {
4069*58b9f456SAndroid Build Coastguard Worker            this->gbump(-1);
4070*58b9f456SAndroid Build Coastguard Worker            return traits_type::not_eof(__c);
4071*58b9f456SAndroid Build Coastguard Worker        }
4072*58b9f456SAndroid Build Coastguard Worker        if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
4073*58b9f456SAndroid Build Coastguard Worker        {
4074*58b9f456SAndroid Build Coastguard Worker            this->gbump(-1);
4075*58b9f456SAndroid Build Coastguard Worker            *this->gptr() = traits_type::to_char_type(__c);
4076*58b9f456SAndroid Build Coastguard Worker            return __c;
4077*58b9f456SAndroid Build Coastguard Worker        }
4078*58b9f456SAndroid Build Coastguard Worker    }
4079*58b9f456SAndroid Build Coastguard Worker    return traits_type::eof();
4080*58b9f456SAndroid Build Coastguard Worker}
4081*58b9f456SAndroid Build Coastguard Worker
4082*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
4083*58b9f456SAndroid Build Coastguard Workertypename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
4084*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c)
4085*58b9f456SAndroid Build Coastguard Worker{
4086*58b9f456SAndroid Build Coastguard Worker    if (__cv_ == 0 || __bufptr_ == 0)
4087*58b9f456SAndroid Build Coastguard Worker        return traits_type::eof();
4088*58b9f456SAndroid Build Coastguard Worker    __write_mode();
4089*58b9f456SAndroid Build Coastguard Worker    char_type __1buf;
4090*58b9f456SAndroid Build Coastguard Worker    char_type* __pb_save = this->pbase();
4091*58b9f456SAndroid Build Coastguard Worker    char_type* __epb_save = this->epptr();
4092*58b9f456SAndroid Build Coastguard Worker    if (!traits_type::eq_int_type(__c, traits_type::eof()))
4093*58b9f456SAndroid Build Coastguard Worker    {
4094*58b9f456SAndroid Build Coastguard Worker        if (this->pptr() == 0)
4095*58b9f456SAndroid Build Coastguard Worker            this->setp(&__1buf, &__1buf+1);
4096*58b9f456SAndroid Build Coastguard Worker        *this->pptr() = traits_type::to_char_type(__c);
4097*58b9f456SAndroid Build Coastguard Worker        this->pbump(1);
4098*58b9f456SAndroid Build Coastguard Worker    }
4099*58b9f456SAndroid Build Coastguard Worker    if (this->pptr() != this->pbase())
4100*58b9f456SAndroid Build Coastguard Worker    {
4101*58b9f456SAndroid Build Coastguard Worker        if (__always_noconv_)
4102*58b9f456SAndroid Build Coastguard Worker        {
4103*58b9f456SAndroid Build Coastguard Worker            streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase());
4104*58b9f456SAndroid Build Coastguard Worker            if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
4105*58b9f456SAndroid Build Coastguard Worker                return traits_type::eof();
4106*58b9f456SAndroid Build Coastguard Worker        }
4107*58b9f456SAndroid Build Coastguard Worker        else
4108*58b9f456SAndroid Build Coastguard Worker        {
4109*58b9f456SAndroid Build Coastguard Worker            char* __extbe = __extbuf_;
4110*58b9f456SAndroid Build Coastguard Worker            codecvt_base::result __r;
4111*58b9f456SAndroid Build Coastguard Worker            do
4112*58b9f456SAndroid Build Coastguard Worker            {
4113*58b9f456SAndroid Build Coastguard Worker                const char_type* __e;
4114*58b9f456SAndroid Build Coastguard Worker                __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e,
4115*58b9f456SAndroid Build Coastguard Worker                                        __extbuf_, __extbuf_ + __ebs_, __extbe);
4116*58b9f456SAndroid Build Coastguard Worker                if (__e == this->pbase())
4117*58b9f456SAndroid Build Coastguard Worker                    return traits_type::eof();
4118*58b9f456SAndroid Build Coastguard Worker                if (__r == codecvt_base::noconv)
4119*58b9f456SAndroid Build Coastguard Worker                {
4120*58b9f456SAndroid Build Coastguard Worker                    streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
4121*58b9f456SAndroid Build Coastguard Worker                    if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
4122*58b9f456SAndroid Build Coastguard Worker                        return traits_type::eof();
4123*58b9f456SAndroid Build Coastguard Worker                }
4124*58b9f456SAndroid Build Coastguard Worker                else if (__r == codecvt_base::ok || __r == codecvt_base::partial)
4125*58b9f456SAndroid Build Coastguard Worker                {
4126*58b9f456SAndroid Build Coastguard Worker                    streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_);
4127*58b9f456SAndroid Build Coastguard Worker                    if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
4128*58b9f456SAndroid Build Coastguard Worker                        return traits_type::eof();
4129*58b9f456SAndroid Build Coastguard Worker                    if (__r == codecvt_base::partial)
4130*58b9f456SAndroid Build Coastguard Worker                    {
4131*58b9f456SAndroid Build Coastguard Worker                        this->setp(const_cast<char_type *>(__e), this->pptr());
4132*58b9f456SAndroid Build Coastguard Worker                        this->__pbump(this->epptr() - this->pbase());
4133*58b9f456SAndroid Build Coastguard Worker                    }
4134*58b9f456SAndroid Build Coastguard Worker                }
4135*58b9f456SAndroid Build Coastguard Worker                else
4136*58b9f456SAndroid Build Coastguard Worker                    return traits_type::eof();
4137*58b9f456SAndroid Build Coastguard Worker            } while (__r == codecvt_base::partial);
4138*58b9f456SAndroid Build Coastguard Worker        }
4139*58b9f456SAndroid Build Coastguard Worker        this->setp(__pb_save, __epb_save);
4140*58b9f456SAndroid Build Coastguard Worker    }
4141*58b9f456SAndroid Build Coastguard Worker    return traits_type::not_eof(__c);
4142*58b9f456SAndroid Build Coastguard Worker}
4143*58b9f456SAndroid Build Coastguard Worker
4144*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
4145*58b9f456SAndroid Build Coastguard Workerbasic_streambuf<_Elem, _Tr>*
4146*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n)
4147*58b9f456SAndroid Build Coastguard Worker{
4148*58b9f456SAndroid Build Coastguard Worker    this->setg(0, 0, 0);
4149*58b9f456SAndroid Build Coastguard Worker    this->setp(0, 0);
4150*58b9f456SAndroid Build Coastguard Worker    if (__owns_eb_)
4151*58b9f456SAndroid Build Coastguard Worker        delete [] __extbuf_;
4152*58b9f456SAndroid Build Coastguard Worker    if (__owns_ib_)
4153*58b9f456SAndroid Build Coastguard Worker        delete [] __intbuf_;
4154*58b9f456SAndroid Build Coastguard Worker    __ebs_ = __n;
4155*58b9f456SAndroid Build Coastguard Worker    if (__ebs_ > sizeof(__extbuf_min_))
4156*58b9f456SAndroid Build Coastguard Worker    {
4157*58b9f456SAndroid Build Coastguard Worker        if (__always_noconv_ && __s)
4158*58b9f456SAndroid Build Coastguard Worker        {
4159*58b9f456SAndroid Build Coastguard Worker            __extbuf_ = (char*)__s;
4160*58b9f456SAndroid Build Coastguard Worker            __owns_eb_ = false;
4161*58b9f456SAndroid Build Coastguard Worker        }
4162*58b9f456SAndroid Build Coastguard Worker        else
4163*58b9f456SAndroid Build Coastguard Worker        {
4164*58b9f456SAndroid Build Coastguard Worker            __extbuf_ = new char[__ebs_];
4165*58b9f456SAndroid Build Coastguard Worker            __owns_eb_ = true;
4166*58b9f456SAndroid Build Coastguard Worker        }
4167*58b9f456SAndroid Build Coastguard Worker    }
4168*58b9f456SAndroid Build Coastguard Worker    else
4169*58b9f456SAndroid Build Coastguard Worker    {
4170*58b9f456SAndroid Build Coastguard Worker        __extbuf_ = __extbuf_min_;
4171*58b9f456SAndroid Build Coastguard Worker        __ebs_ = sizeof(__extbuf_min_);
4172*58b9f456SAndroid Build Coastguard Worker        __owns_eb_ = false;
4173*58b9f456SAndroid Build Coastguard Worker    }
4174*58b9f456SAndroid Build Coastguard Worker    if (!__always_noconv_)
4175*58b9f456SAndroid Build Coastguard Worker    {
4176*58b9f456SAndroid Build Coastguard Worker        __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_));
4177*58b9f456SAndroid Build Coastguard Worker        if (__s && __ibs_ >= sizeof(__extbuf_min_))
4178*58b9f456SAndroid Build Coastguard Worker        {
4179*58b9f456SAndroid Build Coastguard Worker            __intbuf_ = __s;
4180*58b9f456SAndroid Build Coastguard Worker            __owns_ib_ = false;
4181*58b9f456SAndroid Build Coastguard Worker        }
4182*58b9f456SAndroid Build Coastguard Worker        else
4183*58b9f456SAndroid Build Coastguard Worker        {
4184*58b9f456SAndroid Build Coastguard Worker            __intbuf_ = new char_type[__ibs_];
4185*58b9f456SAndroid Build Coastguard Worker            __owns_ib_ = true;
4186*58b9f456SAndroid Build Coastguard Worker        }
4187*58b9f456SAndroid Build Coastguard Worker    }
4188*58b9f456SAndroid Build Coastguard Worker    else
4189*58b9f456SAndroid Build Coastguard Worker    {
4190*58b9f456SAndroid Build Coastguard Worker        __ibs_ = 0;
4191*58b9f456SAndroid Build Coastguard Worker        __intbuf_ = 0;
4192*58b9f456SAndroid Build Coastguard Worker        __owns_ib_ = false;
4193*58b9f456SAndroid Build Coastguard Worker    }
4194*58b9f456SAndroid Build Coastguard Worker    return this;
4195*58b9f456SAndroid Build Coastguard Worker}
4196*58b9f456SAndroid Build Coastguard Worker
4197*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
4198*58b9f456SAndroid Build Coastguard Workertypename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
4199*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way,
4200*58b9f456SAndroid Build Coastguard Worker                                        ios_base::openmode __om)
4201*58b9f456SAndroid Build Coastguard Worker{
4202*58b9f456SAndroid Build Coastguard Worker    int __width = __cv_->encoding();
4203*58b9f456SAndroid Build Coastguard Worker    if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync())
4204*58b9f456SAndroid Build Coastguard Worker        return pos_type(off_type(-1));
4205*58b9f456SAndroid Build Coastguard Worker    // __width > 0 || __off == 0, now check __way
4206*58b9f456SAndroid Build Coastguard Worker    if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end)
4207*58b9f456SAndroid Build Coastguard Worker        return pos_type(off_type(-1));
4208*58b9f456SAndroid Build Coastguard Worker    pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om);
4209*58b9f456SAndroid Build Coastguard Worker    __r.state(__st_);
4210*58b9f456SAndroid Build Coastguard Worker    return __r;
4211*58b9f456SAndroid Build Coastguard Worker}
4212*58b9f456SAndroid Build Coastguard Worker
4213*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
4214*58b9f456SAndroid Build Coastguard Workertypename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
4215*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch)
4216*58b9f456SAndroid Build Coastguard Worker{
4217*58b9f456SAndroid Build Coastguard Worker    if (__cv_ == 0 || __bufptr_ == 0 || sync())
4218*58b9f456SAndroid Build Coastguard Worker        return pos_type(off_type(-1));
4219*58b9f456SAndroid Build Coastguard Worker    if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1)))
4220*58b9f456SAndroid Build Coastguard Worker        return pos_type(off_type(-1));
4221*58b9f456SAndroid Build Coastguard Worker    return __sp;
4222*58b9f456SAndroid Build Coastguard Worker}
4223*58b9f456SAndroid Build Coastguard Worker
4224*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
4225*58b9f456SAndroid Build Coastguard Workerint
4226*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::sync()
4227*58b9f456SAndroid Build Coastguard Worker{
4228*58b9f456SAndroid Build Coastguard Worker    if (__cv_ == 0 || __bufptr_ == 0)
4229*58b9f456SAndroid Build Coastguard Worker        return 0;
4230*58b9f456SAndroid Build Coastguard Worker    if (__cm_ & ios_base::out)
4231*58b9f456SAndroid Build Coastguard Worker    {
4232*58b9f456SAndroid Build Coastguard Worker        if (this->pptr() != this->pbase())
4233*58b9f456SAndroid Build Coastguard Worker            if (overflow() == traits_type::eof())
4234*58b9f456SAndroid Build Coastguard Worker                return -1;
4235*58b9f456SAndroid Build Coastguard Worker        codecvt_base::result __r;
4236*58b9f456SAndroid Build Coastguard Worker        do
4237*58b9f456SAndroid Build Coastguard Worker        {
4238*58b9f456SAndroid Build Coastguard Worker            char* __extbe;
4239*58b9f456SAndroid Build Coastguard Worker            __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
4240*58b9f456SAndroid Build Coastguard Worker            streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_);
4241*58b9f456SAndroid Build Coastguard Worker            if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
4242*58b9f456SAndroid Build Coastguard Worker                return -1;
4243*58b9f456SAndroid Build Coastguard Worker        } while (__r == codecvt_base::partial);
4244*58b9f456SAndroid Build Coastguard Worker        if (__r == codecvt_base::error)
4245*58b9f456SAndroid Build Coastguard Worker            return -1;
4246*58b9f456SAndroid Build Coastguard Worker        if (__bufptr_->pubsync())
4247*58b9f456SAndroid Build Coastguard Worker            return -1;
4248*58b9f456SAndroid Build Coastguard Worker    }
4249*58b9f456SAndroid Build Coastguard Worker    else if (__cm_ & ios_base::in)
4250*58b9f456SAndroid Build Coastguard Worker    {
4251*58b9f456SAndroid Build Coastguard Worker        off_type __c;
4252*58b9f456SAndroid Build Coastguard Worker        if (__always_noconv_)
4253*58b9f456SAndroid Build Coastguard Worker            __c = this->egptr() - this->gptr();
4254*58b9f456SAndroid Build Coastguard Worker        else
4255*58b9f456SAndroid Build Coastguard Worker        {
4256*58b9f456SAndroid Build Coastguard Worker            int __width = __cv_->encoding();
4257*58b9f456SAndroid Build Coastguard Worker            __c = __extbufend_ - __extbufnext_;
4258*58b9f456SAndroid Build Coastguard Worker            if (__width > 0)
4259*58b9f456SAndroid Build Coastguard Worker                __c += __width * (this->egptr() - this->gptr());
4260*58b9f456SAndroid Build Coastguard Worker            else
4261*58b9f456SAndroid Build Coastguard Worker            {
4262*58b9f456SAndroid Build Coastguard Worker                if (this->gptr() != this->egptr())
4263*58b9f456SAndroid Build Coastguard Worker                {
4264*58b9f456SAndroid Build Coastguard Worker                    reverse(this->gptr(), this->egptr());
4265*58b9f456SAndroid Build Coastguard Worker                    codecvt_base::result __r;
4266*58b9f456SAndroid Build Coastguard Worker                    const char_type* __e = this->gptr();
4267*58b9f456SAndroid Build Coastguard Worker                    char* __extbe;
4268*58b9f456SAndroid Build Coastguard Worker                    do
4269*58b9f456SAndroid Build Coastguard Worker                    {
4270*58b9f456SAndroid Build Coastguard Worker                        __r = __cv_->out(__st_, __e, this->egptr(), __e,
4271*58b9f456SAndroid Build Coastguard Worker                                         __extbuf_, __extbuf_ + __ebs_, __extbe);
4272*58b9f456SAndroid Build Coastguard Worker                        switch (__r)
4273*58b9f456SAndroid Build Coastguard Worker                        {
4274*58b9f456SAndroid Build Coastguard Worker                        case codecvt_base::noconv:
4275*58b9f456SAndroid Build Coastguard Worker                            __c += this->egptr() - this->gptr();
4276*58b9f456SAndroid Build Coastguard Worker                            break;
4277*58b9f456SAndroid Build Coastguard Worker                        case codecvt_base::ok:
4278*58b9f456SAndroid Build Coastguard Worker                        case codecvt_base::partial:
4279*58b9f456SAndroid Build Coastguard Worker                            __c += __extbe - __extbuf_;
4280*58b9f456SAndroid Build Coastguard Worker                            break;
4281*58b9f456SAndroid Build Coastguard Worker                        default:
4282*58b9f456SAndroid Build Coastguard Worker                            return -1;
4283*58b9f456SAndroid Build Coastguard Worker                        }
4284*58b9f456SAndroid Build Coastguard Worker                    } while (__r == codecvt_base::partial);
4285*58b9f456SAndroid Build Coastguard Worker                }
4286*58b9f456SAndroid Build Coastguard Worker            }
4287*58b9f456SAndroid Build Coastguard Worker        }
4288*58b9f456SAndroid Build Coastguard Worker        if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1)))
4289*58b9f456SAndroid Build Coastguard Worker            return -1;
4290*58b9f456SAndroid Build Coastguard Worker        this->setg(0, 0, 0);
4291*58b9f456SAndroid Build Coastguard Worker        __cm_ = 0;
4292*58b9f456SAndroid Build Coastguard Worker    }
4293*58b9f456SAndroid Build Coastguard Worker    return 0;
4294*58b9f456SAndroid Build Coastguard Worker}
4295*58b9f456SAndroid Build Coastguard Worker
4296*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
4297*58b9f456SAndroid Build Coastguard Workerbool
4298*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode()
4299*58b9f456SAndroid Build Coastguard Worker{
4300*58b9f456SAndroid Build Coastguard Worker    if (!(__cm_ & ios_base::in))
4301*58b9f456SAndroid Build Coastguard Worker    {
4302*58b9f456SAndroid Build Coastguard Worker        this->setp(0, 0);
4303*58b9f456SAndroid Build Coastguard Worker        if (__always_noconv_)
4304*58b9f456SAndroid Build Coastguard Worker            this->setg((char_type*)__extbuf_,
4305*58b9f456SAndroid Build Coastguard Worker                       (char_type*)__extbuf_ + __ebs_,
4306*58b9f456SAndroid Build Coastguard Worker                       (char_type*)__extbuf_ + __ebs_);
4307*58b9f456SAndroid Build Coastguard Worker        else
4308*58b9f456SAndroid Build Coastguard Worker            this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_);
4309*58b9f456SAndroid Build Coastguard Worker        __cm_ = ios_base::in;
4310*58b9f456SAndroid Build Coastguard Worker        return true;
4311*58b9f456SAndroid Build Coastguard Worker    }
4312*58b9f456SAndroid Build Coastguard Worker    return false;
4313*58b9f456SAndroid Build Coastguard Worker}
4314*58b9f456SAndroid Build Coastguard Worker
4315*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
4316*58b9f456SAndroid Build Coastguard Workervoid
4317*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode()
4318*58b9f456SAndroid Build Coastguard Worker{
4319*58b9f456SAndroid Build Coastguard Worker    if (!(__cm_ & ios_base::out))
4320*58b9f456SAndroid Build Coastguard Worker    {
4321*58b9f456SAndroid Build Coastguard Worker        this->setg(0, 0, 0);
4322*58b9f456SAndroid Build Coastguard Worker        if (__ebs_ > sizeof(__extbuf_min_))
4323*58b9f456SAndroid Build Coastguard Worker        {
4324*58b9f456SAndroid Build Coastguard Worker            if (__always_noconv_)
4325*58b9f456SAndroid Build Coastguard Worker                this->setp((char_type*)__extbuf_,
4326*58b9f456SAndroid Build Coastguard Worker                           (char_type*)__extbuf_ + (__ebs_ - 1));
4327*58b9f456SAndroid Build Coastguard Worker            else
4328*58b9f456SAndroid Build Coastguard Worker                this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1));
4329*58b9f456SAndroid Build Coastguard Worker        }
4330*58b9f456SAndroid Build Coastguard Worker        else
4331*58b9f456SAndroid Build Coastguard Worker            this->setp(0, 0);
4332*58b9f456SAndroid Build Coastguard Worker        __cm_ = ios_base::out;
4333*58b9f456SAndroid Build Coastguard Worker    }
4334*58b9f456SAndroid Build Coastguard Worker}
4335*58b9f456SAndroid Build Coastguard Worker
4336*58b9f456SAndroid Build Coastguard Workertemplate <class _Codecvt, class _Elem, class _Tr>
4337*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>*
4338*58b9f456SAndroid Build Coastguard Workerwbuffer_convert<_Codecvt, _Elem, _Tr>::__close()
4339*58b9f456SAndroid Build Coastguard Worker{
4340*58b9f456SAndroid Build Coastguard Worker    wbuffer_convert* __rt = 0;
4341*58b9f456SAndroid Build Coastguard Worker    if (__cv_ != 0 && __bufptr_ != 0)
4342*58b9f456SAndroid Build Coastguard Worker    {
4343*58b9f456SAndroid Build Coastguard Worker        __rt = this;
4344*58b9f456SAndroid Build Coastguard Worker        if ((__cm_ & ios_base::out) && sync())
4345*58b9f456SAndroid Build Coastguard Worker            __rt = 0;
4346*58b9f456SAndroid Build Coastguard Worker    }
4347*58b9f456SAndroid Build Coastguard Worker    return __rt;
4348*58b9f456SAndroid Build Coastguard Worker}
4349*58b9f456SAndroid Build Coastguard Worker
4350*58b9f456SAndroid Build Coastguard Worker_LIBCPP_END_NAMESPACE_STD
4351*58b9f456SAndroid Build Coastguard Worker
4352*58b9f456SAndroid Build Coastguard Worker_LIBCPP_POP_MACROS
4353*58b9f456SAndroid Build Coastguard Worker
4354*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_LOCALE
4355