1*404b540aSrobert // Locale support -*- C++ -*-
2*404b540aSrobert 
3*404b540aSrobert // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4*404b540aSrobert // Free Software Foundation, Inc.
5*404b540aSrobert //
6*404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
7*404b540aSrobert // software; you can redistribute it and/or modify it under the
8*404b540aSrobert // terms of the GNU General Public License as published by the
9*404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
10*404b540aSrobert // any later version.
11*404b540aSrobert 
12*404b540aSrobert // This library is distributed in the hope that it will be useful,
13*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
14*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*404b540aSrobert // GNU General Public License for more details.
16*404b540aSrobert 
17*404b540aSrobert // You should have received a copy of the GNU General Public License along
18*404b540aSrobert // with this library; see the file COPYING.  If not, write to the Free
19*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20*404b540aSrobert // USA.
21*404b540aSrobert 
22*404b540aSrobert // As a special exception, you may use this file as part of a free software
23*404b540aSrobert // library without restriction.  Specifically, if other files instantiate
24*404b540aSrobert // templates or use macros or inline functions from this file, or you compile
25*404b540aSrobert // this file and link it with other files to produce an executable, this
26*404b540aSrobert // file does not by itself cause the resulting executable to be covered by
27*404b540aSrobert // the GNU General Public License.  This exception does not however
28*404b540aSrobert // invalidate any other reasons why the executable file might be covered by
29*404b540aSrobert // the GNU General Public License.
30*404b540aSrobert 
31*404b540aSrobert /** @file locale_facets.h
32*404b540aSrobert  *  This is an internal header file, included by other library headers.
33*404b540aSrobert  *  You should not attempt to use it directly.
34*404b540aSrobert  */
35*404b540aSrobert 
36*404b540aSrobert //
37*404b540aSrobert // ISO C++ 14882: 22.1  Locales
38*404b540aSrobert //
39*404b540aSrobert 
40*404b540aSrobert #ifndef _LOCALE_FACETS_H
41*404b540aSrobert #define _LOCALE_FACETS_H 1
42*404b540aSrobert 
43*404b540aSrobert #pragma GCC system_header
44*404b540aSrobert 
45*404b540aSrobert #include <ctime>	// For struct tm
46*404b540aSrobert #include <cwctype>	// For wctype_t
47*404b540aSrobert #include <bits/ctype_base.h>
48*404b540aSrobert #include <iosfwd>
49*404b540aSrobert #include <bits/ios_base.h>  // For ios_base, ios_base::iostate
50*404b540aSrobert #include <streambuf>
51*404b540aSrobert #include <bits/cpp_type_traits.h>
52*404b540aSrobert 
53*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
54*404b540aSrobert 
55*404b540aSrobert   // NB: Don't instantiate required wchar_t facets if no wchar_t support.
56*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T
57*404b540aSrobert # define  _GLIBCXX_NUM_FACETS 28
58*404b540aSrobert #else
59*404b540aSrobert # define  _GLIBCXX_NUM_FACETS 14
60*404b540aSrobert #endif
61*404b540aSrobert 
62*404b540aSrobert   // Convert string to numeric value of type _Tv and store results.
63*404b540aSrobert   // NB: This is specialized for all required types, there is no
64*404b540aSrobert   // generic definition.
65*404b540aSrobert   template<typename _Tv>
66*404b540aSrobert     void
67*404b540aSrobert     __convert_to_v(const char* __in, _Tv& __out, ios_base::iostate& __err,
68*404b540aSrobert 		   const __c_locale& __cloc);
69*404b540aSrobert 
70*404b540aSrobert   // Explicit specializations for required types.
71*404b540aSrobert   template<>
72*404b540aSrobert     void
73*404b540aSrobert     __convert_to_v(const char*, float&, ios_base::iostate&,
74*404b540aSrobert 		   const __c_locale&);
75*404b540aSrobert 
76*404b540aSrobert   template<>
77*404b540aSrobert     void
78*404b540aSrobert     __convert_to_v(const char*, double&, ios_base::iostate&,
79*404b540aSrobert 		   const __c_locale&);
80*404b540aSrobert 
81*404b540aSrobert   template<>
82*404b540aSrobert     void
83*404b540aSrobert     __convert_to_v(const char*, long double&, ios_base::iostate&,
84*404b540aSrobert 		   const __c_locale&);
85*404b540aSrobert 
86*404b540aSrobert   // NB: __pad is a struct, rather than a function, so it can be
87*404b540aSrobert   // partially-specialized.
88*404b540aSrobert   template<typename _CharT, typename _Traits>
89*404b540aSrobert     struct __pad
90*404b540aSrobert     {
91*404b540aSrobert       static void
92*404b540aSrobert       _S_pad(ios_base& __io, _CharT __fill, _CharT* __news,
93*404b540aSrobert 	     const _CharT* __olds, const streamsize __newlen,
94*404b540aSrobert 	     const streamsize __oldlen, const bool __num);
95*404b540aSrobert     };
96*404b540aSrobert 
97*404b540aSrobert   // Used by both numeric and monetary facets.
98*404b540aSrobert   // Inserts "group separator" characters into an array of characters.
99*404b540aSrobert   // It's recursive, one iteration per group.  It moves the characters
100*404b540aSrobert   // in the buffer this way: "xxxx12345" -> "12,345xxx".  Call this
101*404b540aSrobert   // only with __glen != 0.
102*404b540aSrobert   template<typename _CharT>
103*404b540aSrobert     _CharT*
104*404b540aSrobert     __add_grouping(_CharT* __s, _CharT __sep,
105*404b540aSrobert 		   const char* __gbeg, size_t __gsize,
106*404b540aSrobert 		   const _CharT* __first, const _CharT* __last);
107*404b540aSrobert 
108*404b540aSrobert   // This template permits specializing facet output code for
109*404b540aSrobert   // ostreambuf_iterator.  For ostreambuf_iterator, sputn is
110*404b540aSrobert   // significantly more efficient than incrementing iterators.
111*404b540aSrobert   template<typename _CharT>
112*404b540aSrobert     inline
113*404b540aSrobert     ostreambuf_iterator<_CharT>
__write(ostreambuf_iterator<_CharT> __s,const _CharT * __ws,int __len)114*404b540aSrobert     __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len)
115*404b540aSrobert     {
116*404b540aSrobert       __s._M_put(__ws, __len);
117*404b540aSrobert       return __s;
118*404b540aSrobert     }
119*404b540aSrobert 
120*404b540aSrobert   // This is the unspecialized form of the template.
121*404b540aSrobert   template<typename _CharT, typename _OutIter>
122*404b540aSrobert     inline
123*404b540aSrobert     _OutIter
__write(_OutIter __s,const _CharT * __ws,int __len)124*404b540aSrobert     __write(_OutIter __s, const _CharT* __ws, int __len)
125*404b540aSrobert     {
126*404b540aSrobert       for (int __j = 0; __j < __len; __j++, ++__s)
127*404b540aSrobert 	*__s = __ws[__j];
128*404b540aSrobert       return __s;
129*404b540aSrobert     }
130*404b540aSrobert 
131*404b540aSrobert 
132*404b540aSrobert   // 22.2.1.1  Template class ctype
133*404b540aSrobert   // Include host and configuration specific ctype enums for ctype_base.
134*404b540aSrobert 
135*404b540aSrobert   // Common base for ctype<_CharT>.
136*404b540aSrobert   /**
137*404b540aSrobert    *  @brief  Common base for ctype facet
138*404b540aSrobert    *
139*404b540aSrobert    *  This template class provides implementations of the public functions
140*404b540aSrobert    *  that forward to the protected virtual functions.
141*404b540aSrobert    *
142*404b540aSrobert    *  This template also provides abtract stubs for the protected virtual
143*404b540aSrobert    *  functions.
144*404b540aSrobert   */
145*404b540aSrobert   template<typename _CharT>
146*404b540aSrobert     class __ctype_abstract_base : public locale::facet, public ctype_base
147*404b540aSrobert     {
148*404b540aSrobert     public:
149*404b540aSrobert       // Types:
150*404b540aSrobert       /// Typedef for the template parameter
151*404b540aSrobert       typedef _CharT char_type;
152*404b540aSrobert 
153*404b540aSrobert       /**
154*404b540aSrobert        *  @brief  Test char_type classification.
155*404b540aSrobert        *
156*404b540aSrobert        *  This function finds a mask M for @a c and compares it to mask @a m.
157*404b540aSrobert        *  It does so by returning the value of ctype<char_type>::do_is().
158*404b540aSrobert        *
159*404b540aSrobert        *  @param c  The char_type to compare the mask of.
160*404b540aSrobert        *  @param m  The mask to compare against.
161*404b540aSrobert        *  @return  (M & m) != 0.
162*404b540aSrobert       */
163*404b540aSrobert       bool
is(mask __m,char_type __c)164*404b540aSrobert       is(mask __m, char_type __c) const
165*404b540aSrobert       { return this->do_is(__m, __c); }
166*404b540aSrobert 
167*404b540aSrobert       /**
168*404b540aSrobert        *  @brief  Return a mask array.
169*404b540aSrobert        *
170*404b540aSrobert        *  This function finds the mask for each char_type in the range [lo,hi)
171*404b540aSrobert        *  and successively writes it to vec.  vec must have as many elements
172*404b540aSrobert        *  as the char array.  It does so by returning the value of
173*404b540aSrobert        *  ctype<char_type>::do_is().
174*404b540aSrobert        *
175*404b540aSrobert        *  @param lo  Pointer to start of range.
176*404b540aSrobert        *  @param hi  Pointer to end of range.
177*404b540aSrobert        *  @param vec  Pointer to an array of mask storage.
178*404b540aSrobert        *  @return  @a hi.
179*404b540aSrobert       */
180*404b540aSrobert       const char_type*
is(const char_type * __lo,const char_type * __hi,mask * __vec)181*404b540aSrobert       is(const char_type *__lo, const char_type *__hi, mask *__vec) const
182*404b540aSrobert       { return this->do_is(__lo, __hi, __vec); }
183*404b540aSrobert 
184*404b540aSrobert       /**
185*404b540aSrobert        *  @brief  Find char_type matching a mask
186*404b540aSrobert        *
187*404b540aSrobert        *  This function searches for and returns the first char_type c in
188*404b540aSrobert        *  [lo,hi) for which is(m,c) is true.  It does so by returning
189*404b540aSrobert        *  ctype<char_type>::do_scan_is().
190*404b540aSrobert        *
191*404b540aSrobert        *  @param m  The mask to compare against.
192*404b540aSrobert        *  @param lo  Pointer to start of range.
193*404b540aSrobert        *  @param hi  Pointer to end of range.
194*404b540aSrobert        *  @return  Pointer to matching char_type if found, else @a hi.
195*404b540aSrobert       */
196*404b540aSrobert       const char_type*
scan_is(mask __m,const char_type * __lo,const char_type * __hi)197*404b540aSrobert       scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
198*404b540aSrobert       { return this->do_scan_is(__m, __lo, __hi); }
199*404b540aSrobert 
200*404b540aSrobert       /**
201*404b540aSrobert        *  @brief  Find char_type not matching a mask
202*404b540aSrobert        *
203*404b540aSrobert        *  This function searches for and returns the first char_type c in
204*404b540aSrobert        *  [lo,hi) for which is(m,c) is false.  It does so by returning
205*404b540aSrobert        *  ctype<char_type>::do_scan_not().
206*404b540aSrobert        *
207*404b540aSrobert        *  @param m  The mask to compare against.
208*404b540aSrobert        *  @param lo  Pointer to first char in range.
209*404b540aSrobert        *  @param hi  Pointer to end of range.
210*404b540aSrobert        *  @return  Pointer to non-matching char if found, else @a hi.
211*404b540aSrobert       */
212*404b540aSrobert       const char_type*
scan_not(mask __m,const char_type * __lo,const char_type * __hi)213*404b540aSrobert       scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
214*404b540aSrobert       { return this->do_scan_not(__m, __lo, __hi); }
215*404b540aSrobert 
216*404b540aSrobert       /**
217*404b540aSrobert        *  @brief  Convert to uppercase.
218*404b540aSrobert        *
219*404b540aSrobert        *  This function converts the argument to uppercase if possible.
220*404b540aSrobert        *  If not possible (for example, '2'), returns the argument.  It does
221*404b540aSrobert        *  so by returning ctype<char_type>::do_toupper().
222*404b540aSrobert        *
223*404b540aSrobert        *  @param c  The char_type to convert.
224*404b540aSrobert        *  @return  The uppercase char_type if convertible, else @a c.
225*404b540aSrobert       */
226*404b540aSrobert       char_type
toupper(char_type __c)227*404b540aSrobert       toupper(char_type __c) const
228*404b540aSrobert       { return this->do_toupper(__c); }
229*404b540aSrobert 
230*404b540aSrobert       /**
231*404b540aSrobert        *  @brief  Convert array to uppercase.
232*404b540aSrobert        *
233*404b540aSrobert        *  This function converts each char_type in the range [lo,hi) to
234*404b540aSrobert        *  uppercase if possible.  Other elements remain untouched.  It does so
235*404b540aSrobert        *  by returning ctype<char_type>:: do_toupper(lo, hi).
236*404b540aSrobert        *
237*404b540aSrobert        *  @param lo  Pointer to start of range.
238*404b540aSrobert        *  @param hi  Pointer to end of range.
239*404b540aSrobert        *  @return  @a hi.
240*404b540aSrobert       */
241*404b540aSrobert       const char_type*
toupper(char_type * __lo,const char_type * __hi)242*404b540aSrobert       toupper(char_type *__lo, const char_type* __hi) const
243*404b540aSrobert       { return this->do_toupper(__lo, __hi); }
244*404b540aSrobert 
245*404b540aSrobert       /**
246*404b540aSrobert        *  @brief  Convert to lowercase.
247*404b540aSrobert        *
248*404b540aSrobert        *  This function converts the argument to lowercase if possible.  If
249*404b540aSrobert        *  not possible (for example, '2'), returns the argument.  It does so
250*404b540aSrobert        *  by returning ctype<char_type>::do_tolower(c).
251*404b540aSrobert        *
252*404b540aSrobert        *  @param c  The char_type to convert.
253*404b540aSrobert        *  @return  The lowercase char_type if convertible, else @a c.
254*404b540aSrobert       */
255*404b540aSrobert       char_type
tolower(char_type __c)256*404b540aSrobert       tolower(char_type __c) const
257*404b540aSrobert       { return this->do_tolower(__c); }
258*404b540aSrobert 
259*404b540aSrobert       /**
260*404b540aSrobert        *  @brief  Convert array to lowercase.
261*404b540aSrobert        *
262*404b540aSrobert        *  This function converts each char_type in the range [lo,hi) to
263*404b540aSrobert        *  lowercase if possible.  Other elements remain untouched.  It does so
264*404b540aSrobert        *  by returning ctype<char_type>:: do_tolower(lo, hi).
265*404b540aSrobert        *
266*404b540aSrobert        *  @param lo  Pointer to start of range.
267*404b540aSrobert        *  @param hi  Pointer to end of range.
268*404b540aSrobert        *  @return  @a hi.
269*404b540aSrobert       */
270*404b540aSrobert       const char_type*
tolower(char_type * __lo,const char_type * __hi)271*404b540aSrobert       tolower(char_type* __lo, const char_type* __hi) const
272*404b540aSrobert       { return this->do_tolower(__lo, __hi); }
273*404b540aSrobert 
274*404b540aSrobert       /**
275*404b540aSrobert        *  @brief  Widen char to char_type
276*404b540aSrobert        *
277*404b540aSrobert        *  This function converts the char argument to char_type using the
278*404b540aSrobert        *  simplest reasonable transformation.  It does so by returning
279*404b540aSrobert        *  ctype<char_type>::do_widen(c).
280*404b540aSrobert        *
281*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
282*404b540aSrobert        *  codecvt for that.
283*404b540aSrobert        *
284*404b540aSrobert        *  @param c  The char to convert.
285*404b540aSrobert        *  @return  The converted char_type.
286*404b540aSrobert       */
287*404b540aSrobert       char_type
widen(char __c)288*404b540aSrobert       widen(char __c) const
289*404b540aSrobert       { return this->do_widen(__c); }
290*404b540aSrobert 
291*404b540aSrobert       /**
292*404b540aSrobert        *  @brief  Widen array to char_type
293*404b540aSrobert        *
294*404b540aSrobert        *  This function converts each char in the input to char_type using the
295*404b540aSrobert        *  simplest reasonable transformation.  It does so by returning
296*404b540aSrobert        *  ctype<char_type>::do_widen(c).
297*404b540aSrobert        *
298*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
299*404b540aSrobert        *  codecvt for that.
300*404b540aSrobert        *
301*404b540aSrobert        *  @param lo  Pointer to start of range.
302*404b540aSrobert        *  @param hi  Pointer to end of range.
303*404b540aSrobert        *  @param to  Pointer to the destination array.
304*404b540aSrobert        *  @return  @a hi.
305*404b540aSrobert       */
306*404b540aSrobert       const char*
widen(const char * __lo,const char * __hi,char_type * __to)307*404b540aSrobert       widen(const char* __lo, const char* __hi, char_type* __to) const
308*404b540aSrobert       { return this->do_widen(__lo, __hi, __to); }
309*404b540aSrobert 
310*404b540aSrobert       /**
311*404b540aSrobert        *  @brief  Narrow char_type to char
312*404b540aSrobert        *
313*404b540aSrobert        *  This function converts the char_type to char using the simplest
314*404b540aSrobert        *  reasonable transformation.  If the conversion fails, dfault is
315*404b540aSrobert        *  returned instead.  It does so by returning
316*404b540aSrobert        *  ctype<char_type>::do_narrow(c).
317*404b540aSrobert        *
318*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
319*404b540aSrobert        *  codecvt for that.
320*404b540aSrobert        *
321*404b540aSrobert        *  @param c  The char_type to convert.
322*404b540aSrobert        *  @param dfault  Char to return if conversion fails.
323*404b540aSrobert        *  @return  The converted char.
324*404b540aSrobert       */
325*404b540aSrobert       char
narrow(char_type __c,char __dfault)326*404b540aSrobert       narrow(char_type __c, char __dfault) const
327*404b540aSrobert       { return this->do_narrow(__c, __dfault); }
328*404b540aSrobert 
329*404b540aSrobert       /**
330*404b540aSrobert        *  @brief  Narrow array to char array
331*404b540aSrobert        *
332*404b540aSrobert        *  This function converts each char_type in the input to char using the
333*404b540aSrobert        *  simplest reasonable transformation and writes the results to the
334*404b540aSrobert        *  destination array.  For any char_type in the input that cannot be
335*404b540aSrobert        *  converted, @a dfault is used instead.  It does so by returning
336*404b540aSrobert        *  ctype<char_type>::do_narrow(lo, hi, dfault, to).
337*404b540aSrobert        *
338*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
339*404b540aSrobert        *  codecvt for that.
340*404b540aSrobert        *
341*404b540aSrobert        *  @param lo  Pointer to start of range.
342*404b540aSrobert        *  @param hi  Pointer to end of range.
343*404b540aSrobert        *  @param dfault  Char to use if conversion fails.
344*404b540aSrobert        *  @param to  Pointer to the destination array.
345*404b540aSrobert        *  @return  @a hi.
346*404b540aSrobert       */
347*404b540aSrobert       const char_type*
narrow(const char_type * __lo,const char_type * __hi,char __dfault,char * __to)348*404b540aSrobert       narrow(const char_type* __lo, const char_type* __hi,
349*404b540aSrobert 	      char __dfault, char *__to) const
350*404b540aSrobert       { return this->do_narrow(__lo, __hi, __dfault, __to); }
351*404b540aSrobert 
352*404b540aSrobert     protected:
353*404b540aSrobert       explicit
facet(__refs)354*404b540aSrobert       __ctype_abstract_base(size_t __refs = 0): facet(__refs) { }
355*404b540aSrobert 
356*404b540aSrobert       virtual
~__ctype_abstract_base()357*404b540aSrobert       ~__ctype_abstract_base() { }
358*404b540aSrobert 
359*404b540aSrobert       /**
360*404b540aSrobert        *  @brief  Test char_type classification.
361*404b540aSrobert        *
362*404b540aSrobert        *  This function finds a mask M for @a c and compares it to mask @a m.
363*404b540aSrobert        *
364*404b540aSrobert        *  do_is() is a hook for a derived facet to change the behavior of
365*404b540aSrobert        *  classifying.  do_is() must always return the same result for the
366*404b540aSrobert        *  same input.
367*404b540aSrobert        *
368*404b540aSrobert        *  @param c  The char_type to find the mask of.
369*404b540aSrobert        *  @param m  The mask to compare against.
370*404b540aSrobert        *  @return  (M & m) != 0.
371*404b540aSrobert       */
372*404b540aSrobert       virtual bool
373*404b540aSrobert       do_is(mask __m, char_type __c) const = 0;
374*404b540aSrobert 
375*404b540aSrobert       /**
376*404b540aSrobert        *  @brief  Return a mask array.
377*404b540aSrobert        *
378*404b540aSrobert        *  This function finds the mask for each char_type in the range [lo,hi)
379*404b540aSrobert        *  and successively writes it to vec.  vec must have as many elements
380*404b540aSrobert        *  as the input.
381*404b540aSrobert        *
382*404b540aSrobert        *  do_is() is a hook for a derived facet to change the behavior of
383*404b540aSrobert        *  classifying.  do_is() must always return the same result for the
384*404b540aSrobert        *  same input.
385*404b540aSrobert        *
386*404b540aSrobert        *  @param lo  Pointer to start of range.
387*404b540aSrobert        *  @param hi  Pointer to end of range.
388*404b540aSrobert        *  @param vec  Pointer to an array of mask storage.
389*404b540aSrobert        *  @return  @a hi.
390*404b540aSrobert       */
391*404b540aSrobert       virtual const char_type*
392*404b540aSrobert       do_is(const char_type* __lo, const char_type* __hi,
393*404b540aSrobert 	    mask* __vec) const = 0;
394*404b540aSrobert 
395*404b540aSrobert       /**
396*404b540aSrobert        *  @brief  Find char_type matching mask
397*404b540aSrobert        *
398*404b540aSrobert        *  This function searches for and returns the first char_type c in
399*404b540aSrobert        *  [lo,hi) for which is(m,c) is true.
400*404b540aSrobert        *
401*404b540aSrobert        *  do_scan_is() is a hook for a derived facet to change the behavior of
402*404b540aSrobert        *  match searching.  do_is() must always return the same result for the
403*404b540aSrobert        *  same input.
404*404b540aSrobert        *
405*404b540aSrobert        *  @param m  The mask to compare against.
406*404b540aSrobert        *  @param lo  Pointer to start of range.
407*404b540aSrobert        *  @param hi  Pointer to end of range.
408*404b540aSrobert        *  @return  Pointer to a matching char_type if found, else @a hi.
409*404b540aSrobert       */
410*404b540aSrobert       virtual const char_type*
411*404b540aSrobert       do_scan_is(mask __m, const char_type* __lo,
412*404b540aSrobert 		 const char_type* __hi) const = 0;
413*404b540aSrobert 
414*404b540aSrobert       /**
415*404b540aSrobert        *  @brief  Find char_type not matching mask
416*404b540aSrobert        *
417*404b540aSrobert        *  This function searches for and returns a pointer to the first
418*404b540aSrobert        *  char_type c of [lo,hi) for which is(m,c) is false.
419*404b540aSrobert        *
420*404b540aSrobert        *  do_scan_is() is a hook for a derived facet to change the behavior of
421*404b540aSrobert        *  match searching.  do_is() must always return the same result for the
422*404b540aSrobert        *  same input.
423*404b540aSrobert        *
424*404b540aSrobert        *  @param m  The mask to compare against.
425*404b540aSrobert        *  @param lo  Pointer to start of range.
426*404b540aSrobert        *  @param hi  Pointer to end of range.
427*404b540aSrobert        *  @return  Pointer to a non-matching char_type if found, else @a hi.
428*404b540aSrobert       */
429*404b540aSrobert       virtual const char_type*
430*404b540aSrobert       do_scan_not(mask __m, const char_type* __lo,
431*404b540aSrobert 		  const char_type* __hi) const = 0;
432*404b540aSrobert 
433*404b540aSrobert       /**
434*404b540aSrobert        *  @brief  Convert to uppercase.
435*404b540aSrobert        *
436*404b540aSrobert        *  This virtual function converts the char_type argument to uppercase
437*404b540aSrobert        *  if possible.  If not possible (for example, '2'), returns the
438*404b540aSrobert        *  argument.
439*404b540aSrobert        *
440*404b540aSrobert        *  do_toupper() is a hook for a derived facet to change the behavior of
441*404b540aSrobert        *  uppercasing.  do_toupper() must always return the same result for
442*404b540aSrobert        *  the same input.
443*404b540aSrobert        *
444*404b540aSrobert        *  @param c  The char_type to convert.
445*404b540aSrobert        *  @return  The uppercase char_type if convertible, else @a c.
446*404b540aSrobert       */
447*404b540aSrobert       virtual char_type
448*404b540aSrobert       do_toupper(char_type) const = 0;
449*404b540aSrobert 
450*404b540aSrobert       /**
451*404b540aSrobert        *  @brief  Convert array to uppercase.
452*404b540aSrobert        *
453*404b540aSrobert        *  This virtual function converts each char_type in the range [lo,hi)
454*404b540aSrobert        *  to uppercase if possible.  Other elements remain untouched.
455*404b540aSrobert        *
456*404b540aSrobert        *  do_toupper() is a hook for a derived facet to change the behavior of
457*404b540aSrobert        *  uppercasing.  do_toupper() must always return the same result for
458*404b540aSrobert        *  the same input.
459*404b540aSrobert        *
460*404b540aSrobert        *  @param lo  Pointer to start of range.
461*404b540aSrobert        *  @param hi  Pointer to end of range.
462*404b540aSrobert        *  @return  @a hi.
463*404b540aSrobert       */
464*404b540aSrobert       virtual const char_type*
465*404b540aSrobert       do_toupper(char_type* __lo, const char_type* __hi) const = 0;
466*404b540aSrobert 
467*404b540aSrobert       /**
468*404b540aSrobert        *  @brief  Convert to lowercase.
469*404b540aSrobert        *
470*404b540aSrobert        *  This virtual function converts the argument to lowercase if
471*404b540aSrobert        *  possible.  If not possible (for example, '2'), returns the argument.
472*404b540aSrobert        *
473*404b540aSrobert        *  do_tolower() is a hook for a derived facet to change the behavior of
474*404b540aSrobert        *  lowercasing.  do_tolower() must always return the same result for
475*404b540aSrobert        *  the same input.
476*404b540aSrobert        *
477*404b540aSrobert        *  @param c  The char_type to convert.
478*404b540aSrobert        *  @return  The lowercase char_type if convertible, else @a c.
479*404b540aSrobert       */
480*404b540aSrobert       virtual char_type
481*404b540aSrobert       do_tolower(char_type) const = 0;
482*404b540aSrobert 
483*404b540aSrobert       /**
484*404b540aSrobert        *  @brief  Convert array to lowercase.
485*404b540aSrobert        *
486*404b540aSrobert        *  This virtual function converts each char_type in the range [lo,hi)
487*404b540aSrobert        *  to lowercase if possible.  Other elements remain untouched.
488*404b540aSrobert        *
489*404b540aSrobert        *  do_tolower() is a hook for a derived facet to change the behavior of
490*404b540aSrobert        *  lowercasing.  do_tolower() must always return the same result for
491*404b540aSrobert        *  the same input.
492*404b540aSrobert        *
493*404b540aSrobert        *  @param lo  Pointer to start of range.
494*404b540aSrobert        *  @param hi  Pointer to end of range.
495*404b540aSrobert        *  @return  @a hi.
496*404b540aSrobert       */
497*404b540aSrobert       virtual const char_type*
498*404b540aSrobert       do_tolower(char_type* __lo, const char_type* __hi) const = 0;
499*404b540aSrobert 
500*404b540aSrobert       /**
501*404b540aSrobert        *  @brief  Widen char
502*404b540aSrobert        *
503*404b540aSrobert        *  This virtual function converts the char to char_type using the
504*404b540aSrobert        *  simplest reasonable transformation.
505*404b540aSrobert        *
506*404b540aSrobert        *  do_widen() is a hook for a derived facet to change the behavior of
507*404b540aSrobert        *  widening.  do_widen() must always return the same result for the
508*404b540aSrobert        *  same input.
509*404b540aSrobert        *
510*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
511*404b540aSrobert        *  codecvt for that.
512*404b540aSrobert        *
513*404b540aSrobert        *  @param c  The char to convert.
514*404b540aSrobert        *  @return  The converted char_type
515*404b540aSrobert       */
516*404b540aSrobert       virtual char_type
517*404b540aSrobert       do_widen(char) const = 0;
518*404b540aSrobert 
519*404b540aSrobert       /**
520*404b540aSrobert        *  @brief  Widen char array
521*404b540aSrobert        *
522*404b540aSrobert        *  This function converts each char in the input to char_type using the
523*404b540aSrobert        *  simplest reasonable transformation.
524*404b540aSrobert        *
525*404b540aSrobert        *  do_widen() is a hook for a derived facet to change the behavior of
526*404b540aSrobert        *  widening.  do_widen() must always return the same result for the
527*404b540aSrobert        *  same input.
528*404b540aSrobert        *
529*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
530*404b540aSrobert        *  codecvt for that.
531*404b540aSrobert        *
532*404b540aSrobert        *  @param lo  Pointer to start range.
533*404b540aSrobert        *  @param hi  Pointer to end of range.
534*404b540aSrobert        *  @param to  Pointer to the destination array.
535*404b540aSrobert        *  @return  @a hi.
536*404b540aSrobert       */
537*404b540aSrobert       virtual const char*
538*404b540aSrobert       do_widen(const char* __lo, const char* __hi,
539*404b540aSrobert 	       char_type* __dest) const = 0;
540*404b540aSrobert 
541*404b540aSrobert       /**
542*404b540aSrobert        *  @brief  Narrow char_type to char
543*404b540aSrobert        *
544*404b540aSrobert        *  This virtual function converts the argument to char using the
545*404b540aSrobert        *  simplest reasonable transformation.  If the conversion fails, dfault
546*404b540aSrobert        *  is returned instead.
547*404b540aSrobert        *
548*404b540aSrobert        *  do_narrow() is a hook for a derived facet to change the behavior of
549*404b540aSrobert        *  narrowing.  do_narrow() must always return the same result for the
550*404b540aSrobert        *  same input.
551*404b540aSrobert        *
552*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
553*404b540aSrobert        *  codecvt for that.
554*404b540aSrobert        *
555*404b540aSrobert        *  @param c  The char_type to convert.
556*404b540aSrobert        *  @param dfault  Char to return if conversion fails.
557*404b540aSrobert        *  @return  The converted char.
558*404b540aSrobert       */
559*404b540aSrobert       virtual char
560*404b540aSrobert       do_narrow(char_type, char __dfault) const = 0;
561*404b540aSrobert 
562*404b540aSrobert       /**
563*404b540aSrobert        *  @brief  Narrow char_type array to char
564*404b540aSrobert        *
565*404b540aSrobert        *  This virtual function converts each char_type in the range [lo,hi) to
566*404b540aSrobert        *  char using the simplest reasonable transformation and writes the
567*404b540aSrobert        *  results to the destination array.  For any element in the input that
568*404b540aSrobert        *  cannot be converted, @a dfault is used instead.
569*404b540aSrobert        *
570*404b540aSrobert        *  do_narrow() is a hook for a derived facet to change the behavior of
571*404b540aSrobert        *  narrowing.  do_narrow() must always return the same result for the
572*404b540aSrobert        *  same input.
573*404b540aSrobert        *
574*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
575*404b540aSrobert        *  codecvt for that.
576*404b540aSrobert        *
577*404b540aSrobert        *  @param lo  Pointer to start of range.
578*404b540aSrobert        *  @param hi  Pointer to end of range.
579*404b540aSrobert        *  @param dfault  Char to use if conversion fails.
580*404b540aSrobert        *  @param to  Pointer to the destination array.
581*404b540aSrobert        *  @return  @a hi.
582*404b540aSrobert       */
583*404b540aSrobert       virtual const char_type*
584*404b540aSrobert       do_narrow(const char_type* __lo, const char_type* __hi,
585*404b540aSrobert 		char __dfault, char* __dest) const = 0;
586*404b540aSrobert     };
587*404b540aSrobert 
588*404b540aSrobert   // NB: Generic, mostly useless implementation.
589*404b540aSrobert   /**
590*404b540aSrobert    *  @brief  Template ctype facet
591*404b540aSrobert    *
592*404b540aSrobert    *  This template class defines classification and conversion functions for
593*404b540aSrobert    *  character sets.  It wraps <cctype> functionality.  Ctype gets used by
594*404b540aSrobert    *  streams for many I/O operations.
595*404b540aSrobert    *
596*404b540aSrobert    *  This template provides the protected virtual functions the developer
597*404b540aSrobert    *  will have to replace in a derived class or specialization to make a
598*404b540aSrobert    *  working facet.  The public functions that access them are defined in
599*404b540aSrobert    *  __ctype_abstract_base, to allow for implementation flexibility.  See
600*404b540aSrobert    *  ctype<wchar_t> for an example.  The functions are documented in
601*404b540aSrobert    *  __ctype_abstract_base.
602*404b540aSrobert    *
603*404b540aSrobert    *  Note: implementations are provided for all the protected virtual
604*404b540aSrobert    *  functions, but will likely not be useful.
605*404b540aSrobert   */
606*404b540aSrobert   template<typename _CharT>
607*404b540aSrobert     class ctype : public __ctype_abstract_base<_CharT>
608*404b540aSrobert     {
609*404b540aSrobert     public:
610*404b540aSrobert       // Types:
611*404b540aSrobert       typedef _CharT			char_type;
612*404b540aSrobert       typedef typename __ctype_abstract_base<_CharT>::mask mask;
613*404b540aSrobert 
614*404b540aSrobert       /// The facet id for ctype<char_type>
615*404b540aSrobert       static locale::id			id;
616*404b540aSrobert 
617*404b540aSrobert       explicit
618*404b540aSrobert       ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
619*404b540aSrobert 
620*404b540aSrobert    protected:
621*404b540aSrobert       virtual
622*404b540aSrobert       ~ctype();
623*404b540aSrobert 
624*404b540aSrobert       virtual bool
625*404b540aSrobert       do_is(mask __m, char_type __c) const;
626*404b540aSrobert 
627*404b540aSrobert       virtual const char_type*
628*404b540aSrobert       do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
629*404b540aSrobert 
630*404b540aSrobert       virtual const char_type*
631*404b540aSrobert       do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
632*404b540aSrobert 
633*404b540aSrobert       virtual const char_type*
634*404b540aSrobert       do_scan_not(mask __m, const char_type* __lo,
635*404b540aSrobert 		  const char_type* __hi) const;
636*404b540aSrobert 
637*404b540aSrobert       virtual char_type
638*404b540aSrobert       do_toupper(char_type __c) const;
639*404b540aSrobert 
640*404b540aSrobert       virtual const char_type*
641*404b540aSrobert       do_toupper(char_type* __lo, const char_type* __hi) const;
642*404b540aSrobert 
643*404b540aSrobert       virtual char_type
644*404b540aSrobert       do_tolower(char_type __c) const;
645*404b540aSrobert 
646*404b540aSrobert       virtual const char_type*
647*404b540aSrobert       do_tolower(char_type* __lo, const char_type* __hi) const;
648*404b540aSrobert 
649*404b540aSrobert       virtual char_type
650*404b540aSrobert       do_widen(char __c) const;
651*404b540aSrobert 
652*404b540aSrobert       virtual const char*
653*404b540aSrobert       do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
654*404b540aSrobert 
655*404b540aSrobert       virtual char
656*404b540aSrobert       do_narrow(char_type, char __dfault) const;
657*404b540aSrobert 
658*404b540aSrobert       virtual const char_type*
659*404b540aSrobert       do_narrow(const char_type* __lo, const char_type* __hi,
660*404b540aSrobert 		char __dfault, char* __dest) const;
661*404b540aSrobert     };
662*404b540aSrobert 
663*404b540aSrobert   template<typename _CharT>
664*404b540aSrobert     locale::id ctype<_CharT>::id;
665*404b540aSrobert 
666*404b540aSrobert   // 22.2.1.3  ctype<char> specialization.
667*404b540aSrobert   /**
668*404b540aSrobert    *  @brief  The ctype<char> specialization.
669*404b540aSrobert    *
670*404b540aSrobert    *  This class defines classification and conversion functions for
671*404b540aSrobert    *  the char type.  It gets used by char streams for many I/O
672*404b540aSrobert    *  operations.  The char specialization provides a number of
673*404b540aSrobert    *  optimizations as well.
674*404b540aSrobert   */
675*404b540aSrobert   template<>
676*404b540aSrobert     class ctype<char> : public locale::facet, public ctype_base
677*404b540aSrobert     {
678*404b540aSrobert     public:
679*404b540aSrobert       // Types:
680*404b540aSrobert       /// Typedef for the template parameter char.
681*404b540aSrobert       typedef char		char_type;
682*404b540aSrobert 
683*404b540aSrobert     protected:
684*404b540aSrobert       // Data Members:
685*404b540aSrobert       __c_locale		_M_c_locale_ctype;
686*404b540aSrobert       bool			_M_del;
687*404b540aSrobert       __to_type			_M_toupper;
688*404b540aSrobert       __to_type			_M_tolower;
689*404b540aSrobert       const mask*		_M_table;
690*404b540aSrobert       mutable char		_M_widen_ok;
691*404b540aSrobert       mutable char		_M_widen[1 + static_cast<unsigned char>(-1)];
692*404b540aSrobert       mutable char		_M_narrow[1 + static_cast<unsigned char>(-1)];
693*404b540aSrobert       mutable char		_M_narrow_ok;	// 0 uninitialized, 1 init,
694*404b540aSrobert 						// 2 memcpy can't be used
695*404b540aSrobert 
696*404b540aSrobert     public:
697*404b540aSrobert       /// The facet id for ctype<char>
698*404b540aSrobert       static locale::id        id;
699*404b540aSrobert       /// The size of the mask table.  It is SCHAR_MAX + 1.
700*404b540aSrobert       static const size_t      table_size = 1 + static_cast<unsigned char>(-1);
701*404b540aSrobert 
702*404b540aSrobert       /**
703*404b540aSrobert        *  @brief  Constructor performs initialization.
704*404b540aSrobert        *
705*404b540aSrobert        *  This is the constructor provided by the standard.
706*404b540aSrobert        *
707*404b540aSrobert        *  @param table If non-zero, table is used as the per-char mask.
708*404b540aSrobert        *               Else classic_table() is used.
709*404b540aSrobert        *  @param del   If true, passes ownership of table to this facet.
710*404b540aSrobert        *  @param refs  Passed to the base facet class.
711*404b540aSrobert       */
712*404b540aSrobert       explicit
713*404b540aSrobert       ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
714*404b540aSrobert 
715*404b540aSrobert       /**
716*404b540aSrobert        *  @brief  Constructor performs static initialization.
717*404b540aSrobert        *
718*404b540aSrobert        *  This constructor is used to construct the initial C locale facet.
719*404b540aSrobert        *
720*404b540aSrobert        *  @param cloc  Handle to C locale data.
721*404b540aSrobert        *  @param table If non-zero, table is used as the per-char mask.
722*404b540aSrobert        *  @param del   If true, passes ownership of table to this facet.
723*404b540aSrobert        *  @param refs  Passed to the base facet class.
724*404b540aSrobert       */
725*404b540aSrobert       explicit
726*404b540aSrobert       ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
727*404b540aSrobert 	    size_t __refs = 0);
728*404b540aSrobert 
729*404b540aSrobert       /**
730*404b540aSrobert        *  @brief  Test char classification.
731*404b540aSrobert        *
732*404b540aSrobert        *  This function compares the mask table[c] to @a m.
733*404b540aSrobert        *
734*404b540aSrobert        *  @param c  The char to compare the mask of.
735*404b540aSrobert        *  @param m  The mask to compare against.
736*404b540aSrobert        *  @return  True if m & table[c] is true, false otherwise.
737*404b540aSrobert       */
738*404b540aSrobert       inline bool
739*404b540aSrobert       is(mask __m, char __c) const;
740*404b540aSrobert 
741*404b540aSrobert       /**
742*404b540aSrobert        *  @brief  Return a mask array.
743*404b540aSrobert        *
744*404b540aSrobert        *  This function finds the mask for each char in the range [lo, hi) and
745*404b540aSrobert        *  successively writes it to vec.  vec must have as many elements as
746*404b540aSrobert        *  the char array.
747*404b540aSrobert        *
748*404b540aSrobert        *  @param lo  Pointer to start of range.
749*404b540aSrobert        *  @param hi  Pointer to end of range.
750*404b540aSrobert        *  @param vec  Pointer to an array of mask storage.
751*404b540aSrobert        *  @return  @a hi.
752*404b540aSrobert       */
753*404b540aSrobert       inline const char*
754*404b540aSrobert       is(const char* __lo, const char* __hi, mask* __vec) const;
755*404b540aSrobert 
756*404b540aSrobert       /**
757*404b540aSrobert        *  @brief  Find char matching a mask
758*404b540aSrobert        *
759*404b540aSrobert        *  This function searches for and returns the first char in [lo,hi) for
760*404b540aSrobert        *  which is(m,char) is true.
761*404b540aSrobert        *
762*404b540aSrobert        *  @param m  The mask to compare against.
763*404b540aSrobert        *  @param lo  Pointer to start of range.
764*404b540aSrobert        *  @param hi  Pointer to end of range.
765*404b540aSrobert        *  @return  Pointer to a matching char if found, else @a hi.
766*404b540aSrobert       */
767*404b540aSrobert       inline const char*
768*404b540aSrobert       scan_is(mask __m, const char* __lo, const char* __hi) const;
769*404b540aSrobert 
770*404b540aSrobert       /**
771*404b540aSrobert        *  @brief  Find char not matching a mask
772*404b540aSrobert        *
773*404b540aSrobert        *  This function searches for and returns a pointer to the first char
774*404b540aSrobert        *  in [lo,hi) for which is(m,char) is false.
775*404b540aSrobert        *
776*404b540aSrobert        *  @param m  The mask to compare against.
777*404b540aSrobert        *  @param lo  Pointer to start of range.
778*404b540aSrobert        *  @param hi  Pointer to end of range.
779*404b540aSrobert        *  @return  Pointer to a non-matching char if found, else @a hi.
780*404b540aSrobert       */
781*404b540aSrobert       inline const char*
782*404b540aSrobert       scan_not(mask __m, const char* __lo, const char* __hi) const;
783*404b540aSrobert 
784*404b540aSrobert       /**
785*404b540aSrobert        *  @brief  Convert to uppercase.
786*404b540aSrobert        *
787*404b540aSrobert        *  This function converts the char argument to uppercase if possible.
788*404b540aSrobert        *  If not possible (for example, '2'), returns the argument.
789*404b540aSrobert        *
790*404b540aSrobert        *  toupper() acts as if it returns ctype<char>::do_toupper(c).
791*404b540aSrobert        *  do_toupper() must always return the same result for the same input.
792*404b540aSrobert        *
793*404b540aSrobert        *  @param c  The char to convert.
794*404b540aSrobert        *  @return  The uppercase char if convertible, else @a c.
795*404b540aSrobert       */
796*404b540aSrobert       char_type
toupper(char_type __c)797*404b540aSrobert       toupper(char_type __c) const
798*404b540aSrobert       { return this->do_toupper(__c); }
799*404b540aSrobert 
800*404b540aSrobert       /**
801*404b540aSrobert        *  @brief  Convert array to uppercase.
802*404b540aSrobert        *
803*404b540aSrobert        *  This function converts each char in the range [lo,hi) to uppercase
804*404b540aSrobert        *  if possible.  Other chars remain untouched.
805*404b540aSrobert        *
806*404b540aSrobert        *  toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi).
807*404b540aSrobert        *  do_toupper() must always return the same result for the same input.
808*404b540aSrobert        *
809*404b540aSrobert        *  @param lo  Pointer to first char in range.
810*404b540aSrobert        *  @param hi  Pointer to end of range.
811*404b540aSrobert        *  @return  @a hi.
812*404b540aSrobert       */
813*404b540aSrobert       const char_type*
toupper(char_type * __lo,const char_type * __hi)814*404b540aSrobert       toupper(char_type *__lo, const char_type* __hi) const
815*404b540aSrobert       { return this->do_toupper(__lo, __hi); }
816*404b540aSrobert 
817*404b540aSrobert       /**
818*404b540aSrobert        *  @brief  Convert to lowercase.
819*404b540aSrobert        *
820*404b540aSrobert        *  This function converts the char argument to lowercase if possible.
821*404b540aSrobert        *  If not possible (for example, '2'), returns the argument.
822*404b540aSrobert        *
823*404b540aSrobert        *  tolower() acts as if it returns ctype<char>::do_tolower(c).
824*404b540aSrobert        *  do_tolower() must always return the same result for the same input.
825*404b540aSrobert        *
826*404b540aSrobert        *  @param c  The char to convert.
827*404b540aSrobert        *  @return  The lowercase char if convertible, else @a c.
828*404b540aSrobert       */
829*404b540aSrobert       char_type
tolower(char_type __c)830*404b540aSrobert       tolower(char_type __c) const
831*404b540aSrobert       { return this->do_tolower(__c); }
832*404b540aSrobert 
833*404b540aSrobert       /**
834*404b540aSrobert        *  @brief  Convert array to lowercase.
835*404b540aSrobert        *
836*404b540aSrobert        *  This function converts each char in the range [lo,hi) to lowercase
837*404b540aSrobert        *  if possible.  Other chars remain untouched.
838*404b540aSrobert        *
839*404b540aSrobert        *  tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi).
840*404b540aSrobert        *  do_tolower() must always return the same result for the same input.
841*404b540aSrobert        *
842*404b540aSrobert        *  @param lo  Pointer to first char in range.
843*404b540aSrobert        *  @param hi  Pointer to end of range.
844*404b540aSrobert        *  @return  @a hi.
845*404b540aSrobert       */
846*404b540aSrobert       const char_type*
tolower(char_type * __lo,const char_type * __hi)847*404b540aSrobert       tolower(char_type* __lo, const char_type* __hi) const
848*404b540aSrobert       { return this->do_tolower(__lo, __hi); }
849*404b540aSrobert 
850*404b540aSrobert       /**
851*404b540aSrobert        *  @brief  Widen char
852*404b540aSrobert        *
853*404b540aSrobert        *  This function converts the char to char_type using the simplest
854*404b540aSrobert        *  reasonable transformation.  For an underived ctype<char> facet, the
855*404b540aSrobert        *  argument will be returned unchanged.
856*404b540aSrobert        *
857*404b540aSrobert        *  This function works as if it returns ctype<char>::do_widen(c).
858*404b540aSrobert        *  do_widen() must always return the same result for the same input.
859*404b540aSrobert        *
860*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
861*404b540aSrobert        *  codecvt for that.
862*404b540aSrobert        *
863*404b540aSrobert        *  @param c  The char to convert.
864*404b540aSrobert        *  @return  The converted character.
865*404b540aSrobert       */
866*404b540aSrobert       char_type
widen(char __c)867*404b540aSrobert       widen(char __c) const
868*404b540aSrobert       {
869*404b540aSrobert 	if (_M_widen_ok)
870*404b540aSrobert 	  return _M_widen[static_cast<unsigned char>(__c)];
871*404b540aSrobert 	this->_M_widen_init();
872*404b540aSrobert 	return this->do_widen(__c);
873*404b540aSrobert       }
874*404b540aSrobert 
875*404b540aSrobert       /**
876*404b540aSrobert        *  @brief  Widen char array
877*404b540aSrobert        *
878*404b540aSrobert        *  This function converts each char in the input to char using the
879*404b540aSrobert        *  simplest reasonable transformation.  For an underived ctype<char>
880*404b540aSrobert        *  facet, the argument will be copied unchanged.
881*404b540aSrobert        *
882*404b540aSrobert        *  This function works as if it returns ctype<char>::do_widen(c).
883*404b540aSrobert        *  do_widen() must always return the same result for the same input.
884*404b540aSrobert        *
885*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
886*404b540aSrobert        *  codecvt for that.
887*404b540aSrobert        *
888*404b540aSrobert        *  @param lo  Pointer to first char in range.
889*404b540aSrobert        *  @param hi  Pointer to end of range.
890*404b540aSrobert        *  @param to  Pointer to the destination array.
891*404b540aSrobert        *  @return  @a hi.
892*404b540aSrobert       */
893*404b540aSrobert       const char*
widen(const char * __lo,const char * __hi,char_type * __to)894*404b540aSrobert       widen(const char* __lo, const char* __hi, char_type* __to) const
895*404b540aSrobert       {
896*404b540aSrobert 	if (_M_widen_ok == 1)
897*404b540aSrobert 	  {
898*404b540aSrobert 	    memcpy(__to, __lo, __hi - __lo);
899*404b540aSrobert 	    return __hi;
900*404b540aSrobert 	  }
901*404b540aSrobert 	if (!_M_widen_ok)
902*404b540aSrobert 	  _M_widen_init();
903*404b540aSrobert 	return this->do_widen(__lo, __hi, __to);
904*404b540aSrobert       }
905*404b540aSrobert 
906*404b540aSrobert       /**
907*404b540aSrobert        *  @brief  Narrow char
908*404b540aSrobert        *
909*404b540aSrobert        *  This function converts the char to char using the simplest
910*404b540aSrobert        *  reasonable transformation.  If the conversion fails, dfault is
911*404b540aSrobert        *  returned instead.  For an underived ctype<char> facet, @a c
912*404b540aSrobert        *  will be returned unchanged.
913*404b540aSrobert        *
914*404b540aSrobert        *  This function works as if it returns ctype<char>::do_narrow(c).
915*404b540aSrobert        *  do_narrow() must always return the same result for the same input.
916*404b540aSrobert        *
917*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
918*404b540aSrobert        *  codecvt for that.
919*404b540aSrobert        *
920*404b540aSrobert        *  @param c  The char to convert.
921*404b540aSrobert        *  @param dfault  Char to return if conversion fails.
922*404b540aSrobert        *  @return  The converted character.
923*404b540aSrobert       */
924*404b540aSrobert       char
narrow(char_type __c,char __dfault)925*404b540aSrobert       narrow(char_type __c, char __dfault) const
926*404b540aSrobert       {
927*404b540aSrobert 	if (_M_narrow[static_cast<unsigned char>(__c)])
928*404b540aSrobert 	  return _M_narrow[static_cast<unsigned char>(__c)];
929*404b540aSrobert 	const char __t = do_narrow(__c, __dfault);
930*404b540aSrobert 	if (__t != __dfault)
931*404b540aSrobert 	  _M_narrow[static_cast<unsigned char>(__c)] = __t;
932*404b540aSrobert 	return __t;
933*404b540aSrobert       }
934*404b540aSrobert 
935*404b540aSrobert       /**
936*404b540aSrobert        *  @brief  Narrow char array
937*404b540aSrobert        *
938*404b540aSrobert        *  This function converts each char in the input to char using the
939*404b540aSrobert        *  simplest reasonable transformation and writes the results to the
940*404b540aSrobert        *  destination array.  For any char in the input that cannot be
941*404b540aSrobert        *  converted, @a dfault is used instead.  For an underived ctype<char>
942*404b540aSrobert        *  facet, the argument will be copied unchanged.
943*404b540aSrobert        *
944*404b540aSrobert        *  This function works as if it returns ctype<char>::do_narrow(lo, hi,
945*404b540aSrobert        *  dfault, to).  do_narrow() must always return the same result for the
946*404b540aSrobert        *  same input.
947*404b540aSrobert        *
948*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
949*404b540aSrobert        *  codecvt for that.
950*404b540aSrobert        *
951*404b540aSrobert        *  @param lo  Pointer to start of range.
952*404b540aSrobert        *  @param hi  Pointer to end of range.
953*404b540aSrobert        *  @param dfault  Char to use if conversion fails.
954*404b540aSrobert        *  @param to  Pointer to the destination array.
955*404b540aSrobert        *  @return  @a hi.
956*404b540aSrobert       */
957*404b540aSrobert       const char_type*
narrow(const char_type * __lo,const char_type * __hi,char __dfault,char * __to)958*404b540aSrobert       narrow(const char_type* __lo, const char_type* __hi,
959*404b540aSrobert 	     char __dfault, char *__to) const
960*404b540aSrobert       {
961*404b540aSrobert 	if (__builtin_expect(_M_narrow_ok == 1, true))
962*404b540aSrobert 	  {
963*404b540aSrobert 	    memcpy(__to, __lo, __hi - __lo);
964*404b540aSrobert 	    return __hi;
965*404b540aSrobert 	  }
966*404b540aSrobert 	if (!_M_narrow_ok)
967*404b540aSrobert 	  _M_narrow_init();
968*404b540aSrobert 	return this->do_narrow(__lo, __hi, __dfault, __to);
969*404b540aSrobert       }
970*404b540aSrobert 
971*404b540aSrobert     protected:
972*404b540aSrobert       /// Returns a pointer to the mask table provided to the constructor, or
973*404b540aSrobert       /// the default from classic_table() if none was provided.
974*404b540aSrobert       const mask*
table()975*404b540aSrobert       table() const throw()
976*404b540aSrobert       { return _M_table; }
977*404b540aSrobert 
978*404b540aSrobert       /// Returns a pointer to the C locale mask table.
979*404b540aSrobert       static const mask*
980*404b540aSrobert       classic_table() throw();
981*404b540aSrobert 
982*404b540aSrobert       /**
983*404b540aSrobert        *  @brief  Destructor.
984*404b540aSrobert        *
985*404b540aSrobert        *  This function deletes table() if @a del was true in the
986*404b540aSrobert        *  constructor.
987*404b540aSrobert       */
988*404b540aSrobert       virtual
989*404b540aSrobert       ~ctype();
990*404b540aSrobert 
991*404b540aSrobert       /**
992*404b540aSrobert        *  @brief  Convert to uppercase.
993*404b540aSrobert        *
994*404b540aSrobert        *  This virtual function converts the char argument to uppercase if
995*404b540aSrobert        *  possible.  If not possible (for example, '2'), returns the argument.
996*404b540aSrobert        *
997*404b540aSrobert        *  do_toupper() is a hook for a derived facet to change the behavior of
998*404b540aSrobert        *  uppercasing.  do_toupper() must always return the same result for
999*404b540aSrobert        *  the same input.
1000*404b540aSrobert        *
1001*404b540aSrobert        *  @param c  The char to convert.
1002*404b540aSrobert        *  @return  The uppercase char if convertible, else @a c.
1003*404b540aSrobert       */
1004*404b540aSrobert       virtual char_type
1005*404b540aSrobert       do_toupper(char_type) const;
1006*404b540aSrobert 
1007*404b540aSrobert       /**
1008*404b540aSrobert        *  @brief  Convert array to uppercase.
1009*404b540aSrobert        *
1010*404b540aSrobert        *  This virtual function converts each char in the range [lo,hi) to
1011*404b540aSrobert        *  uppercase if possible.  Other chars remain untouched.
1012*404b540aSrobert        *
1013*404b540aSrobert        *  do_toupper() is a hook for a derived facet to change the behavior of
1014*404b540aSrobert        *  uppercasing.  do_toupper() must always return the same result for
1015*404b540aSrobert        *  the same input.
1016*404b540aSrobert        *
1017*404b540aSrobert        *  @param lo  Pointer to start of range.
1018*404b540aSrobert        *  @param hi  Pointer to end of range.
1019*404b540aSrobert        *  @return  @a hi.
1020*404b540aSrobert       */
1021*404b540aSrobert       virtual const char_type*
1022*404b540aSrobert       do_toupper(char_type* __lo, const char_type* __hi) const;
1023*404b540aSrobert 
1024*404b540aSrobert       /**
1025*404b540aSrobert        *  @brief  Convert to lowercase.
1026*404b540aSrobert        *
1027*404b540aSrobert        *  This virtual function converts the char argument to lowercase if
1028*404b540aSrobert        *  possible.  If not possible (for example, '2'), returns the argument.
1029*404b540aSrobert        *
1030*404b540aSrobert        *  do_tolower() is a hook for a derived facet to change the behavior of
1031*404b540aSrobert        *  lowercasing.  do_tolower() must always return the same result for
1032*404b540aSrobert        *  the same input.
1033*404b540aSrobert        *
1034*404b540aSrobert        *  @param c  The char to convert.
1035*404b540aSrobert        *  @return  The lowercase char if convertible, else @a c.
1036*404b540aSrobert       */
1037*404b540aSrobert       virtual char_type
1038*404b540aSrobert       do_tolower(char_type) const;
1039*404b540aSrobert 
1040*404b540aSrobert       /**
1041*404b540aSrobert        *  @brief  Convert array to lowercase.
1042*404b540aSrobert        *
1043*404b540aSrobert        *  This virtual function converts each char in the range [lo,hi) to
1044*404b540aSrobert        *  lowercase if possible.  Other chars remain untouched.
1045*404b540aSrobert        *
1046*404b540aSrobert        *  do_tolower() is a hook for a derived facet to change the behavior of
1047*404b540aSrobert        *  lowercasing.  do_tolower() must always return the same result for
1048*404b540aSrobert        *  the same input.
1049*404b540aSrobert        *
1050*404b540aSrobert        *  @param lo  Pointer to first char in range.
1051*404b540aSrobert        *  @param hi  Pointer to end of range.
1052*404b540aSrobert        *  @return  @a hi.
1053*404b540aSrobert       */
1054*404b540aSrobert       virtual const char_type*
1055*404b540aSrobert       do_tolower(char_type* __lo, const char_type* __hi) const;
1056*404b540aSrobert 
1057*404b540aSrobert       /**
1058*404b540aSrobert        *  @brief  Widen char
1059*404b540aSrobert        *
1060*404b540aSrobert        *  This virtual function converts the char to char using the simplest
1061*404b540aSrobert        *  reasonable transformation.  For an underived ctype<char> facet, the
1062*404b540aSrobert        *  argument will be returned unchanged.
1063*404b540aSrobert        *
1064*404b540aSrobert        *  do_widen() is a hook for a derived facet to change the behavior of
1065*404b540aSrobert        *  widening.  do_widen() must always return the same result for the
1066*404b540aSrobert        *  same input.
1067*404b540aSrobert        *
1068*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
1069*404b540aSrobert        *  codecvt for that.
1070*404b540aSrobert        *
1071*404b540aSrobert        *  @param c  The char to convert.
1072*404b540aSrobert        *  @return  The converted character.
1073*404b540aSrobert       */
1074*404b540aSrobert       virtual char_type
do_widen(char __c)1075*404b540aSrobert       do_widen(char __c) const
1076*404b540aSrobert       { return __c; }
1077*404b540aSrobert 
1078*404b540aSrobert       /**
1079*404b540aSrobert        *  @brief  Widen char array
1080*404b540aSrobert        *
1081*404b540aSrobert        *  This function converts each char in the range [lo,hi) to char using
1082*404b540aSrobert        *  the simplest reasonable transformation.  For an underived
1083*404b540aSrobert        *  ctype<char> facet, the argument will be copied unchanged.
1084*404b540aSrobert        *
1085*404b540aSrobert        *  do_widen() is a hook for a derived facet to change the behavior of
1086*404b540aSrobert        *  widening.  do_widen() must always return the same result for the
1087*404b540aSrobert        *  same input.
1088*404b540aSrobert        *
1089*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
1090*404b540aSrobert        *  codecvt for that.
1091*404b540aSrobert        *
1092*404b540aSrobert        *  @param lo  Pointer to start of range.
1093*404b540aSrobert        *  @param hi  Pointer to end of range.
1094*404b540aSrobert        *  @param to  Pointer to the destination array.
1095*404b540aSrobert        *  @return  @a hi.
1096*404b540aSrobert       */
1097*404b540aSrobert       virtual const char*
do_widen(const char * __lo,const char * __hi,char_type * __dest)1098*404b540aSrobert       do_widen(const char* __lo, const char* __hi, char_type* __dest) const
1099*404b540aSrobert       {
1100*404b540aSrobert 	memcpy(__dest, __lo, __hi - __lo);
1101*404b540aSrobert 	return __hi;
1102*404b540aSrobert       }
1103*404b540aSrobert 
1104*404b540aSrobert       /**
1105*404b540aSrobert        *  @brief  Narrow char
1106*404b540aSrobert        *
1107*404b540aSrobert        *  This virtual function converts the char to char using the simplest
1108*404b540aSrobert        *  reasonable transformation.  If the conversion fails, dfault is
1109*404b540aSrobert        *  returned instead.  For an underived ctype<char> facet, @a c will be
1110*404b540aSrobert        *  returned unchanged.
1111*404b540aSrobert        *
1112*404b540aSrobert        *  do_narrow() is a hook for a derived facet to change the behavior of
1113*404b540aSrobert        *  narrowing.  do_narrow() must always return the same result for the
1114*404b540aSrobert        *  same input.
1115*404b540aSrobert        *
1116*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
1117*404b540aSrobert        *  codecvt for that.
1118*404b540aSrobert        *
1119*404b540aSrobert        *  @param c  The char to convert.
1120*404b540aSrobert        *  @param dfault  Char to return if conversion fails.
1121*404b540aSrobert        *  @return  The converted char.
1122*404b540aSrobert       */
1123*404b540aSrobert       virtual char
do_narrow(char_type __c,char)1124*404b540aSrobert       do_narrow(char_type __c, char) const
1125*404b540aSrobert       { return __c; }
1126*404b540aSrobert 
1127*404b540aSrobert       /**
1128*404b540aSrobert        *  @brief  Narrow char array to char array
1129*404b540aSrobert        *
1130*404b540aSrobert        *  This virtual function converts each char in the range [lo,hi) to
1131*404b540aSrobert        *  char using the simplest reasonable transformation and writes the
1132*404b540aSrobert        *  results to the destination array.  For any char in the input that
1133*404b540aSrobert        *  cannot be converted, @a dfault is used instead.  For an underived
1134*404b540aSrobert        *  ctype<char> facet, the argument will be copied unchanged.
1135*404b540aSrobert        *
1136*404b540aSrobert        *  do_narrow() is a hook for a derived facet to change the behavior of
1137*404b540aSrobert        *  narrowing.  do_narrow() must always return the same result for the
1138*404b540aSrobert        *  same input.
1139*404b540aSrobert        *
1140*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
1141*404b540aSrobert        *  codecvt for that.
1142*404b540aSrobert        *
1143*404b540aSrobert        *  @param lo  Pointer to start of range.
1144*404b540aSrobert        *  @param hi  Pointer to end of range.
1145*404b540aSrobert        *  @param dfault  Char to use if conversion fails.
1146*404b540aSrobert        *  @param to  Pointer to the destination array.
1147*404b540aSrobert        *  @return  @a hi.
1148*404b540aSrobert       */
1149*404b540aSrobert       virtual const char_type*
do_narrow(const char_type * __lo,const char_type * __hi,char,char * __dest)1150*404b540aSrobert       do_narrow(const char_type* __lo, const char_type* __hi,
1151*404b540aSrobert 		char, char* __dest) const
1152*404b540aSrobert       {
1153*404b540aSrobert 	memcpy(__dest, __lo, __hi - __lo);
1154*404b540aSrobert 	return __hi;
1155*404b540aSrobert       }
1156*404b540aSrobert 
1157*404b540aSrobert     private:
1158*404b540aSrobert 
_M_widen_init()1159*404b540aSrobert       void _M_widen_init() const
1160*404b540aSrobert       {
1161*404b540aSrobert 	char __tmp[sizeof(_M_widen)];
1162*404b540aSrobert 	for (size_t __i = 0; __i < sizeof(_M_widen); ++__i)
1163*404b540aSrobert 	  __tmp[__i] = __i;
1164*404b540aSrobert 	do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen);
1165*404b540aSrobert 
1166*404b540aSrobert 	_M_widen_ok = 1;
1167*404b540aSrobert 	// Set _M_widen_ok to 2 if memcpy can't be used.
1168*404b540aSrobert 	if (memcmp(__tmp, _M_widen, sizeof(_M_widen)))
1169*404b540aSrobert 	  _M_widen_ok = 2;
1170*404b540aSrobert       }
1171*404b540aSrobert 
1172*404b540aSrobert       // Fill in the narrowing cache and flag whether all values are
1173*404b540aSrobert       // valid or not.  _M_narrow_ok is set to 2 if memcpy can't
1174*404b540aSrobert       // be used.
_M_narrow_init()1175*404b540aSrobert       void _M_narrow_init() const
1176*404b540aSrobert       {
1177*404b540aSrobert 	char __tmp[sizeof(_M_narrow)];
1178*404b540aSrobert 	for (size_t __i = 0; __i < sizeof(_M_narrow); ++__i)
1179*404b540aSrobert 	  __tmp[__i] = __i;
1180*404b540aSrobert 	do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow);
1181*404b540aSrobert 
1182*404b540aSrobert 	_M_narrow_ok = 1;
1183*404b540aSrobert 	if (memcmp(__tmp, _M_narrow, sizeof(_M_narrow)))
1184*404b540aSrobert 	  _M_narrow_ok = 2;
1185*404b540aSrobert 	else
1186*404b540aSrobert 	  {
1187*404b540aSrobert 	    // Deal with the special case of zero: renarrow with a
1188*404b540aSrobert 	    // different default and compare.
1189*404b540aSrobert 	    char __c;
1190*404b540aSrobert 	    do_narrow(__tmp, __tmp + 1, 1, &__c);
1191*404b540aSrobert 	    if (__c == 1)
1192*404b540aSrobert 	      _M_narrow_ok = 2;
1193*404b540aSrobert 	  }
1194*404b540aSrobert       }
1195*404b540aSrobert     };
1196*404b540aSrobert 
1197*404b540aSrobert   template<>
1198*404b540aSrobert     const ctype<char>&
1199*404b540aSrobert     use_facet<ctype<char> >(const locale& __loc);
1200*404b540aSrobert 
1201*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T
1202*404b540aSrobert   // 22.2.1.3  ctype<wchar_t> specialization
1203*404b540aSrobert   /**
1204*404b540aSrobert    *  @brief  The ctype<wchar_t> specialization.
1205*404b540aSrobert    *
1206*404b540aSrobert    *  This class defines classification and conversion functions for the
1207*404b540aSrobert    *  wchar_t type.  It gets used by wchar_t streams for many I/O operations.
1208*404b540aSrobert    *  The wchar_t specialization provides a number of optimizations as well.
1209*404b540aSrobert    *
1210*404b540aSrobert    *  ctype<wchar_t> inherits its public methods from
1211*404b540aSrobert    *  __ctype_abstract_base<wchar_t>.
1212*404b540aSrobert   */
1213*404b540aSrobert   template<>
1214*404b540aSrobert     class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
1215*404b540aSrobert     {
1216*404b540aSrobert     public:
1217*404b540aSrobert       // Types:
1218*404b540aSrobert       /// Typedef for the template parameter wchar_t.
1219*404b540aSrobert       typedef wchar_t		char_type;
1220*404b540aSrobert       typedef wctype_t		__wmask_type;
1221*404b540aSrobert 
1222*404b540aSrobert     protected:
1223*404b540aSrobert       __c_locale		_M_c_locale_ctype;
1224*404b540aSrobert 
1225*404b540aSrobert       // Pre-computed narrowed and widened chars.
1226*404b540aSrobert       bool                      _M_narrow_ok;
1227*404b540aSrobert       char                      _M_narrow[128];
1228*404b540aSrobert       wint_t                    _M_widen[1 + static_cast<unsigned char>(-1)];
1229*404b540aSrobert 
1230*404b540aSrobert       // Pre-computed elements for do_is.
1231*404b540aSrobert       mask                      _M_bit[16];
1232*404b540aSrobert       __wmask_type              _M_wmask[16];
1233*404b540aSrobert 
1234*404b540aSrobert     public:
1235*404b540aSrobert       // Data Members:
1236*404b540aSrobert       /// The facet id for ctype<wchar_t>
1237*404b540aSrobert       static locale::id		id;
1238*404b540aSrobert 
1239*404b540aSrobert       /**
1240*404b540aSrobert        *  @brief  Constructor performs initialization.
1241*404b540aSrobert        *
1242*404b540aSrobert        *  This is the constructor provided by the standard.
1243*404b540aSrobert        *
1244*404b540aSrobert        *  @param refs  Passed to the base facet class.
1245*404b540aSrobert       */
1246*404b540aSrobert       explicit
1247*404b540aSrobert       ctype(size_t __refs = 0);
1248*404b540aSrobert 
1249*404b540aSrobert       /**
1250*404b540aSrobert        *  @brief  Constructor performs static initialization.
1251*404b540aSrobert        *
1252*404b540aSrobert        *  This constructor is used to construct the initial C locale facet.
1253*404b540aSrobert        *
1254*404b540aSrobert        *  @param cloc  Handle to C locale data.
1255*404b540aSrobert        *  @param refs  Passed to the base facet class.
1256*404b540aSrobert       */
1257*404b540aSrobert       explicit
1258*404b540aSrobert       ctype(__c_locale __cloc, size_t __refs = 0);
1259*404b540aSrobert 
1260*404b540aSrobert     protected:
1261*404b540aSrobert       __wmask_type
1262*404b540aSrobert       _M_convert_to_wmask(const mask __m) const;
1263*404b540aSrobert 
1264*404b540aSrobert       /// Destructor
1265*404b540aSrobert       virtual
1266*404b540aSrobert       ~ctype();
1267*404b540aSrobert 
1268*404b540aSrobert       /**
1269*404b540aSrobert        *  @brief  Test wchar_t classification.
1270*404b540aSrobert        *
1271*404b540aSrobert        *  This function finds a mask M for @a c and compares it to mask @a m.
1272*404b540aSrobert        *
1273*404b540aSrobert        *  do_is() is a hook for a derived facet to change the behavior of
1274*404b540aSrobert        *  classifying.  do_is() must always return the same result for the
1275*404b540aSrobert        *  same input.
1276*404b540aSrobert        *
1277*404b540aSrobert        *  @param c  The wchar_t to find the mask of.
1278*404b540aSrobert        *  @param m  The mask to compare against.
1279*404b540aSrobert        *  @return  (M & m) != 0.
1280*404b540aSrobert       */
1281*404b540aSrobert       virtual bool
1282*404b540aSrobert       do_is(mask __m, char_type __c) const;
1283*404b540aSrobert 
1284*404b540aSrobert       /**
1285*404b540aSrobert        *  @brief  Return a mask array.
1286*404b540aSrobert        *
1287*404b540aSrobert        *  This function finds the mask for each wchar_t in the range [lo,hi)
1288*404b540aSrobert        *  and successively writes it to vec.  vec must have as many elements
1289*404b540aSrobert        *  as the input.
1290*404b540aSrobert        *
1291*404b540aSrobert        *  do_is() is a hook for a derived facet to change the behavior of
1292*404b540aSrobert        *  classifying.  do_is() must always return the same result for the
1293*404b540aSrobert        *  same input.
1294*404b540aSrobert        *
1295*404b540aSrobert        *  @param lo  Pointer to start of range.
1296*404b540aSrobert        *  @param hi  Pointer to end of range.
1297*404b540aSrobert        *  @param vec  Pointer to an array of mask storage.
1298*404b540aSrobert        *  @return  @a hi.
1299*404b540aSrobert       */
1300*404b540aSrobert       virtual const char_type*
1301*404b540aSrobert       do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
1302*404b540aSrobert 
1303*404b540aSrobert       /**
1304*404b540aSrobert        *  @brief  Find wchar_t matching mask
1305*404b540aSrobert        *
1306*404b540aSrobert        *  This function searches for and returns the first wchar_t c in
1307*404b540aSrobert        *  [lo,hi) for which is(m,c) is true.
1308*404b540aSrobert        *
1309*404b540aSrobert        *  do_scan_is() is a hook for a derived facet to change the behavior of
1310*404b540aSrobert        *  match searching.  do_is() must always return the same result for the
1311*404b540aSrobert        *  same input.
1312*404b540aSrobert        *
1313*404b540aSrobert        *  @param m  The mask to compare against.
1314*404b540aSrobert        *  @param lo  Pointer to start of range.
1315*404b540aSrobert        *  @param hi  Pointer to end of range.
1316*404b540aSrobert        *  @return  Pointer to a matching wchar_t if found, else @a hi.
1317*404b540aSrobert       */
1318*404b540aSrobert       virtual const char_type*
1319*404b540aSrobert       do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
1320*404b540aSrobert 
1321*404b540aSrobert       /**
1322*404b540aSrobert        *  @brief  Find wchar_t not matching mask
1323*404b540aSrobert        *
1324*404b540aSrobert        *  This function searches for and returns a pointer to the first
1325*404b540aSrobert        *  wchar_t c of [lo,hi) for which is(m,c) is false.
1326*404b540aSrobert        *
1327*404b540aSrobert        *  do_scan_is() is a hook for a derived facet to change the behavior of
1328*404b540aSrobert        *  match searching.  do_is() must always return the same result for the
1329*404b540aSrobert        *  same input.
1330*404b540aSrobert        *
1331*404b540aSrobert        *  @param m  The mask to compare against.
1332*404b540aSrobert        *  @param lo  Pointer to start of range.
1333*404b540aSrobert        *  @param hi  Pointer to end of range.
1334*404b540aSrobert        *  @return  Pointer to a non-matching wchar_t if found, else @a hi.
1335*404b540aSrobert       */
1336*404b540aSrobert       virtual const char_type*
1337*404b540aSrobert       do_scan_not(mask __m, const char_type* __lo,
1338*404b540aSrobert 		  const char_type* __hi) const;
1339*404b540aSrobert 
1340*404b540aSrobert       /**
1341*404b540aSrobert        *  @brief  Convert to uppercase.
1342*404b540aSrobert        *
1343*404b540aSrobert        *  This virtual function converts the wchar_t argument to uppercase if
1344*404b540aSrobert        *  possible.  If not possible (for example, '2'), returns the argument.
1345*404b540aSrobert        *
1346*404b540aSrobert        *  do_toupper() is a hook for a derived facet to change the behavior of
1347*404b540aSrobert        *  uppercasing.  do_toupper() must always return the same result for
1348*404b540aSrobert        *  the same input.
1349*404b540aSrobert        *
1350*404b540aSrobert        *  @param c  The wchar_t to convert.
1351*404b540aSrobert        *  @return  The uppercase wchar_t if convertible, else @a c.
1352*404b540aSrobert       */
1353*404b540aSrobert       virtual char_type
1354*404b540aSrobert       do_toupper(char_type) const;
1355*404b540aSrobert 
1356*404b540aSrobert       /**
1357*404b540aSrobert        *  @brief  Convert array to uppercase.
1358*404b540aSrobert        *
1359*404b540aSrobert        *  This virtual function converts each wchar_t in the range [lo,hi) to
1360*404b540aSrobert        *  uppercase if possible.  Other elements remain untouched.
1361*404b540aSrobert        *
1362*404b540aSrobert        *  do_toupper() is a hook for a derived facet to change the behavior of
1363*404b540aSrobert        *  uppercasing.  do_toupper() must always return the same result for
1364*404b540aSrobert        *  the same input.
1365*404b540aSrobert        *
1366*404b540aSrobert        *  @param lo  Pointer to start of range.
1367*404b540aSrobert        *  @param hi  Pointer to end of range.
1368*404b540aSrobert        *  @return  @a hi.
1369*404b540aSrobert       */
1370*404b540aSrobert       virtual const char_type*
1371*404b540aSrobert       do_toupper(char_type* __lo, const char_type* __hi) const;
1372*404b540aSrobert 
1373*404b540aSrobert       /**
1374*404b540aSrobert        *  @brief  Convert to lowercase.
1375*404b540aSrobert        *
1376*404b540aSrobert        *  This virtual function converts the argument to lowercase if
1377*404b540aSrobert        *  possible.  If not possible (for example, '2'), returns the argument.
1378*404b540aSrobert        *
1379*404b540aSrobert        *  do_tolower() is a hook for a derived facet to change the behavior of
1380*404b540aSrobert        *  lowercasing.  do_tolower() must always return the same result for
1381*404b540aSrobert        *  the same input.
1382*404b540aSrobert        *
1383*404b540aSrobert        *  @param c  The wchar_t to convert.
1384*404b540aSrobert        *  @return  The lowercase wchar_t if convertible, else @a c.
1385*404b540aSrobert       */
1386*404b540aSrobert       virtual char_type
1387*404b540aSrobert       do_tolower(char_type) const;
1388*404b540aSrobert 
1389*404b540aSrobert       /**
1390*404b540aSrobert        *  @brief  Convert array to lowercase.
1391*404b540aSrobert        *
1392*404b540aSrobert        *  This virtual function converts each wchar_t in the range [lo,hi) to
1393*404b540aSrobert        *  lowercase if possible.  Other elements remain untouched.
1394*404b540aSrobert        *
1395*404b540aSrobert        *  do_tolower() is a hook for a derived facet to change the behavior of
1396*404b540aSrobert        *  lowercasing.  do_tolower() must always return the same result for
1397*404b540aSrobert        *  the same input.
1398*404b540aSrobert        *
1399*404b540aSrobert        *  @param lo  Pointer to start of range.
1400*404b540aSrobert        *  @param hi  Pointer to end of range.
1401*404b540aSrobert        *  @return  @a hi.
1402*404b540aSrobert       */
1403*404b540aSrobert       virtual const char_type*
1404*404b540aSrobert       do_tolower(char_type* __lo, const char_type* __hi) const;
1405*404b540aSrobert 
1406*404b540aSrobert       /**
1407*404b540aSrobert        *  @brief  Widen char to wchar_t
1408*404b540aSrobert        *
1409*404b540aSrobert        *  This virtual function converts the char to wchar_t using the
1410*404b540aSrobert        *  simplest reasonable transformation.  For an underived ctype<wchar_t>
1411*404b540aSrobert        *  facet, the argument will be cast to wchar_t.
1412*404b540aSrobert        *
1413*404b540aSrobert        *  do_widen() is a hook for a derived facet to change the behavior of
1414*404b540aSrobert        *  widening.  do_widen() must always return the same result for the
1415*404b540aSrobert        *  same input.
1416*404b540aSrobert        *
1417*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
1418*404b540aSrobert        *  codecvt for that.
1419*404b540aSrobert        *
1420*404b540aSrobert        *  @param c  The char to convert.
1421*404b540aSrobert        *  @return  The converted wchar_t.
1422*404b540aSrobert       */
1423*404b540aSrobert       virtual char_type
1424*404b540aSrobert       do_widen(char) const;
1425*404b540aSrobert 
1426*404b540aSrobert       /**
1427*404b540aSrobert        *  @brief  Widen char array to wchar_t array
1428*404b540aSrobert        *
1429*404b540aSrobert        *  This function converts each char in the input to wchar_t using the
1430*404b540aSrobert        *  simplest reasonable transformation.  For an underived ctype<wchar_t>
1431*404b540aSrobert        *  facet, the argument will be copied, casting each element to wchar_t.
1432*404b540aSrobert        *
1433*404b540aSrobert        *  do_widen() is a hook for a derived facet to change the behavior of
1434*404b540aSrobert        *  widening.  do_widen() must always return the same result for the
1435*404b540aSrobert        *  same input.
1436*404b540aSrobert        *
1437*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
1438*404b540aSrobert        *  codecvt for that.
1439*404b540aSrobert        *
1440*404b540aSrobert        *  @param lo  Pointer to start range.
1441*404b540aSrobert        *  @param hi  Pointer to end of range.
1442*404b540aSrobert        *  @param to  Pointer to the destination array.
1443*404b540aSrobert        *  @return  @a hi.
1444*404b540aSrobert       */
1445*404b540aSrobert       virtual const char*
1446*404b540aSrobert       do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
1447*404b540aSrobert 
1448*404b540aSrobert       /**
1449*404b540aSrobert        *  @brief  Narrow wchar_t to char
1450*404b540aSrobert        *
1451*404b540aSrobert        *  This virtual function converts the argument to char using
1452*404b540aSrobert        *  the simplest reasonable transformation.  If the conversion
1453*404b540aSrobert        *  fails, dfault is returned instead.  For an underived
1454*404b540aSrobert        *  ctype<wchar_t> facet, @a c will be cast to char and
1455*404b540aSrobert        *  returned.
1456*404b540aSrobert        *
1457*404b540aSrobert        *  do_narrow() is a hook for a derived facet to change the
1458*404b540aSrobert        *  behavior of narrowing.  do_narrow() must always return the
1459*404b540aSrobert        *  same result for the same input.
1460*404b540aSrobert        *
1461*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
1462*404b540aSrobert        *  codecvt for that.
1463*404b540aSrobert        *
1464*404b540aSrobert        *  @param c  The wchar_t to convert.
1465*404b540aSrobert        *  @param dfault  Char to return if conversion fails.
1466*404b540aSrobert        *  @return  The converted char.
1467*404b540aSrobert       */
1468*404b540aSrobert       virtual char
1469*404b540aSrobert       do_narrow(char_type, char __dfault) const;
1470*404b540aSrobert 
1471*404b540aSrobert       /**
1472*404b540aSrobert        *  @brief  Narrow wchar_t array to char array
1473*404b540aSrobert        *
1474*404b540aSrobert        *  This virtual function converts each wchar_t in the range [lo,hi) to
1475*404b540aSrobert        *  char using the simplest reasonable transformation and writes the
1476*404b540aSrobert        *  results to the destination array.  For any wchar_t in the input that
1477*404b540aSrobert        *  cannot be converted, @a dfault is used instead.  For an underived
1478*404b540aSrobert        *  ctype<wchar_t> facet, the argument will be copied, casting each
1479*404b540aSrobert        *  element to char.
1480*404b540aSrobert        *
1481*404b540aSrobert        *  do_narrow() is a hook for a derived facet to change the behavior of
1482*404b540aSrobert        *  narrowing.  do_narrow() must always return the same result for the
1483*404b540aSrobert        *  same input.
1484*404b540aSrobert        *
1485*404b540aSrobert        *  Note: this is not what you want for codepage conversions.  See
1486*404b540aSrobert        *  codecvt for that.
1487*404b540aSrobert        *
1488*404b540aSrobert        *  @param lo  Pointer to start of range.
1489*404b540aSrobert        *  @param hi  Pointer to end of range.
1490*404b540aSrobert        *  @param dfault  Char to use if conversion fails.
1491*404b540aSrobert        *  @param to  Pointer to the destination array.
1492*404b540aSrobert        *  @return  @a hi.
1493*404b540aSrobert       */
1494*404b540aSrobert       virtual const char_type*
1495*404b540aSrobert       do_narrow(const char_type* __lo, const char_type* __hi,
1496*404b540aSrobert 		char __dfault, char* __dest) const;
1497*404b540aSrobert 
1498*404b540aSrobert       // For use at construction time only.
1499*404b540aSrobert       void
1500*404b540aSrobert       _M_initialize_ctype();
1501*404b540aSrobert     };
1502*404b540aSrobert 
1503*404b540aSrobert   template<>
1504*404b540aSrobert     const ctype<wchar_t>&
1505*404b540aSrobert     use_facet<ctype<wchar_t> >(const locale& __loc);
1506*404b540aSrobert #endif //_GLIBCXX_USE_WCHAR_T
1507*404b540aSrobert 
1508*404b540aSrobert   /// @brief  class ctype_byname [22.2.1.2].
1509*404b540aSrobert   template<typename _CharT>
1510*404b540aSrobert     class ctype_byname : public ctype<_CharT>
1511*404b540aSrobert     {
1512*404b540aSrobert     public:
1513*404b540aSrobert       typedef _CharT		char_type;
1514*404b540aSrobert 
1515*404b540aSrobert       explicit
1516*404b540aSrobert       ctype_byname(const char* __s, size_t __refs = 0);
1517*404b540aSrobert 
1518*404b540aSrobert     protected:
1519*404b540aSrobert       virtual
~ctype_byname()1520*404b540aSrobert       ~ctype_byname() { };
1521*404b540aSrobert     };
1522*404b540aSrobert 
1523*404b540aSrobert   /// 22.2.1.4  Class ctype_byname specializations.
1524*404b540aSrobert   template<>
1525*404b540aSrobert     ctype_byname<char>::ctype_byname(const char*, size_t refs);
1526*404b540aSrobert 
1527*404b540aSrobert   template<>
1528*404b540aSrobert     ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs);
1529*404b540aSrobert 
1530*404b540aSrobert _GLIBCXX_END_NAMESPACE
1531*404b540aSrobert 
1532*404b540aSrobert // Include host and configuration specific ctype inlines.
1533*404b540aSrobert #include <bits/ctype_inline.h>
1534*404b540aSrobert 
1535*404b540aSrobert // 22.2.1.5  Template class codecvt
1536*404b540aSrobert #include <bits/codecvt.h>
1537*404b540aSrobert 
_GLIBCXX_BEGIN_NAMESPACE(std)1538*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
1539*404b540aSrobert 
1540*404b540aSrobert   // 22.2.2  The numeric category.
1541*404b540aSrobert   class __num_base
1542*404b540aSrobert   {
1543*404b540aSrobert   public:
1544*404b540aSrobert     // NB: Code depends on the order of _S_atoms_out elements.
1545*404b540aSrobert     // Below are the indices into _S_atoms_out.
1546*404b540aSrobert     enum
1547*404b540aSrobert       {
1548*404b540aSrobert         _S_ominus,
1549*404b540aSrobert         _S_oplus,
1550*404b540aSrobert         _S_ox,
1551*404b540aSrobert         _S_oX,
1552*404b540aSrobert         _S_odigits,
1553*404b540aSrobert         _S_odigits_end = _S_odigits + 16,
1554*404b540aSrobert         _S_oudigits = _S_odigits_end,
1555*404b540aSrobert         _S_oudigits_end = _S_oudigits + 16,
1556*404b540aSrobert         _S_oe = _S_odigits + 14,  // For scientific notation, 'e'
1557*404b540aSrobert         _S_oE = _S_oudigits + 14, // For scientific notation, 'E'
1558*404b540aSrobert 	_S_oend = _S_oudigits_end
1559*404b540aSrobert       };
1560*404b540aSrobert 
1561*404b540aSrobert     // A list of valid numeric literals for output.  This array
1562*404b540aSrobert     // contains chars that will be passed through the current locale's
1563*404b540aSrobert     // ctype<_CharT>.widen() and then used to render numbers.
1564*404b540aSrobert     // For the standard "C" locale, this is
1565*404b540aSrobert     // "-+xX0123456789abcdef0123456789ABCDEF".
1566*404b540aSrobert     static const char* _S_atoms_out;
1567*404b540aSrobert 
1568*404b540aSrobert     // String literal of acceptable (narrow) input, for num_get.
1569*404b540aSrobert     // "-+xX0123456789abcdefABCDEF"
1570*404b540aSrobert     static const char* _S_atoms_in;
1571*404b540aSrobert 
1572*404b540aSrobert     enum
1573*404b540aSrobert     {
1574*404b540aSrobert       _S_iminus,
1575*404b540aSrobert       _S_iplus,
1576*404b540aSrobert       _S_ix,
1577*404b540aSrobert       _S_iX,
1578*404b540aSrobert       _S_izero,
1579*404b540aSrobert       _S_ie = _S_izero + 14,
1580*404b540aSrobert       _S_iE = _S_izero + 20,
1581*404b540aSrobert       _S_iend = 26
1582*404b540aSrobert     };
1583*404b540aSrobert 
1584*404b540aSrobert     // num_put
1585*404b540aSrobert     // Construct and return valid scanf format for floating point types.
1586*404b540aSrobert     static void
1587*404b540aSrobert     _S_format_float(const ios_base& __io, char* __fptr, char __mod);
1588*404b540aSrobert   };
1589*404b540aSrobert 
1590*404b540aSrobert   template<typename _CharT>
1591*404b540aSrobert     struct __numpunct_cache : public locale::facet
1592*404b540aSrobert     {
1593*404b540aSrobert       const char*			_M_grouping;
1594*404b540aSrobert       size_t                            _M_grouping_size;
1595*404b540aSrobert       bool				_M_use_grouping;
1596*404b540aSrobert       const _CharT*			_M_truename;
1597*404b540aSrobert       size_t                            _M_truename_size;
1598*404b540aSrobert       const _CharT*			_M_falsename;
1599*404b540aSrobert       size_t                            _M_falsename_size;
1600*404b540aSrobert       _CharT				_M_decimal_point;
1601*404b540aSrobert       _CharT				_M_thousands_sep;
1602*404b540aSrobert 
1603*404b540aSrobert       // A list of valid numeric literals for output: in the standard
1604*404b540aSrobert       // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1605*404b540aSrobert       // This array contains the chars after having been passed
1606*404b540aSrobert       // through the current locale's ctype<_CharT>.widen().
1607*404b540aSrobert       _CharT				_M_atoms_out[__num_base::_S_oend];
1608*404b540aSrobert 
1609*404b540aSrobert       // A list of valid numeric literals for input: in the standard
1610*404b540aSrobert       // "C" locale, this is "-+xX0123456789abcdefABCDEF"
1611*404b540aSrobert       // This array contains the chars after having been passed
1612*404b540aSrobert       // through the current locale's ctype<_CharT>.widen().
1613*404b540aSrobert       _CharT				_M_atoms_in[__num_base::_S_iend];
1614*404b540aSrobert 
1615*404b540aSrobert       bool				_M_allocated;
1616*404b540aSrobert 
facet__numpunct_cache1617*404b540aSrobert       __numpunct_cache(size_t __refs = 0) : facet(__refs),
1618*404b540aSrobert       _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
1619*404b540aSrobert       _M_truename(NULL), _M_truename_size(0), _M_falsename(NULL),
1620*404b540aSrobert       _M_falsename_size(0), _M_decimal_point(_CharT()),
1621*404b540aSrobert       _M_thousands_sep(_CharT()), _M_allocated(false)
1622*404b540aSrobert       { }
1623*404b540aSrobert 
1624*404b540aSrobert       ~__numpunct_cache();
1625*404b540aSrobert 
1626*404b540aSrobert       void
1627*404b540aSrobert       _M_cache(const locale& __loc);
1628*404b540aSrobert 
1629*404b540aSrobert     private:
1630*404b540aSrobert       __numpunct_cache&
1631*404b540aSrobert       operator=(const __numpunct_cache&);
1632*404b540aSrobert 
1633*404b540aSrobert       explicit
1634*404b540aSrobert       __numpunct_cache(const __numpunct_cache&);
1635*404b540aSrobert     };
1636*404b540aSrobert 
1637*404b540aSrobert   template<typename _CharT>
~__numpunct_cache()1638*404b540aSrobert     __numpunct_cache<_CharT>::~__numpunct_cache()
1639*404b540aSrobert     {
1640*404b540aSrobert       if (_M_allocated)
1641*404b540aSrobert 	{
1642*404b540aSrobert 	  delete [] _M_grouping;
1643*404b540aSrobert 	  delete [] _M_truename;
1644*404b540aSrobert 	  delete [] _M_falsename;
1645*404b540aSrobert 	}
1646*404b540aSrobert     }
1647*404b540aSrobert 
1648*404b540aSrobert   /**
1649*404b540aSrobert    *  @brief  Numpunct facet.
1650*404b540aSrobert    *
1651*404b540aSrobert    *  This facet stores several pieces of information related to printing and
1652*404b540aSrobert    *  scanning numbers, such as the decimal point character.  It takes a
1653*404b540aSrobert    *  template parameter specifying the char type.  The numpunct facet is
1654*404b540aSrobert    *  used by streams for many I/O operations involving numbers.
1655*404b540aSrobert    *
1656*404b540aSrobert    *  The numpunct template uses protected virtual functions to provide the
1657*404b540aSrobert    *  actual results.  The public accessors forward the call to the virtual
1658*404b540aSrobert    *  functions.  These virtual functions are hooks for developers to
1659*404b540aSrobert    *  implement the behavior they require from a numpunct facet.
1660*404b540aSrobert   */
1661*404b540aSrobert   template<typename _CharT>
1662*404b540aSrobert     class numpunct : public locale::facet
1663*404b540aSrobert     {
1664*404b540aSrobert     public:
1665*404b540aSrobert       // Types:
1666*404b540aSrobert       //@{
1667*404b540aSrobert       /// Public typedefs
1668*404b540aSrobert       typedef _CharT			char_type;
1669*404b540aSrobert       typedef basic_string<_CharT>	string_type;
1670*404b540aSrobert       //@}
1671*404b540aSrobert       typedef __numpunct_cache<_CharT>  __cache_type;
1672*404b540aSrobert 
1673*404b540aSrobert     protected:
1674*404b540aSrobert       __cache_type*			_M_data;
1675*404b540aSrobert 
1676*404b540aSrobert     public:
1677*404b540aSrobert       /// Numpunct facet id.
1678*404b540aSrobert       static locale::id			id;
1679*404b540aSrobert 
1680*404b540aSrobert       /**
1681*404b540aSrobert        *  @brief  Numpunct constructor.
1682*404b540aSrobert        *
1683*404b540aSrobert        *  @param  refs  Refcount to pass to the base class.
1684*404b540aSrobert        */
1685*404b540aSrobert       explicit
facet(__refs)1686*404b540aSrobert       numpunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
1687*404b540aSrobert       { _M_initialize_numpunct(); }
1688*404b540aSrobert 
1689*404b540aSrobert       /**
1690*404b540aSrobert        *  @brief  Internal constructor.  Not for general use.
1691*404b540aSrobert        *
1692*404b540aSrobert        *  This is a constructor for use by the library itself to set up the
1693*404b540aSrobert        *  predefined locale facets.
1694*404b540aSrobert        *
1695*404b540aSrobert        *  @param  cache  __numpunct_cache object.
1696*404b540aSrobert        *  @param  refs  Refcount to pass to the base class.
1697*404b540aSrobert        */
1698*404b540aSrobert       explicit
1699*404b540aSrobert       numpunct(__cache_type* __cache, size_t __refs = 0)
facet(__refs)1700*404b540aSrobert       : facet(__refs), _M_data(__cache)
1701*404b540aSrobert       { _M_initialize_numpunct(); }
1702*404b540aSrobert 
1703*404b540aSrobert       /**
1704*404b540aSrobert        *  @brief  Internal constructor.  Not for general use.
1705*404b540aSrobert        *
1706*404b540aSrobert        *  This is a constructor for use by the library itself to set up new
1707*404b540aSrobert        *  locales.
1708*404b540aSrobert        *
1709*404b540aSrobert        *  @param  cloc  The "C" locale.
1710*404b540aSrobert        *  @param  refs  Refcount to pass to the base class.
1711*404b540aSrobert        */
1712*404b540aSrobert       explicit
1713*404b540aSrobert       numpunct(__c_locale __cloc, size_t __refs = 0)
facet(__refs)1714*404b540aSrobert       : facet(__refs), _M_data(NULL)
1715*404b540aSrobert       { _M_initialize_numpunct(__cloc); }
1716*404b540aSrobert 
1717*404b540aSrobert       /**
1718*404b540aSrobert        *  @brief  Return decimal point character.
1719*404b540aSrobert        *
1720*404b540aSrobert        *  This function returns a char_type to use as a decimal point.  It
1721*404b540aSrobert        *  does so by returning returning
1722*404b540aSrobert        *  numpunct<char_type>::do_decimal_point().
1723*404b540aSrobert        *
1724*404b540aSrobert        *  @return  @a char_type representing a decimal point.
1725*404b540aSrobert       */
1726*404b540aSrobert       char_type
decimal_point()1727*404b540aSrobert       decimal_point() const
1728*404b540aSrobert       { return this->do_decimal_point(); }
1729*404b540aSrobert 
1730*404b540aSrobert       /**
1731*404b540aSrobert        *  @brief  Return thousands separator character.
1732*404b540aSrobert        *
1733*404b540aSrobert        *  This function returns a char_type to use as a thousands
1734*404b540aSrobert        *  separator.  It does so by returning returning
1735*404b540aSrobert        *  numpunct<char_type>::do_thousands_sep().
1736*404b540aSrobert        *
1737*404b540aSrobert        *  @return  char_type representing a thousands separator.
1738*404b540aSrobert       */
1739*404b540aSrobert       char_type
thousands_sep()1740*404b540aSrobert       thousands_sep() const
1741*404b540aSrobert       { return this->do_thousands_sep(); }
1742*404b540aSrobert 
1743*404b540aSrobert       /**
1744*404b540aSrobert        *  @brief  Return grouping specification.
1745*404b540aSrobert        *
1746*404b540aSrobert        *  This function returns a string representing groupings for the
1747*404b540aSrobert        *  integer part of a number.  Groupings indicate where thousands
1748*404b540aSrobert        *  separators should be inserted in the integer part of a number.
1749*404b540aSrobert        *
1750*404b540aSrobert        *  Each char in the return string is interpret as an integer
1751*404b540aSrobert        *  rather than a character.  These numbers represent the number
1752*404b540aSrobert        *  of digits in a group.  The first char in the string
1753*404b540aSrobert        *  represents the number of digits in the least significant
1754*404b540aSrobert        *  group.  If a char is negative, it indicates an unlimited
1755*404b540aSrobert        *  number of digits for the group.  If more chars from the
1756*404b540aSrobert        *  string are required to group a number, the last char is used
1757*404b540aSrobert        *  repeatedly.
1758*404b540aSrobert        *
1759*404b540aSrobert        *  For example, if the grouping() returns "\003\002" and is
1760*404b540aSrobert        *  applied to the number 123456789, this corresponds to
1761*404b540aSrobert        *  12,34,56,789.  Note that if the string was "32", this would
1762*404b540aSrobert        *  put more than 50 digits into the least significant group if
1763*404b540aSrobert        *  the character set is ASCII.
1764*404b540aSrobert        *
1765*404b540aSrobert        *  The string is returned by calling
1766*404b540aSrobert        *  numpunct<char_type>::do_grouping().
1767*404b540aSrobert        *
1768*404b540aSrobert        *  @return  string representing grouping specification.
1769*404b540aSrobert       */
1770*404b540aSrobert       string
grouping()1771*404b540aSrobert       grouping() const
1772*404b540aSrobert       { return this->do_grouping(); }
1773*404b540aSrobert 
1774*404b540aSrobert       /**
1775*404b540aSrobert        *  @brief  Return string representation of bool true.
1776*404b540aSrobert        *
1777*404b540aSrobert        *  This function returns a string_type containing the text
1778*404b540aSrobert        *  representation for true bool variables.  It does so by calling
1779*404b540aSrobert        *  numpunct<char_type>::do_truename().
1780*404b540aSrobert        *
1781*404b540aSrobert        *  @return  string_type representing printed form of true.
1782*404b540aSrobert       */
1783*404b540aSrobert       string_type
truename()1784*404b540aSrobert       truename() const
1785*404b540aSrobert       { return this->do_truename(); }
1786*404b540aSrobert 
1787*404b540aSrobert       /**
1788*404b540aSrobert        *  @brief  Return string representation of bool false.
1789*404b540aSrobert        *
1790*404b540aSrobert        *  This function returns a string_type containing the text
1791*404b540aSrobert        *  representation for false bool variables.  It does so by calling
1792*404b540aSrobert        *  numpunct<char_type>::do_falsename().
1793*404b540aSrobert        *
1794*404b540aSrobert        *  @return  string_type representing printed form of false.
1795*404b540aSrobert       */
1796*404b540aSrobert       string_type
falsename()1797*404b540aSrobert       falsename() const
1798*404b540aSrobert       { return this->do_falsename(); }
1799*404b540aSrobert 
1800*404b540aSrobert     protected:
1801*404b540aSrobert       /// Destructor.
1802*404b540aSrobert       virtual
1803*404b540aSrobert       ~numpunct();
1804*404b540aSrobert 
1805*404b540aSrobert       /**
1806*404b540aSrobert        *  @brief  Return decimal point character.
1807*404b540aSrobert        *
1808*404b540aSrobert        *  Returns a char_type to use as a decimal point.  This function is a
1809*404b540aSrobert        *  hook for derived classes to change the value returned.
1810*404b540aSrobert        *
1811*404b540aSrobert        *  @return  @a char_type representing a decimal point.
1812*404b540aSrobert       */
1813*404b540aSrobert       virtual char_type
do_decimal_point()1814*404b540aSrobert       do_decimal_point() const
1815*404b540aSrobert       { return _M_data->_M_decimal_point; }
1816*404b540aSrobert 
1817*404b540aSrobert       /**
1818*404b540aSrobert        *  @brief  Return thousands separator character.
1819*404b540aSrobert        *
1820*404b540aSrobert        *  Returns a char_type to use as a thousands separator.  This function
1821*404b540aSrobert        *  is a hook for derived classes to change the value returned.
1822*404b540aSrobert        *
1823*404b540aSrobert        *  @return  @a char_type representing a thousands separator.
1824*404b540aSrobert       */
1825*404b540aSrobert       virtual char_type
do_thousands_sep()1826*404b540aSrobert       do_thousands_sep() const
1827*404b540aSrobert       { return _M_data->_M_thousands_sep; }
1828*404b540aSrobert 
1829*404b540aSrobert       /**
1830*404b540aSrobert        *  @brief  Return grouping specification.
1831*404b540aSrobert        *
1832*404b540aSrobert        *  Returns a string representing groupings for the integer part of a
1833*404b540aSrobert        *  number.  This function is a hook for derived classes to change the
1834*404b540aSrobert        *  value returned.  @see grouping() for details.
1835*404b540aSrobert        *
1836*404b540aSrobert        *  @return  String representing grouping specification.
1837*404b540aSrobert       */
1838*404b540aSrobert       virtual string
do_grouping()1839*404b540aSrobert       do_grouping() const
1840*404b540aSrobert       { return _M_data->_M_grouping; }
1841*404b540aSrobert 
1842*404b540aSrobert       /**
1843*404b540aSrobert        *  @brief  Return string representation of bool true.
1844*404b540aSrobert        *
1845*404b540aSrobert        *  Returns a string_type containing the text representation for true
1846*404b540aSrobert        *  bool variables.  This function is a hook for derived classes to
1847*404b540aSrobert        *  change the value returned.
1848*404b540aSrobert        *
1849*404b540aSrobert        *  @return  string_type representing printed form of true.
1850*404b540aSrobert       */
1851*404b540aSrobert       virtual string_type
do_truename()1852*404b540aSrobert       do_truename() const
1853*404b540aSrobert       { return _M_data->_M_truename; }
1854*404b540aSrobert 
1855*404b540aSrobert       /**
1856*404b540aSrobert        *  @brief  Return string representation of bool false.
1857*404b540aSrobert        *
1858*404b540aSrobert        *  Returns a string_type containing the text representation for false
1859*404b540aSrobert        *  bool variables.  This function is a hook for derived classes to
1860*404b540aSrobert        *  change the value returned.
1861*404b540aSrobert        *
1862*404b540aSrobert        *  @return  string_type representing printed form of false.
1863*404b540aSrobert       */
1864*404b540aSrobert       virtual string_type
do_falsename()1865*404b540aSrobert       do_falsename() const
1866*404b540aSrobert       { return _M_data->_M_falsename; }
1867*404b540aSrobert 
1868*404b540aSrobert       // For use at construction time only.
1869*404b540aSrobert       void
1870*404b540aSrobert       _M_initialize_numpunct(__c_locale __cloc = NULL);
1871*404b540aSrobert     };
1872*404b540aSrobert 
1873*404b540aSrobert   template<typename _CharT>
1874*404b540aSrobert     locale::id numpunct<_CharT>::id;
1875*404b540aSrobert 
1876*404b540aSrobert   template<>
1877*404b540aSrobert     numpunct<char>::~numpunct();
1878*404b540aSrobert 
1879*404b540aSrobert   template<>
1880*404b540aSrobert     void
1881*404b540aSrobert     numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
1882*404b540aSrobert 
1883*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T
1884*404b540aSrobert   template<>
1885*404b540aSrobert     numpunct<wchar_t>::~numpunct();
1886*404b540aSrobert 
1887*404b540aSrobert   template<>
1888*404b540aSrobert     void
1889*404b540aSrobert     numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
1890*404b540aSrobert #endif
1891*404b540aSrobert 
1892*404b540aSrobert   /// @brief  class numpunct_byname [22.2.3.2].
1893*404b540aSrobert   template<typename _CharT>
1894*404b540aSrobert     class numpunct_byname : public numpunct<_CharT>
1895*404b540aSrobert     {
1896*404b540aSrobert     public:
1897*404b540aSrobert       typedef _CharT			char_type;
1898*404b540aSrobert       typedef basic_string<_CharT>	string_type;
1899*404b540aSrobert 
1900*404b540aSrobert       explicit
1901*404b540aSrobert       numpunct_byname(const char* __s, size_t __refs = 0)
1902*404b540aSrobert       : numpunct<_CharT>(__refs)
1903*404b540aSrobert       {
1904*404b540aSrobert 	if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
1905*404b540aSrobert 	  {
1906*404b540aSrobert 	    __c_locale __tmp;
1907*404b540aSrobert 	    this->_S_create_c_locale(__tmp, __s);
1908*404b540aSrobert 	    this->_M_initialize_numpunct(__tmp);
1909*404b540aSrobert 	    this->_S_destroy_c_locale(__tmp);
1910*404b540aSrobert 	  }
1911*404b540aSrobert       }
1912*404b540aSrobert 
1913*404b540aSrobert     protected:
1914*404b540aSrobert       virtual
~numpunct_byname()1915*404b540aSrobert       ~numpunct_byname() { }
1916*404b540aSrobert     };
1917*404b540aSrobert 
1918*404b540aSrobert _GLIBCXX_BEGIN_LDBL_NAMESPACE
1919*404b540aSrobert   /**
1920*404b540aSrobert    *  @brief  Facet for parsing number strings.
1921*404b540aSrobert    *
1922*404b540aSrobert    *  This facet encapsulates the code to parse and return a number
1923*404b540aSrobert    *  from a string.  It is used by the istream numeric extraction
1924*404b540aSrobert    *  operators.
1925*404b540aSrobert    *
1926*404b540aSrobert    *  The num_get template uses protected virtual functions to provide the
1927*404b540aSrobert    *  actual results.  The public accessors forward the call to the virtual
1928*404b540aSrobert    *  functions.  These virtual functions are hooks for developers to
1929*404b540aSrobert    *  implement the behavior they require from the num_get facet.
1930*404b540aSrobert   */
1931*404b540aSrobert   template<typename _CharT, typename _InIter>
1932*404b540aSrobert     class num_get : public locale::facet
1933*404b540aSrobert     {
1934*404b540aSrobert     public:
1935*404b540aSrobert       // Types:
1936*404b540aSrobert       //@{
1937*404b540aSrobert       /// Public typedefs
1938*404b540aSrobert       typedef _CharT			char_type;
1939*404b540aSrobert       typedef _InIter			iter_type;
1940*404b540aSrobert       //@}
1941*404b540aSrobert 
1942*404b540aSrobert       /// Numpunct facet id.
1943*404b540aSrobert       static locale::id			id;
1944*404b540aSrobert 
1945*404b540aSrobert       /**
1946*404b540aSrobert        *  @brief  Constructor performs initialization.
1947*404b540aSrobert        *
1948*404b540aSrobert        *  This is the constructor provided by the standard.
1949*404b540aSrobert        *
1950*404b540aSrobert        *  @param refs  Passed to the base facet class.
1951*404b540aSrobert       */
1952*404b540aSrobert       explicit
facet(__refs)1953*404b540aSrobert       num_get(size_t __refs = 0) : facet(__refs) { }
1954*404b540aSrobert 
1955*404b540aSrobert       /**
1956*404b540aSrobert        *  @brief  Numeric parsing.
1957*404b540aSrobert        *
1958*404b540aSrobert        *  Parses the input stream into the bool @a v.  It does so by calling
1959*404b540aSrobert        *  num_get::do_get().
1960*404b540aSrobert        *
1961*404b540aSrobert        *  If ios_base::boolalpha is set, attempts to read
1962*404b540aSrobert        *  ctype<CharT>::truename() or ctype<CharT>::falsename().  Sets
1963*404b540aSrobert        *  @a v to true or false if successful.  Sets err to
1964*404b540aSrobert        *  ios_base::failbit if reading the string fails.  Sets err to
1965*404b540aSrobert        *  ios_base::eofbit if the stream is emptied.
1966*404b540aSrobert        *
1967*404b540aSrobert        *  If ios_base::boolalpha is not set, proceeds as with reading a long,
1968*404b540aSrobert        *  except if the value is 1, sets @a v to true, if the value is 0, sets
1969*404b540aSrobert        *  @a v to false, and otherwise set err to ios_base::failbit.
1970*404b540aSrobert        *
1971*404b540aSrobert        *  @param  in  Start of input stream.
1972*404b540aSrobert        *  @param  end  End of input stream.
1973*404b540aSrobert        *  @param  io  Source of locale and flags.
1974*404b540aSrobert        *  @param  err  Error flags to set.
1975*404b540aSrobert        *  @param  v  Value to format and insert.
1976*404b540aSrobert        *  @return  Iterator after reading.
1977*404b540aSrobert       */
1978*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,bool & __v)1979*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
1980*404b540aSrobert 	  ios_base::iostate& __err, bool& __v) const
1981*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
1982*404b540aSrobert 
1983*404b540aSrobert       //@{
1984*404b540aSrobert       /**
1985*404b540aSrobert        *  @brief  Numeric parsing.
1986*404b540aSrobert        *
1987*404b540aSrobert        *  Parses the input stream into the integral variable @a v.  It does so
1988*404b540aSrobert        *  by calling num_get::do_get().
1989*404b540aSrobert        *
1990*404b540aSrobert        *  Parsing is affected by the flag settings in @a io.
1991*404b540aSrobert        *
1992*404b540aSrobert        *  The basic parse is affected by the value of io.flags() &
1993*404b540aSrobert        *  ios_base::basefield.  If equal to ios_base::oct, parses like the
1994*404b540aSrobert        *  scanf %o specifier.  Else if equal to ios_base::hex, parses like %X
1995*404b540aSrobert        *  specifier.  Else if basefield equal to 0, parses like the %i
1996*404b540aSrobert        *  specifier.  Otherwise, parses like %d for signed and %u for unsigned
1997*404b540aSrobert        *  types.  The matching type length modifier is also used.
1998*404b540aSrobert        *
1999*404b540aSrobert        *  Digit grouping is intrepreted according to numpunct::grouping() and
2000*404b540aSrobert        *  numpunct::thousands_sep().  If the pattern of digit groups isn't
2001*404b540aSrobert        *  consistent, sets err to ios_base::failbit.
2002*404b540aSrobert        *
2003*404b540aSrobert        *  If parsing the string yields a valid value for @a v, @a v is set.
2004*404b540aSrobert        *  Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2005*404b540aSrobert        *  Sets err to ios_base::eofbit if the stream is emptied.
2006*404b540aSrobert        *
2007*404b540aSrobert        *  @param  in  Start of input stream.
2008*404b540aSrobert        *  @param  end  End of input stream.
2009*404b540aSrobert        *  @param  io  Source of locale and flags.
2010*404b540aSrobert        *  @param  err  Error flags to set.
2011*404b540aSrobert        *  @param  v  Value to format and insert.
2012*404b540aSrobert        *  @return  Iterator after reading.
2013*404b540aSrobert       */
2014*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,long & __v)2015*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2016*404b540aSrobert 	  ios_base::iostate& __err, long& __v) const
2017*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2018*404b540aSrobert 
2019*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,unsigned short & __v)2020*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2021*404b540aSrobert 	  ios_base::iostate& __err, unsigned short& __v) const
2022*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2023*404b540aSrobert 
2024*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,unsigned int & __v)2025*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2026*404b540aSrobert 	  ios_base::iostate& __err, unsigned int& __v)   const
2027*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2028*404b540aSrobert 
2029*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,unsigned long & __v)2030*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2031*404b540aSrobert 	  ios_base::iostate& __err, unsigned long& __v)  const
2032*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2033*404b540aSrobert 
2034*404b540aSrobert #ifdef _GLIBCXX_USE_LONG_LONG
2035*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,long long & __v)2036*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2037*404b540aSrobert 	  ios_base::iostate& __err, long long& __v) const
2038*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2039*404b540aSrobert 
2040*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,unsigned long long & __v)2041*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2042*404b540aSrobert 	  ios_base::iostate& __err, unsigned long long& __v)  const
2043*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2044*404b540aSrobert #endif
2045*404b540aSrobert       //@}
2046*404b540aSrobert 
2047*404b540aSrobert       //@{
2048*404b540aSrobert       /**
2049*404b540aSrobert        *  @brief  Numeric parsing.
2050*404b540aSrobert        *
2051*404b540aSrobert        *  Parses the input stream into the integral variable @a v.  It does so
2052*404b540aSrobert        *  by calling num_get::do_get().
2053*404b540aSrobert        *
2054*404b540aSrobert        *  The input characters are parsed like the scanf %g specifier.  The
2055*404b540aSrobert        *  matching type length modifier is also used.
2056*404b540aSrobert        *
2057*404b540aSrobert        *  The decimal point character used is numpunct::decimal_point().
2058*404b540aSrobert        *  Digit grouping is intrepreted according to numpunct::grouping() and
2059*404b540aSrobert        *  numpunct::thousands_sep().  If the pattern of digit groups isn't
2060*404b540aSrobert        *  consistent, sets err to ios_base::failbit.
2061*404b540aSrobert        *
2062*404b540aSrobert        *  If parsing the string yields a valid value for @a v, @a v is set.
2063*404b540aSrobert        *  Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2064*404b540aSrobert        *  Sets err to ios_base::eofbit if the stream is emptied.
2065*404b540aSrobert        *
2066*404b540aSrobert        *  @param  in  Start of input stream.
2067*404b540aSrobert        *  @param  end  End of input stream.
2068*404b540aSrobert        *  @param  io  Source of locale and flags.
2069*404b540aSrobert        *  @param  err  Error flags to set.
2070*404b540aSrobert        *  @param  v  Value to format and insert.
2071*404b540aSrobert        *  @return  Iterator after reading.
2072*404b540aSrobert       */
2073*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,float & __v)2074*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2075*404b540aSrobert 	  ios_base::iostate& __err, float& __v) const
2076*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2077*404b540aSrobert 
2078*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,double & __v)2079*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2080*404b540aSrobert 	  ios_base::iostate& __err, double& __v) const
2081*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2082*404b540aSrobert 
2083*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,long double & __v)2084*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2085*404b540aSrobert 	  ios_base::iostate& __err, long double& __v) const
2086*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2087*404b540aSrobert       //@}
2088*404b540aSrobert 
2089*404b540aSrobert       /**
2090*404b540aSrobert        *  @brief  Numeric parsing.
2091*404b540aSrobert        *
2092*404b540aSrobert        *  Parses the input stream into the pointer variable @a v.  It does so
2093*404b540aSrobert        *  by calling num_get::do_get().
2094*404b540aSrobert        *
2095*404b540aSrobert        *  The input characters are parsed like the scanf %p specifier.
2096*404b540aSrobert        *
2097*404b540aSrobert        *  Digit grouping is intrepreted according to numpunct::grouping() and
2098*404b540aSrobert        *  numpunct::thousands_sep().  If the pattern of digit groups isn't
2099*404b540aSrobert        *  consistent, sets err to ios_base::failbit.
2100*404b540aSrobert        *
2101*404b540aSrobert        *  Note that the digit grouping effect for pointers is a bit ambiguous
2102*404b540aSrobert        *  in the standard and shouldn't be relied on.  See DR 344.
2103*404b540aSrobert        *
2104*404b540aSrobert        *  If parsing the string yields a valid value for @a v, @a v is set.
2105*404b540aSrobert        *  Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2106*404b540aSrobert        *  Sets err to ios_base::eofbit if the stream is emptied.
2107*404b540aSrobert        *
2108*404b540aSrobert        *  @param  in  Start of input stream.
2109*404b540aSrobert        *  @param  end  End of input stream.
2110*404b540aSrobert        *  @param  io  Source of locale and flags.
2111*404b540aSrobert        *  @param  err  Error flags to set.
2112*404b540aSrobert        *  @param  v  Value to format and insert.
2113*404b540aSrobert        *  @return  Iterator after reading.
2114*404b540aSrobert       */
2115*404b540aSrobert       iter_type
get(iter_type __in,iter_type __end,ios_base & __io,ios_base::iostate & __err,void * & __v)2116*404b540aSrobert       get(iter_type __in, iter_type __end, ios_base& __io,
2117*404b540aSrobert 	  ios_base::iostate& __err, void*& __v) const
2118*404b540aSrobert       { return this->do_get(__in, __end, __io, __err, __v); }
2119*404b540aSrobert 
2120*404b540aSrobert     protected:
2121*404b540aSrobert       /// Destructor.
~num_get()2122*404b540aSrobert       virtual ~num_get() { }
2123*404b540aSrobert 
2124*404b540aSrobert       iter_type
2125*404b540aSrobert       _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
2126*404b540aSrobert 		       string& __xtrc) const;
2127*404b540aSrobert 
2128*404b540aSrobert       template<typename _ValueT>
2129*404b540aSrobert         iter_type
2130*404b540aSrobert         _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
2131*404b540aSrobert 		       _ValueT& __v) const;
2132*404b540aSrobert 
2133*404b540aSrobert       template<typename _CharT2>
2134*404b540aSrobert       typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, int>::__type
_M_find(const _CharT2 *,size_t __len,_CharT2 __c)2135*404b540aSrobert         _M_find(const _CharT2*, size_t __len, _CharT2 __c) const
2136*404b540aSrobert         {
2137*404b540aSrobert 	  int __ret = -1;
2138*404b540aSrobert 	  if (__len <= 10)
2139*404b540aSrobert 	    {
2140*404b540aSrobert 	      if (__c >= _CharT2('0') && __c < _CharT2(_CharT2('0') + __len))
2141*404b540aSrobert 		__ret = __c - _CharT2('0');
2142*404b540aSrobert 	    }
2143*404b540aSrobert 	  else
2144*404b540aSrobert 	    {
2145*404b540aSrobert 	      if (__c >= _CharT2('0') && __c <= _CharT2('9'))
2146*404b540aSrobert 		__ret = __c - _CharT2('0');
2147*404b540aSrobert 	      else if (__c >= _CharT2('a') && __c <= _CharT2('f'))
2148*404b540aSrobert 		__ret = 10 + (__c - _CharT2('a'));
2149*404b540aSrobert 	      else if (__c >= _CharT2('A') && __c <= _CharT2('F'))
2150*404b540aSrobert 		__ret = 10 + (__c - _CharT2('A'));
2151*404b540aSrobert 	    }
2152*404b540aSrobert 	  return __ret;
2153*404b540aSrobert 	}
2154*404b540aSrobert 
2155*404b540aSrobert       template<typename _CharT2>
2156*404b540aSrobert       typename __gnu_cxx::__enable_if<!__is_char<_CharT2>::__value,
2157*404b540aSrobert 				      int>::__type
_M_find(const _CharT2 * __zero,size_t __len,_CharT2 __c)2158*404b540aSrobert         _M_find(const _CharT2* __zero, size_t __len, _CharT2 __c) const
2159*404b540aSrobert         {
2160*404b540aSrobert 	  int __ret = -1;
2161*404b540aSrobert 	  const char_type* __q = char_traits<_CharT2>::find(__zero, __len, __c);
2162*404b540aSrobert 	  if (__q)
2163*404b540aSrobert 	    {
2164*404b540aSrobert 	      __ret = __q - __zero;
2165*404b540aSrobert 	      if (__ret > 15)
2166*404b540aSrobert 		__ret -= 6;
2167*404b540aSrobert 	    }
2168*404b540aSrobert 	  return __ret;
2169*404b540aSrobert 	}
2170*404b540aSrobert 
2171*404b540aSrobert       //@{
2172*404b540aSrobert       /**
2173*404b540aSrobert        *  @brief  Numeric parsing.
2174*404b540aSrobert        *
2175*404b540aSrobert        *  Parses the input stream into the variable @a v.  This function is a
2176*404b540aSrobert        *  hook for derived classes to change the value returned.  @see get()
2177*404b540aSrobert        *  for more details.
2178*404b540aSrobert        *
2179*404b540aSrobert        *  @param  in  Start of input stream.
2180*404b540aSrobert        *  @param  end  End of input stream.
2181*404b540aSrobert        *  @param  io  Source of locale and flags.
2182*404b540aSrobert        *  @param  err  Error flags to set.
2183*404b540aSrobert        *  @param  v  Value to format and insert.
2184*404b540aSrobert        *  @return  Iterator after reading.
2185*404b540aSrobert       */
2186*404b540aSrobert       virtual iter_type
2187*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
2188*404b540aSrobert 
2189*404b540aSrobert 
2190*404b540aSrobert       virtual iter_type
2191*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
2192*404b540aSrobert 
2193*404b540aSrobert       virtual iter_type
2194*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2195*404b540aSrobert 	      unsigned short&) const;
2196*404b540aSrobert 
2197*404b540aSrobert       virtual iter_type
2198*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2199*404b540aSrobert 	     unsigned int&) const;
2200*404b540aSrobert 
2201*404b540aSrobert       virtual iter_type
2202*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2203*404b540aSrobert 	     unsigned long&) const;
2204*404b540aSrobert 
2205*404b540aSrobert #ifdef _GLIBCXX_USE_LONG_LONG
2206*404b540aSrobert       virtual iter_type
2207*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2208*404b540aSrobert 	     long long&) const;
2209*404b540aSrobert 
2210*404b540aSrobert       virtual iter_type
2211*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2212*404b540aSrobert 	     unsigned long long&) const;
2213*404b540aSrobert #endif
2214*404b540aSrobert 
2215*404b540aSrobert       virtual iter_type
2216*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2217*404b540aSrobert 	     float&) const;
2218*404b540aSrobert 
2219*404b540aSrobert       virtual iter_type
2220*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2221*404b540aSrobert 	     double&) const;
2222*404b540aSrobert 
2223*404b540aSrobert       // XXX GLIBCXX_ABI Deprecated
2224*404b540aSrobert #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2225*404b540aSrobert       virtual iter_type
2226*404b540aSrobert       __do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2227*404b540aSrobert 	       double&) const;
2228*404b540aSrobert #else
2229*404b540aSrobert       virtual iter_type
2230*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2231*404b540aSrobert 	     long double&) const;
2232*404b540aSrobert #endif
2233*404b540aSrobert 
2234*404b540aSrobert       virtual iter_type
2235*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2236*404b540aSrobert 	     void*&) const;
2237*404b540aSrobert 
2238*404b540aSrobert       // XXX GLIBCXX_ABI Deprecated
2239*404b540aSrobert #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2240*404b540aSrobert       virtual iter_type
2241*404b540aSrobert       do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2242*404b540aSrobert 	     long double&) const;
2243*404b540aSrobert #endif
2244*404b540aSrobert       //@}
2245*404b540aSrobert     };
2246*404b540aSrobert 
2247*404b540aSrobert   template<typename _CharT, typename _InIter>
2248*404b540aSrobert     locale::id num_get<_CharT, _InIter>::id;
2249*404b540aSrobert 
2250*404b540aSrobert 
2251*404b540aSrobert   /**
2252*404b540aSrobert    *  @brief  Facet for converting numbers to strings.
2253*404b540aSrobert    *
2254*404b540aSrobert    *  This facet encapsulates the code to convert a number to a string.  It is
2255*404b540aSrobert    *  used by the ostream numeric insertion operators.
2256*404b540aSrobert    *
2257*404b540aSrobert    *  The num_put template uses protected virtual functions to provide the
2258*404b540aSrobert    *  actual results.  The public accessors forward the call to the virtual
2259*404b540aSrobert    *  functions.  These virtual functions are hooks for developers to
2260*404b540aSrobert    *  implement the behavior they require from the num_put facet.
2261*404b540aSrobert   */
2262*404b540aSrobert   template<typename _CharT, typename _OutIter>
2263*404b540aSrobert     class num_put : public locale::facet
2264*404b540aSrobert     {
2265*404b540aSrobert     public:
2266*404b540aSrobert       // Types:
2267*404b540aSrobert       //@{
2268*404b540aSrobert       /// Public typedefs
2269*404b540aSrobert       typedef _CharT		char_type;
2270*404b540aSrobert       typedef _OutIter		iter_type;
2271*404b540aSrobert       //@}
2272*404b540aSrobert 
2273*404b540aSrobert       /// Numpunct facet id.
2274*404b540aSrobert       static locale::id		id;
2275*404b540aSrobert 
2276*404b540aSrobert       /**
2277*404b540aSrobert        *  @brief  Constructor performs initialization.
2278*404b540aSrobert        *
2279*404b540aSrobert        *  This is the constructor provided by the standard.
2280*404b540aSrobert        *
2281*404b540aSrobert        *  @param refs  Passed to the base facet class.
2282*404b540aSrobert       */
2283*404b540aSrobert       explicit
facet(__refs)2284*404b540aSrobert       num_put(size_t __refs = 0) : facet(__refs) { }
2285*404b540aSrobert 
2286*404b540aSrobert       /**
2287*404b540aSrobert        *  @brief  Numeric formatting.
2288*404b540aSrobert        *
2289*404b540aSrobert        *  Formats the boolean @a v and inserts it into a stream.  It does so
2290*404b540aSrobert        *  by calling num_put::do_put().
2291*404b540aSrobert        *
2292*404b540aSrobert        *  If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2293*404b540aSrobert        *  ctype<CharT>::falsename().  Otherwise formats @a v as an int.
2294*404b540aSrobert        *
2295*404b540aSrobert        *  @param  s  Stream to write to.
2296*404b540aSrobert        *  @param  io  Source of locale and flags.
2297*404b540aSrobert        *  @param  fill  Char_type to use for filling.
2298*404b540aSrobert        *  @param  v  Value to format and insert.
2299*404b540aSrobert        *  @return  Iterator after writing.
2300*404b540aSrobert       */
2301*404b540aSrobert       iter_type
put(iter_type __s,ios_base & __f,char_type __fill,bool __v)2302*404b540aSrobert       put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
2303*404b540aSrobert       { return this->do_put(__s, __f, __fill, __v); }
2304*404b540aSrobert 
2305*404b540aSrobert       //@{
2306*404b540aSrobert       /**
2307*404b540aSrobert        *  @brief  Numeric formatting.
2308*404b540aSrobert        *
2309*404b540aSrobert        *  Formats the integral value @a v and inserts it into a
2310*404b540aSrobert        *  stream.  It does so by calling num_put::do_put().
2311*404b540aSrobert        *
2312*404b540aSrobert        *  Formatting is affected by the flag settings in @a io.
2313*404b540aSrobert        *
2314*404b540aSrobert        *  The basic format is affected by the value of io.flags() &
2315*404b540aSrobert        *  ios_base::basefield.  If equal to ios_base::oct, formats like the
2316*404b540aSrobert        *  printf %o specifier.  Else if equal to ios_base::hex, formats like
2317*404b540aSrobert        *  %x or %X with ios_base::uppercase unset or set respectively.
2318*404b540aSrobert        *  Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2319*404b540aSrobert        *  for unsigned values.  Note that if both oct and hex are set, neither
2320*404b540aSrobert        *  will take effect.
2321*404b540aSrobert        *
2322*404b540aSrobert        *  If ios_base::showpos is set, '+' is output before positive values.
2323*404b540aSrobert        *  If ios_base::showbase is set, '0' precedes octal values (except 0)
2324*404b540aSrobert        *  and '0[xX]' precedes hex values.
2325*404b540aSrobert        *
2326*404b540aSrobert        *  Thousands separators are inserted according to numpunct::grouping()
2327*404b540aSrobert        *  and numpunct::thousands_sep().  The decimal point character used is
2328*404b540aSrobert        *  numpunct::decimal_point().
2329*404b540aSrobert        *
2330*404b540aSrobert        *  If io.width() is non-zero, enough @a fill characters are inserted to
2331*404b540aSrobert        *  make the result at least that wide.  If
2332*404b540aSrobert        *  (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2333*404b540aSrobert        *  padded at the end.  If ios_base::internal, then padding occurs
2334*404b540aSrobert        *  immediately after either a '+' or '-' or after '0x' or '0X'.
2335*404b540aSrobert        *  Otherwise, padding occurs at the beginning.
2336*404b540aSrobert        *
2337*404b540aSrobert        *  @param  s  Stream to write to.
2338*404b540aSrobert        *  @param  io  Source of locale and flags.
2339*404b540aSrobert        *  @param  fill  Char_type to use for filling.
2340*404b540aSrobert        *  @param  v  Value to format and insert.
2341*404b540aSrobert        *  @return  Iterator after writing.
2342*404b540aSrobert       */
2343*404b540aSrobert       iter_type
put(iter_type __s,ios_base & __f,char_type __fill,long __v)2344*404b540aSrobert       put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
2345*404b540aSrobert       { return this->do_put(__s, __f, __fill, __v); }
2346*404b540aSrobert 
2347*404b540aSrobert       iter_type
put(iter_type __s,ios_base & __f,char_type __fill,unsigned long __v)2348*404b540aSrobert       put(iter_type __s, ios_base& __f, char_type __fill,
2349*404b540aSrobert 	  unsigned long __v) const
2350*404b540aSrobert       { return this->do_put(__s, __f, __fill, __v); }
2351*404b540aSrobert 
2352*404b540aSrobert #ifdef _GLIBCXX_USE_LONG_LONG
2353*404b540aSrobert       iter_type
put(iter_type __s,ios_base & __f,char_type __fill,long long __v)2354*404b540aSrobert       put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
2355*404b540aSrobert       { return this->do_put(__s, __f, __fill, __v); }
2356*404b540aSrobert 
2357*404b540aSrobert       iter_type
put(iter_type __s,ios_base & __f,char_type __fill,unsigned long long __v)2358*404b540aSrobert       put(iter_type __s, ios_base& __f, char_type __fill,
2359*404b540aSrobert 	  unsigned long long __v) const
2360*404b540aSrobert       { return this->do_put(__s, __f, __fill, __v); }
2361*404b540aSrobert #endif
2362*404b540aSrobert       //@}
2363*404b540aSrobert 
2364*404b540aSrobert       //@{
2365*404b540aSrobert       /**
2366*404b540aSrobert        *  @brief  Numeric formatting.
2367*404b540aSrobert        *
2368*404b540aSrobert        *  Formats the floating point value @a v and inserts it into a stream.
2369*404b540aSrobert        *  It does so by calling num_put::do_put().
2370*404b540aSrobert        *
2371*404b540aSrobert        *  Formatting is affected by the flag settings in @a io.
2372*404b540aSrobert        *
2373*404b540aSrobert        *  The basic format is affected by the value of io.flags() &
2374*404b540aSrobert        *  ios_base::floatfield.  If equal to ios_base::fixed, formats like the
2375*404b540aSrobert        *  printf %f specifier.  Else if equal to ios_base::scientific, formats
2376*404b540aSrobert        *  like %e or %E with ios_base::uppercase unset or set respectively.
2377*404b540aSrobert        *  Otherwise, formats like %g or %G depending on uppercase.  Note that
2378*404b540aSrobert        *  if both fixed and scientific are set, the effect will also be like
2379*404b540aSrobert        *  %g or %G.
2380*404b540aSrobert        *
2381*404b540aSrobert        *  The output precision is given by io.precision().  This precision is
2382*404b540aSrobert        *  capped at numeric_limits::digits10 + 2 (different for double and
2383*404b540aSrobert        *  long double).  The default precision is 6.
2384*404b540aSrobert        *
2385*404b540aSrobert        *  If ios_base::showpos is set, '+' is output before positive values.
2386*404b540aSrobert        *  If ios_base::showpoint is set, a decimal point will always be
2387*404b540aSrobert        *  output.
2388*404b540aSrobert        *
2389*404b540aSrobert        *  Thousands separators are inserted according to numpunct::grouping()
2390*404b540aSrobert        *  and numpunct::thousands_sep().  The decimal point character used is
2391*404b540aSrobert        *  numpunct::decimal_point().
2392*404b540aSrobert        *
2393*404b540aSrobert        *  If io.width() is non-zero, enough @a fill characters are inserted to
2394*404b540aSrobert        *  make the result at least that wide.  If
2395*404b540aSrobert        *  (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2396*404b540aSrobert        *  padded at the end.  If ios_base::internal, then padding occurs
2397*404b540aSrobert        *  immediately after either a '+' or '-' or after '0x' or '0X'.
2398*404b540aSrobert        *  Otherwise, padding occurs at the beginning.
2399*404b540aSrobert        *
2400*404b540aSrobert        *  @param  s  Stream to write to.
2401*404b540aSrobert        *  @param  io  Source of locale and flags.
2402*404b540aSrobert        *  @param  fill  Char_type to use for filling.
2403*404b540aSrobert        *  @param  v  Value to format and insert.
2404*404b540aSrobert        *  @return  Iterator after writing.
2405*404b540aSrobert       */
2406*404b540aSrobert       iter_type
put(iter_type __s,ios_base & __f,char_type __fill,double __v)2407*404b540aSrobert       put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
2408*404b540aSrobert       { return this->do_put(__s, __f, __fill, __v); }
2409*404b540aSrobert 
2410*404b540aSrobert       iter_type
put(iter_type __s,ios_base & __f,char_type __fill,long double __v)2411*404b540aSrobert       put(iter_type __s, ios_base& __f, char_type __fill,
2412*404b540aSrobert 	  long double __v) const
2413*404b540aSrobert       { return this->do_put(__s, __f, __fill, __v); }
2414*404b540aSrobert       //@}
2415*404b540aSrobert 
2416*404b540aSrobert       /**
2417*404b540aSrobert        *  @brief  Numeric formatting.
2418*404b540aSrobert        *
2419*404b540aSrobert        *  Formats the pointer value @a v and inserts it into a stream.  It
2420*404b540aSrobert        *  does so by calling num_put::do_put().
2421*404b540aSrobert        *
2422*404b540aSrobert        *  This function formats @a v as an unsigned long with ios_base::hex
2423*404b540aSrobert        *  and ios_base::showbase set.
2424*404b540aSrobert        *
2425*404b540aSrobert        *  @param  s  Stream to write to.
2426*404b540aSrobert        *  @param  io  Source of locale and flags.
2427*404b540aSrobert        *  @param  fill  Char_type to use for filling.
2428*404b540aSrobert        *  @param  v  Value to format and insert.
2429*404b540aSrobert        *  @return  Iterator after writing.
2430*404b540aSrobert       */
2431*404b540aSrobert       iter_type
put(iter_type __s,ios_base & __f,char_type __fill,const void * __v)2432*404b540aSrobert       put(iter_type __s, ios_base& __f, char_type __fill,
2433*404b540aSrobert 	  const void* __v) const
2434*404b540aSrobert       { return this->do_put(__s, __f, __fill, __v); }
2435*404b540aSrobert 
2436*404b540aSrobert     protected:
2437*404b540aSrobert       template<typename _ValueT>
2438*404b540aSrobert         iter_type
2439*404b540aSrobert         _M_insert_float(iter_type, ios_base& __io, char_type __fill,
2440*404b540aSrobert 			char __mod, _ValueT __v) const;
2441*404b540aSrobert 
2442*404b540aSrobert       void
2443*404b540aSrobert       _M_group_float(const char* __grouping, size_t __grouping_size,
2444*404b540aSrobert 		     char_type __sep, const char_type* __p, char_type* __new,
2445*404b540aSrobert 		     char_type* __cs, int& __len) const;
2446*404b540aSrobert 
2447*404b540aSrobert       template<typename _ValueT>
2448*404b540aSrobert         iter_type
2449*404b540aSrobert         _M_insert_int(iter_type, ios_base& __io, char_type __fill,
2450*404b540aSrobert 		      _ValueT __v) const;
2451*404b540aSrobert 
2452*404b540aSrobert       void
2453*404b540aSrobert       _M_group_int(const char* __grouping, size_t __grouping_size,
2454*404b540aSrobert 		   char_type __sep, ios_base& __io, char_type* __new,
2455*404b540aSrobert 		   char_type* __cs, int& __len) const;
2456*404b540aSrobert 
2457*404b540aSrobert       void
2458*404b540aSrobert       _M_pad(char_type __fill, streamsize __w, ios_base& __io,
2459*404b540aSrobert 	     char_type* __new, const char_type* __cs, int& __len) const;
2460*404b540aSrobert 
2461*404b540aSrobert       /// Destructor.
2462*404b540aSrobert       virtual
~num_put()2463*404b540aSrobert       ~num_put() { };
2464*404b540aSrobert 
2465*404b540aSrobert       //@{
2466*404b540aSrobert       /**
2467*404b540aSrobert        *  @brief  Numeric formatting.
2468*404b540aSrobert        *
2469*404b540aSrobert        *  These functions do the work of formatting numeric values and
2470*404b540aSrobert        *  inserting them into a stream. This function is a hook for derived
2471*404b540aSrobert        *  classes to change the value returned.
2472*404b540aSrobert        *
2473*404b540aSrobert        *  @param  s  Stream to write to.
2474*404b540aSrobert        *  @param  io  Source of locale and flags.
2475*404b540aSrobert        *  @param  fill  Char_type to use for filling.
2476*404b540aSrobert        *  @param  v  Value to format and insert.
2477*404b540aSrobert        *  @return  Iterator after writing.
2478*404b540aSrobert       */
2479*404b540aSrobert       virtual iter_type
2480*404b540aSrobert       do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
2481*404b540aSrobert 
2482*404b540aSrobert       virtual iter_type
2483*404b540aSrobert       do_put(iter_type, ios_base&, char_type __fill, long __v) const;
2484*404b540aSrobert 
2485*404b540aSrobert       virtual iter_type
2486*404b540aSrobert       do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
2487*404b540aSrobert 
2488*404b540aSrobert #ifdef _GLIBCXX_USE_LONG_LONG
2489*404b540aSrobert       virtual iter_type
2490*404b540aSrobert       do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
2491*404b540aSrobert 
2492*404b540aSrobert       virtual iter_type
2493*404b540aSrobert       do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
2494*404b540aSrobert #endif
2495*404b540aSrobert 
2496*404b540aSrobert       virtual iter_type
2497*404b540aSrobert       do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2498*404b540aSrobert 
2499*404b540aSrobert       // XXX GLIBCXX_ABI Deprecated
2500*404b540aSrobert #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2501*404b540aSrobert       virtual iter_type
2502*404b540aSrobert       __do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2503*404b540aSrobert #else
2504*404b540aSrobert       virtual iter_type
2505*404b540aSrobert       do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2506*404b540aSrobert #endif
2507*404b540aSrobert 
2508*404b540aSrobert       virtual iter_type
2509*404b540aSrobert       do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
2510*404b540aSrobert 
2511*404b540aSrobert       // XXX GLIBCXX_ABI Deprecated
2512*404b540aSrobert #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2513*404b540aSrobert       virtual iter_type
2514*404b540aSrobert       do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2515*404b540aSrobert #endif
2516*404b540aSrobert       //@}
2517*404b540aSrobert     };
2518*404b540aSrobert 
2519*404b540aSrobert   template <typename _CharT, typename _OutIter>
2520*404b540aSrobert     locale::id num_put<_CharT, _OutIter>::id;
2521*404b540aSrobert 
2522*404b540aSrobert _GLIBCXX_END_LDBL_NAMESPACE
2523*404b540aSrobert 
2524*404b540aSrobert   /**
2525*404b540aSrobert    *  @brief  Facet for localized string comparison.
2526*404b540aSrobert    *
2527*404b540aSrobert    *  This facet encapsulates the code to compare strings in a localized
2528*404b540aSrobert    *  manner.
2529*404b540aSrobert    *
2530*404b540aSrobert    *  The collate template uses protected virtual functions to provide
2531*404b540aSrobert    *  the actual results.  The public accessors forward the call to
2532*404b540aSrobert    *  the virtual functions.  These virtual functions are hooks for
2533*404b540aSrobert    *  developers to implement the behavior they require from the
2534*404b540aSrobert    *  collate facet.
2535*404b540aSrobert   */
2536*404b540aSrobert   template<typename _CharT>
2537*404b540aSrobert     class collate : public locale::facet
2538*404b540aSrobert     {
2539*404b540aSrobert     public:
2540*404b540aSrobert       // Types:
2541*404b540aSrobert       //@{
2542*404b540aSrobert       /// Public typedefs
2543*404b540aSrobert       typedef _CharT			char_type;
2544*404b540aSrobert       typedef basic_string<_CharT>	string_type;
2545*404b540aSrobert       //@}
2546*404b540aSrobert 
2547*404b540aSrobert     protected:
2548*404b540aSrobert       // Underlying "C" library locale information saved from
2549*404b540aSrobert       // initialization, needed by collate_byname as well.
2550*404b540aSrobert       __c_locale			_M_c_locale_collate;
2551*404b540aSrobert 
2552*404b540aSrobert     public:
2553*404b540aSrobert       /// Numpunct facet id.
2554*404b540aSrobert       static locale::id			id;
2555*404b540aSrobert 
2556*404b540aSrobert       /**
2557*404b540aSrobert        *  @brief  Constructor performs initialization.
2558*404b540aSrobert        *
2559*404b540aSrobert        *  This is the constructor provided by the standard.
2560*404b540aSrobert        *
2561*404b540aSrobert        *  @param refs  Passed to the base facet class.
2562*404b540aSrobert       */
2563*404b540aSrobert       explicit
2564*404b540aSrobert       collate(size_t __refs = 0)
facet(__refs)2565*404b540aSrobert       : facet(__refs), _M_c_locale_collate(_S_get_c_locale())
2566*404b540aSrobert       { }
2567*404b540aSrobert 
2568*404b540aSrobert       /**
2569*404b540aSrobert        *  @brief  Internal constructor. Not for general use.
2570*404b540aSrobert        *
2571*404b540aSrobert        *  This is a constructor for use by the library itself to set up new
2572*404b540aSrobert        *  locales.
2573*404b540aSrobert        *
2574*404b540aSrobert        *  @param cloc  The "C" locale.
2575*404b540aSrobert        *  @param refs  Passed to the base facet class.
2576*404b540aSrobert       */
2577*404b540aSrobert       explicit
2578*404b540aSrobert       collate(__c_locale __cloc, size_t __refs = 0)
facet(__refs)2579*404b540aSrobert       : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc))
2580*404b540aSrobert       { }
2581*404b540aSrobert 
2582*404b540aSrobert       /**
2583*404b540aSrobert        *  @brief  Compare two strings.
2584*404b540aSrobert        *
2585*404b540aSrobert        *  This function compares two strings and returns the result by calling
2586*404b540aSrobert        *  collate::do_compare().
2587*404b540aSrobert        *
2588*404b540aSrobert        *  @param lo1  Start of string 1.
2589*404b540aSrobert        *  @param hi1  End of string 1.
2590*404b540aSrobert        *  @param lo2  Start of string 2.
2591*404b540aSrobert        *  @param hi2  End of string 2.
2592*404b540aSrobert        *  @return  1 if string1 > string2, -1 if string1 < string2, else 0.
2593*404b540aSrobert       */
2594*404b540aSrobert       int
compare(const _CharT * __lo1,const _CharT * __hi1,const _CharT * __lo2,const _CharT * __hi2)2595*404b540aSrobert       compare(const _CharT* __lo1, const _CharT* __hi1,
2596*404b540aSrobert 	      const _CharT* __lo2, const _CharT* __hi2) const
2597*404b540aSrobert       { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
2598*404b540aSrobert 
2599*404b540aSrobert       /**
2600*404b540aSrobert        *  @brief  Transform string to comparable form.
2601*404b540aSrobert        *
2602*404b540aSrobert        *  This function is a wrapper for strxfrm functionality.  It takes the
2603*404b540aSrobert        *  input string and returns a modified string that can be directly
2604*404b540aSrobert        *  compared to other transformed strings.  In the "C" locale, this
2605*404b540aSrobert        *  function just returns a copy of the input string.  In some other
2606*404b540aSrobert        *  locales, it may replace two chars with one, change a char for
2607*404b540aSrobert        *  another, etc.  It does so by returning collate::do_transform().
2608*404b540aSrobert        *
2609*404b540aSrobert        *  @param lo  Start of string.
2610*404b540aSrobert        *  @param hi  End of string.
2611*404b540aSrobert        *  @return  Transformed string_type.
2612*404b540aSrobert       */
2613*404b540aSrobert       string_type
transform(const _CharT * __lo,const _CharT * __hi)2614*404b540aSrobert       transform(const _CharT* __lo, const _CharT* __hi) const
2615*404b540aSrobert       { return this->do_transform(__lo, __hi); }
2616*404b540aSrobert 
2617*404b540aSrobert       /**
2618*404b540aSrobert        *  @brief  Return hash of a string.
2619*404b540aSrobert        *
2620*404b540aSrobert        *  This function computes and returns a hash on the input string.  It
2621*404b540aSrobert        *  does so by returning collate::do_hash().
2622*404b540aSrobert        *
2623*404b540aSrobert        *  @param lo  Start of string.
2624*404b540aSrobert        *  @param hi  End of string.
2625*404b540aSrobert        *  @return  Hash value.
2626*404b540aSrobert       */
2627*404b540aSrobert       long
hash(const _CharT * __lo,const _CharT * __hi)2628*404b540aSrobert       hash(const _CharT* __lo, const _CharT* __hi) const
2629*404b540aSrobert       { return this->do_hash(__lo, __hi); }
2630*404b540aSrobert 
2631*404b540aSrobert       // Used to abstract out _CharT bits in virtual member functions, below.
2632*404b540aSrobert       int
2633*404b540aSrobert       _M_compare(const _CharT*, const _CharT*) const;
2634*404b540aSrobert 
2635*404b540aSrobert       size_t
2636*404b540aSrobert       _M_transform(_CharT*, const _CharT*, size_t) const;
2637*404b540aSrobert 
2638*404b540aSrobert   protected:
2639*404b540aSrobert       /// Destructor.
2640*404b540aSrobert       virtual
~collate()2641*404b540aSrobert       ~collate()
2642*404b540aSrobert       { _S_destroy_c_locale(_M_c_locale_collate); }
2643*404b540aSrobert 
2644*404b540aSrobert       /**
2645*404b540aSrobert        *  @brief  Compare two strings.
2646*404b540aSrobert        *
2647*404b540aSrobert        *  This function is a hook for derived classes to change the value
2648*404b540aSrobert        *  returned.  @see compare().
2649*404b540aSrobert        *
2650*404b540aSrobert        *  @param lo1  Start of string 1.
2651*404b540aSrobert        *  @param hi1  End of string 1.
2652*404b540aSrobert        *  @param lo2  Start of string 2.
2653*404b540aSrobert        *  @param hi2  End of string 2.
2654*404b540aSrobert        *  @return  1 if string1 > string2, -1 if string1 < string2, else 0.
2655*404b540aSrobert       */
2656*404b540aSrobert       virtual int
2657*404b540aSrobert       do_compare(const _CharT* __lo1, const _CharT* __hi1,
2658*404b540aSrobert 		 const _CharT* __lo2, const _CharT* __hi2) const;
2659*404b540aSrobert 
2660*404b540aSrobert       /**
2661*404b540aSrobert        *  @brief  Transform string to comparable form.
2662*404b540aSrobert        *
2663*404b540aSrobert        *  This function is a hook for derived classes to change the value
2664*404b540aSrobert        *  returned.
2665*404b540aSrobert        *
2666*404b540aSrobert        *  @param lo1  Start of string 1.
2667*404b540aSrobert        *  @param hi1  End of string 1.
2668*404b540aSrobert        *  @param lo2  Start of string 2.
2669*404b540aSrobert        *  @param hi2  End of string 2.
2670*404b540aSrobert        *  @return  1 if string1 > string2, -1 if string1 < string2, else 0.
2671*404b540aSrobert       */
2672*404b540aSrobert       virtual string_type
2673*404b540aSrobert       do_transform(const _CharT* __lo, const _CharT* __hi) const;
2674*404b540aSrobert 
2675*404b540aSrobert       /**
2676*404b540aSrobert        *  @brief  Return hash of a string.
2677*404b540aSrobert        *
2678*404b540aSrobert        *  This function computes and returns a hash on the input string.  This
2679*404b540aSrobert        *  function is a hook for derived classes to change the value returned.
2680*404b540aSrobert        *
2681*404b540aSrobert        *  @param lo  Start of string.
2682*404b540aSrobert        *  @param hi  End of string.
2683*404b540aSrobert        *  @return  Hash value.
2684*404b540aSrobert       */
2685*404b540aSrobert       virtual long
2686*404b540aSrobert       do_hash(const _CharT* __lo, const _CharT* __hi) const;
2687*404b540aSrobert     };
2688*404b540aSrobert 
2689*404b540aSrobert   template<typename _CharT>
2690*404b540aSrobert     locale::id collate<_CharT>::id;
2691*404b540aSrobert 
2692*404b540aSrobert   // Specializations.
2693*404b540aSrobert   template<>
2694*404b540aSrobert     int
2695*404b540aSrobert     collate<char>::_M_compare(const char*, const char*) const;
2696*404b540aSrobert 
2697*404b540aSrobert   template<>
2698*404b540aSrobert     size_t
2699*404b540aSrobert     collate<char>::_M_transform(char*, const char*, size_t) const;
2700*404b540aSrobert 
2701*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T
2702*404b540aSrobert   template<>
2703*404b540aSrobert     int
2704*404b540aSrobert     collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
2705*404b540aSrobert 
2706*404b540aSrobert   template<>
2707*404b540aSrobert     size_t
2708*404b540aSrobert     collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
2709*404b540aSrobert #endif
2710*404b540aSrobert 
2711*404b540aSrobert   /// @brief  class collate_byname [22.2.4.2].
2712*404b540aSrobert   template<typename _CharT>
2713*404b540aSrobert     class collate_byname : public collate<_CharT>
2714*404b540aSrobert     {
2715*404b540aSrobert     public:
2716*404b540aSrobert       //@{
2717*404b540aSrobert       /// Public typedefs
2718*404b540aSrobert       typedef _CharT               char_type;
2719*404b540aSrobert       typedef basic_string<_CharT> string_type;
2720*404b540aSrobert       //@}
2721*404b540aSrobert 
2722*404b540aSrobert       explicit
2723*404b540aSrobert       collate_byname(const char* __s, size_t __refs = 0)
2724*404b540aSrobert       : collate<_CharT>(__refs)
2725*404b540aSrobert       {
2726*404b540aSrobert 	if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
2727*404b540aSrobert 	  {
2728*404b540aSrobert 	    this->_S_destroy_c_locale(this->_M_c_locale_collate);
2729*404b540aSrobert 	    this->_S_create_c_locale(this->_M_c_locale_collate, __s);
2730*404b540aSrobert 	  }
2731*404b540aSrobert       }
2732*404b540aSrobert 
2733*404b540aSrobert     protected:
2734*404b540aSrobert       virtual
~collate_byname()2735*404b540aSrobert       ~collate_byname() { }
2736*404b540aSrobert     };
2737*404b540aSrobert 
2738*404b540aSrobert 
2739*404b540aSrobert   /**
2740*404b540aSrobert    *  @brief  Time format ordering data.
2741*404b540aSrobert    *
2742*404b540aSrobert    *  This class provides an enum representing different orderings of day,
2743*404b540aSrobert    *  month, and year.
2744*404b540aSrobert   */
2745*404b540aSrobert   class time_base
2746*404b540aSrobert   {
2747*404b540aSrobert   public:
2748*404b540aSrobert     enum dateorder { no_order, dmy, mdy, ymd, ydm };
2749*404b540aSrobert   };
2750*404b540aSrobert 
2751*404b540aSrobert   template<typename _CharT>
2752*404b540aSrobert     struct __timepunct_cache : public locale::facet
2753*404b540aSrobert     {
2754*404b540aSrobert       // List of all known timezones, with GMT first.
2755*404b540aSrobert       static const _CharT*		_S_timezones[14];
2756*404b540aSrobert 
2757*404b540aSrobert       const _CharT*			_M_date_format;
2758*404b540aSrobert       const _CharT*			_M_date_era_format;
2759*404b540aSrobert       const _CharT*			_M_time_format;
2760*404b540aSrobert       const _CharT*			_M_time_era_format;
2761*404b540aSrobert       const _CharT*			_M_date_time_format;
2762*404b540aSrobert       const _CharT*			_M_date_time_era_format;
2763*404b540aSrobert       const _CharT*			_M_am;
2764*404b540aSrobert       const _CharT*			_M_pm;
2765*404b540aSrobert       const _CharT*			_M_am_pm_format;
2766*404b540aSrobert 
2767*404b540aSrobert       // Day names, starting with "C"'s Sunday.
2768*404b540aSrobert       const _CharT*			_M_day1;
2769*404b540aSrobert       const _CharT*			_M_day2;
2770*404b540aSrobert       const _CharT*			_M_day3;
2771*404b540aSrobert       const _CharT*			_M_day4;
2772*404b540aSrobert       const _CharT*			_M_day5;
2773*404b540aSrobert       const _CharT*			_M_day6;
2774*404b540aSrobert       const _CharT*			_M_day7;
2775*404b540aSrobert 
2776*404b540aSrobert       // Abbreviated day names, starting with "C"'s Sun.
2777*404b540aSrobert       const _CharT*			_M_aday1;
2778*404b540aSrobert       const _CharT*			_M_aday2;
2779*404b540aSrobert       const _CharT*			_M_aday3;
2780*404b540aSrobert       const _CharT*			_M_aday4;
2781*404b540aSrobert       const _CharT*			_M_aday5;
2782*404b540aSrobert       const _CharT*			_M_aday6;
2783*404b540aSrobert       const _CharT*			_M_aday7;
2784*404b540aSrobert 
2785*404b540aSrobert       // Month names, starting with "C"'s January.
2786*404b540aSrobert       const _CharT*			_M_month01;
2787*404b540aSrobert       const _CharT*			_M_month02;
2788*404b540aSrobert       const _CharT*			_M_month03;
2789*404b540aSrobert       const _CharT*			_M_month04;
2790*404b540aSrobert       const _CharT*			_M_month05;
2791*404b540aSrobert       const _CharT*			_M_month06;
2792*404b540aSrobert       const _CharT*			_M_month07;
2793*404b540aSrobert       const _CharT*			_M_month08;
2794*404b540aSrobert       const _CharT*			_M_month09;
2795*404b540aSrobert       const _CharT*			_M_month10;
2796*404b540aSrobert       const _CharT*			_M_month11;
2797*404b540aSrobert       const _CharT*			_M_month12;
2798*404b540aSrobert 
2799*404b540aSrobert       // Abbreviated month names, starting with "C"'s Jan.
2800*404b540aSrobert       const _CharT*			_M_amonth01;
2801*404b540aSrobert       const _CharT*			_M_amonth02;
2802*404b540aSrobert       const _CharT*			_M_amonth03;
2803*404b540aSrobert       const _CharT*			_M_amonth04;
2804*404b540aSrobert       const _CharT*			_M_amonth05;
2805*404b540aSrobert       const _CharT*			_M_amonth06;
2806*404b540aSrobert       const _CharT*			_M_amonth07;
2807*404b540aSrobert       const _CharT*			_M_amonth08;
2808*404b540aSrobert       const _CharT*			_M_amonth09;
2809*404b540aSrobert       const _CharT*			_M_amonth10;
2810*404b540aSrobert       const _CharT*			_M_amonth11;
2811*404b540aSrobert       const _CharT*			_M_amonth12;
2812*404b540aSrobert 
2813*404b540aSrobert       bool				_M_allocated;
2814*404b540aSrobert 
facet__timepunct_cache2815*404b540aSrobert       __timepunct_cache(size_t __refs = 0) : facet(__refs),
2816*404b540aSrobert       _M_date_format(NULL), _M_date_era_format(NULL), _M_time_format(NULL),
2817*404b540aSrobert       _M_time_era_format(NULL), _M_date_time_format(NULL),
2818*404b540aSrobert       _M_date_time_era_format(NULL), _M_am(NULL), _M_pm(NULL),
2819*404b540aSrobert       _M_am_pm_format(NULL), _M_day1(NULL), _M_day2(NULL), _M_day3(NULL),
2820*404b540aSrobert       _M_day4(NULL), _M_day5(NULL), _M_day6(NULL), _M_day7(NULL),
2821*404b540aSrobert       _M_aday1(NULL), _M_aday2(NULL), _M_aday3(NULL), _M_aday4(NULL),
2822*404b540aSrobert       _M_aday5(NULL), _M_aday6(NULL), _M_aday7(NULL), _M_month01(NULL),
2823*404b540aSrobert       _M_month02(NULL), _M_month03(NULL), _M_month04(NULL), _M_month05(NULL),
2824*404b540aSrobert       _M_month06(NULL), _M_month07(NULL), _M_month08(NULL), _M_month09(NULL),
2825*404b540aSrobert       _M_month10(NULL), _M_month11(NULL), _M_month12(NULL), _M_amonth01(NULL),
2826*404b540aSrobert       _M_amonth02(NULL), _M_amonth03(NULL), _M_amonth04(NULL),
2827*404b540aSrobert       _M_amonth05(NULL), _M_amonth06(NULL), _M_amonth07(NULL),
2828*404b540aSrobert       _M_amonth08(NULL), _M_amonth09(NULL), _M_amonth10(NULL),
2829*404b540aSrobert       _M_amonth11(NULL), _M_amonth12(NULL), _M_allocated(false)
2830*404b540aSrobert       { }
2831*404b540aSrobert 
2832*404b540aSrobert       ~__timepunct_cache();
2833*404b540aSrobert 
2834*404b540aSrobert       void
2835*404b540aSrobert       _M_cache(const locale& __loc);
2836*404b540aSrobert 
2837*404b540aSrobert     private:
2838*404b540aSrobert       __timepunct_cache&
2839*404b540aSrobert       operator=(const __timepunct_cache&);
2840*404b540aSrobert 
2841*404b540aSrobert       explicit
2842*404b540aSrobert       __timepunct_cache(const __timepunct_cache&);
2843*404b540aSrobert     };
2844*404b540aSrobert 
2845*404b540aSrobert   template<typename _CharT>
~__timepunct_cache()2846*404b540aSrobert     __timepunct_cache<_CharT>::~__timepunct_cache()
2847*404b540aSrobert     {
2848*404b540aSrobert       if (_M_allocated)
2849*404b540aSrobert 	{
2850*404b540aSrobert 	  // Unused.
2851*404b540aSrobert 	}
2852*404b540aSrobert     }
2853*404b540aSrobert 
2854*404b540aSrobert   // Specializations.
2855*404b540aSrobert   template<>
2856*404b540aSrobert     const char*
2857*404b540aSrobert     __timepunct_cache<char>::_S_timezones[14];
2858*404b540aSrobert 
2859*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T
2860*404b540aSrobert   template<>
2861*404b540aSrobert     const wchar_t*
2862*404b540aSrobert     __timepunct_cache<wchar_t>::_S_timezones[14];
2863*404b540aSrobert #endif
2864*404b540aSrobert 
2865*404b540aSrobert   // Generic.
2866*404b540aSrobert   template<typename _CharT>
2867*404b540aSrobert     const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
2868*404b540aSrobert 
2869*404b540aSrobert   template<typename _CharT>
2870*404b540aSrobert     class __timepunct : public locale::facet
2871*404b540aSrobert     {
2872*404b540aSrobert     public:
2873*404b540aSrobert       // Types:
2874*404b540aSrobert       typedef _CharT			__char_type;
2875*404b540aSrobert       typedef basic_string<_CharT>	__string_type;
2876*404b540aSrobert       typedef __timepunct_cache<_CharT>	__cache_type;
2877*404b540aSrobert 
2878*404b540aSrobert     protected:
2879*404b540aSrobert       __cache_type*			_M_data;
2880*404b540aSrobert       __c_locale			_M_c_locale_timepunct;
2881*404b540aSrobert       const char*			_M_name_timepunct;
2882*404b540aSrobert 
2883*404b540aSrobert     public:
2884*404b540aSrobert       /// Numpunct facet id.
2885*404b540aSrobert       static locale::id			id;
2886*404b540aSrobert 
2887*404b540aSrobert       explicit
2888*404b540aSrobert       __timepunct(size_t __refs = 0);
2889*404b540aSrobert 
2890*404b540aSrobert       explicit
2891*404b540aSrobert       __timepunct(__cache_type* __cache, size_t __refs = 0);
2892*404b540aSrobert 
2893*404b540aSrobert       /**
2894*404b540aSrobert        *  @brief  Internal constructor. Not for general use.
2895*404b540aSrobert        *
2896*404b540aSrobert        *  This is a constructor for use by the library itself to set up new
2897*404b540aSrobert        *  locales.
2898*404b540aSrobert        *
2899*404b540aSrobert        *  @param cloc  The "C" locale.
2900*404b540aSrobert        *  @param s  The name of a locale.
2901*404b540aSrobert        *  @param refs  Passed to the base facet class.
2902*404b540aSrobert       */
2903*404b540aSrobert       explicit
2904*404b540aSrobert       __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
2905*404b540aSrobert 
2906*404b540aSrobert       // FIXME: for error checking purposes _M_put should return the return
2907*404b540aSrobert       // value of strftime/wcsftime.
2908*404b540aSrobert       void
2909*404b540aSrobert       _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
2910*404b540aSrobert 	     const tm* __tm) const;
2911*404b540aSrobert 
2912*404b540aSrobert       void
_M_date_formats(const _CharT ** __date)2913*404b540aSrobert       _M_date_formats(const _CharT** __date) const
2914*404b540aSrobert       {
2915*404b540aSrobert 	// Always have default first.
2916*404b540aSrobert 	__date[0] = _M_data->_M_date_format;
2917*404b540aSrobert 	__date[1] = _M_data->_M_date_era_format;
2918*404b540aSrobert       }
2919*404b540aSrobert 
2920*404b540aSrobert       void
_M_time_formats(const _CharT ** __time)2921*404b540aSrobert       _M_time_formats(const _CharT** __time) const
2922*404b540aSrobert       {
2923*404b540aSrobert 	// Always have default first.
2924*404b540aSrobert 	__time[0] = _M_data->_M_time_format;
2925*404b540aSrobert 	__time[1] = _M_data->_M_time_era_format;
2926*404b540aSrobert       }
2927*404b540aSrobert 
2928*404b540aSrobert       void
_M_date_time_formats(const _CharT ** __dt)2929*404b540aSrobert       _M_date_time_formats(const _CharT** __dt) const
2930*404b540aSrobert       {
2931*404b540aSrobert 	// Always have default first.
2932*404b540aSrobert 	__dt[0] = _M_data->_M_date_time_format;
2933*404b540aSrobert 	__dt[1] = _M_data->_M_date_time_era_format;
2934*404b540aSrobert       }
2935*404b540aSrobert 
2936*404b540aSrobert       void
_M_am_pm_format(const _CharT * __ampm)2937*404b540aSrobert       _M_am_pm_format(const _CharT* __ampm) const
2938*404b540aSrobert       { __ampm = _M_data->_M_am_pm_format; }
2939*404b540aSrobert 
2940*404b540aSrobert       void
_M_am_pm(const _CharT ** __ampm)2941*404b540aSrobert       _M_am_pm(const _CharT** __ampm) const
2942*404b540aSrobert       {
2943*404b540aSrobert 	__ampm[0] = _M_data->_M_am;
2944*404b540aSrobert 	__ampm[1] = _M_data->_M_pm;
2945*404b540aSrobert       }
2946*404b540aSrobert 
2947*404b540aSrobert       void
_M_days(const _CharT ** __days)2948*404b540aSrobert       _M_days(const _CharT** __days) const
2949*404b540aSrobert       {
2950*404b540aSrobert 	__days[0] = _M_data->_M_day1;
2951*404b540aSrobert 	__days[1] = _M_data->_M_day2;
2952*404b540aSrobert 	__days[2] = _M_data->_M_day3;
2953*404b540aSrobert 	__days[3] = _M_data->_M_day4;
2954*404b540aSrobert 	__days[4] = _M_data->_M_day5;
2955*404b540aSrobert 	__days[5] = _M_data->_M_day6;
2956*404b540aSrobert 	__days[6] = _M_data->_M_day7;
2957*404b540aSrobert       }
2958*404b540aSrobert 
2959*404b540aSrobert       void
_M_days_abbreviated(const _CharT ** __days)2960*404b540aSrobert       _M_days_abbreviated(const _CharT** __days) const
2961*404b540aSrobert       {
2962*404b540aSrobert 	__days[0] = _M_data->_M_aday1;
2963*404b540aSrobert 	__days[1] = _M_data->_M_aday2;
2964*404b540aSrobert 	__days[2] = _M_data->_M_aday3;
2965*404b540aSrobert 	__days[3] = _M_data->_M_aday4;
2966*404b540aSrobert 	__days[4] = _M_data->_M_aday5;
2967*404b540aSrobert 	__days[5] = _M_data->_M_aday6;
2968*404b540aSrobert 	__days[6] = _M_data->_M_aday7;
2969*404b540aSrobert       }
2970*404b540aSrobert 
2971*404b540aSrobert       void
_M_months(const _CharT ** __months)2972*404b540aSrobert       _M_months(const _CharT** __months) const
2973*404b540aSrobert       {
2974*404b540aSrobert 	__months[0] = _M_data->_M_month01;
2975*404b540aSrobert 	__months[1] = _M_data->_M_month02;
2976*404b540aSrobert 	__months[2] = _M_data->_M_month03;
2977*404b540aSrobert 	__months[3] = _M_data->_M_month04;
2978*404b540aSrobert 	__months[4] = _M_data->_M_month05;
2979*404b540aSrobert 	__months[5] = _M_data->_M_month06;
2980*404b540aSrobert 	__months[6] = _M_data->_M_month07;
2981*404b540aSrobert 	__months[7] = _M_data->_M_month08;
2982*404b540aSrobert 	__months[8] = _M_data->_M_month09;
2983*404b540aSrobert 	__months[9] = _M_data->_M_month10;
2984*404b540aSrobert 	__months[10] = _M_data->_M_month11;
2985*404b540aSrobert 	__months[11] = _M_data->_M_month12;
2986*404b540aSrobert       }
2987*404b540aSrobert 
2988*404b540aSrobert       void
_M_months_abbreviated(const _CharT ** __months)2989*404b540aSrobert       _M_months_abbreviated(const _CharT** __months) const
2990*404b540aSrobert       {
2991*404b540aSrobert 	__months[0] = _M_data->_M_amonth01;
2992*404b540aSrobert 	__months[1] = _M_data->_M_amonth02;
2993*404b540aSrobert 	__months[2] = _M_data->_M_amonth03;
2994*404b540aSrobert 	__months[3] = _M_data->_M_amonth04;
2995*404b540aSrobert 	__months[4] = _M_data->_M_amonth05;
2996*404b540aSrobert 	__months[5] = _M_data->_M_amonth06;
2997*404b540aSrobert 	__months[6] = _M_data->_M_amonth07;
2998*404b540aSrobert 	__months[7] = _M_data->_M_amonth08;
2999*404b540aSrobert 	__months[8] = _M_data->_M_amonth09;
3000*404b540aSrobert 	__months[9] = _M_data->_M_amonth10;
3001*404b540aSrobert 	__months[10] = _M_data->_M_amonth11;
3002*404b540aSrobert 	__months[11] = _M_data->_M_amonth12;
3003*404b540aSrobert       }
3004*404b540aSrobert 
3005*404b540aSrobert     protected:
3006*404b540aSrobert       virtual
3007*404b540aSrobert       ~__timepunct();
3008*404b540aSrobert 
3009*404b540aSrobert       // For use at construction time only.
3010*404b540aSrobert       void
3011*404b540aSrobert       _M_initialize_timepunct(__c_locale __cloc = NULL);
3012*404b540aSrobert     };
3013*404b540aSrobert 
3014*404b540aSrobert   template<typename _CharT>
3015*404b540aSrobert     locale::id __timepunct<_CharT>::id;
3016*404b540aSrobert 
3017*404b540aSrobert   // Specializations.
3018*404b540aSrobert   template<>
3019*404b540aSrobert     void
3020*404b540aSrobert     __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
3021*404b540aSrobert 
3022*404b540aSrobert   template<>
3023*404b540aSrobert     void
3024*404b540aSrobert     __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const;
3025*404b540aSrobert 
3026*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T
3027*404b540aSrobert   template<>
3028*404b540aSrobert     void
3029*404b540aSrobert     __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
3030*404b540aSrobert 
3031*404b540aSrobert   template<>
3032*404b540aSrobert     void
3033*404b540aSrobert     __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
3034*404b540aSrobert 				 const tm*) const;
3035*404b540aSrobert #endif
3036*404b540aSrobert 
3037*404b540aSrobert _GLIBCXX_END_NAMESPACE
3038*404b540aSrobert 
3039*404b540aSrobert   // Include host and configuration specific timepunct functions.
3040*404b540aSrobert   #include <bits/time_members.h>
3041*404b540aSrobert 
_GLIBCXX_BEGIN_NAMESPACE(std)3042*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
3043*404b540aSrobert 
3044*404b540aSrobert   /**
3045*404b540aSrobert    *  @brief  Facet for parsing dates and times.
3046*404b540aSrobert    *
3047*404b540aSrobert    *  This facet encapsulates the code to parse and return a date or
3048*404b540aSrobert    *  time from a string.  It is used by the istream numeric
3049*404b540aSrobert    *  extraction operators.
3050*404b540aSrobert    *
3051*404b540aSrobert    *  The time_get template uses protected virtual functions to provide the
3052*404b540aSrobert    *  actual results.  The public accessors forward the call to the virtual
3053*404b540aSrobert    *  functions.  These virtual functions are hooks for developers to
3054*404b540aSrobert    *  implement the behavior they require from the time_get facet.
3055*404b540aSrobert   */
3056*404b540aSrobert   template<typename _CharT, typename _InIter>
3057*404b540aSrobert     class time_get : public locale::facet, public time_base
3058*404b540aSrobert     {
3059*404b540aSrobert     public:
3060*404b540aSrobert       // Types:
3061*404b540aSrobert       //@{
3062*404b540aSrobert       /// Public typedefs
3063*404b540aSrobert       typedef _CharT			char_type;
3064*404b540aSrobert       typedef _InIter			iter_type;
3065*404b540aSrobert       //@}
3066*404b540aSrobert       typedef basic_string<_CharT>	__string_type;
3067*404b540aSrobert 
3068*404b540aSrobert       /// Numpunct facet id.
3069*404b540aSrobert       static locale::id			id;
3070*404b540aSrobert 
3071*404b540aSrobert       /**
3072*404b540aSrobert        *  @brief  Constructor performs initialization.
3073*404b540aSrobert        *
3074*404b540aSrobert        *  This is the constructor provided by the standard.
3075*404b540aSrobert        *
3076*404b540aSrobert        *  @param refs  Passed to the base facet class.
3077*404b540aSrobert       */
3078*404b540aSrobert       explicit
3079*404b540aSrobert       time_get(size_t __refs = 0)
3080*404b540aSrobert       : facet (__refs) { }
3081*404b540aSrobert 
3082*404b540aSrobert       /**
3083*404b540aSrobert        *  @brief  Return preferred order of month, day, and year.
3084*404b540aSrobert        *
3085*404b540aSrobert        *  This function returns an enum from timebase::dateorder giving the
3086*404b540aSrobert        *  preferred ordering if the format "x" given to time_put::put() only
3087*404b540aSrobert        *  uses month, day, and year.  If the format "x" for the associated
3088*404b540aSrobert        *  locale uses other fields, this function returns
3089*404b540aSrobert        *  timebase::dateorder::noorder.
3090*404b540aSrobert        *
3091*404b540aSrobert        *  NOTE: The library always returns noorder at the moment.
3092*404b540aSrobert        *
3093*404b540aSrobert        *  @return  A member of timebase::dateorder.
3094*404b540aSrobert       */
3095*404b540aSrobert       dateorder
3096*404b540aSrobert       date_order()  const
3097*404b540aSrobert       { return this->do_date_order(); }
3098*404b540aSrobert 
3099*404b540aSrobert       /**
3100*404b540aSrobert        *  @brief  Parse input time string.
3101*404b540aSrobert        *
3102*404b540aSrobert        *  This function parses a time according to the format "x" and puts the
3103*404b540aSrobert        *  results into a user-supplied struct tm.  The result is returned by
3104*404b540aSrobert        *  calling time_get::do_get_time().
3105*404b540aSrobert        *
3106*404b540aSrobert        *  If there is a valid time string according to format "x", @a tm will
3107*404b540aSrobert        *  be filled in accordingly and the returned iterator will point to the
3108*404b540aSrobert        *  first character beyond the time string.  If an error occurs before
3109*404b540aSrobert        *  the end, err |= ios_base::failbit.  If parsing reads all the
3110*404b540aSrobert        *  characters, err |= ios_base::eofbit.
3111*404b540aSrobert        *
3112*404b540aSrobert        *  @param  beg  Start of string to parse.
3113*404b540aSrobert        *  @param  end  End of string to parse.
3114*404b540aSrobert        *  @param  io  Source of the locale.
3115*404b540aSrobert        *  @param  err  Error flags to set.
3116*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3117*404b540aSrobert        *  @return  Iterator to first char beyond time string.
3118*404b540aSrobert       */
3119*404b540aSrobert       iter_type
3120*404b540aSrobert       get_time(iter_type __beg, iter_type __end, ios_base& __io,
3121*404b540aSrobert 	       ios_base::iostate& __err, tm* __tm)  const
3122*404b540aSrobert       { return this->do_get_time(__beg, __end, __io, __err, __tm); }
3123*404b540aSrobert 
3124*404b540aSrobert       /**
3125*404b540aSrobert        *  @brief  Parse input date string.
3126*404b540aSrobert        *
3127*404b540aSrobert        *  This function parses a date according to the format "X" and puts the
3128*404b540aSrobert        *  results into a user-supplied struct tm.  The result is returned by
3129*404b540aSrobert        *  calling time_get::do_get_date().
3130*404b540aSrobert        *
3131*404b540aSrobert        *  If there is a valid date string according to format "X", @a tm will
3132*404b540aSrobert        *  be filled in accordingly and the returned iterator will point to the
3133*404b540aSrobert        *  first character beyond the date string.  If an error occurs before
3134*404b540aSrobert        *  the end, err |= ios_base::failbit.  If parsing reads all the
3135*404b540aSrobert        *  characters, err |= ios_base::eofbit.
3136*404b540aSrobert        *
3137*404b540aSrobert        *  @param  beg  Start of string to parse.
3138*404b540aSrobert        *  @param  end  End of string to parse.
3139*404b540aSrobert        *  @param  io  Source of the locale.
3140*404b540aSrobert        *  @param  err  Error flags to set.
3141*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3142*404b540aSrobert        *  @return  Iterator to first char beyond date string.
3143*404b540aSrobert       */
3144*404b540aSrobert       iter_type
3145*404b540aSrobert       get_date(iter_type __beg, iter_type __end, ios_base& __io,
3146*404b540aSrobert 	       ios_base::iostate& __err, tm* __tm)  const
3147*404b540aSrobert       { return this->do_get_date(__beg, __end, __io, __err, __tm); }
3148*404b540aSrobert 
3149*404b540aSrobert       /**
3150*404b540aSrobert        *  @brief  Parse input weekday string.
3151*404b540aSrobert        *
3152*404b540aSrobert        *  This function parses a weekday name and puts the results into a
3153*404b540aSrobert        *  user-supplied struct tm.  The result is returned by calling
3154*404b540aSrobert        *  time_get::do_get_weekday().
3155*404b540aSrobert        *
3156*404b540aSrobert        *  Parsing starts by parsing an abbreviated weekday name.  If a valid
3157*404b540aSrobert        *  abbreviation is followed by a character that would lead to the full
3158*404b540aSrobert        *  weekday name, parsing continues until the full name is found or an
3159*404b540aSrobert        *  error occurs.  Otherwise parsing finishes at the end of the
3160*404b540aSrobert        *  abbreviated name.
3161*404b540aSrobert        *
3162*404b540aSrobert        *  If an error occurs before the end, err |= ios_base::failbit.  If
3163*404b540aSrobert        *  parsing reads all the characters, err |= ios_base::eofbit.
3164*404b540aSrobert        *
3165*404b540aSrobert        *  @param  beg  Start of string to parse.
3166*404b540aSrobert        *  @param  end  End of string to parse.
3167*404b540aSrobert        *  @param  io  Source of the locale.
3168*404b540aSrobert        *  @param  err  Error flags to set.
3169*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3170*404b540aSrobert        *  @return  Iterator to first char beyond weekday name.
3171*404b540aSrobert       */
3172*404b540aSrobert       iter_type
3173*404b540aSrobert       get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
3174*404b540aSrobert 		  ios_base::iostate& __err, tm* __tm) const
3175*404b540aSrobert       { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
3176*404b540aSrobert 
3177*404b540aSrobert       /**
3178*404b540aSrobert        *  @brief  Parse input month string.
3179*404b540aSrobert        *
3180*404b540aSrobert        *  This function parses a month name and puts the results into a
3181*404b540aSrobert        *  user-supplied struct tm.  The result is returned by calling
3182*404b540aSrobert        *  time_get::do_get_monthname().
3183*404b540aSrobert        *
3184*404b540aSrobert        *  Parsing starts by parsing an abbreviated month name.  If a valid
3185*404b540aSrobert        *  abbreviation is followed by a character that would lead to the full
3186*404b540aSrobert        *  month name, parsing continues until the full name is found or an
3187*404b540aSrobert        *  error occurs.  Otherwise parsing finishes at the end of the
3188*404b540aSrobert        *  abbreviated name.
3189*404b540aSrobert        *
3190*404b540aSrobert        *  If an error occurs before the end, err |= ios_base::failbit.  If
3191*404b540aSrobert        *  parsing reads all the characters, err |=
3192*404b540aSrobert        *  ios_base::eofbit.
3193*404b540aSrobert        *
3194*404b540aSrobert        *  @param  beg  Start of string to parse.
3195*404b540aSrobert        *  @param  end  End of string to parse.
3196*404b540aSrobert        *  @param  io  Source of the locale.
3197*404b540aSrobert        *  @param  err  Error flags to set.
3198*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3199*404b540aSrobert        *  @return  Iterator to first char beyond month name.
3200*404b540aSrobert       */
3201*404b540aSrobert       iter_type
3202*404b540aSrobert       get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
3203*404b540aSrobert 		    ios_base::iostate& __err, tm* __tm) const
3204*404b540aSrobert       { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
3205*404b540aSrobert 
3206*404b540aSrobert       /**
3207*404b540aSrobert        *  @brief  Parse input year string.
3208*404b540aSrobert        *
3209*404b540aSrobert        *  This function reads up to 4 characters to parse a year string and
3210*404b540aSrobert        *  puts the results into a user-supplied struct tm.  The result is
3211*404b540aSrobert        *  returned by calling time_get::do_get_year().
3212*404b540aSrobert        *
3213*404b540aSrobert        *  4 consecutive digits are interpreted as a full year.  If there are
3214*404b540aSrobert        *  exactly 2 consecutive digits, the library interprets this as the
3215*404b540aSrobert        *  number of years since 1900.
3216*404b540aSrobert        *
3217*404b540aSrobert        *  If an error occurs before the end, err |= ios_base::failbit.  If
3218*404b540aSrobert        *  parsing reads all the characters, err |= ios_base::eofbit.
3219*404b540aSrobert        *
3220*404b540aSrobert        *  @param  beg  Start of string to parse.
3221*404b540aSrobert        *  @param  end  End of string to parse.
3222*404b540aSrobert        *  @param  io  Source of the locale.
3223*404b540aSrobert        *  @param  err  Error flags to set.
3224*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3225*404b540aSrobert        *  @return  Iterator to first char beyond year.
3226*404b540aSrobert       */
3227*404b540aSrobert       iter_type
3228*404b540aSrobert       get_year(iter_type __beg, iter_type __end, ios_base& __io,
3229*404b540aSrobert 	       ios_base::iostate& __err, tm* __tm) const
3230*404b540aSrobert       { return this->do_get_year(__beg, __end, __io, __err, __tm); }
3231*404b540aSrobert 
3232*404b540aSrobert     protected:
3233*404b540aSrobert       /// Destructor.
3234*404b540aSrobert       virtual
3235*404b540aSrobert       ~time_get() { }
3236*404b540aSrobert 
3237*404b540aSrobert       /**
3238*404b540aSrobert        *  @brief  Return preferred order of month, day, and year.
3239*404b540aSrobert        *
3240*404b540aSrobert        *  This function returns an enum from timebase::dateorder giving the
3241*404b540aSrobert        *  preferred ordering if the format "x" given to time_put::put() only
3242*404b540aSrobert        *  uses month, day, and year.  This function is a hook for derived
3243*404b540aSrobert        *  classes to change the value returned.
3244*404b540aSrobert        *
3245*404b540aSrobert        *  @return  A member of timebase::dateorder.
3246*404b540aSrobert       */
3247*404b540aSrobert       virtual dateorder
3248*404b540aSrobert       do_date_order() const;
3249*404b540aSrobert 
3250*404b540aSrobert       /**
3251*404b540aSrobert        *  @brief  Parse input time string.
3252*404b540aSrobert        *
3253*404b540aSrobert        *  This function parses a time according to the format "x" and puts the
3254*404b540aSrobert        *  results into a user-supplied struct tm.  This function is a hook for
3255*404b540aSrobert        *  derived classes to change the value returned.  @see get_time() for
3256*404b540aSrobert        *  details.
3257*404b540aSrobert        *
3258*404b540aSrobert        *  @param  beg  Start of string to parse.
3259*404b540aSrobert        *  @param  end  End of string to parse.
3260*404b540aSrobert        *  @param  io  Source of the locale.
3261*404b540aSrobert        *  @param  err  Error flags to set.
3262*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3263*404b540aSrobert        *  @return  Iterator to first char beyond time string.
3264*404b540aSrobert       */
3265*404b540aSrobert       virtual iter_type
3266*404b540aSrobert       do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
3267*404b540aSrobert 		  ios_base::iostate& __err, tm* __tm) const;
3268*404b540aSrobert 
3269*404b540aSrobert       /**
3270*404b540aSrobert        *  @brief  Parse input date string.
3271*404b540aSrobert        *
3272*404b540aSrobert        *  This function parses a date according to the format "X" and puts the
3273*404b540aSrobert        *  results into a user-supplied struct tm.  This function is a hook for
3274*404b540aSrobert        *  derived classes to change the value returned.  @see get_date() for
3275*404b540aSrobert        *  details.
3276*404b540aSrobert        *
3277*404b540aSrobert        *  @param  beg  Start of string to parse.
3278*404b540aSrobert        *  @param  end  End of string to parse.
3279*404b540aSrobert        *  @param  io  Source of the locale.
3280*404b540aSrobert        *  @param  err  Error flags to set.
3281*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3282*404b540aSrobert        *  @return  Iterator to first char beyond date string.
3283*404b540aSrobert       */
3284*404b540aSrobert       virtual iter_type
3285*404b540aSrobert       do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
3286*404b540aSrobert 		  ios_base::iostate& __err, tm* __tm) const;
3287*404b540aSrobert 
3288*404b540aSrobert       /**
3289*404b540aSrobert        *  @brief  Parse input weekday string.
3290*404b540aSrobert        *
3291*404b540aSrobert        *  This function parses a weekday name and puts the results into a
3292*404b540aSrobert        *  user-supplied struct tm.  This function is a hook for derived
3293*404b540aSrobert        *  classes to change the value returned.  @see get_weekday() for
3294*404b540aSrobert        *  details.
3295*404b540aSrobert        *
3296*404b540aSrobert        *  @param  beg  Start of string to parse.
3297*404b540aSrobert        *  @param  end  End of string to parse.
3298*404b540aSrobert        *  @param  io  Source of the locale.
3299*404b540aSrobert        *  @param  err  Error flags to set.
3300*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3301*404b540aSrobert        *  @return  Iterator to first char beyond weekday name.
3302*404b540aSrobert       */
3303*404b540aSrobert       virtual iter_type
3304*404b540aSrobert       do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
3305*404b540aSrobert 		     ios_base::iostate& __err, tm* __tm) const;
3306*404b540aSrobert 
3307*404b540aSrobert       /**
3308*404b540aSrobert        *  @brief  Parse input month string.
3309*404b540aSrobert        *
3310*404b540aSrobert        *  This function parses a month name and puts the results into a
3311*404b540aSrobert        *  user-supplied struct tm.  This function is a hook for derived
3312*404b540aSrobert        *  classes to change the value returned.  @see get_monthname() for
3313*404b540aSrobert        *  details.
3314*404b540aSrobert        *
3315*404b540aSrobert        *  @param  beg  Start of string to parse.
3316*404b540aSrobert        *  @param  end  End of string to parse.
3317*404b540aSrobert        *  @param  io  Source of the locale.
3318*404b540aSrobert        *  @param  err  Error flags to set.
3319*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3320*404b540aSrobert        *  @return  Iterator to first char beyond month name.
3321*404b540aSrobert       */
3322*404b540aSrobert       virtual iter_type
3323*404b540aSrobert       do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
3324*404b540aSrobert 		       ios_base::iostate& __err, tm* __tm) const;
3325*404b540aSrobert 
3326*404b540aSrobert       /**
3327*404b540aSrobert        *  @brief  Parse input year string.
3328*404b540aSrobert        *
3329*404b540aSrobert        *  This function reads up to 4 characters to parse a year string and
3330*404b540aSrobert        *  puts the results into a user-supplied struct tm.  This function is a
3331*404b540aSrobert        *  hook for derived classes to change the value returned.  @see
3332*404b540aSrobert        *  get_year() for details.
3333*404b540aSrobert        *
3334*404b540aSrobert        *  @param  beg  Start of string to parse.
3335*404b540aSrobert        *  @param  end  End of string to parse.
3336*404b540aSrobert        *  @param  io  Source of the locale.
3337*404b540aSrobert        *  @param  err  Error flags to set.
3338*404b540aSrobert        *  @param  tm  Pointer to struct tm to fill in.
3339*404b540aSrobert        *  @return  Iterator to first char beyond year.
3340*404b540aSrobert       */
3341*404b540aSrobert       virtual iter_type
3342*404b540aSrobert       do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
3343*404b540aSrobert 		  ios_base::iostate& __err, tm* __tm) const;
3344*404b540aSrobert 
3345*404b540aSrobert       // Extract numeric component of length __len.
3346*404b540aSrobert       iter_type
3347*404b540aSrobert       _M_extract_num(iter_type __beg, iter_type __end, int& __member,
3348*404b540aSrobert 		     int __min, int __max, size_t __len,
3349*404b540aSrobert 		     ios_base& __io, ios_base::iostate& __err) const;
3350*404b540aSrobert 
3351*404b540aSrobert       // Extract day or month name, or any unique array of string
3352*404b540aSrobert       // literals in a const _CharT* array.
3353*404b540aSrobert       iter_type
3354*404b540aSrobert       _M_extract_name(iter_type __beg, iter_type __end, int& __member,
3355*404b540aSrobert 		      const _CharT** __names, size_t __indexlen,
3356*404b540aSrobert 		      ios_base& __io, ios_base::iostate& __err) const;
3357*404b540aSrobert 
3358*404b540aSrobert       // Extract on a component-by-component basis, via __format argument.
3359*404b540aSrobert       iter_type
3360*404b540aSrobert       _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
3361*404b540aSrobert 			    ios_base::iostate& __err, tm* __tm,
3362*404b540aSrobert 			    const _CharT* __format) const;
3363*404b540aSrobert     };
3364*404b540aSrobert 
3365*404b540aSrobert   template<typename _CharT, typename _InIter>
3366*404b540aSrobert     locale::id time_get<_CharT, _InIter>::id;
3367*404b540aSrobert 
3368*404b540aSrobert   /// @brief  class time_get_byname [22.2.5.2].
3369*404b540aSrobert   template<typename _CharT, typename _InIter>
3370*404b540aSrobert     class time_get_byname : public time_get<_CharT, _InIter>
3371*404b540aSrobert     {
3372*404b540aSrobert     public:
3373*404b540aSrobert       // Types:
3374*404b540aSrobert       typedef _CharT			char_type;
3375*404b540aSrobert       typedef _InIter			iter_type;
3376*404b540aSrobert 
3377*404b540aSrobert       explicit
3378*404b540aSrobert       time_get_byname(const char*, size_t __refs = 0)
3379*404b540aSrobert       : time_get<_CharT, _InIter>(__refs) { }
3380*404b540aSrobert 
3381*404b540aSrobert     protected:
3382*404b540aSrobert       virtual
~time_get_byname()3383*404b540aSrobert       ~time_get_byname() { }
3384*404b540aSrobert     };
3385*404b540aSrobert 
3386*404b540aSrobert   /**
3387*404b540aSrobert    *  @brief  Facet for outputting dates and times.
3388*404b540aSrobert    *
3389*404b540aSrobert    *  This facet encapsulates the code to format and output dates and times
3390*404b540aSrobert    *  according to formats used by strftime().
3391*404b540aSrobert    *
3392*404b540aSrobert    *  The time_put template uses protected virtual functions to provide the
3393*404b540aSrobert    *  actual results.  The public accessors forward the call to the virtual
3394*404b540aSrobert    *  functions.  These virtual functions are hooks for developers to
3395*404b540aSrobert    *  implement the behavior they require from the time_put facet.
3396*404b540aSrobert   */
3397*404b540aSrobert   template<typename _CharT, typename _OutIter>
3398*404b540aSrobert     class time_put : public locale::facet
3399*404b540aSrobert     {
3400*404b540aSrobert     public:
3401*404b540aSrobert       // Types:
3402*404b540aSrobert       //@{
3403*404b540aSrobert       /// Public typedefs
3404*404b540aSrobert       typedef _CharT			char_type;
3405*404b540aSrobert       typedef _OutIter			iter_type;
3406*404b540aSrobert       //@}
3407*404b540aSrobert 
3408*404b540aSrobert       /// Numpunct facet id.
3409*404b540aSrobert       static locale::id			id;
3410*404b540aSrobert 
3411*404b540aSrobert       /**
3412*404b540aSrobert        *  @brief  Constructor performs initialization.
3413*404b540aSrobert        *
3414*404b540aSrobert        *  This is the constructor provided by the standard.
3415*404b540aSrobert        *
3416*404b540aSrobert        *  @param refs  Passed to the base facet class.
3417*404b540aSrobert       */
3418*404b540aSrobert       explicit
3419*404b540aSrobert       time_put(size_t __refs = 0)
facet(__refs)3420*404b540aSrobert       : facet(__refs) { }
3421*404b540aSrobert 
3422*404b540aSrobert       /**
3423*404b540aSrobert        *  @brief  Format and output a time or date.
3424*404b540aSrobert        *
3425*404b540aSrobert        *  This function formats the data in struct tm according to the
3426*404b540aSrobert        *  provided format string.  The format string is interpreted as by
3427*404b540aSrobert        *  strftime().
3428*404b540aSrobert        *
3429*404b540aSrobert        *  @param  s  The stream to write to.
3430*404b540aSrobert        *  @param  io  Source of locale.
3431*404b540aSrobert        *  @param  fill  char_type to use for padding.
3432*404b540aSrobert        *  @param  tm  Struct tm with date and time info to format.
3433*404b540aSrobert        *  @param  beg  Start of format string.
3434*404b540aSrobert        *  @param  end  End of format string.
3435*404b540aSrobert        *  @return  Iterator after writing.
3436*404b540aSrobert        */
3437*404b540aSrobert       iter_type
3438*404b540aSrobert       put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
3439*404b540aSrobert 	  const _CharT* __beg, const _CharT* __end) const;
3440*404b540aSrobert 
3441*404b540aSrobert       /**
3442*404b540aSrobert        *  @brief  Format and output a time or date.
3443*404b540aSrobert        *
3444*404b540aSrobert        *  This function formats the data in struct tm according to the
3445*404b540aSrobert        *  provided format char and optional modifier.  The format and modifier
3446*404b540aSrobert        *  are interpreted as by strftime().  It does so by returning
3447*404b540aSrobert        *  time_put::do_put().
3448*404b540aSrobert        *
3449*404b540aSrobert        *  @param  s  The stream to write to.
3450*404b540aSrobert        *  @param  io  Source of locale.
3451*404b540aSrobert        *  @param  fill  char_type to use for padding.
3452*404b540aSrobert        *  @param  tm  Struct tm with date and time info to format.
3453*404b540aSrobert        *  @param  format  Format char.
3454*404b540aSrobert        *  @param  mod  Optional modifier char.
3455*404b540aSrobert        *  @return  Iterator after writing.
3456*404b540aSrobert        */
3457*404b540aSrobert       iter_type
3458*404b540aSrobert       put(iter_type __s, ios_base& __io, char_type __fill,
3459*404b540aSrobert 	  const tm* __tm, char __format, char __mod = 0) const
3460*404b540aSrobert       { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
3461*404b540aSrobert 
3462*404b540aSrobert     protected:
3463*404b540aSrobert       /// Destructor.
3464*404b540aSrobert       virtual
~time_put()3465*404b540aSrobert       ~time_put()
3466*404b540aSrobert       { }
3467*404b540aSrobert 
3468*404b540aSrobert       /**
3469*404b540aSrobert        *  @brief  Format and output a time or date.
3470*404b540aSrobert        *
3471*404b540aSrobert        *  This function formats the data in struct tm according to the
3472*404b540aSrobert        *  provided format char and optional modifier.  This function is a hook
3473*404b540aSrobert        *  for derived classes to change the value returned.  @see put() for
3474*404b540aSrobert        *  more details.
3475*404b540aSrobert        *
3476*404b540aSrobert        *  @param  s  The stream to write to.
3477*404b540aSrobert        *  @param  io  Source of locale.
3478*404b540aSrobert        *  @param  fill  char_type to use for padding.
3479*404b540aSrobert        *  @param  tm  Struct tm with date and time info to format.
3480*404b540aSrobert        *  @param  format  Format char.
3481*404b540aSrobert        *  @param  mod  Optional modifier char.
3482*404b540aSrobert        *  @return  Iterator after writing.
3483*404b540aSrobert        */
3484*404b540aSrobert       virtual iter_type
3485*404b540aSrobert       do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
3486*404b540aSrobert 	     char __format, char __mod) const;
3487*404b540aSrobert     };
3488*404b540aSrobert 
3489*404b540aSrobert   template<typename _CharT, typename _OutIter>
3490*404b540aSrobert     locale::id time_put<_CharT, _OutIter>::id;
3491*404b540aSrobert 
3492*404b540aSrobert   /// @brief  class time_put_byname [22.2.5.4].
3493*404b540aSrobert   template<typename _CharT, typename _OutIter>
3494*404b540aSrobert     class time_put_byname : public time_put<_CharT, _OutIter>
3495*404b540aSrobert     {
3496*404b540aSrobert     public:
3497*404b540aSrobert       // Types:
3498*404b540aSrobert       typedef _CharT			char_type;
3499*404b540aSrobert       typedef _OutIter			iter_type;
3500*404b540aSrobert 
3501*404b540aSrobert       explicit
3502*404b540aSrobert       time_put_byname(const char*, size_t __refs = 0)
3503*404b540aSrobert       : time_put<_CharT, _OutIter>(__refs)
3504*404b540aSrobert       { };
3505*404b540aSrobert 
3506*404b540aSrobert     protected:
3507*404b540aSrobert       virtual
~time_put_byname()3508*404b540aSrobert       ~time_put_byname() { }
3509*404b540aSrobert     };
3510*404b540aSrobert 
3511*404b540aSrobert 
3512*404b540aSrobert   /**
3513*404b540aSrobert    *  @brief  Money format ordering data.
3514*404b540aSrobert    *
3515*404b540aSrobert    *  This class contains an ordered array of 4 fields to represent the
3516*404b540aSrobert    *  pattern for formatting a money amount.  Each field may contain one entry
3517*404b540aSrobert    *  from the part enum.  symbol, sign, and value must be present and the
3518*404b540aSrobert    *  remaining field must contain either none or space.  @see
3519*404b540aSrobert    *  moneypunct::pos_format() and moneypunct::neg_format() for details of how
3520*404b540aSrobert    *  these fields are interpreted.
3521*404b540aSrobert   */
3522*404b540aSrobert   class money_base
3523*404b540aSrobert   {
3524*404b540aSrobert   public:
3525*404b540aSrobert     enum part { none, space, symbol, sign, value };
3526*404b540aSrobert     struct pattern { char field[4]; };
3527*404b540aSrobert 
3528*404b540aSrobert     static const pattern _S_default_pattern;
3529*404b540aSrobert 
3530*404b540aSrobert     enum
3531*404b540aSrobert     {
3532*404b540aSrobert       _S_minus,
3533*404b540aSrobert       _S_zero,
3534*404b540aSrobert       _S_end = 11
3535*404b540aSrobert     };
3536*404b540aSrobert 
3537*404b540aSrobert     // String literal of acceptable (narrow) input/output, for
3538*404b540aSrobert     // money_get/money_put. "-0123456789"
3539*404b540aSrobert     static const char* _S_atoms;
3540*404b540aSrobert 
3541*404b540aSrobert     // Construct and return valid pattern consisting of some combination of:
3542*404b540aSrobert     // space none symbol sign value
3543*404b540aSrobert     static pattern
3544*404b540aSrobert     _S_construct_pattern(char __precedes, char __space, char __posn);
3545*404b540aSrobert   };
3546*404b540aSrobert 
3547*404b540aSrobert   template<typename _CharT, bool _Intl>
3548*404b540aSrobert     struct __moneypunct_cache : public locale::facet
3549*404b540aSrobert     {
3550*404b540aSrobert       const char*			_M_grouping;
3551*404b540aSrobert       size_t                            _M_grouping_size;
3552*404b540aSrobert       bool				_M_use_grouping;
3553*404b540aSrobert       _CharT				_M_decimal_point;
3554*404b540aSrobert       _CharT				_M_thousands_sep;
3555*404b540aSrobert       const _CharT*			_M_curr_symbol;
3556*404b540aSrobert       size_t                            _M_curr_symbol_size;
3557*404b540aSrobert       const _CharT*			_M_positive_sign;
3558*404b540aSrobert       size_t                            _M_positive_sign_size;
3559*404b540aSrobert       const _CharT*			_M_negative_sign;
3560*404b540aSrobert       size_t                            _M_negative_sign_size;
3561*404b540aSrobert       int				_M_frac_digits;
3562*404b540aSrobert       money_base::pattern		_M_pos_format;
3563*404b540aSrobert       money_base::pattern	        _M_neg_format;
3564*404b540aSrobert 
3565*404b540aSrobert       // A list of valid numeric literals for input and output: in the standard
3566*404b540aSrobert       // "C" locale, this is "-0123456789". This array contains the chars after
3567*404b540aSrobert       // having been passed through the current locale's ctype<_CharT>.widen().
3568*404b540aSrobert       _CharT				_M_atoms[money_base::_S_end];
3569*404b540aSrobert 
3570*404b540aSrobert       bool				_M_allocated;
3571*404b540aSrobert 
facet__moneypunct_cache3572*404b540aSrobert       __moneypunct_cache(size_t __refs = 0) : facet(__refs),
3573*404b540aSrobert       _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
3574*404b540aSrobert       _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
3575*404b540aSrobert       _M_curr_symbol(NULL), _M_curr_symbol_size(0),
3576*404b540aSrobert       _M_positive_sign(NULL), _M_positive_sign_size(0),
3577*404b540aSrobert       _M_negative_sign(NULL), _M_negative_sign_size(0),
3578*404b540aSrobert       _M_frac_digits(0),
3579*404b540aSrobert       _M_pos_format(money_base::pattern()),
3580*404b540aSrobert       _M_neg_format(money_base::pattern()), _M_allocated(false)
3581*404b540aSrobert       { }
3582*404b540aSrobert 
3583*404b540aSrobert       ~__moneypunct_cache();
3584*404b540aSrobert 
3585*404b540aSrobert       void
3586*404b540aSrobert       _M_cache(const locale& __loc);
3587*404b540aSrobert 
3588*404b540aSrobert     private:
3589*404b540aSrobert       __moneypunct_cache&
3590*404b540aSrobert       operator=(const __moneypunct_cache&);
3591*404b540aSrobert 
3592*404b540aSrobert       explicit
3593*404b540aSrobert       __moneypunct_cache(const __moneypunct_cache&);
3594*404b540aSrobert     };
3595*404b540aSrobert 
3596*404b540aSrobert   template<typename _CharT, bool _Intl>
~__moneypunct_cache()3597*404b540aSrobert     __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
3598*404b540aSrobert     {
3599*404b540aSrobert       if (_M_allocated)
3600*404b540aSrobert 	{
3601*404b540aSrobert 	  delete [] _M_grouping;
3602*404b540aSrobert 	  delete [] _M_curr_symbol;
3603*404b540aSrobert 	  delete [] _M_positive_sign;
3604*404b540aSrobert 	  delete [] _M_negative_sign;
3605*404b540aSrobert 	}
3606*404b540aSrobert     }
3607*404b540aSrobert 
3608*404b540aSrobert   /**
3609*404b540aSrobert    *  @brief  Facet for formatting data for money amounts.
3610*404b540aSrobert    *
3611*404b540aSrobert    *  This facet encapsulates the punctuation, grouping and other formatting
3612*404b540aSrobert    *  features of money amount string representations.
3613*404b540aSrobert   */
3614*404b540aSrobert   template<typename _CharT, bool _Intl>
3615*404b540aSrobert     class moneypunct : public locale::facet, public money_base
3616*404b540aSrobert     {
3617*404b540aSrobert     public:
3618*404b540aSrobert       // Types:
3619*404b540aSrobert       //@{
3620*404b540aSrobert       /// Public typedefs
3621*404b540aSrobert       typedef _CharT			char_type;
3622*404b540aSrobert       typedef basic_string<_CharT>	string_type;
3623*404b540aSrobert       //@}
3624*404b540aSrobert       typedef __moneypunct_cache<_CharT, _Intl>     __cache_type;
3625*404b540aSrobert 
3626*404b540aSrobert     private:
3627*404b540aSrobert       __cache_type*			_M_data;
3628*404b540aSrobert 
3629*404b540aSrobert     public:
3630*404b540aSrobert       /// This value is provided by the standard, but no reason for its
3631*404b540aSrobert       /// existence.
3632*404b540aSrobert       static const bool			intl = _Intl;
3633*404b540aSrobert       /// Numpunct facet id.
3634*404b540aSrobert       static locale::id			id;
3635*404b540aSrobert 
3636*404b540aSrobert       /**
3637*404b540aSrobert        *  @brief  Constructor performs initialization.
3638*404b540aSrobert        *
3639*404b540aSrobert        *  This is the constructor provided by the standard.
3640*404b540aSrobert        *
3641*404b540aSrobert        *  @param refs  Passed to the base facet class.
3642*404b540aSrobert       */
3643*404b540aSrobert       explicit
facet(__refs)3644*404b540aSrobert       moneypunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
3645*404b540aSrobert       { _M_initialize_moneypunct(); }
3646*404b540aSrobert 
3647*404b540aSrobert       /**
3648*404b540aSrobert        *  @brief  Constructor performs initialization.
3649*404b540aSrobert        *
3650*404b540aSrobert        *  This is an internal constructor.
3651*404b540aSrobert        *
3652*404b540aSrobert        *  @param cache  Cache for optimization.
3653*404b540aSrobert        *  @param refs  Passed to the base facet class.
3654*404b540aSrobert       */
3655*404b540aSrobert       explicit
3656*404b540aSrobert       moneypunct(__cache_type* __cache, size_t __refs = 0)
facet(__refs)3657*404b540aSrobert       : facet(__refs), _M_data(__cache)
3658*404b540aSrobert       { _M_initialize_moneypunct(); }
3659*404b540aSrobert 
3660*404b540aSrobert       /**
3661*404b540aSrobert        *  @brief  Internal constructor. Not for general use.
3662*404b540aSrobert        *
3663*404b540aSrobert        *  This is a constructor for use by the library itself to set up new
3664*404b540aSrobert        *  locales.
3665*404b540aSrobert        *
3666*404b540aSrobert        *  @param cloc  The "C" locale.
3667*404b540aSrobert        *  @param s  The name of a locale.
3668*404b540aSrobert        *  @param refs  Passed to the base facet class.
3669*404b540aSrobert       */
3670*404b540aSrobert       explicit
3671*404b540aSrobert       moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
facet(__refs)3672*404b540aSrobert       : facet(__refs), _M_data(NULL)
3673*404b540aSrobert       { _M_initialize_moneypunct(__cloc, __s); }
3674*404b540aSrobert 
3675*404b540aSrobert       /**
3676*404b540aSrobert        *  @brief  Return decimal point character.
3677*404b540aSrobert        *
3678*404b540aSrobert        *  This function returns a char_type to use as a decimal point.  It
3679*404b540aSrobert        *  does so by returning returning
3680*404b540aSrobert        *  moneypunct<char_type>::do_decimal_point().
3681*404b540aSrobert        *
3682*404b540aSrobert        *  @return  @a char_type representing a decimal point.
3683*404b540aSrobert       */
3684*404b540aSrobert       char_type
decimal_point()3685*404b540aSrobert       decimal_point() const
3686*404b540aSrobert       { return this->do_decimal_point(); }
3687*404b540aSrobert 
3688*404b540aSrobert       /**
3689*404b540aSrobert        *  @brief  Return thousands separator character.
3690*404b540aSrobert        *
3691*404b540aSrobert        *  This function returns a char_type to use as a thousands
3692*404b540aSrobert        *  separator.  It does so by returning returning
3693*404b540aSrobert        *  moneypunct<char_type>::do_thousands_sep().
3694*404b540aSrobert        *
3695*404b540aSrobert        *  @return  char_type representing a thousands separator.
3696*404b540aSrobert       */
3697*404b540aSrobert       char_type
thousands_sep()3698*404b540aSrobert       thousands_sep() const
3699*404b540aSrobert       { return this->do_thousands_sep(); }
3700*404b540aSrobert 
3701*404b540aSrobert       /**
3702*404b540aSrobert        *  @brief  Return grouping specification.
3703*404b540aSrobert        *
3704*404b540aSrobert        *  This function returns a string representing groupings for the
3705*404b540aSrobert        *  integer part of an amount.  Groupings indicate where thousands
3706*404b540aSrobert        *  separators should be inserted.
3707*404b540aSrobert        *
3708*404b540aSrobert        *  Each char in the return string is interpret as an integer rather
3709*404b540aSrobert        *  than a character.  These numbers represent the number of digits in a
3710*404b540aSrobert        *  group.  The first char in the string represents the number of digits
3711*404b540aSrobert        *  in the least significant group.  If a char is negative, it indicates
3712*404b540aSrobert        *  an unlimited number of digits for the group.  If more chars from the
3713*404b540aSrobert        *  string are required to group a number, the last char is used
3714*404b540aSrobert        *  repeatedly.
3715*404b540aSrobert        *
3716*404b540aSrobert        *  For example, if the grouping() returns "\003\002" and is applied to
3717*404b540aSrobert        *  the number 123456789, this corresponds to 12,34,56,789.  Note that
3718*404b540aSrobert        *  if the string was "32", this would put more than 50 digits into the
3719*404b540aSrobert        *  least significant group if the character set is ASCII.
3720*404b540aSrobert        *
3721*404b540aSrobert        *  The string is returned by calling
3722*404b540aSrobert        *  moneypunct<char_type>::do_grouping().
3723*404b540aSrobert        *
3724*404b540aSrobert        *  @return  string representing grouping specification.
3725*404b540aSrobert       */
3726*404b540aSrobert       string
grouping()3727*404b540aSrobert       grouping() const
3728*404b540aSrobert       { return this->do_grouping(); }
3729*404b540aSrobert 
3730*404b540aSrobert       /**
3731*404b540aSrobert        *  @brief  Return currency symbol string.
3732*404b540aSrobert        *
3733*404b540aSrobert        *  This function returns a string_type to use as a currency symbol.  It
3734*404b540aSrobert        *  does so by returning returning
3735*404b540aSrobert        *  moneypunct<char_type>::do_curr_symbol().
3736*404b540aSrobert        *
3737*404b540aSrobert        *  @return  @a string_type representing a currency symbol.
3738*404b540aSrobert       */
3739*404b540aSrobert       string_type
curr_symbol()3740*404b540aSrobert       curr_symbol() const
3741*404b540aSrobert       { return this->do_curr_symbol(); }
3742*404b540aSrobert 
3743*404b540aSrobert       /**
3744*404b540aSrobert        *  @brief  Return positive sign string.
3745*404b540aSrobert        *
3746*404b540aSrobert        *  This function returns a string_type to use as a sign for positive
3747*404b540aSrobert        *  amounts.  It does so by returning returning
3748*404b540aSrobert        *  moneypunct<char_type>::do_positive_sign().
3749*404b540aSrobert        *
3750*404b540aSrobert        *  If the return value contains more than one character, the first
3751*404b540aSrobert        *  character appears in the position indicated by pos_format() and the
3752*404b540aSrobert        *  remainder appear at the end of the formatted string.
3753*404b540aSrobert        *
3754*404b540aSrobert        *  @return  @a string_type representing a positive sign.
3755*404b540aSrobert       */
3756*404b540aSrobert       string_type
positive_sign()3757*404b540aSrobert       positive_sign() const
3758*404b540aSrobert       { return this->do_positive_sign(); }
3759*404b540aSrobert 
3760*404b540aSrobert       /**
3761*404b540aSrobert        *  @brief  Return negative sign string.
3762*404b540aSrobert        *
3763*404b540aSrobert        *  This function returns a string_type to use as a sign for negative
3764*404b540aSrobert        *  amounts.  It does so by returning returning
3765*404b540aSrobert        *  moneypunct<char_type>::do_negative_sign().
3766*404b540aSrobert        *
3767*404b540aSrobert        *  If the return value contains more than one character, the first
3768*404b540aSrobert        *  character appears in the position indicated by neg_format() and the
3769*404b540aSrobert        *  remainder appear at the end of the formatted string.
3770*404b540aSrobert        *
3771*404b540aSrobert        *  @return  @a string_type representing a negative sign.
3772*404b540aSrobert       */
3773*404b540aSrobert       string_type
negative_sign()3774*404b540aSrobert       negative_sign() const
3775*404b540aSrobert       { return this->do_negative_sign(); }
3776*404b540aSrobert 
3777*404b540aSrobert       /**
3778*404b540aSrobert        *  @brief  Return number of digits in fraction.
3779*404b540aSrobert        *
3780*404b540aSrobert        *  This function returns the exact number of digits that make up the
3781*404b540aSrobert        *  fractional part of a money amount.  It does so by returning
3782*404b540aSrobert        *  returning moneypunct<char_type>::do_frac_digits().
3783*404b540aSrobert        *
3784*404b540aSrobert        *  The fractional part of a money amount is optional.  But if it is
3785*404b540aSrobert        *  present, there must be frac_digits() digits.
3786*404b540aSrobert        *
3787*404b540aSrobert        *  @return  Number of digits in amount fraction.
3788*404b540aSrobert       */
3789*404b540aSrobert       int
frac_digits()3790*404b540aSrobert       frac_digits() const
3791*404b540aSrobert       { return this->do_frac_digits(); }
3792*404b540aSrobert 
3793*404b540aSrobert       //@{
3794*404b540aSrobert       /**
3795*404b540aSrobert        *  @brief  Return pattern for money values.
3796*404b540aSrobert        *
3797*404b540aSrobert        *  This function returns a pattern describing the formatting of a
3798*404b540aSrobert        *  positive or negative valued money amount.  It does so by returning
3799*404b540aSrobert        *  returning moneypunct<char_type>::do_pos_format() or
3800*404b540aSrobert        *  moneypunct<char_type>::do_neg_format().
3801*404b540aSrobert        *
3802*404b540aSrobert        *  The pattern has 4 fields describing the ordering of symbol, sign,
3803*404b540aSrobert        *  value, and none or space.  There must be one of each in the pattern.
3804*404b540aSrobert        *  The none and space enums may not appear in the first field and space
3805*404b540aSrobert        *  may not appear in the final field.
3806*404b540aSrobert        *
3807*404b540aSrobert        *  The parts of a money string must appear in the order indicated by
3808*404b540aSrobert        *  the fields of the pattern.  The symbol field indicates that the
3809*404b540aSrobert        *  value of curr_symbol() may be present.  The sign field indicates
3810*404b540aSrobert        *  that the value of positive_sign() or negative_sign() must be
3811*404b540aSrobert        *  present.  The value field indicates that the absolute value of the
3812*404b540aSrobert        *  money amount is present.  none indicates 0 or more whitespace
3813*404b540aSrobert        *  characters, except at the end, where it permits no whitespace.
3814*404b540aSrobert        *  space indicates that 1 or more whitespace characters must be
3815*404b540aSrobert        *  present.
3816*404b540aSrobert        *
3817*404b540aSrobert        *  For example, for the US locale and pos_format() pattern
3818*404b540aSrobert        *  {symbol,sign,value,none}, curr_symbol() == '$' positive_sign() ==
3819*404b540aSrobert        *  '+', and value 10.01, and options set to force the symbol, the
3820*404b540aSrobert        *  corresponding string is "$+10.01".
3821*404b540aSrobert        *
3822*404b540aSrobert        *  @return  Pattern for money values.
3823*404b540aSrobert       */
3824*404b540aSrobert       pattern
pos_format()3825*404b540aSrobert       pos_format() const
3826*404b540aSrobert       { return this->do_pos_format(); }
3827*404b540aSrobert 
3828*404b540aSrobert       pattern
neg_format()3829*404b540aSrobert       neg_format() const
3830*404b540aSrobert       { return this->do_neg_format(); }
3831*404b540aSrobert       //@}
3832*404b540aSrobert 
3833*404b540aSrobert     protected:
3834*404b540aSrobert       /// Destructor.
3835*404b540aSrobert       virtual
3836*404b540aSrobert       ~moneypunct();
3837*404b540aSrobert 
3838*404b540aSrobert       /**
3839*404b540aSrobert        *  @brief  Return decimal point character.
3840*404b540aSrobert        *
3841*404b540aSrobert        *  Returns a char_type to use as a decimal point.  This function is a
3842*404b540aSrobert        *  hook for derived classes to change the value returned.
3843*404b540aSrobert        *
3844*404b540aSrobert        *  @return  @a char_type representing a decimal point.
3845*404b540aSrobert       */
3846*404b540aSrobert       virtual char_type
do_decimal_point()3847*404b540aSrobert       do_decimal_point() const
3848*404b540aSrobert       { return _M_data->_M_decimal_point; }
3849*404b540aSrobert 
3850*404b540aSrobert       /**
3851*404b540aSrobert        *  @brief  Return thousands separator character.
3852*404b540aSrobert        *
3853*404b540aSrobert        *  Returns a char_type to use as a thousands separator.  This function
3854*404b540aSrobert        *  is a hook for derived classes to change the value returned.
3855*404b540aSrobert        *
3856*404b540aSrobert        *  @return  @a char_type representing a thousands separator.
3857*404b540aSrobert       */
3858*404b540aSrobert       virtual char_type
do_thousands_sep()3859*404b540aSrobert       do_thousands_sep() const
3860*404b540aSrobert       { return _M_data->_M_thousands_sep; }
3861*404b540aSrobert 
3862*404b540aSrobert       /**
3863*404b540aSrobert        *  @brief  Return grouping specification.
3864*404b540aSrobert        *
3865*404b540aSrobert        *  Returns a string representing groupings for the integer part of a
3866*404b540aSrobert        *  number.  This function is a hook for derived classes to change the
3867*404b540aSrobert        *  value returned.  @see grouping() for details.
3868*404b540aSrobert        *
3869*404b540aSrobert        *  @return  String representing grouping specification.
3870*404b540aSrobert       */
3871*404b540aSrobert       virtual string
do_grouping()3872*404b540aSrobert       do_grouping() const
3873*404b540aSrobert       { return _M_data->_M_grouping; }
3874*404b540aSrobert 
3875*404b540aSrobert       /**
3876*404b540aSrobert        *  @brief  Return currency symbol string.
3877*404b540aSrobert        *
3878*404b540aSrobert        *  This function returns a string_type to use as a currency symbol.
3879*404b540aSrobert        *  This function is a hook for derived classes to change the value
3880*404b540aSrobert        *  returned.  @see curr_symbol() for details.
3881*404b540aSrobert        *
3882*404b540aSrobert        *  @return  @a string_type representing a currency symbol.
3883*404b540aSrobert       */
3884*404b540aSrobert       virtual string_type
do_curr_symbol()3885*404b540aSrobert       do_curr_symbol()   const
3886*404b540aSrobert       { return _M_data->_M_curr_symbol; }
3887*404b540aSrobert 
3888*404b540aSrobert       /**
3889*404b540aSrobert        *  @brief  Return positive sign string.
3890*404b540aSrobert        *
3891*404b540aSrobert        *  This function returns a string_type to use as a sign for positive
3892*404b540aSrobert        *  amounts.  This function is a hook for derived classes to change the
3893*404b540aSrobert        *  value returned.  @see positive_sign() for details.
3894*404b540aSrobert        *
3895*404b540aSrobert        *  @return  @a string_type representing a positive sign.
3896*404b540aSrobert       */
3897*404b540aSrobert       virtual string_type
do_positive_sign()3898*404b540aSrobert       do_positive_sign() const
3899*404b540aSrobert       { return _M_data->_M_positive_sign; }
3900*404b540aSrobert 
3901*404b540aSrobert       /**
3902*404b540aSrobert        *  @brief  Return negative sign string.
3903*404b540aSrobert        *
3904*404b540aSrobert        *  This function returns a string_type to use as a sign for negative
3905*404b540aSrobert        *  amounts.  This function is a hook for derived classes to change the
3906*404b540aSrobert        *  value returned.  @see negative_sign() for details.
3907*404b540aSrobert        *
3908*404b540aSrobert        *  @return  @a string_type representing a negative sign.
3909*404b540aSrobert       */
3910*404b540aSrobert       virtual string_type
do_negative_sign()3911*404b540aSrobert       do_negative_sign() const
3912*404b540aSrobert       { return _M_data->_M_negative_sign; }
3913*404b540aSrobert 
3914*404b540aSrobert       /**
3915*404b540aSrobert        *  @brief  Return number of digits in fraction.
3916*404b540aSrobert        *
3917*404b540aSrobert        *  This function returns the exact number of digits that make up the
3918*404b540aSrobert        *  fractional part of a money amount.  This function is a hook for
3919*404b540aSrobert        *  derived classes to change the value returned.  @see frac_digits()
3920*404b540aSrobert        *  for details.
3921*404b540aSrobert        *
3922*404b540aSrobert        *  @return  Number of digits in amount fraction.
3923*404b540aSrobert       */
3924*404b540aSrobert       virtual int
do_frac_digits()3925*404b540aSrobert       do_frac_digits() const
3926*404b540aSrobert       { return _M_data->_M_frac_digits; }
3927*404b540aSrobert 
3928*404b540aSrobert       /**
3929*404b540aSrobert        *  @brief  Return pattern for money values.
3930*404b540aSrobert        *
3931*404b540aSrobert        *  This function returns a pattern describing the formatting of a
3932*404b540aSrobert        *  positive valued money amount.  This function is a hook for derived
3933*404b540aSrobert        *  classes to change the value returned.  @see pos_format() for
3934*404b540aSrobert        *  details.
3935*404b540aSrobert        *
3936*404b540aSrobert        *  @return  Pattern for money values.
3937*404b540aSrobert       */
3938*404b540aSrobert       virtual pattern
do_pos_format()3939*404b540aSrobert       do_pos_format() const
3940*404b540aSrobert       { return _M_data->_M_pos_format; }
3941*404b540aSrobert 
3942*404b540aSrobert       /**
3943*404b540aSrobert        *  @brief  Return pattern for money values.
3944*404b540aSrobert        *
3945*404b540aSrobert        *  This function returns a pattern describing the formatting of a
3946*404b540aSrobert        *  negative valued money amount.  This function is a hook for derived
3947*404b540aSrobert        *  classes to change the value returned.  @see neg_format() for
3948*404b540aSrobert        *  details.
3949*404b540aSrobert        *
3950*404b540aSrobert        *  @return  Pattern for money values.
3951*404b540aSrobert       */
3952*404b540aSrobert       virtual pattern
do_neg_format()3953*404b540aSrobert       do_neg_format() const
3954*404b540aSrobert       { return _M_data->_M_neg_format; }
3955*404b540aSrobert 
3956*404b540aSrobert       // For use at construction time only.
3957*404b540aSrobert        void
3958*404b540aSrobert        _M_initialize_moneypunct(__c_locale __cloc = NULL,
3959*404b540aSrobert 				const char* __name = NULL);
3960*404b540aSrobert     };
3961*404b540aSrobert 
3962*404b540aSrobert   template<typename _CharT, bool _Intl>
3963*404b540aSrobert     locale::id moneypunct<_CharT, _Intl>::id;
3964*404b540aSrobert 
3965*404b540aSrobert   template<typename _CharT, bool _Intl>
3966*404b540aSrobert     const bool moneypunct<_CharT, _Intl>::intl;
3967*404b540aSrobert 
3968*404b540aSrobert   template<>
3969*404b540aSrobert     moneypunct<char, true>::~moneypunct();
3970*404b540aSrobert 
3971*404b540aSrobert   template<>
3972*404b540aSrobert     moneypunct<char, false>::~moneypunct();
3973*404b540aSrobert 
3974*404b540aSrobert   template<>
3975*404b540aSrobert     void
3976*404b540aSrobert     moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
3977*404b540aSrobert 
3978*404b540aSrobert   template<>
3979*404b540aSrobert     void
3980*404b540aSrobert     moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
3981*404b540aSrobert 
3982*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T
3983*404b540aSrobert   template<>
3984*404b540aSrobert     moneypunct<wchar_t, true>::~moneypunct();
3985*404b540aSrobert 
3986*404b540aSrobert   template<>
3987*404b540aSrobert     moneypunct<wchar_t, false>::~moneypunct();
3988*404b540aSrobert 
3989*404b540aSrobert   template<>
3990*404b540aSrobert     void
3991*404b540aSrobert     moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
3992*404b540aSrobert 							const char*);
3993*404b540aSrobert 
3994*404b540aSrobert   template<>
3995*404b540aSrobert     void
3996*404b540aSrobert     moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
3997*404b540aSrobert 							 const char*);
3998*404b540aSrobert #endif
3999*404b540aSrobert 
4000*404b540aSrobert   /// @brief  class moneypunct_byname [22.2.6.4].
4001*404b540aSrobert   template<typename _CharT, bool _Intl>
4002*404b540aSrobert     class moneypunct_byname : public moneypunct<_CharT, _Intl>
4003*404b540aSrobert     {
4004*404b540aSrobert     public:
4005*404b540aSrobert       typedef _CharT			char_type;
4006*404b540aSrobert       typedef basic_string<_CharT>	string_type;
4007*404b540aSrobert 
4008*404b540aSrobert       static const bool intl = _Intl;
4009*404b540aSrobert 
4010*404b540aSrobert       explicit
4011*404b540aSrobert       moneypunct_byname(const char* __s, size_t __refs = 0)
4012*404b540aSrobert       : moneypunct<_CharT, _Intl>(__refs)
4013*404b540aSrobert       {
4014*404b540aSrobert 	if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
4015*404b540aSrobert 	  {
4016*404b540aSrobert 	    __c_locale __tmp;
4017*404b540aSrobert 	    this->_S_create_c_locale(__tmp, __s);
4018*404b540aSrobert 	    this->_M_initialize_moneypunct(__tmp);
4019*404b540aSrobert 	    this->_S_destroy_c_locale(__tmp);
4020*404b540aSrobert 	  }
4021*404b540aSrobert       }
4022*404b540aSrobert 
4023*404b540aSrobert     protected:
4024*404b540aSrobert       virtual
~moneypunct_byname()4025*404b540aSrobert       ~moneypunct_byname() { }
4026*404b540aSrobert     };
4027*404b540aSrobert 
4028*404b540aSrobert   template<typename _CharT, bool _Intl>
4029*404b540aSrobert     const bool moneypunct_byname<_CharT, _Intl>::intl;
4030*404b540aSrobert 
4031*404b540aSrobert _GLIBCXX_BEGIN_LDBL_NAMESPACE
4032*404b540aSrobert   /**
4033*404b540aSrobert    *  @brief  Facet for parsing monetary amounts.
4034*404b540aSrobert    *
4035*404b540aSrobert    *  This facet encapsulates the code to parse and return a monetary
4036*404b540aSrobert    *  amount from a string.
4037*404b540aSrobert    *
4038*404b540aSrobert    *  The money_get template uses protected virtual functions to
4039*404b540aSrobert    *  provide the actual results.  The public accessors forward the
4040*404b540aSrobert    *  call to the virtual functions.  These virtual functions are
4041*404b540aSrobert    *  hooks for developers to implement the behavior they require from
4042*404b540aSrobert    *  the money_get facet.
4043*404b540aSrobert   */
4044*404b540aSrobert   template<typename _CharT, typename _InIter>
4045*404b540aSrobert     class money_get : public locale::facet
4046*404b540aSrobert     {
4047*404b540aSrobert     public:
4048*404b540aSrobert       // Types:
4049*404b540aSrobert       //@{
4050*404b540aSrobert       /// Public typedefs
4051*404b540aSrobert       typedef _CharT			char_type;
4052*404b540aSrobert       typedef _InIter			iter_type;
4053*404b540aSrobert       typedef basic_string<_CharT>	string_type;
4054*404b540aSrobert       //@}
4055*404b540aSrobert 
4056*404b540aSrobert       /// Numpunct facet id.
4057*404b540aSrobert       static locale::id			id;
4058*404b540aSrobert 
4059*404b540aSrobert       /**
4060*404b540aSrobert        *  @brief  Constructor performs initialization.
4061*404b540aSrobert        *
4062*404b540aSrobert        *  This is the constructor provided by the standard.
4063*404b540aSrobert        *
4064*404b540aSrobert        *  @param refs  Passed to the base facet class.
4065*404b540aSrobert       */
4066*404b540aSrobert       explicit
facet(__refs)4067*404b540aSrobert       money_get(size_t __refs = 0) : facet(__refs) { }
4068*404b540aSrobert 
4069*404b540aSrobert       /**
4070*404b540aSrobert        *  @brief  Read and parse a monetary value.
4071*404b540aSrobert        *
4072*404b540aSrobert        *  This function reads characters from @a s, interprets them as a
4073*404b540aSrobert        *  monetary value according to moneypunct and ctype facets retrieved
4074*404b540aSrobert        *  from io.getloc(), and returns the result in @a units as an integral
4075*404b540aSrobert        *  value moneypunct::frac_digits() * the actual amount.  For example,
4076*404b540aSrobert        *  the string $10.01 in a US locale would store 1001 in @a units.
4077*404b540aSrobert        *
4078*404b540aSrobert        *  Any characters not part of a valid money amount are not consumed.
4079*404b540aSrobert        *
4080*404b540aSrobert        *  If a money value cannot be parsed from the input stream, sets
4081*404b540aSrobert        *  err=(err|io.failbit).  If the stream is consumed before finishing
4082*404b540aSrobert        *  parsing,  sets err=(err|io.failbit|io.eofbit).  @a units is
4083*404b540aSrobert        *  unchanged if parsing fails.
4084*404b540aSrobert        *
4085*404b540aSrobert        *  This function works by returning the result of do_get().
4086*404b540aSrobert        *
4087*404b540aSrobert        *  @param  s  Start of characters to parse.
4088*404b540aSrobert        *  @param  end  End of characters to parse.
4089*404b540aSrobert        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
4090*404b540aSrobert        *  @param  io  Source of facets and io state.
4091*404b540aSrobert        *  @param  err  Error field to set if parsing fails.
4092*404b540aSrobert        *  @param  units  Place to store result of parsing.
4093*404b540aSrobert        *  @return  Iterator referencing first character beyond valid money
4094*404b540aSrobert        *	   amount.
4095*404b540aSrobert        */
4096*404b540aSrobert       iter_type
get(iter_type __s,iter_type __end,bool __intl,ios_base & __io,ios_base::iostate & __err,long double & __units)4097*404b540aSrobert       get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4098*404b540aSrobert 	  ios_base::iostate& __err, long double& __units) const
4099*404b540aSrobert       { return this->do_get(__s, __end, __intl, __io, __err, __units); }
4100*404b540aSrobert 
4101*404b540aSrobert       /**
4102*404b540aSrobert        *  @brief  Read and parse a monetary value.
4103*404b540aSrobert        *
4104*404b540aSrobert        *  This function reads characters from @a s, interprets them as a
4105*404b540aSrobert        *  monetary value according to moneypunct and ctype facets retrieved
4106*404b540aSrobert        *  from io.getloc(), and returns the result in @a digits.  For example,
4107*404b540aSrobert        *  the string $10.01 in a US locale would store "1001" in @a digits.
4108*404b540aSrobert        *
4109*404b540aSrobert        *  Any characters not part of a valid money amount are not consumed.
4110*404b540aSrobert        *
4111*404b540aSrobert        *  If a money value cannot be parsed from the input stream, sets
4112*404b540aSrobert        *  err=(err|io.failbit).  If the stream is consumed before finishing
4113*404b540aSrobert        *  parsing,  sets err=(err|io.failbit|io.eofbit).
4114*404b540aSrobert        *
4115*404b540aSrobert        *  This function works by returning the result of do_get().
4116*404b540aSrobert        *
4117*404b540aSrobert        *  @param  s  Start of characters to parse.
4118*404b540aSrobert        *  @param  end  End of characters to parse.
4119*404b540aSrobert        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
4120*404b540aSrobert        *  @param  io  Source of facets and io state.
4121*404b540aSrobert        *  @param  err  Error field to set if parsing fails.
4122*404b540aSrobert        *  @param  digits  Place to store result of parsing.
4123*404b540aSrobert        *  @return  Iterator referencing first character beyond valid money
4124*404b540aSrobert        *	   amount.
4125*404b540aSrobert        */
4126*404b540aSrobert       iter_type
get(iter_type __s,iter_type __end,bool __intl,ios_base & __io,ios_base::iostate & __err,string_type & __digits)4127*404b540aSrobert       get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4128*404b540aSrobert 	  ios_base::iostate& __err, string_type& __digits) const
4129*404b540aSrobert       { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
4130*404b540aSrobert 
4131*404b540aSrobert     protected:
4132*404b540aSrobert       /// Destructor.
4133*404b540aSrobert       virtual
~money_get()4134*404b540aSrobert       ~money_get() { }
4135*404b540aSrobert 
4136*404b540aSrobert       /**
4137*404b540aSrobert        *  @brief  Read and parse a monetary value.
4138*404b540aSrobert        *
4139*404b540aSrobert        *  This function reads and parses characters representing a monetary
4140*404b540aSrobert        *  value.  This function is a hook for derived classes to change the
4141*404b540aSrobert        *  value returned.  @see get() for details.
4142*404b540aSrobert        */
4143*404b540aSrobert       // XXX GLIBCXX_ABI Deprecated
4144*404b540aSrobert #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4145*404b540aSrobert       virtual iter_type
4146*404b540aSrobert       __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4147*404b540aSrobert 	       ios_base::iostate& __err, double& __units) const;
4148*404b540aSrobert #else
4149*404b540aSrobert       virtual iter_type
4150*404b540aSrobert       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4151*404b540aSrobert 	     ios_base::iostate& __err, long double& __units) const;
4152*404b540aSrobert #endif
4153*404b540aSrobert 
4154*404b540aSrobert       /**
4155*404b540aSrobert        *  @brief  Read and parse a monetary value.
4156*404b540aSrobert        *
4157*404b540aSrobert        *  This function reads and parses characters representing a monetary
4158*404b540aSrobert        *  value.  This function is a hook for derived classes to change the
4159*404b540aSrobert        *  value returned.  @see get() for details.
4160*404b540aSrobert        */
4161*404b540aSrobert       virtual iter_type
4162*404b540aSrobert       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4163*404b540aSrobert 	     ios_base::iostate& __err, string_type& __digits) const;
4164*404b540aSrobert 
4165*404b540aSrobert       // XXX GLIBCXX_ABI Deprecated
4166*404b540aSrobert #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4167*404b540aSrobert       virtual iter_type
4168*404b540aSrobert       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4169*404b540aSrobert 	     ios_base::iostate& __err, long double& __units) const;
4170*404b540aSrobert #endif
4171*404b540aSrobert 
4172*404b540aSrobert       template<bool _Intl>
4173*404b540aSrobert         iter_type
4174*404b540aSrobert         _M_extract(iter_type __s, iter_type __end, ios_base& __io,
4175*404b540aSrobert 		   ios_base::iostate& __err, string& __digits) const;
4176*404b540aSrobert     };
4177*404b540aSrobert 
4178*404b540aSrobert   template<typename _CharT, typename _InIter>
4179*404b540aSrobert     locale::id money_get<_CharT, _InIter>::id;
4180*404b540aSrobert 
4181*404b540aSrobert   /**
4182*404b540aSrobert    *  @brief  Facet for outputting monetary amounts.
4183*404b540aSrobert    *
4184*404b540aSrobert    *  This facet encapsulates the code to format and output a monetary
4185*404b540aSrobert    *  amount.
4186*404b540aSrobert    *
4187*404b540aSrobert    *  The money_put template uses protected virtual functions to
4188*404b540aSrobert    *  provide the actual results.  The public accessors forward the
4189*404b540aSrobert    *  call to the virtual functions.  These virtual functions are
4190*404b540aSrobert    *  hooks for developers to implement the behavior they require from
4191*404b540aSrobert    *  the money_put facet.
4192*404b540aSrobert   */
4193*404b540aSrobert   template<typename _CharT, typename _OutIter>
4194*404b540aSrobert     class money_put : public locale::facet
4195*404b540aSrobert     {
4196*404b540aSrobert     public:
4197*404b540aSrobert       //@{
4198*404b540aSrobert       /// Public typedefs
4199*404b540aSrobert       typedef _CharT			char_type;
4200*404b540aSrobert       typedef _OutIter			iter_type;
4201*404b540aSrobert       typedef basic_string<_CharT>	string_type;
4202*404b540aSrobert       //@}
4203*404b540aSrobert 
4204*404b540aSrobert       /// Numpunct facet id.
4205*404b540aSrobert       static locale::id			id;
4206*404b540aSrobert 
4207*404b540aSrobert       /**
4208*404b540aSrobert        *  @brief  Constructor performs initialization.
4209*404b540aSrobert        *
4210*404b540aSrobert        *  This is the constructor provided by the standard.
4211*404b540aSrobert        *
4212*404b540aSrobert        *  @param refs  Passed to the base facet class.
4213*404b540aSrobert       */
4214*404b540aSrobert       explicit
facet(__refs)4215*404b540aSrobert       money_put(size_t __refs = 0) : facet(__refs) { }
4216*404b540aSrobert 
4217*404b540aSrobert       /**
4218*404b540aSrobert        *  @brief  Format and output a monetary value.
4219*404b540aSrobert        *
4220*404b540aSrobert        *  This function formats @a units as a monetary value according to
4221*404b540aSrobert        *  moneypunct and ctype facets retrieved from io.getloc(), and writes
4222*404b540aSrobert        *  the resulting characters to @a s.  For example, the value 1001 in a
4223*404b540aSrobert        *  US locale would write "$10.01" to @a s.
4224*404b540aSrobert        *
4225*404b540aSrobert        *  This function works by returning the result of do_put().
4226*404b540aSrobert        *
4227*404b540aSrobert        *  @param  s  The stream to write to.
4228*404b540aSrobert        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
4229*404b540aSrobert        *  @param  io  Source of facets and io state.
4230*404b540aSrobert        *  @param  fill  char_type to use for padding.
4231*404b540aSrobert        *  @param  units  Place to store result of parsing.
4232*404b540aSrobert        *  @return  Iterator after writing.
4233*404b540aSrobert        */
4234*404b540aSrobert       iter_type
put(iter_type __s,bool __intl,ios_base & __io,char_type __fill,long double __units)4235*404b540aSrobert       put(iter_type __s, bool __intl, ios_base& __io,
4236*404b540aSrobert 	  char_type __fill, long double __units) const
4237*404b540aSrobert       { return this->do_put(__s, __intl, __io, __fill, __units); }
4238*404b540aSrobert 
4239*404b540aSrobert       /**
4240*404b540aSrobert        *  @brief  Format and output a monetary value.
4241*404b540aSrobert        *
4242*404b540aSrobert        *  This function formats @a digits as a monetary value according to
4243*404b540aSrobert        *  moneypunct and ctype facets retrieved from io.getloc(), and writes
4244*404b540aSrobert        *  the resulting characters to @a s.  For example, the string "1001" in
4245*404b540aSrobert        *  a US locale would write "$10.01" to @a s.
4246*404b540aSrobert        *
4247*404b540aSrobert        *  This function works by returning the result of do_put().
4248*404b540aSrobert        *
4249*404b540aSrobert        *  @param  s  The stream to write to.
4250*404b540aSrobert        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
4251*404b540aSrobert        *  @param  io  Source of facets and io state.
4252*404b540aSrobert        *  @param  fill  char_type to use for padding.
4253*404b540aSrobert        *  @param  units  Place to store result of parsing.
4254*404b540aSrobert        *  @return  Iterator after writing.
4255*404b540aSrobert        */
4256*404b540aSrobert       iter_type
put(iter_type __s,bool __intl,ios_base & __io,char_type __fill,const string_type & __digits)4257*404b540aSrobert       put(iter_type __s, bool __intl, ios_base& __io,
4258*404b540aSrobert 	  char_type __fill, const string_type& __digits) const
4259*404b540aSrobert       { return this->do_put(__s, __intl, __io, __fill, __digits); }
4260*404b540aSrobert 
4261*404b540aSrobert     protected:
4262*404b540aSrobert       /// Destructor.
4263*404b540aSrobert       virtual
~money_put()4264*404b540aSrobert       ~money_put() { }
4265*404b540aSrobert 
4266*404b540aSrobert       /**
4267*404b540aSrobert        *  @brief  Format and output a monetary value.
4268*404b540aSrobert        *
4269*404b540aSrobert        *  This function formats @a units as a monetary value according to
4270*404b540aSrobert        *  moneypunct and ctype facets retrieved from io.getloc(), and writes
4271*404b540aSrobert        *  the resulting characters to @a s.  For example, the value 1001 in a
4272*404b540aSrobert        *  US locale would write "$10.01" to @a s.
4273*404b540aSrobert        *
4274*404b540aSrobert        *  This function is a hook for derived classes to change the value
4275*404b540aSrobert        *  returned.  @see put().
4276*404b540aSrobert        *
4277*404b540aSrobert        *  @param  s  The stream to write to.
4278*404b540aSrobert        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
4279*404b540aSrobert        *  @param  io  Source of facets and io state.
4280*404b540aSrobert        *  @param  fill  char_type to use for padding.
4281*404b540aSrobert        *  @param  units  Place to store result of parsing.
4282*404b540aSrobert        *  @return  Iterator after writing.
4283*404b540aSrobert        */
4284*404b540aSrobert       // XXX GLIBCXX_ABI Deprecated
4285*404b540aSrobert #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4286*404b540aSrobert       virtual iter_type
4287*404b540aSrobert       __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4288*404b540aSrobert 	       double __units) const;
4289*404b540aSrobert #else
4290*404b540aSrobert       virtual iter_type
4291*404b540aSrobert       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4292*404b540aSrobert 	     long double __units) const;
4293*404b540aSrobert #endif
4294*404b540aSrobert 
4295*404b540aSrobert       /**
4296*404b540aSrobert        *  @brief  Format and output a monetary value.
4297*404b540aSrobert        *
4298*404b540aSrobert        *  This function formats @a digits as a monetary value according to
4299*404b540aSrobert        *  moneypunct and ctype facets retrieved from io.getloc(), and writes
4300*404b540aSrobert        *  the resulting characters to @a s.  For example, the string "1001" in
4301*404b540aSrobert        *  a US locale would write "$10.01" to @a s.
4302*404b540aSrobert        *
4303*404b540aSrobert        *  This function is a hook for derived classes to change the value
4304*404b540aSrobert        *  returned.  @see put().
4305*404b540aSrobert        *
4306*404b540aSrobert        *  @param  s  The stream to write to.
4307*404b540aSrobert        *  @param  intl  Parameter to use_facet<moneypunct<CharT,intl> >.
4308*404b540aSrobert        *  @param  io  Source of facets and io state.
4309*404b540aSrobert        *  @param  fill  char_type to use for padding.
4310*404b540aSrobert        *  @param  units  Place to store result of parsing.
4311*404b540aSrobert        *  @return  Iterator after writing.
4312*404b540aSrobert        */
4313*404b540aSrobert       virtual iter_type
4314*404b540aSrobert       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4315*404b540aSrobert 	     const string_type& __digits) const;
4316*404b540aSrobert 
4317*404b540aSrobert       // XXX GLIBCXX_ABI Deprecated
4318*404b540aSrobert #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4319*404b540aSrobert       virtual iter_type
4320*404b540aSrobert       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4321*404b540aSrobert 	     long double __units) const;
4322*404b540aSrobert #endif
4323*404b540aSrobert 
4324*404b540aSrobert       template<bool _Intl>
4325*404b540aSrobert         iter_type
4326*404b540aSrobert         _M_insert(iter_type __s, ios_base& __io, char_type __fill,
4327*404b540aSrobert 		  const string_type& __digits) const;
4328*404b540aSrobert     };
4329*404b540aSrobert 
4330*404b540aSrobert   template<typename _CharT, typename _OutIter>
4331*404b540aSrobert     locale::id money_put<_CharT, _OutIter>::id;
4332*404b540aSrobert 
4333*404b540aSrobert _GLIBCXX_END_LDBL_NAMESPACE
4334*404b540aSrobert 
4335*404b540aSrobert   /**
4336*404b540aSrobert    *  @brief  Messages facet base class providing catalog typedef.
4337*404b540aSrobert    */
4338*404b540aSrobert   struct messages_base
4339*404b540aSrobert   {
4340*404b540aSrobert     typedef int catalog;
4341*404b540aSrobert   };
4342*404b540aSrobert 
4343*404b540aSrobert   /**
4344*404b540aSrobert    *  @brief  Facet for handling message catalogs
4345*404b540aSrobert    *
4346*404b540aSrobert    *  This facet encapsulates the code to retrieve messages from
4347*404b540aSrobert    *  message catalogs.  The only thing defined by the standard for this facet
4348*404b540aSrobert    *  is the interface.  All underlying functionality is
4349*404b540aSrobert    *  implementation-defined.
4350*404b540aSrobert    *
4351*404b540aSrobert    *  This library currently implements 3 versions of the message facet.  The
4352*404b540aSrobert    *  first version (gnu) is a wrapper around gettext, provided by libintl.
4353*404b540aSrobert    *  The second version (ieee) is a wrapper around catgets.  The final
4354*404b540aSrobert    *  version (default) does no actual translation.  These implementations are
4355*404b540aSrobert    *  only provided for char and wchar_t instantiations.
4356*404b540aSrobert    *
4357*404b540aSrobert    *  The messages template uses protected virtual functions to
4358*404b540aSrobert    *  provide the actual results.  The public accessors forward the
4359*404b540aSrobert    *  call to the virtual functions.  These virtual functions are
4360*404b540aSrobert    *  hooks for developers to implement the behavior they require from
4361*404b540aSrobert    *  the messages facet.
4362*404b540aSrobert   */
4363*404b540aSrobert   template<typename _CharT>
4364*404b540aSrobert     class messages : public locale::facet, public messages_base
4365*404b540aSrobert     {
4366*404b540aSrobert     public:
4367*404b540aSrobert       // Types:
4368*404b540aSrobert       //@{
4369*404b540aSrobert       /// Public typedefs
4370*404b540aSrobert       typedef _CharT			char_type;
4371*404b540aSrobert       typedef basic_string<_CharT>	string_type;
4372*404b540aSrobert       //@}
4373*404b540aSrobert 
4374*404b540aSrobert     protected:
4375*404b540aSrobert       // Underlying "C" library locale information saved from
4376*404b540aSrobert       // initialization, needed by messages_byname as well.
4377*404b540aSrobert       __c_locale			_M_c_locale_messages;
4378*404b540aSrobert       const char*			_M_name_messages;
4379*404b540aSrobert 
4380*404b540aSrobert     public:
4381*404b540aSrobert       /// Numpunct facet id.
4382*404b540aSrobert       static locale::id			id;
4383*404b540aSrobert 
4384*404b540aSrobert       /**
4385*404b540aSrobert        *  @brief  Constructor performs initialization.
4386*404b540aSrobert        *
4387*404b540aSrobert        *  This is the constructor provided by the standard.
4388*404b540aSrobert        *
4389*404b540aSrobert        *  @param refs  Passed to the base facet class.
4390*404b540aSrobert       */
4391*404b540aSrobert       explicit
4392*404b540aSrobert       messages(size_t __refs = 0);
4393*404b540aSrobert 
4394*404b540aSrobert       // Non-standard.
4395*404b540aSrobert       /**
4396*404b540aSrobert        *  @brief  Internal constructor.  Not for general use.
4397*404b540aSrobert        *
4398*404b540aSrobert        *  This is a constructor for use by the library itself to set up new
4399*404b540aSrobert        *  locales.
4400*404b540aSrobert        *
4401*404b540aSrobert        *  @param  cloc  The "C" locale.
4402*404b540aSrobert        *  @param  s  The name of a locale.
4403*404b540aSrobert        *  @param  refs  Refcount to pass to the base class.
4404*404b540aSrobert        */
4405*404b540aSrobert       explicit
4406*404b540aSrobert       messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
4407*404b540aSrobert 
4408*404b540aSrobert       /*
4409*404b540aSrobert        *  @brief  Open a message catalog.
4410*404b540aSrobert        *
4411*404b540aSrobert        *  This function opens and returns a handle to a message catalog by
4412*404b540aSrobert        *  returning do_open(s, loc).
4413*404b540aSrobert        *
4414*404b540aSrobert        *  @param  s  The catalog to open.
4415*404b540aSrobert        *  @param  loc  Locale to use for character set conversions.
4416*404b540aSrobert        *  @return  Handle to the catalog or value < 0 if open fails.
4417*404b540aSrobert       */
4418*404b540aSrobert       catalog
open(const basic_string<char> & __s,const locale & __loc)4419*404b540aSrobert       open(const basic_string<char>& __s, const locale& __loc) const
4420*404b540aSrobert       { return this->do_open(__s, __loc); }
4421*404b540aSrobert 
4422*404b540aSrobert       // Non-standard and unorthodox, yet effective.
4423*404b540aSrobert       /*
4424*404b540aSrobert        *  @brief  Open a message catalog.
4425*404b540aSrobert        *
4426*404b540aSrobert        *  This non-standard function opens and returns a handle to a message
4427*404b540aSrobert        *  catalog by returning do_open(s, loc).  The third argument provides a
4428*404b540aSrobert        *  message catalog root directory for gnu gettext and is ignored
4429*404b540aSrobert        *  otherwise.
4430*404b540aSrobert        *
4431*404b540aSrobert        *  @param  s  The catalog to open.
4432*404b540aSrobert        *  @param  loc  Locale to use for character set conversions.
4433*404b540aSrobert        *  @param  dir  Message catalog root directory.
4434*404b540aSrobert        *  @return  Handle to the catalog or value < 0 if open fails.
4435*404b540aSrobert       */
4436*404b540aSrobert       catalog
4437*404b540aSrobert       open(const basic_string<char>&, const locale&, const char*) const;
4438*404b540aSrobert 
4439*404b540aSrobert       /*
4440*404b540aSrobert        *  @brief  Look up a string in a message catalog.
4441*404b540aSrobert        *
4442*404b540aSrobert        *  This function retrieves and returns a message from a catalog by
4443*404b540aSrobert        *  returning do_get(c, set, msgid, s).
4444*404b540aSrobert        *
4445*404b540aSrobert        *  For gnu, @a set and @a msgid are ignored.  Returns gettext(s).
4446*404b540aSrobert        *  For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4447*404b540aSrobert        *
4448*404b540aSrobert        *  @param  c  The catalog to access.
4449*404b540aSrobert        *  @param  set  Implementation-defined.
4450*404b540aSrobert        *  @param  msgid  Implementation-defined.
4451*404b540aSrobert        *  @param  s  Default return value if retrieval fails.
4452*404b540aSrobert        *  @return  Retrieved message or @a s if get fails.
4453*404b540aSrobert       */
4454*404b540aSrobert       string_type
get(catalog __c,int __set,int __msgid,const string_type & __s)4455*404b540aSrobert       get(catalog __c, int __set, int __msgid, const string_type& __s) const
4456*404b540aSrobert       { return this->do_get(__c, __set, __msgid, __s); }
4457*404b540aSrobert 
4458*404b540aSrobert       /*
4459*404b540aSrobert        *  @brief  Close a message catalog.
4460*404b540aSrobert        *
4461*404b540aSrobert        *  Closes catalog @a c by calling do_close(c).
4462*404b540aSrobert        *
4463*404b540aSrobert        *  @param  c  The catalog to close.
4464*404b540aSrobert       */
4465*404b540aSrobert       void
close(catalog __c)4466*404b540aSrobert       close(catalog __c) const
4467*404b540aSrobert       { return this->do_close(__c); }
4468*404b540aSrobert 
4469*404b540aSrobert     protected:
4470*404b540aSrobert       /// Destructor.
4471*404b540aSrobert       virtual
4472*404b540aSrobert       ~messages();
4473*404b540aSrobert 
4474*404b540aSrobert       /*
4475*404b540aSrobert        *  @brief  Open a message catalog.
4476*404b540aSrobert        *
4477*404b540aSrobert        *  This function opens and returns a handle to a message catalog in an
4478*404b540aSrobert        *  implementation-defined manner.  This function is a hook for derived
4479*404b540aSrobert        *  classes to change the value returned.
4480*404b540aSrobert        *
4481*404b540aSrobert        *  @param  s  The catalog to open.
4482*404b540aSrobert        *  @param  loc  Locale to use for character set conversions.
4483*404b540aSrobert        *  @return  Handle to the opened catalog, value < 0 if open failed.
4484*404b540aSrobert       */
4485*404b540aSrobert       virtual catalog
4486*404b540aSrobert       do_open(const basic_string<char>&, const locale&) const;
4487*404b540aSrobert 
4488*404b540aSrobert       /*
4489*404b540aSrobert        *  @brief  Look up a string in a message catalog.
4490*404b540aSrobert        *
4491*404b540aSrobert        *  This function retrieves and returns a message from a catalog in an
4492*404b540aSrobert        *  implementation-defined manner.  This function is a hook for derived
4493*404b540aSrobert        *  classes to change the value returned.
4494*404b540aSrobert        *
4495*404b540aSrobert        *  For gnu, @a set and @a msgid are ignored.  Returns gettext(s).
4496*404b540aSrobert        *  For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4497*404b540aSrobert        *
4498*404b540aSrobert        *  @param  c  The catalog to access.
4499*404b540aSrobert        *  @param  set  Implementation-defined.
4500*404b540aSrobert        *  @param  msgid  Implementation-defined.
4501*404b540aSrobert        *  @param  s  Default return value if retrieval fails.
4502*404b540aSrobert        *  @return  Retrieved message or @a s if get fails.
4503*404b540aSrobert       */
4504*404b540aSrobert       virtual string_type
4505*404b540aSrobert       do_get(catalog, int, int, const string_type& __dfault) const;
4506*404b540aSrobert 
4507*404b540aSrobert       /*
4508*404b540aSrobert        *  @brief  Close a message catalog.
4509*404b540aSrobert        *
4510*404b540aSrobert        *  @param  c  The catalog to close.
4511*404b540aSrobert       */
4512*404b540aSrobert       virtual void
4513*404b540aSrobert       do_close(catalog) const;
4514*404b540aSrobert 
4515*404b540aSrobert       // Returns a locale and codeset-converted string, given a char* message.
4516*404b540aSrobert       char*
_M_convert_to_char(const string_type & __msg)4517*404b540aSrobert       _M_convert_to_char(const string_type& __msg) const
4518*404b540aSrobert       {
4519*404b540aSrobert 	// XXX
4520*404b540aSrobert 	return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
4521*404b540aSrobert       }
4522*404b540aSrobert 
4523*404b540aSrobert       // Returns a locale and codeset-converted string, given a char* message.
4524*404b540aSrobert       string_type
_M_convert_from_char(char *)4525*404b540aSrobert       _M_convert_from_char(char*) const
4526*404b540aSrobert       {
4527*404b540aSrobert #if 0
4528*404b540aSrobert 	// Length of message string without terminating null.
4529*404b540aSrobert 	size_t __len = char_traits<char>::length(__msg) - 1;
4530*404b540aSrobert 
4531*404b540aSrobert 	// "everybody can easily convert the string using
4532*404b540aSrobert 	// mbsrtowcs/wcsrtombs or with iconv()"
4533*404b540aSrobert 
4534*404b540aSrobert 	// Convert char* to _CharT in locale used to open catalog.
4535*404b540aSrobert 	// XXX need additional template parameter on messages class for this..
4536*404b540aSrobert 	// typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
4537*404b540aSrobert 	typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;
4538*404b540aSrobert 
4539*404b540aSrobert 	__codecvt_type::state_type __state;
4540*404b540aSrobert 	// XXX may need to initialize state.
4541*404b540aSrobert 	//initialize_state(__state._M_init());
4542*404b540aSrobert 
4543*404b540aSrobert 	char* __from_next;
4544*404b540aSrobert 	// XXX what size for this string?
4545*404b540aSrobert 	_CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
4546*404b540aSrobert 	const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
4547*404b540aSrobert 	__cvt.out(__state, __msg, __msg + __len, __from_next,
4548*404b540aSrobert 		  __to, __to + __len + 1, __to_next);
4549*404b540aSrobert 	return string_type(__to);
4550*404b540aSrobert #endif
4551*404b540aSrobert #if 0
4552*404b540aSrobert 	typedef ctype<_CharT> __ctype_type;
4553*404b540aSrobert 	// const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
4554*404b540aSrobert 	const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
4555*404b540aSrobert 	// XXX Again, proper length of converted string an issue here.
4556*404b540aSrobert 	// For now, assume the converted length is not larger.
4557*404b540aSrobert 	_CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
4558*404b540aSrobert 	__cvt.widen(__msg, __msg + __len, __dest);
4559*404b540aSrobert 	return basic_string<_CharT>(__dest);
4560*404b540aSrobert #endif
4561*404b540aSrobert 	return string_type();
4562*404b540aSrobert       }
4563*404b540aSrobert      };
4564*404b540aSrobert 
4565*404b540aSrobert   template<typename _CharT>
4566*404b540aSrobert     locale::id messages<_CharT>::id;
4567*404b540aSrobert 
4568*404b540aSrobert   // Specializations for required instantiations.
4569*404b540aSrobert   template<>
4570*404b540aSrobert     string
4571*404b540aSrobert     messages<char>::do_get(catalog, int, int, const string&) const;
4572*404b540aSrobert 
4573*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T
4574*404b540aSrobert   template<>
4575*404b540aSrobert     wstring
4576*404b540aSrobert     messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
4577*404b540aSrobert #endif
4578*404b540aSrobert 
4579*404b540aSrobert    /// @brief class messages_byname [22.2.7.2].
4580*404b540aSrobert    template<typename _CharT>
4581*404b540aSrobert     class messages_byname : public messages<_CharT>
4582*404b540aSrobert     {
4583*404b540aSrobert     public:
4584*404b540aSrobert       typedef _CharT			char_type;
4585*404b540aSrobert       typedef basic_string<_CharT>	string_type;
4586*404b540aSrobert 
4587*404b540aSrobert       explicit
4588*404b540aSrobert       messages_byname(const char* __s, size_t __refs = 0);
4589*404b540aSrobert 
4590*404b540aSrobert     protected:
4591*404b540aSrobert       virtual
~messages_byname()4592*404b540aSrobert       ~messages_byname()
4593*404b540aSrobert       { }
4594*404b540aSrobert     };
4595*404b540aSrobert 
4596*404b540aSrobert _GLIBCXX_END_NAMESPACE
4597*404b540aSrobert 
4598*404b540aSrobert   // Include host and configuration specific messages functions.
4599*404b540aSrobert   #include <bits/messages_members.h>
4600*404b540aSrobert 
_GLIBCXX_BEGIN_NAMESPACE(std)4601*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
4602*404b540aSrobert 
4603*404b540aSrobert   // Subclause convenience interfaces, inlines.
4604*404b540aSrobert   // NB: These are inline because, when used in a loop, some compilers
4605*404b540aSrobert   // can hoist the body out of the loop; then it's just as fast as the
4606*404b540aSrobert   // C is*() function.
4607*404b540aSrobert 
4608*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::space, __c).
4609*404b540aSrobert   template<typename _CharT>
4610*404b540aSrobert     inline bool
4611*404b540aSrobert     isspace(_CharT __c, const locale& __loc)
4612*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
4613*404b540aSrobert 
4614*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::print, __c).
4615*404b540aSrobert   template<typename _CharT>
4616*404b540aSrobert     inline bool
isprint(_CharT __c,const locale & __loc)4617*404b540aSrobert     isprint(_CharT __c, const locale& __loc)
4618*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
4619*404b540aSrobert 
4620*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::cntrl, __c).
4621*404b540aSrobert   template<typename _CharT>
4622*404b540aSrobert     inline bool
iscntrl(_CharT __c,const locale & __loc)4623*404b540aSrobert     iscntrl(_CharT __c, const locale& __loc)
4624*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
4625*404b540aSrobert 
4626*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::upper, __c).
4627*404b540aSrobert   template<typename _CharT>
4628*404b540aSrobert     inline bool
isupper(_CharT __c,const locale & __loc)4629*404b540aSrobert     isupper(_CharT __c, const locale& __loc)
4630*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
4631*404b540aSrobert 
4632*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::lower, __c).
4633*404b540aSrobert   template<typename _CharT>
4634*404b540aSrobert     inline bool
islower(_CharT __c,const locale & __loc)4635*404b540aSrobert     islower(_CharT __c, const locale& __loc)
4636*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
4637*404b540aSrobert 
4638*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::alpha, __c).
4639*404b540aSrobert   template<typename _CharT>
4640*404b540aSrobert     inline bool
isalpha(_CharT __c,const locale & __loc)4641*404b540aSrobert     isalpha(_CharT __c, const locale& __loc)
4642*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
4643*404b540aSrobert 
4644*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::digit, __c).
4645*404b540aSrobert   template<typename _CharT>
4646*404b540aSrobert     inline bool
isdigit(_CharT __c,const locale & __loc)4647*404b540aSrobert     isdigit(_CharT __c, const locale& __loc)
4648*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
4649*404b540aSrobert 
4650*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::punct, __c).
4651*404b540aSrobert   template<typename _CharT>
4652*404b540aSrobert     inline bool
ispunct(_CharT __c,const locale & __loc)4653*404b540aSrobert     ispunct(_CharT __c, const locale& __loc)
4654*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
4655*404b540aSrobert 
4656*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::xdigit, __c).
4657*404b540aSrobert   template<typename _CharT>
4658*404b540aSrobert     inline bool
isxdigit(_CharT __c,const locale & __loc)4659*404b540aSrobert     isxdigit(_CharT __c, const locale& __loc)
4660*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
4661*404b540aSrobert 
4662*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::alnum, __c).
4663*404b540aSrobert   template<typename _CharT>
4664*404b540aSrobert     inline bool
isalnum(_CharT __c,const locale & __loc)4665*404b540aSrobert     isalnum(_CharT __c, const locale& __loc)
4666*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
4667*404b540aSrobert 
4668*404b540aSrobert   /// Convenience interface to ctype.is(ctype_base::graph, __c).
4669*404b540aSrobert   template<typename _CharT>
4670*404b540aSrobert     inline bool
isgraph(_CharT __c,const locale & __loc)4671*404b540aSrobert     isgraph(_CharT __c, const locale& __loc)
4672*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
4673*404b540aSrobert 
4674*404b540aSrobert   /// Convenience interface to ctype.toupper(__c).
4675*404b540aSrobert   template<typename _CharT>
4676*404b540aSrobert     inline _CharT
toupper(_CharT __c,const locale & __loc)4677*404b540aSrobert     toupper(_CharT __c, const locale& __loc)
4678*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
4679*404b540aSrobert 
4680*404b540aSrobert   /// Convenience interface to ctype.tolower(__c).
4681*404b540aSrobert   template<typename _CharT>
4682*404b540aSrobert     inline _CharT
tolower(_CharT __c,const locale & __loc)4683*404b540aSrobert     tolower(_CharT __c, const locale& __loc)
4684*404b540aSrobert     { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
4685*404b540aSrobert 
4686*404b540aSrobert _GLIBCXX_END_NAMESPACE
4687*404b540aSrobert 
4688*404b540aSrobert #endif
4689