xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/include/bits/locale_facets_nonio.h (revision 9fb66d812c00ebfb445c0b47dea128f32aa6fe96)
1 // Locale support -*- C++ -*-
2 
3 // Copyright (C) 2007-2019 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /** @file bits/locale_facets_nonio.h
26  *  This is an internal header file, included by other library headers.
27  *  Do not attempt to use it directly. @headername{locale}
28  */
29 
30 //
31 // ISO C++ 14882: 22.1  Locales
32 //
33 
34 #ifndef _LOCALE_FACETS_NONIO_H
35 #define _LOCALE_FACETS_NONIO_H 1
36 
37 #pragma GCC system_header
38 
39 #include <ctime>	// For struct tm
40 
41 namespace std _GLIBCXX_VISIBILITY(default)
42 {
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
44 
45   /**
46    *  @brief  Time format ordering data.
47    *  @ingroup locales
48    *
49    *  This class provides an enum representing different orderings of
50    *  time: day, month, and year.
51   */
52   class time_base
53   {
54   public:
55     enum dateorder { no_order, dmy, mdy, ymd, ydm };
56   };
57 
58   template<typename _CharT>
59     struct __timepunct_cache : public locale::facet
60     {
61       // List of all known timezones, with GMT first.
62       static const _CharT*		_S_timezones[14];
63 
64       const _CharT*			_M_date_format;
65       const _CharT*			_M_date_era_format;
66       const _CharT*			_M_time_format;
67       const _CharT*			_M_time_era_format;
68       const _CharT*			_M_date_time_format;
69       const _CharT*			_M_date_time_era_format;
70       const _CharT*			_M_am;
71       const _CharT*			_M_pm;
72       const _CharT*			_M_am_pm_format;
73 
74       // Day names, starting with "C"'s Sunday.
75       const _CharT*			_M_day1;
76       const _CharT*			_M_day2;
77       const _CharT*			_M_day3;
78       const _CharT*			_M_day4;
79       const _CharT*			_M_day5;
80       const _CharT*			_M_day6;
81       const _CharT*			_M_day7;
82 
83       // Abbreviated day names, starting with "C"'s Sun.
84       const _CharT*			_M_aday1;
85       const _CharT*			_M_aday2;
86       const _CharT*			_M_aday3;
87       const _CharT*			_M_aday4;
88       const _CharT*			_M_aday5;
89       const _CharT*			_M_aday6;
90       const _CharT*			_M_aday7;
91 
92       // Month names, starting with "C"'s January.
93       const _CharT*			_M_month01;
94       const _CharT*			_M_month02;
95       const _CharT*			_M_month03;
96       const _CharT*			_M_month04;
97       const _CharT*			_M_month05;
98       const _CharT*			_M_month06;
99       const _CharT*			_M_month07;
100       const _CharT*			_M_month08;
101       const _CharT*			_M_month09;
102       const _CharT*			_M_month10;
103       const _CharT*			_M_month11;
104       const _CharT*			_M_month12;
105 
106       // Abbreviated month names, starting with "C"'s Jan.
107       const _CharT*			_M_amonth01;
108       const _CharT*			_M_amonth02;
109       const _CharT*			_M_amonth03;
110       const _CharT*			_M_amonth04;
111       const _CharT*			_M_amonth05;
112       const _CharT*			_M_amonth06;
113       const _CharT*			_M_amonth07;
114       const _CharT*			_M_amonth08;
115       const _CharT*			_M_amonth09;
116       const _CharT*			_M_amonth10;
117       const _CharT*			_M_amonth11;
118       const _CharT*			_M_amonth12;
119 
120       bool				_M_allocated;
121 
122       __timepunct_cache(size_t __refs = 0) : facet(__refs),
123       _M_date_format(0), _M_date_era_format(0), _M_time_format(0),
124       _M_time_era_format(0), _M_date_time_format(0),
125       _M_date_time_era_format(0), _M_am(0), _M_pm(0),
126       _M_am_pm_format(0), _M_day1(0), _M_day2(0), _M_day3(0),
127       _M_day4(0), _M_day5(0), _M_day6(0), _M_day7(0),
128       _M_aday1(0), _M_aday2(0), _M_aday3(0), _M_aday4(0),
129       _M_aday5(0), _M_aday6(0), _M_aday7(0), _M_month01(0),
130       _M_month02(0), _M_month03(0), _M_month04(0), _M_month05(0),
131       _M_month06(0), _M_month07(0), _M_month08(0), _M_month09(0),
132       _M_month10(0), _M_month11(0), _M_month12(0), _M_amonth01(0),
133       _M_amonth02(0), _M_amonth03(0), _M_amonth04(0),
134       _M_amonth05(0), _M_amonth06(0), _M_amonth07(0),
135       _M_amonth08(0), _M_amonth09(0), _M_amonth10(0),
136       _M_amonth11(0), _M_amonth12(0), _M_allocated(false)
137       { }
138 
139       ~__timepunct_cache();
140 
141     private:
142       __timepunct_cache&
143       operator=(const __timepunct_cache&);
144 
145       explicit
146       __timepunct_cache(const __timepunct_cache&);
147     };
148 
149   template<typename _CharT>
150     __timepunct_cache<_CharT>::~__timepunct_cache()
151     {
152       if (_M_allocated)
153 	{
154 	  // Unused.
155 	}
156     }
157 
158   // Specializations.
159   template<>
160     const char*
161     __timepunct_cache<char>::_S_timezones[14];
162 
163 #ifdef _GLIBCXX_USE_WCHAR_T
164   template<>
165     const wchar_t*
166     __timepunct_cache<wchar_t>::_S_timezones[14];
167 #endif
168 
169   // Generic.
170   template<typename _CharT>
171     const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
172 
173   template<typename _CharT>
174     class __timepunct : public locale::facet
175     {
176     public:
177       // Types:
178       typedef _CharT			__char_type;
179       typedef __timepunct_cache<_CharT>	__cache_type;
180 
181     protected:
182       __cache_type*			_M_data;
183       __c_locale			_M_c_locale_timepunct;
184       const char*			_M_name_timepunct;
185 
186     public:
187       /// Numpunct facet id.
188       static locale::id			id;
189 
190       explicit
191       __timepunct(size_t __refs = 0);
192 
193       explicit
194       __timepunct(__cache_type* __cache, size_t __refs = 0);
195 
196       /**
197        *  @brief  Internal constructor. Not for general use.
198        *
199        *  This is a constructor for use by the library itself to set up new
200        *  locales.
201        *
202        *  @param __cloc  The C locale.
203        *  @param __s  The name of a locale.
204        *  @param refs  Passed to the base facet class.
205       */
206       explicit
207       __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
208 
209       // FIXME: for error checking purposes _M_put should return the return
210       // value of strftime/wcsftime.
211       void
212       _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
213 	     const tm* __tm) const throw ();
214 
215       void
216       _M_date_formats(const _CharT** __date) const
217       {
218 	// Always have default first.
219 	__date[0] = _M_data->_M_date_format;
220 	__date[1] = _M_data->_M_date_era_format;
221       }
222 
223       void
224       _M_time_formats(const _CharT** __time) const
225       {
226 	// Always have default first.
227 	__time[0] = _M_data->_M_time_format;
228 	__time[1] = _M_data->_M_time_era_format;
229       }
230 
231       void
232       _M_date_time_formats(const _CharT** __dt) const
233       {
234 	// Always have default first.
235 	__dt[0] = _M_data->_M_date_time_format;
236 	__dt[1] = _M_data->_M_date_time_era_format;
237       }
238 
239 #if !_GLIBCXX_INLINE_VERSION
240       void
241       _M_am_pm_format(const _CharT*) const
242       { /* Kept for ABI compatibility, see PR65927 */ }
243 #endif
244 
245       void
246       _M_am_pm(const _CharT** __ampm) const
247       {
248 	__ampm[0] = _M_data->_M_am;
249 	__ampm[1] = _M_data->_M_pm;
250       }
251 
252       void
253       _M_days(const _CharT** __days) const
254       {
255 	__days[0] = _M_data->_M_day1;
256 	__days[1] = _M_data->_M_day2;
257 	__days[2] = _M_data->_M_day3;
258 	__days[3] = _M_data->_M_day4;
259 	__days[4] = _M_data->_M_day5;
260 	__days[5] = _M_data->_M_day6;
261 	__days[6] = _M_data->_M_day7;
262       }
263 
264       void
265       _M_days_abbreviated(const _CharT** __days) const
266       {
267 	__days[0] = _M_data->_M_aday1;
268 	__days[1] = _M_data->_M_aday2;
269 	__days[2] = _M_data->_M_aday3;
270 	__days[3] = _M_data->_M_aday4;
271 	__days[4] = _M_data->_M_aday5;
272 	__days[5] = _M_data->_M_aday6;
273 	__days[6] = _M_data->_M_aday7;
274       }
275 
276       void
277       _M_months(const _CharT** __months) const
278       {
279 	__months[0] = _M_data->_M_month01;
280 	__months[1] = _M_data->_M_month02;
281 	__months[2] = _M_data->_M_month03;
282 	__months[3] = _M_data->_M_month04;
283 	__months[4] = _M_data->_M_month05;
284 	__months[5] = _M_data->_M_month06;
285 	__months[6] = _M_data->_M_month07;
286 	__months[7] = _M_data->_M_month08;
287 	__months[8] = _M_data->_M_month09;
288 	__months[9] = _M_data->_M_month10;
289 	__months[10] = _M_data->_M_month11;
290 	__months[11] = _M_data->_M_month12;
291       }
292 
293       void
294       _M_months_abbreviated(const _CharT** __months) const
295       {
296 	__months[0] = _M_data->_M_amonth01;
297 	__months[1] = _M_data->_M_amonth02;
298 	__months[2] = _M_data->_M_amonth03;
299 	__months[3] = _M_data->_M_amonth04;
300 	__months[4] = _M_data->_M_amonth05;
301 	__months[5] = _M_data->_M_amonth06;
302 	__months[6] = _M_data->_M_amonth07;
303 	__months[7] = _M_data->_M_amonth08;
304 	__months[8] = _M_data->_M_amonth09;
305 	__months[9] = _M_data->_M_amonth10;
306 	__months[10] = _M_data->_M_amonth11;
307 	__months[11] = _M_data->_M_amonth12;
308       }
309 
310     protected:
311       virtual
312       ~__timepunct();
313 
314       // For use at construction time only.
315       void
316       _M_initialize_timepunct(__c_locale __cloc = 0);
317     };
318 
319   template<typename _CharT>
320     locale::id __timepunct<_CharT>::id;
321 
322   // Specializations.
323   template<>
324     void
325     __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
326 
327   template<>
328     void
329     __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const throw ();
330 
331 #ifdef _GLIBCXX_USE_WCHAR_T
332   template<>
333     __timepunct<wchar_t>::~__timepunct();
334   template<>
335     void
336     __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
337 
338   template<>
339     void
340     __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
341 				 const tm*) const throw ();
342 #endif
343 
344 _GLIBCXX_END_NAMESPACE_VERSION
345 } // namespace
346 
347   // Include host and configuration specific timepunct functions.
348   #include <bits/time_members.h>
349 
350 namespace std _GLIBCXX_VISIBILITY(default)
351 {
352 _GLIBCXX_BEGIN_NAMESPACE_VERSION
353 
354 _GLIBCXX_BEGIN_NAMESPACE_CXX11
355 
356   /**
357    *  @brief  Primary class template time_get.
358    *  @ingroup locales
359    *
360    *  This facet encapsulates the code to parse and return a date or
361    *  time from a string.  It is used by the istream numeric
362    *  extraction operators.
363    *
364    *  The time_get template uses protected virtual functions to provide the
365    *  actual results.  The public accessors forward the call to the virtual
366    *  functions.  These virtual functions are hooks for developers to
367    *  implement the behavior they require from the time_get facet.
368   */
369   template<typename _CharT, typename _InIter>
370     class time_get : public locale::facet, public time_base
371     {
372     public:
373       // Types:
374       //@{
375       /// Public typedefs
376       typedef _CharT			char_type;
377       typedef _InIter			iter_type;
378       //@}
379 
380       /// Numpunct facet id.
381       static locale::id			id;
382 
383       /**
384        *  @brief  Constructor performs initialization.
385        *
386        *  This is the constructor provided by the standard.
387        *
388        *  @param __refs  Passed to the base facet class.
389       */
390       explicit
391       time_get(size_t __refs = 0)
392       : facet (__refs) { }
393 
394       /**
395        *  @brief  Return preferred order of month, day, and year.
396        *
397        *  This function returns an enum from time_base::dateorder giving the
398        *  preferred ordering if the format @a x given to time_put::put() only
399        *  uses month, day, and year.  If the format @a x for the associated
400        *  locale uses other fields, this function returns
401        *  time_base::dateorder::noorder.
402        *
403        *  NOTE: The library always returns noorder at the moment.
404        *
405        *  @return  A member of time_base::dateorder.
406       */
407       dateorder
408       date_order()  const
409       { return this->do_date_order(); }
410 
411       /**
412        *  @brief  Parse input time string.
413        *
414        *  This function parses a time according to the format @a X and puts the
415        *  results into a user-supplied struct tm.  The result is returned by
416        *  calling time_get::do_get_time().
417        *
418        *  If there is a valid time string according to format @a X, @a tm will
419        *  be filled in accordingly and the returned iterator will point to the
420        *  first character beyond the time string.  If an error occurs before
421        *  the end, err |= ios_base::failbit.  If parsing reads all the
422        *  characters, err |= ios_base::eofbit.
423        *
424        *  @param  __beg  Start of string to parse.
425        *  @param  __end  End of string to parse.
426        *  @param  __io  Source of the locale.
427        *  @param  __err  Error flags to set.
428        *  @param  __tm  Pointer to struct tm to fill in.
429        *  @return  Iterator to first char beyond time string.
430       */
431       iter_type
432       get_time(iter_type __beg, iter_type __end, ios_base& __io,
433 	       ios_base::iostate& __err, tm* __tm)  const
434       { return this->do_get_time(__beg, __end, __io, __err, __tm); }
435 
436       /**
437        *  @brief  Parse input date string.
438        *
439        *  This function parses a date according to the format @a x and puts the
440        *  results into a user-supplied struct tm.  The result is returned by
441        *  calling time_get::do_get_date().
442        *
443        *  If there is a valid date string according to format @a x, @a tm will
444        *  be filled in accordingly and the returned iterator will point to the
445        *  first character beyond the date string.  If an error occurs before
446        *  the end, err |= ios_base::failbit.  If parsing reads all the
447        *  characters, err |= ios_base::eofbit.
448        *
449        *  @param  __beg  Start of string to parse.
450        *  @param  __end  End of string to parse.
451        *  @param  __io  Source of the locale.
452        *  @param  __err  Error flags to set.
453        *  @param  __tm  Pointer to struct tm to fill in.
454        *  @return  Iterator to first char beyond date string.
455       */
456       iter_type
457       get_date(iter_type __beg, iter_type __end, ios_base& __io,
458 	       ios_base::iostate& __err, tm* __tm)  const
459       { return this->do_get_date(__beg, __end, __io, __err, __tm); }
460 
461       /**
462        *  @brief  Parse input weekday string.
463        *
464        *  This function parses a weekday name and puts the results into a
465        *  user-supplied struct tm.  The result is returned by calling
466        *  time_get::do_get_weekday().
467        *
468        *  Parsing starts by parsing an abbreviated weekday name.  If a valid
469        *  abbreviation is followed by a character that would lead to the full
470        *  weekday name, parsing continues until the full name is found or an
471        *  error occurs.  Otherwise parsing finishes at the end of the
472        *  abbreviated name.
473        *
474        *  If an error occurs before the end, err |= ios_base::failbit.  If
475        *  parsing reads all the characters, err |= ios_base::eofbit.
476        *
477        *  @param  __beg  Start of string to parse.
478        *  @param  __end  End of string to parse.
479        *  @param  __io  Source of the locale.
480        *  @param  __err  Error flags to set.
481        *  @param  __tm  Pointer to struct tm to fill in.
482        *  @return  Iterator to first char beyond weekday name.
483       */
484       iter_type
485       get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
486 		  ios_base::iostate& __err, tm* __tm) const
487       { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
488 
489       /**
490        *  @brief  Parse input month string.
491        *
492        *  This function parses a month name and puts the results into a
493        *  user-supplied struct tm.  The result is returned by calling
494        *  time_get::do_get_monthname().
495        *
496        *  Parsing starts by parsing an abbreviated month name.  If a valid
497        *  abbreviation is followed by a character that would lead to the full
498        *  month name, parsing continues until the full name is found or an
499        *  error occurs.  Otherwise parsing finishes at the end of the
500        *  abbreviated name.
501        *
502        *  If an error occurs before the end, err |= ios_base::failbit.  If
503        *  parsing reads all the characters, err |=
504        *  ios_base::eofbit.
505        *
506        *  @param  __beg  Start of string to parse.
507        *  @param  __end  End of string to parse.
508        *  @param  __io  Source of the locale.
509        *  @param  __err  Error flags to set.
510        *  @param  __tm  Pointer to struct tm to fill in.
511        *  @return  Iterator to first char beyond month name.
512       */
513       iter_type
514       get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
515 		    ios_base::iostate& __err, tm* __tm) const
516       { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
517 
518       /**
519        *  @brief  Parse input year string.
520        *
521        *  This function reads up to 4 characters to parse a year string and
522        *  puts the results into a user-supplied struct tm.  The result is
523        *  returned by calling time_get::do_get_year().
524        *
525        *  4 consecutive digits are interpreted as a full year.  If there are
526        *  exactly 2 consecutive digits, the library interprets this as the
527        *  number of years since 1900.
528        *
529        *  If an error occurs before the end, err |= ios_base::failbit.  If
530        *  parsing reads all the characters, err |= ios_base::eofbit.
531        *
532        *  @param  __beg  Start of string to parse.
533        *  @param  __end  End of string to parse.
534        *  @param  __io  Source of the locale.
535        *  @param  __err  Error flags to set.
536        *  @param  __tm  Pointer to struct tm to fill in.
537        *  @return  Iterator to first char beyond year.
538       */
539       iter_type
540       get_year(iter_type __beg, iter_type __end, ios_base& __io,
541 	       ios_base::iostate& __err, tm* __tm) const
542       { return this->do_get_year(__beg, __end, __io, __err, __tm); }
543 
544 #if __cplusplus >= 201103L
545       /**
546        *  @brief  Parse input string according to format.
547        *
548        *  This function calls time_get::do_get with the provided
549        *  parameters.  @see do_get() and get().
550        *
551        *  @param __s        Start of string to parse.
552        *  @param __end      End of string to parse.
553        *  @param __io       Source of the locale.
554        *  @param __err      Error flags to set.
555        *  @param __tm       Pointer to struct tm to fill in.
556        *  @param __format   Format specifier.
557        *  @param __modifier Format modifier.
558        *  @return  Iterator to first char not parsed.
559        */
560       inline
561       iter_type get(iter_type __s, iter_type __end, ios_base& __io,
562                     ios_base::iostate& __err, tm* __tm, char __format,
563                     char __modifier = 0) const
564       {
565         return this->do_get(__s, __end, __io, __err, __tm, __format,
566                             __modifier);
567       }
568 
569       /**
570        *  @brief  Parse input string according to format.
571        *
572        *  This function parses the input string according to a
573        *  provided format string.  It does the inverse of
574        *  time_put::put.  The format string follows the format
575        *  specified for strftime(3)/strptime(3).  The actual parsing
576        *  is done by time_get::do_get.
577        *
578        *  @param __s        Start of string to parse.
579        *  @param __end      End of string to parse.
580        *  @param __io       Source of the locale.
581        *  @param __err      Error flags to set.
582        *  @param __tm       Pointer to struct tm to fill in.
583        *  @param __fmt      Start of the format string.
584        *  @param __fmtend   End of the format string.
585        *  @return  Iterator to first char not parsed.
586        */
587       iter_type get(iter_type __s, iter_type __end, ios_base& __io,
588                     ios_base::iostate& __err, tm* __tm, const char_type* __fmt,
589                     const char_type* __fmtend) const;
590 #endif // __cplusplus >= 201103L
591 
592     protected:
593       /// Destructor.
594       virtual
595       ~time_get() { }
596 
597       /**
598        *  @brief  Return preferred order of month, day, and year.
599        *
600        *  This function returns an enum from time_base::dateorder giving the
601        *  preferred ordering if the format @a x given to time_put::put() only
602        *  uses month, day, and year.  This function is a hook for derived
603        *  classes to change the value returned.
604        *
605        *  @return  A member of time_base::dateorder.
606       */
607       virtual dateorder
608       do_date_order() const;
609 
610       /**
611        *  @brief  Parse input time string.
612        *
613        *  This function parses a time according to the format @a x and puts the
614        *  results into a user-supplied struct tm.  This function is a hook for
615        *  derived classes to change the value returned.  @see get_time() for
616        *  details.
617        *
618        *  @param  __beg  Start of string to parse.
619        *  @param  __end  End of string to parse.
620        *  @param  __io  Source of the locale.
621        *  @param  __err  Error flags to set.
622        *  @param  __tm  Pointer to struct tm to fill in.
623        *  @return  Iterator to first char beyond time string.
624       */
625       virtual iter_type
626       do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
627 		  ios_base::iostate& __err, tm* __tm) const;
628 
629       /**
630        *  @brief  Parse input date string.
631        *
632        *  This function parses a date according to the format @a X and puts the
633        *  results into a user-supplied struct tm.  This function is a hook for
634        *  derived classes to change the value returned.  @see get_date() for
635        *  details.
636        *
637        *  @param  __beg  Start of string to parse.
638        *  @param  __end  End of string to parse.
639        *  @param  __io  Source of the locale.
640        *  @param  __err  Error flags to set.
641        *  @param  __tm  Pointer to struct tm to fill in.
642        *  @return  Iterator to first char beyond date string.
643       */
644       virtual iter_type
645       do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
646 		  ios_base::iostate& __err, tm* __tm) const;
647 
648       /**
649        *  @brief  Parse input weekday string.
650        *
651        *  This function parses a weekday name and puts the results into a
652        *  user-supplied struct tm.  This function is a hook for derived
653        *  classes to change the value returned.  @see get_weekday() for
654        *  details.
655        *
656        *  @param  __beg  Start of string to parse.
657        *  @param  __end  End of string to parse.
658        *  @param  __io  Source of the locale.
659        *  @param  __err  Error flags to set.
660        *  @param  __tm  Pointer to struct tm to fill in.
661        *  @return  Iterator to first char beyond weekday name.
662       */
663       virtual iter_type
664       do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
665 		     ios_base::iostate& __err, tm* __tm) const;
666 
667       /**
668        *  @brief  Parse input month string.
669        *
670        *  This function parses a month name and puts the results into a
671        *  user-supplied struct tm.  This function is a hook for derived
672        *  classes to change the value returned.  @see get_monthname() for
673        *  details.
674        *
675        *  @param  __beg  Start of string to parse.
676        *  @param  __end  End of string to parse.
677        *  @param  __io  Source of the locale.
678        *  @param  __err  Error flags to set.
679        *  @param  __tm  Pointer to struct tm to fill in.
680        *  @return  Iterator to first char beyond month name.
681       */
682       virtual iter_type
683       do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
684 		       ios_base::iostate& __err, tm* __tm) const;
685 
686       /**
687        *  @brief  Parse input year string.
688        *
689        *  This function reads up to 4 characters to parse a year string and
690        *  puts the results into a user-supplied struct tm.  This function is a
691        *  hook for derived classes to change the value returned.  @see
692        *  get_year() for details.
693        *
694        *  @param  __beg  Start of string to parse.
695        *  @param  __end  End of string to parse.
696        *  @param  __io  Source of the locale.
697        *  @param  __err  Error flags to set.
698        *  @param  __tm  Pointer to struct tm to fill in.
699        *  @return  Iterator to first char beyond year.
700       */
701       virtual iter_type
702       do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
703 		  ios_base::iostate& __err, tm* __tm) const;
704 
705 #if __cplusplus >= 201103L
706       /**
707        *  @brief  Parse input string according to format.
708        *
709        *  This function parses the string according to the provided
710        *  format and optional modifier.  This function is a hook for
711        *  derived classes to change the value returned.  @see get()
712        *  for more details.
713        *
714        *  @param __s        Start of string to parse.
715        *  @param __end      End of string to parse.
716        *  @param __f        Source of the locale.
717        *  @param __err      Error flags to set.
718        *  @param __tm       Pointer to struct tm to fill in.
719        *  @param __format   Format specifier.
720        *  @param __modifier Format modifier.
721        *  @return  Iterator to first char not parsed.
722        */
723 #if _GLIBCXX_USE_CXX11_ABI
724       virtual
725 #endif
726       iter_type
727       do_get(iter_type __s, iter_type __end, ios_base& __f,
728              ios_base::iostate& __err, tm* __tm,
729              char __format, char __modifier) const;
730 #endif // __cplusplus >= 201103L
731 
732       // Extract numeric component of length __len.
733       iter_type
734       _M_extract_num(iter_type __beg, iter_type __end, int& __member,
735 		     int __min, int __max, size_t __len,
736 		     ios_base& __io, ios_base::iostate& __err) const;
737 
738       // Extract any unique array of string literals in a const _CharT* array.
739       iter_type
740       _M_extract_name(iter_type __beg, iter_type __end, int& __member,
741 		      const _CharT** __names, size_t __indexlen,
742 		      ios_base& __io, ios_base::iostate& __err) const;
743 
744       // Extract day or month name in a const _CharT* array.
745       iter_type
746       _M_extract_wday_or_month(iter_type __beg, iter_type __end, int& __member,
747 			       const _CharT** __names, size_t __indexlen,
748 			       ios_base& __io, ios_base::iostate& __err) const;
749 
750       // Extract on a component-by-component basis, via __format argument.
751       iter_type
752       _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
753 			    ios_base::iostate& __err, tm* __tm,
754 			    const _CharT* __format) const;
755     };
756 
757   template<typename _CharT, typename _InIter>
758     locale::id time_get<_CharT, _InIter>::id;
759 
760   /// class time_get_byname [22.2.5.2].
761   template<typename _CharT, typename _InIter>
762     class time_get_byname : public time_get<_CharT, _InIter>
763     {
764     public:
765       // Types:
766       typedef _CharT			char_type;
767       typedef _InIter			iter_type;
768 
769       explicit
770       time_get_byname(const char*, size_t __refs = 0)
771       : time_get<_CharT, _InIter>(__refs) { }
772 
773 #if __cplusplus >= 201103L
774       explicit
775       time_get_byname(const string& __s, size_t __refs = 0)
776       : time_get_byname(__s.c_str(), __refs) { }
777 #endif
778 
779     protected:
780       virtual
781       ~time_get_byname() { }
782     };
783 
784 _GLIBCXX_END_NAMESPACE_CXX11
785 
786   /**
787    *  @brief  Primary class template time_put.
788    *  @ingroup locales
789    *
790    *  This facet encapsulates the code to format and output dates and times
791    *  according to formats used by strftime().
792    *
793    *  The time_put template uses protected virtual functions to provide the
794    *  actual results.  The public accessors forward the call to the virtual
795    *  functions.  These virtual functions are hooks for developers to
796    *  implement the behavior they require from the time_put facet.
797   */
798   template<typename _CharT, typename _OutIter>
799     class time_put : public locale::facet
800     {
801     public:
802       // Types:
803       //@{
804       /// Public typedefs
805       typedef _CharT			char_type;
806       typedef _OutIter			iter_type;
807       //@}
808 
809       /// Numpunct facet id.
810       static locale::id			id;
811 
812       /**
813        *  @brief  Constructor performs initialization.
814        *
815        *  This is the constructor provided by the standard.
816        *
817        *  @param __refs  Passed to the base facet class.
818       */
819       explicit
820       time_put(size_t __refs = 0)
821       : facet(__refs) { }
822 
823       /**
824        *  @brief  Format and output a time or date.
825        *
826        *  This function formats the data in struct tm according to the
827        *  provided format string.  The format string is interpreted as by
828        *  strftime().
829        *
830        *  @param  __s  The stream to write to.
831        *  @param  __io  Source of locale.
832        *  @param  __fill  char_type to use for padding.
833        *  @param  __tm  Struct tm with date and time info to format.
834        *  @param  __beg  Start of format string.
835        *  @param  __end  End of format string.
836        *  @return  Iterator after writing.
837        */
838       iter_type
839       put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
840 	  const _CharT* __beg, const _CharT* __end) const;
841 
842       /**
843        *  @brief  Format and output a time or date.
844        *
845        *  This function formats the data in struct tm according to the
846        *  provided format char and optional modifier.  The format and modifier
847        *  are interpreted as by strftime().  It does so by returning
848        *  time_put::do_put().
849        *
850        *  @param  __s  The stream to write to.
851        *  @param  __io  Source of locale.
852        *  @param  __fill  char_type to use for padding.
853        *  @param  __tm  Struct tm with date and time info to format.
854        *  @param  __format  Format char.
855        *  @param  __mod  Optional modifier char.
856        *  @return  Iterator after writing.
857        */
858       iter_type
859       put(iter_type __s, ios_base& __io, char_type __fill,
860 	  const tm* __tm, char __format, char __mod = 0) const
861       { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
862 
863     protected:
864       /// Destructor.
865       virtual
866       ~time_put()
867       { }
868 
869       /**
870        *  @brief  Format and output a time or date.
871        *
872        *  This function formats the data in struct tm according to the
873        *  provided format char and optional modifier.  This function is a hook
874        *  for derived classes to change the value returned.  @see put() for
875        *  more details.
876        *
877        *  @param  __s  The stream to write to.
878        *  @param  __io  Source of locale.
879        *  @param  __fill  char_type to use for padding.
880        *  @param  __tm  Struct tm with date and time info to format.
881        *  @param  __format  Format char.
882        *  @param  __mod  Optional modifier char.
883        *  @return  Iterator after writing.
884        */
885       virtual iter_type
886       do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
887 	     char __format, char __mod) const;
888     };
889 
890   template<typename _CharT, typename _OutIter>
891     locale::id time_put<_CharT, _OutIter>::id;
892 
893   /// class time_put_byname [22.2.5.4].
894   template<typename _CharT, typename _OutIter>
895     class time_put_byname : public time_put<_CharT, _OutIter>
896     {
897     public:
898       // Types:
899       typedef _CharT			char_type;
900       typedef _OutIter			iter_type;
901 
902       explicit
903       time_put_byname(const char*, size_t __refs = 0)
904       : time_put<_CharT, _OutIter>(__refs)
905       { }
906 
907 #if __cplusplus >= 201103L
908       explicit
909       time_put_byname(const string& __s, size_t __refs = 0)
910       : time_put_byname(__s.c_str(), __refs) { }
911 #endif
912 
913     protected:
914       virtual
915       ~time_put_byname() { }
916     };
917 
918 
919   /**
920    *  @brief  Money format ordering data.
921    *  @ingroup locales
922    *
923    *  This class contains an ordered array of 4 fields to represent the
924    *  pattern for formatting a money amount.  Each field may contain one entry
925    *  from the part enum.  symbol, sign, and value must be present and the
926    *  remaining field must contain either none or space.  @see
927    *  moneypunct::pos_format() and moneypunct::neg_format() for details of how
928    *  these fields are interpreted.
929   */
930   class money_base
931   {
932   public:
933     enum part { none, space, symbol, sign, value };
934     struct pattern { char field[4]; };
935 
936     static const pattern _S_default_pattern;
937 
938     enum
939     {
940       _S_minus,
941       _S_zero,
942       _S_end = 11
943     };
944 
945     // String literal of acceptable (narrow) input/output, for
946     // money_get/money_put. "-0123456789"
947     static const char* _S_atoms;
948 
949     // Construct and return valid pattern consisting of some combination of:
950     // space none symbol sign value
951     _GLIBCXX_CONST static pattern
952     _S_construct_pattern(char __precedes, char __space, char __posn) throw ();
953   };
954 
955   template<typename _CharT, bool _Intl>
956     struct __moneypunct_cache : public locale::facet
957     {
958       const char*			_M_grouping;
959       size_t                            _M_grouping_size;
960       bool				_M_use_grouping;
961       _CharT				_M_decimal_point;
962       _CharT				_M_thousands_sep;
963       const _CharT*			_M_curr_symbol;
964       size_t                            _M_curr_symbol_size;
965       const _CharT*			_M_positive_sign;
966       size_t                            _M_positive_sign_size;
967       const _CharT*			_M_negative_sign;
968       size_t                            _M_negative_sign_size;
969       int				_M_frac_digits;
970       money_base::pattern		_M_pos_format;
971       money_base::pattern	        _M_neg_format;
972 
973       // A list of valid numeric literals for input and output: in the standard
974       // "C" locale, this is "-0123456789". This array contains the chars after
975       // having been passed through the current locale's ctype<_CharT>.widen().
976       _CharT				_M_atoms[money_base::_S_end];
977 
978       bool				_M_allocated;
979 
980       __moneypunct_cache(size_t __refs = 0) : facet(__refs),
981       _M_grouping(0), _M_grouping_size(0), _M_use_grouping(false),
982       _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
983       _M_curr_symbol(0), _M_curr_symbol_size(0),
984       _M_positive_sign(0), _M_positive_sign_size(0),
985       _M_negative_sign(0), _M_negative_sign_size(0),
986       _M_frac_digits(0),
987       _M_pos_format(money_base::pattern()),
988       _M_neg_format(money_base::pattern()), _M_allocated(false)
989       { }
990 
991       ~__moneypunct_cache();
992 
993       void
994       _M_cache(const locale& __loc);
995 
996     private:
997       __moneypunct_cache&
998       operator=(const __moneypunct_cache&);
999 
1000       explicit
1001       __moneypunct_cache(const __moneypunct_cache&);
1002     };
1003 
1004   template<typename _CharT, bool _Intl>
1005     __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
1006     {
1007       if (_M_allocated)
1008 	{
1009 	  delete [] _M_grouping;
1010 	  delete [] _M_curr_symbol;
1011 	  delete [] _M_positive_sign;
1012 	  delete [] _M_negative_sign;
1013 	}
1014     }
1015 
1016 _GLIBCXX_BEGIN_NAMESPACE_CXX11
1017 
1018   /**
1019    *  @brief  Primary class template moneypunct.
1020    *  @ingroup locales
1021    *
1022    *  This facet encapsulates the punctuation, grouping and other formatting
1023    *  features of money amount string representations.
1024   */
1025   template<typename _CharT, bool _Intl>
1026     class moneypunct : public locale::facet, public money_base
1027     {
1028     public:
1029       // Types:
1030       //@{
1031       /// Public typedefs
1032       typedef _CharT			char_type;
1033       typedef basic_string<_CharT>	string_type;
1034       //@}
1035       typedef __moneypunct_cache<_CharT, _Intl>     __cache_type;
1036 
1037     private:
1038       __cache_type*			_M_data;
1039 
1040     public:
1041       /// This value is provided by the standard, but no reason for its
1042       /// existence.
1043       static const bool			intl = _Intl;
1044       /// Numpunct facet id.
1045       static locale::id			id;
1046 
1047       /**
1048        *  @brief  Constructor performs initialization.
1049        *
1050        *  This is the constructor provided by the standard.
1051        *
1052        *  @param __refs  Passed to the base facet class.
1053       */
1054       explicit
1055       moneypunct(size_t __refs = 0)
1056       : facet(__refs), _M_data(0)
1057       { _M_initialize_moneypunct(); }
1058 
1059       /**
1060        *  @brief  Constructor performs initialization.
1061        *
1062        *  This is an internal constructor.
1063        *
1064        *  @param __cache  Cache for optimization.
1065        *  @param __refs  Passed to the base facet class.
1066       */
1067       explicit
1068       moneypunct(__cache_type* __cache, size_t __refs = 0)
1069       : facet(__refs), _M_data(__cache)
1070       { _M_initialize_moneypunct(); }
1071 
1072       /**
1073        *  @brief  Internal constructor. Not for general use.
1074        *
1075        *  This is a constructor for use by the library itself to set up new
1076        *  locales.
1077        *
1078        *  @param __cloc  The C locale.
1079        *  @param __s  The name of a locale.
1080        *  @param __refs  Passed to the base facet class.
1081       */
1082       explicit
1083       moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
1084       : facet(__refs), _M_data(0)
1085       { _M_initialize_moneypunct(__cloc, __s); }
1086 
1087       /**
1088        *  @brief  Return decimal point character.
1089        *
1090        *  This function returns a char_type to use as a decimal point.  It
1091        *  does so by returning returning
1092        *  moneypunct<char_type>::do_decimal_point().
1093        *
1094        *  @return  @a char_type representing a decimal point.
1095       */
1096       char_type
1097       decimal_point() const
1098       { return this->do_decimal_point(); }
1099 
1100       /**
1101        *  @brief  Return thousands separator character.
1102        *
1103        *  This function returns a char_type to use as a thousands
1104        *  separator.  It does so by returning returning
1105        *  moneypunct<char_type>::do_thousands_sep().
1106        *
1107        *  @return  char_type representing a thousands separator.
1108       */
1109       char_type
1110       thousands_sep() const
1111       { return this->do_thousands_sep(); }
1112 
1113       /**
1114        *  @brief  Return grouping specification.
1115        *
1116        *  This function returns a string representing groupings for the
1117        *  integer part of an amount.  Groupings indicate where thousands
1118        *  separators should be inserted.
1119        *
1120        *  Each char in the return string is interpret as an integer rather
1121        *  than a character.  These numbers represent the number of digits in a
1122        *  group.  The first char in the string represents the number of digits
1123        *  in the least significant group.  If a char is negative, it indicates
1124        *  an unlimited number of digits for the group.  If more chars from the
1125        *  string are required to group a number, the last char is used
1126        *  repeatedly.
1127        *
1128        *  For example, if the grouping() returns <code>\003\002</code>
1129        *  and is applied to the number 123456789, this corresponds to
1130        *  12,34,56,789.  Note that if the string was <code>32</code>, this would
1131        *  put more than 50 digits into the least significant group if
1132        *  the character set is ASCII.
1133        *
1134        *  The string is returned by calling
1135        *  moneypunct<char_type>::do_grouping().
1136        *
1137        *  @return  string representing grouping specification.
1138       */
1139       string
1140       grouping() const
1141       { return this->do_grouping(); }
1142 
1143       /**
1144        *  @brief  Return currency symbol string.
1145        *
1146        *  This function returns a string_type to use as a currency symbol.  It
1147        *  does so by returning returning
1148        *  moneypunct<char_type>::do_curr_symbol().
1149        *
1150        *  @return  @a string_type representing a currency symbol.
1151       */
1152       string_type
1153       curr_symbol() const
1154       { return this->do_curr_symbol(); }
1155 
1156       /**
1157        *  @brief  Return positive sign string.
1158        *
1159        *  This function returns a string_type to use as a sign for positive
1160        *  amounts.  It does so by returning returning
1161        *  moneypunct<char_type>::do_positive_sign().
1162        *
1163        *  If the return value contains more than one character, the first
1164        *  character appears in the position indicated by pos_format() and the
1165        *  remainder appear at the end of the formatted string.
1166        *
1167        *  @return  @a string_type representing a positive sign.
1168       */
1169       string_type
1170       positive_sign() const
1171       { return this->do_positive_sign(); }
1172 
1173       /**
1174        *  @brief  Return negative sign string.
1175        *
1176        *  This function returns a string_type to use as a sign for negative
1177        *  amounts.  It does so by returning returning
1178        *  moneypunct<char_type>::do_negative_sign().
1179        *
1180        *  If the return value contains more than one character, the first
1181        *  character appears in the position indicated by neg_format() and the
1182        *  remainder appear at the end of the formatted string.
1183        *
1184        *  @return  @a string_type representing a negative sign.
1185       */
1186       string_type
1187       negative_sign() const
1188       { return this->do_negative_sign(); }
1189 
1190       /**
1191        *  @brief  Return number of digits in fraction.
1192        *
1193        *  This function returns the exact number of digits that make up the
1194        *  fractional part of a money amount.  It does so by returning
1195        *  returning moneypunct<char_type>::do_frac_digits().
1196        *
1197        *  The fractional part of a money amount is optional.  But if it is
1198        *  present, there must be frac_digits() digits.
1199        *
1200        *  @return  Number of digits in amount fraction.
1201       */
1202       int
1203       frac_digits() const
1204       { return this->do_frac_digits(); }
1205 
1206       //@{
1207       /**
1208        *  @brief  Return pattern for money values.
1209        *
1210        *  This function returns a pattern describing the formatting of a
1211        *  positive or negative valued money amount.  It does so by returning
1212        *  returning moneypunct<char_type>::do_pos_format() or
1213        *  moneypunct<char_type>::do_neg_format().
1214        *
1215        *  The pattern has 4 fields describing the ordering of symbol, sign,
1216        *  value, and none or space.  There must be one of each in the pattern.
1217        *  The none and space enums may not appear in the first field and space
1218        *  may not appear in the final field.
1219        *
1220        *  The parts of a money string must appear in the order indicated by
1221        *  the fields of the pattern.  The symbol field indicates that the
1222        *  value of curr_symbol() may be present.  The sign field indicates
1223        *  that the value of positive_sign() or negative_sign() must be
1224        *  present.  The value field indicates that the absolute value of the
1225        *  money amount is present.  none indicates 0 or more whitespace
1226        *  characters, except at the end, where it permits no whitespace.
1227        *  space indicates that 1 or more whitespace characters must be
1228        *  present.
1229        *
1230        *  For example, for the US locale and pos_format() pattern
1231        *  {symbol,sign,value,none}, curr_symbol() == &apos;$&apos;
1232        *  positive_sign() == &apos;+&apos;, and value 10.01, and
1233        *  options set to force the symbol, the corresponding string is
1234        *  <code>$+10.01</code>.
1235        *
1236        *  @return  Pattern for money values.
1237       */
1238       pattern
1239       pos_format() const
1240       { return this->do_pos_format(); }
1241 
1242       pattern
1243       neg_format() const
1244       { return this->do_neg_format(); }
1245       //@}
1246 
1247     protected:
1248       /// Destructor.
1249       virtual
1250       ~moneypunct();
1251 
1252       /**
1253        *  @brief  Return decimal point character.
1254        *
1255        *  Returns a char_type to use as a decimal point.  This function is a
1256        *  hook for derived classes to change the value returned.
1257        *
1258        *  @return  @a char_type representing a decimal point.
1259       */
1260       virtual char_type
1261       do_decimal_point() const
1262       { return _M_data->_M_decimal_point; }
1263 
1264       /**
1265        *  @brief  Return thousands separator character.
1266        *
1267        *  Returns a char_type to use as a thousands separator.  This function
1268        *  is a hook for derived classes to change the value returned.
1269        *
1270        *  @return  @a char_type representing a thousands separator.
1271       */
1272       virtual char_type
1273       do_thousands_sep() const
1274       { return _M_data->_M_thousands_sep; }
1275 
1276       /**
1277        *  @brief  Return grouping specification.
1278        *
1279        *  Returns a string representing groupings for the integer part of a
1280        *  number.  This function is a hook for derived classes to change the
1281        *  value returned.  @see grouping() for details.
1282        *
1283        *  @return  String representing grouping specification.
1284       */
1285       virtual string
1286       do_grouping() const
1287       { return _M_data->_M_grouping; }
1288 
1289       /**
1290        *  @brief  Return currency symbol string.
1291        *
1292        *  This function returns a string_type to use as a currency symbol.
1293        *  This function is a hook for derived classes to change the value
1294        *  returned.  @see curr_symbol() for details.
1295        *
1296        *  @return  @a string_type representing a currency symbol.
1297       */
1298       virtual string_type
1299       do_curr_symbol()   const
1300       { return _M_data->_M_curr_symbol; }
1301 
1302       /**
1303        *  @brief  Return positive sign string.
1304        *
1305        *  This function returns a string_type to use as a sign for positive
1306        *  amounts.  This function is a hook for derived classes to change the
1307        *  value returned.  @see positive_sign() for details.
1308        *
1309        *  @return  @a string_type representing a positive sign.
1310       */
1311       virtual string_type
1312       do_positive_sign() const
1313       { return _M_data->_M_positive_sign; }
1314 
1315       /**
1316        *  @brief  Return negative sign string.
1317        *
1318        *  This function returns a string_type to use as a sign for negative
1319        *  amounts.  This function is a hook for derived classes to change the
1320        *  value returned.  @see negative_sign() for details.
1321        *
1322        *  @return  @a string_type representing a negative sign.
1323       */
1324       virtual string_type
1325       do_negative_sign() const
1326       { return _M_data->_M_negative_sign; }
1327 
1328       /**
1329        *  @brief  Return number of digits in fraction.
1330        *
1331        *  This function returns the exact number of digits that make up the
1332        *  fractional part of a money amount.  This function is a hook for
1333        *  derived classes to change the value returned.  @see frac_digits()
1334        *  for details.
1335        *
1336        *  @return  Number of digits in amount fraction.
1337       */
1338       virtual int
1339       do_frac_digits() const
1340       { return _M_data->_M_frac_digits; }
1341 
1342       /**
1343        *  @brief  Return pattern for money values.
1344        *
1345        *  This function returns a pattern describing the formatting of a
1346        *  positive valued money amount.  This function is a hook for derived
1347        *  classes to change the value returned.  @see pos_format() for
1348        *  details.
1349        *
1350        *  @return  Pattern for money values.
1351       */
1352       virtual pattern
1353       do_pos_format() const
1354       { return _M_data->_M_pos_format; }
1355 
1356       /**
1357        *  @brief  Return pattern for money values.
1358        *
1359        *  This function returns a pattern describing the formatting of a
1360        *  negative valued money amount.  This function is a hook for derived
1361        *  classes to change the value returned.  @see neg_format() for
1362        *  details.
1363        *
1364        *  @return  Pattern for money values.
1365       */
1366       virtual pattern
1367       do_neg_format() const
1368       { return _M_data->_M_neg_format; }
1369 
1370       // For use at construction time only.
1371        void
1372        _M_initialize_moneypunct(__c_locale __cloc = 0,
1373 				const char* __name = 0);
1374     };
1375 
1376   template<typename _CharT, bool _Intl>
1377     locale::id moneypunct<_CharT, _Intl>::id;
1378 
1379   template<typename _CharT, bool _Intl>
1380     const bool moneypunct<_CharT, _Intl>::intl;
1381 
1382   template<>
1383     moneypunct<char, true>::~moneypunct();
1384 
1385   template<>
1386     moneypunct<char, false>::~moneypunct();
1387 
1388   template<>
1389     void
1390     moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
1391 
1392   template<>
1393     void
1394     moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
1395 
1396 #ifdef _GLIBCXX_USE_WCHAR_T
1397   template<>
1398     moneypunct<wchar_t, true>::~moneypunct();
1399 
1400   template<>
1401     moneypunct<wchar_t, false>::~moneypunct();
1402 
1403   template<>
1404     void
1405     moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
1406 							const char*);
1407 
1408   template<>
1409     void
1410     moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
1411 							 const char*);
1412 #endif
1413 
1414   /// class moneypunct_byname [22.2.6.4].
1415   template<typename _CharT, bool _Intl>
1416     class moneypunct_byname : public moneypunct<_CharT, _Intl>
1417     {
1418     public:
1419       typedef _CharT			char_type;
1420       typedef basic_string<_CharT>	string_type;
1421 
1422       static const bool intl = _Intl;
1423 
1424       explicit
1425       moneypunct_byname(const char* __s, size_t __refs = 0)
1426       : moneypunct<_CharT, _Intl>(__refs)
1427       {
1428 	if (__builtin_strcmp(__s, "C") != 0
1429 	    && __builtin_strcmp(__s, "POSIX") != 0)
1430 	  {
1431 	    __c_locale __tmp;
1432 	    this->_S_create_c_locale(__tmp, __s);
1433 	    this->_M_initialize_moneypunct(__tmp);
1434 	    this->_S_destroy_c_locale(__tmp);
1435 	  }
1436       }
1437 
1438 #if __cplusplus >= 201103L
1439       explicit
1440       moneypunct_byname(const string& __s, size_t __refs = 0)
1441       : moneypunct_byname(__s.c_str(), __refs) { }
1442 #endif
1443 
1444     protected:
1445       virtual
1446       ~moneypunct_byname() { }
1447     };
1448 
1449   template<typename _CharT, bool _Intl>
1450     const bool moneypunct_byname<_CharT, _Intl>::intl;
1451 
1452 _GLIBCXX_END_NAMESPACE_CXX11
1453 
1454 _GLIBCXX_BEGIN_NAMESPACE_LDBL_OR_CXX11
1455 
1456   /**
1457    *  @brief  Primary class template money_get.
1458    *  @ingroup locales
1459    *
1460    *  This facet encapsulates the code to parse and return a monetary
1461    *  amount from a string.
1462    *
1463    *  The money_get template uses protected virtual functions to
1464    *  provide the actual results.  The public accessors forward the
1465    *  call to the virtual functions.  These virtual functions are
1466    *  hooks for developers to implement the behavior they require from
1467    *  the money_get facet.
1468   */
1469   template<typename _CharT, typename _InIter>
1470     class money_get : public locale::facet
1471     {
1472     public:
1473       // Types:
1474       //@{
1475       /// Public typedefs
1476       typedef _CharT			char_type;
1477       typedef _InIter			iter_type;
1478       typedef basic_string<_CharT>	string_type;
1479       //@}
1480 
1481       /// Numpunct facet id.
1482       static locale::id			id;
1483 
1484       /**
1485        *  @brief  Constructor performs initialization.
1486        *
1487        *  This is the constructor provided by the standard.
1488        *
1489        *  @param __refs  Passed to the base facet class.
1490       */
1491       explicit
1492       money_get(size_t __refs = 0) : facet(__refs) { }
1493 
1494       /**
1495        *  @brief  Read and parse a monetary value.
1496        *
1497        *  This function reads characters from @a __s, interprets them as a
1498        *  monetary value according to moneypunct and ctype facets retrieved
1499        *  from io.getloc(), and returns the result in @a units as an integral
1500        *  value moneypunct::frac_digits() * the actual amount.  For example,
1501        *  the string $10.01 in a US locale would store 1001 in @a units.
1502        *
1503        *  Any characters not part of a valid money amount are not consumed.
1504        *
1505        *  If a money value cannot be parsed from the input stream, sets
1506        *  err=(err|io.failbit).  If the stream is consumed before finishing
1507        *  parsing,  sets err=(err|io.failbit|io.eofbit).  @a units is
1508        *  unchanged if parsing fails.
1509        *
1510        *  This function works by returning the result of do_get().
1511        *
1512        *  @param  __s  Start of characters to parse.
1513        *  @param  __end  End of characters to parse.
1514        *  @param  __intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1515        *  @param  __io  Source of facets and io state.
1516        *  @param  __err  Error field to set if parsing fails.
1517        *  @param  __units  Place to store result of parsing.
1518        *  @return  Iterator referencing first character beyond valid money
1519        *	   amount.
1520        */
1521       iter_type
1522       get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1523 	  ios_base::iostate& __err, long double& __units) const
1524       { return this->do_get(__s, __end, __intl, __io, __err, __units); }
1525 
1526       /**
1527        *  @brief  Read and parse a monetary value.
1528        *
1529        *  This function reads characters from @a __s, interprets them as
1530        *  a monetary value according to moneypunct and ctype facets
1531        *  retrieved from io.getloc(), and returns the result in @a
1532        *  digits.  For example, the string $10.01 in a US locale would
1533        *  store <code>1001</code> in @a digits.
1534        *
1535        *  Any characters not part of a valid money amount are not consumed.
1536        *
1537        *  If a money value cannot be parsed from the input stream, sets
1538        *  err=(err|io.failbit).  If the stream is consumed before finishing
1539        *  parsing,  sets err=(err|io.failbit|io.eofbit).
1540        *
1541        *  This function works by returning the result of do_get().
1542        *
1543        *  @param  __s  Start of characters to parse.
1544        *  @param  __end  End of characters to parse.
1545        *  @param  __intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1546        *  @param  __io  Source of facets and io state.
1547        *  @param  __err  Error field to set if parsing fails.
1548        *  @param  __digits  Place to store result of parsing.
1549        *  @return  Iterator referencing first character beyond valid money
1550        *	   amount.
1551        */
1552       iter_type
1553       get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1554 	  ios_base::iostate& __err, string_type& __digits) const
1555       { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
1556 
1557     protected:
1558       /// Destructor.
1559       virtual
1560       ~money_get() { }
1561 
1562       /**
1563        *  @brief  Read and parse a monetary value.
1564        *
1565        *  This function reads and parses characters representing a monetary
1566        *  value.  This function is a hook for derived classes to change the
1567        *  value returned.  @see get() for details.
1568        */
1569       // XXX GLIBCXX_ABI Deprecated
1570 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1571       && _GLIBCXX_USE_CXX11_ABI == 0
1572       virtual iter_type
1573       __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1574 	       ios_base::iostate& __err, double& __units) const;
1575 #else
1576       virtual iter_type
1577       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1578 	     ios_base::iostate& __err, long double& __units) const;
1579 #endif
1580 
1581       /**
1582        *  @brief  Read and parse a monetary value.
1583        *
1584        *  This function reads and parses characters representing a monetary
1585        *  value.  This function is a hook for derived classes to change the
1586        *  value returned.  @see get() for details.
1587        */
1588       virtual iter_type
1589       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1590 	     ios_base::iostate& __err, string_type& __digits) const;
1591 
1592       // XXX GLIBCXX_ABI Deprecated
1593 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1594       && _GLIBCXX_USE_CXX11_ABI == 0
1595       virtual iter_type
1596       do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1597 	     ios_base::iostate& __err, long double& __units) const;
1598 #endif
1599 
1600       template<bool _Intl>
1601         iter_type
1602         _M_extract(iter_type __s, iter_type __end, ios_base& __io,
1603 		   ios_base::iostate& __err, string& __digits) const;
1604     };
1605 
1606   template<typename _CharT, typename _InIter>
1607     locale::id money_get<_CharT, _InIter>::id;
1608 
1609   /**
1610    *  @brief  Primary class template money_put.
1611    *  @ingroup locales
1612    *
1613    *  This facet encapsulates the code to format and output a monetary
1614    *  amount.
1615    *
1616    *  The money_put template uses protected virtual functions to
1617    *  provide the actual results.  The public accessors forward the
1618    *  call to the virtual functions.  These virtual functions are
1619    *  hooks for developers to implement the behavior they require from
1620    *  the money_put facet.
1621   */
1622   template<typename _CharT, typename _OutIter>
1623     class money_put : public locale::facet
1624     {
1625     public:
1626       //@{
1627       /// Public typedefs
1628       typedef _CharT			char_type;
1629       typedef _OutIter			iter_type;
1630       typedef basic_string<_CharT>	string_type;
1631       //@}
1632 
1633       /// Numpunct facet id.
1634       static locale::id			id;
1635 
1636       /**
1637        *  @brief  Constructor performs initialization.
1638        *
1639        *  This is the constructor provided by the standard.
1640        *
1641        *  @param __refs  Passed to the base facet class.
1642       */
1643       explicit
1644       money_put(size_t __refs = 0) : facet(__refs) { }
1645 
1646       /**
1647        *  @brief  Format and output a monetary value.
1648        *
1649        *  This function formats @a units as a monetary value according to
1650        *  moneypunct and ctype facets retrieved from io.getloc(), and writes
1651        *  the resulting characters to @a __s.  For example, the value 1001 in a
1652        *  US locale would write <code>$10.01</code> to @a __s.
1653        *
1654        *  This function works by returning the result of do_put().
1655        *
1656        *  @param  __s  The stream to write to.
1657        *  @param  __intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1658        *  @param  __io  Source of facets and io state.
1659        *  @param  __fill  char_type to use for padding.
1660        *  @param  __units  Place to store result of parsing.
1661        *  @return  Iterator after writing.
1662        */
1663       iter_type
1664       put(iter_type __s, bool __intl, ios_base& __io,
1665 	  char_type __fill, long double __units) const
1666       { return this->do_put(__s, __intl, __io, __fill, __units); }
1667 
1668       /**
1669        *  @brief  Format and output a monetary value.
1670        *
1671        *  This function formats @a digits as a monetary value
1672        *  according to moneypunct and ctype facets retrieved from
1673        *  io.getloc(), and writes the resulting characters to @a __s.
1674        *  For example, the string <code>1001</code> in a US locale
1675        *  would write <code>$10.01</code> to @a __s.
1676        *
1677        *  This function works by returning the result of do_put().
1678        *
1679        *  @param  __s  The stream to write to.
1680        *  @param  __intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1681        *  @param  __io  Source of facets and io state.
1682        *  @param  __fill  char_type to use for padding.
1683        *  @param  __digits  Place to store result of parsing.
1684        *  @return  Iterator after writing.
1685        */
1686       iter_type
1687       put(iter_type __s, bool __intl, ios_base& __io,
1688 	  char_type __fill, const string_type& __digits) const
1689       { return this->do_put(__s, __intl, __io, __fill, __digits); }
1690 
1691     protected:
1692       /// Destructor.
1693       virtual
1694       ~money_put() { }
1695 
1696       /**
1697        *  @brief  Format and output a monetary value.
1698        *
1699        *  This function formats @a units as a monetary value according to
1700        *  moneypunct and ctype facets retrieved from io.getloc(), and writes
1701        *  the resulting characters to @a __s.  For example, the value 1001 in a
1702        *  US locale would write <code>$10.01</code> to @a __s.
1703        *
1704        *  This function is a hook for derived classes to change the value
1705        *  returned.  @see put().
1706        *
1707        *  @param  __s  The stream to write to.
1708        *  @param  __intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1709        *  @param  __io  Source of facets and io state.
1710        *  @param  __fill  char_type to use for padding.
1711        *  @param  __units  Place to store result of parsing.
1712        *  @return  Iterator after writing.
1713        */
1714       // XXX GLIBCXX_ABI Deprecated
1715 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1716       && _GLIBCXX_USE_CXX11_ABI == 0
1717       virtual iter_type
1718       __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1719 	       double __units) const;
1720 #else
1721       virtual iter_type
1722       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1723 	     long double __units) const;
1724 #endif
1725 
1726       /**
1727        *  @brief  Format and output a monetary value.
1728        *
1729        *  This function formats @a digits as a monetary value
1730        *  according to moneypunct and ctype facets retrieved from
1731        *  io.getloc(), and writes the resulting characters to @a __s.
1732        *  For example, the string <code>1001</code> in a US locale
1733        *  would write <code>$10.01</code> to @a __s.
1734        *
1735        *  This function is a hook for derived classes to change the value
1736        *  returned.  @see put().
1737        *
1738        *  @param  __s  The stream to write to.
1739        *  @param  __intl  Parameter to use_facet<moneypunct<CharT,intl> >.
1740        *  @param  __io  Source of facets and io state.
1741        *  @param  __fill  char_type to use for padding.
1742        *  @param  __digits  Place to store result of parsing.
1743        *  @return  Iterator after writing.
1744        */
1745       virtual iter_type
1746       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1747 	     const string_type& __digits) const;
1748 
1749       // XXX GLIBCXX_ABI Deprecated
1750 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
1751       && _GLIBCXX_USE_CXX11_ABI == 0
1752       virtual iter_type
1753       do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1754 	     long double __units) const;
1755 #endif
1756 
1757       template<bool _Intl>
1758         iter_type
1759         _M_insert(iter_type __s, ios_base& __io, char_type __fill,
1760 		  const string_type& __digits) const;
1761     };
1762 
1763   template<typename _CharT, typename _OutIter>
1764     locale::id money_put<_CharT, _OutIter>::id;
1765 
1766 _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
1767 
1768   /**
1769    *  @brief  Messages facet base class providing catalog typedef.
1770    *  @ingroup locales
1771    */
1772   struct messages_base
1773   {
1774     typedef int catalog;
1775   };
1776 
1777 _GLIBCXX_BEGIN_NAMESPACE_CXX11
1778 
1779   /**
1780    *  @brief  Primary class template messages.
1781    *  @ingroup locales
1782    *
1783    *  This facet encapsulates the code to retrieve messages from
1784    *  message catalogs.  The only thing defined by the standard for this facet
1785    *  is the interface.  All underlying functionality is
1786    *  implementation-defined.
1787    *
1788    *  This library currently implements 3 versions of the message facet.  The
1789    *  first version (gnu) is a wrapper around gettext, provided by libintl.
1790    *  The second version (ieee) is a wrapper around catgets.  The final
1791    *  version (default) does no actual translation.  These implementations are
1792    *  only provided for char and wchar_t instantiations.
1793    *
1794    *  The messages template uses protected virtual functions to
1795    *  provide the actual results.  The public accessors forward the
1796    *  call to the virtual functions.  These virtual functions are
1797    *  hooks for developers to implement the behavior they require from
1798    *  the messages facet.
1799   */
1800   template<typename _CharT>
1801     class messages : public locale::facet, public messages_base
1802     {
1803     public:
1804       // Types:
1805       //@{
1806       /// Public typedefs
1807       typedef _CharT			char_type;
1808       typedef basic_string<_CharT>	string_type;
1809       //@}
1810 
1811     protected:
1812       // Underlying "C" library locale information saved from
1813       // initialization, needed by messages_byname as well.
1814       __c_locale			_M_c_locale_messages;
1815       const char*			_M_name_messages;
1816 
1817     public:
1818       /// Numpunct facet id.
1819       static locale::id			id;
1820 
1821       /**
1822        *  @brief  Constructor performs initialization.
1823        *
1824        *  This is the constructor provided by the standard.
1825        *
1826        *  @param __refs  Passed to the base facet class.
1827       */
1828       explicit
1829       messages(size_t __refs = 0);
1830 
1831       // Non-standard.
1832       /**
1833        *  @brief  Internal constructor.  Not for general use.
1834        *
1835        *  This is a constructor for use by the library itself to set up new
1836        *  locales.
1837        *
1838        *  @param  __cloc  The C locale.
1839        *  @param  __s  The name of a locale.
1840        *  @param  __refs  Refcount to pass to the base class.
1841        */
1842       explicit
1843       messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
1844 
1845       /*
1846        *  @brief  Open a message catalog.
1847        *
1848        *  This function opens and returns a handle to a message catalog by
1849        *  returning do_open(__s, __loc).
1850        *
1851        *  @param  __s  The catalog to open.
1852        *  @param  __loc  Locale to use for character set conversions.
1853        *  @return  Handle to the catalog or value < 0 if open fails.
1854       */
1855       catalog
1856       open(const basic_string<char>& __s, const locale& __loc) const
1857       { return this->do_open(__s, __loc); }
1858 
1859       // Non-standard and unorthodox, yet effective.
1860       /*
1861        *  @brief  Open a message catalog.
1862        *
1863        *  This non-standard function opens and returns a handle to a message
1864        *  catalog by returning do_open(s, loc).  The third argument provides a
1865        *  message catalog root directory for gnu gettext and is ignored
1866        *  otherwise.
1867        *
1868        *  @param  __s  The catalog to open.
1869        *  @param  __loc  Locale to use for character set conversions.
1870        *  @param  __dir  Message catalog root directory.
1871        *  @return  Handle to the catalog or value < 0 if open fails.
1872       */
1873       catalog
1874       open(const basic_string<char>&, const locale&, const char*) const;
1875 
1876       /*
1877        *  @brief  Look up a string in a message catalog.
1878        *
1879        *  This function retrieves and returns a message from a catalog by
1880        *  returning do_get(c, set, msgid, s).
1881        *
1882        *  For gnu, @a __set and @a msgid are ignored.  Returns gettext(s).
1883        *  For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1884        *
1885        *  @param  __c  The catalog to access.
1886        *  @param  __set  Implementation-defined.
1887        *  @param  __msgid  Implementation-defined.
1888        *  @param  __s  Default return value if retrieval fails.
1889        *  @return  Retrieved message or @a __s if get fails.
1890       */
1891       string_type
1892       get(catalog __c, int __set, int __msgid, const string_type& __s) const
1893       { return this->do_get(__c, __set, __msgid, __s); }
1894 
1895       /*
1896        *  @brief  Close a message catalog.
1897        *
1898        *  Closes catalog @a c by calling do_close(c).
1899        *
1900        *  @param  __c  The catalog to close.
1901       */
1902       void
1903       close(catalog __c) const
1904       { return this->do_close(__c); }
1905 
1906     protected:
1907       /// Destructor.
1908       virtual
1909       ~messages();
1910 
1911       /*
1912        *  @brief  Open a message catalog.
1913        *
1914        *  This function opens and returns a handle to a message catalog in an
1915        *  implementation-defined manner.  This function is a hook for derived
1916        *  classes to change the value returned.
1917        *
1918        *  @param  __s  The catalog to open.
1919        *  @param  __loc  Locale to use for character set conversions.
1920        *  @return  Handle to the opened catalog, value < 0 if open failed.
1921       */
1922       virtual catalog
1923       do_open(const basic_string<char>&, const locale&) const;
1924 
1925       /*
1926        *  @brief  Look up a string in a message catalog.
1927        *
1928        *  This function retrieves and returns a message from a catalog in an
1929        *  implementation-defined manner.  This function is a hook for derived
1930        *  classes to change the value returned.
1931        *
1932        *  For gnu, @a __set and @a __msgid are ignored.  Returns gettext(s).
1933        *  For default, returns s. For ieee, returns catgets(c,set,msgid,s).
1934        *
1935        *  @param  __c  The catalog to access.
1936        *  @param  __set  Implementation-defined.
1937        *  @param  __msgid  Implementation-defined.
1938        *  @param  __s  Default return value if retrieval fails.
1939        *  @return  Retrieved message or @a __s if get fails.
1940       */
1941       virtual string_type
1942       do_get(catalog, int, int, const string_type& __dfault) const;
1943 
1944       /*
1945        *  @brief  Close a message catalog.
1946        *
1947        *  @param  __c  The catalog to close.
1948       */
1949       virtual void
1950       do_close(catalog) const;
1951 
1952       // Returns a locale and codeset-converted string, given a char* message.
1953       char*
1954       _M_convert_to_char(const string_type& __msg) const
1955       {
1956 	// XXX
1957 	return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
1958       }
1959 
1960       // Returns a locale and codeset-converted string, given a char* message.
1961       string_type
1962       _M_convert_from_char(char*) const
1963       {
1964 	// XXX
1965 	return string_type();
1966       }
1967      };
1968 
1969   template<typename _CharT>
1970     locale::id messages<_CharT>::id;
1971 
1972   /// Specializations for required instantiations.
1973   template<>
1974     string
1975     messages<char>::do_get(catalog, int, int, const string&) const;
1976 
1977 #ifdef _GLIBCXX_USE_WCHAR_T
1978   template<>
1979     wstring
1980     messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
1981 #endif
1982 
1983    /// class messages_byname [22.2.7.2].
1984    template<typename _CharT>
1985     class messages_byname : public messages<_CharT>
1986     {
1987     public:
1988       typedef _CharT			char_type;
1989       typedef basic_string<_CharT>	string_type;
1990 
1991       explicit
1992       messages_byname(const char* __s, size_t __refs = 0);
1993 
1994 #if __cplusplus >= 201103L
1995       explicit
1996       messages_byname(const string& __s, size_t __refs = 0)
1997       : messages_byname(__s.c_str(), __refs) { }
1998 #endif
1999 
2000     protected:
2001       virtual
2002       ~messages_byname()
2003       { }
2004     };
2005 
2006 _GLIBCXX_END_NAMESPACE_CXX11
2007 
2008 _GLIBCXX_END_NAMESPACE_VERSION
2009 } // namespace
2010 
2011 // Include host and configuration specific messages functions.
2012 #include <bits/messages_members.h>
2013 
2014 // 22.2.1.5  Template class codecvt
2015 #include <bits/codecvt.h>
2016 
2017 #include <bits/locale_facets_nonio.tcc>
2018 
2019 #endif
2020