locale_facets.h (time_get::_M_extract_name): Add ctype argument.
[gcc.git] / libstdc++-v3 / include / bits / locale_facets.h
1 // Locale support -*- C++ -*-
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 //
32 // ISO C++ 14882: 22.1 Locales
33 //
34
35 /** @file locale_facets.h
36 * This is an internal header file, included by other library headers.
37 * You should not attempt to use it directly.
38 */
39
40 #ifndef _LOCALE_FACETS_H
41 #define _LOCALE_FACETS_H 1
42
43 #pragma GCC system_header
44
45 #include <ctime> // For struct tm
46 #include <cwctype> // For wctype_t
47 #include <iosfwd>
48 #include <bits/ios_base.h> // For ios_base, ios_base::iostate
49 #include <streambuf>
50
51 namespace std
52 {
53 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
54 #ifdef _GLIBCXX_USE_WCHAR_T
55 # define _GLIBCXX_NUM_FACETS 28
56 #else
57 # define _GLIBCXX_NUM_FACETS 14
58 #endif
59
60 // Convert string to numeric value of type _Tv and store results.
61 // NB: This is specialized for all required types, there is no
62 // generic definition.
63 template<typename _Tv>
64 void
65 __convert_to_v(const char* __in, _Tv& __out, ios_base::iostate& __err,
66 const __c_locale& __cloc, int __base = 10);
67
68 // Explicit specializations for required types.
69 template<>
70 void
71 __convert_to_v(const char*, long&, ios_base::iostate&,
72 const __c_locale&, int);
73
74 template<>
75 void
76 __convert_to_v(const char*, unsigned long&, ios_base::iostate&,
77 const __c_locale&, int);
78
79 #ifdef _GLIBCXX_USE_LONG_LONG
80 template<>
81 void
82 __convert_to_v(const char*, long long&, ios_base::iostate&,
83 const __c_locale&, int);
84
85 template<>
86 void
87 __convert_to_v(const char*, unsigned long long&, ios_base::iostate&,
88 const __c_locale&, int);
89 #endif
90
91 template<>
92 void
93 __convert_to_v(const char*, float&, ios_base::iostate&,
94 const __c_locale&, int);
95
96 template<>
97 void
98 __convert_to_v(const char*, double&, ios_base::iostate&,
99 const __c_locale&, int);
100
101 template<>
102 void
103 __convert_to_v(const char*, long double&, ios_base::iostate&,
104 const __c_locale&, int);
105
106 // NB: __pad is a struct, rather than a function, so it can be
107 // partially-specialized.
108 template<typename _CharT, typename _Traits>
109 struct __pad
110 {
111 static void
112 _S_pad(ios_base& __io, _CharT __fill, _CharT* __news,
113 const _CharT* __olds, const streamsize __newlen,
114 const streamsize __oldlen, const bool __num);
115 };
116
117 // Used by both numeric and monetary facets.
118 // Check to make sure that the __grouping_tmp string constructed in
119 // money_get or num_get matches the canonical grouping for a given
120 // locale.
121 // __grouping_tmp is parsed L to R
122 // 1,222,444 == __grouping_tmp of "\1\3\3"
123 // __grouping is parsed R to L
124 // 1,222,444 == __grouping of "\3" == "\3\3\3"
125 template<typename _CharT>
126 bool
127 __verify_grouping(const basic_string<_CharT>& __grouping,
128 const basic_string<_CharT>& __grouping_tmp);
129
130 // Used by both numeric and monetary facets.
131 // Inserts "group separator" characters into an array of characters.
132 // It's recursive, one iteration per group. It moves the characters
133 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
134 // only with __gbeg != __gend.
135 template<typename _CharT>
136 _CharT*
137 __add_grouping(_CharT* __s, _CharT __sep,
138 const char* __gbeg, const char* __gend,
139 const _CharT* __first, const _CharT* __last);
140
141 // This template permits specializing facet output code for
142 // ostreambuf_iterator. For ostreambuf_iterator, sputn is
143 // significantly more efficient than incrementing iterators.
144 template<typename _CharT>
145 inline
146 ostreambuf_iterator<_CharT>
147 __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len)
148 {
149 __s._M_put(__ws, __len);
150 return __s;
151 }
152
153 // This is the unspecialized form of the template.
154 template<typename _CharT, typename _OutIter>
155 inline
156 _OutIter
157 __write(_OutIter __s, const _CharT* __ws, int __len)
158 {
159 for (int __j = 0; __j < __len; __j++, ++__s)
160 *__s = __ws[__j];
161 return __s;
162 }
163
164
165 // 22.2.1.1 Template class ctype
166 // Include host and configuration specific ctype enums for ctype_base.
167 #include <bits/ctype_base.h>
168
169 // Common base for ctype<_CharT>.
170 template<typename _CharT>
171 class __ctype_abstract_base : public locale::facet, public ctype_base
172 {
173 public:
174 // Types:
175 typedef _CharT char_type;
176
177 bool
178 is(mask __m, char_type __c) const
179 { return this->do_is(__m, __c); }
180
181 const char_type*
182 is(const char_type *__lo, const char_type *__hi, mask *__vec) const
183 { return this->do_is(__lo, __hi, __vec); }
184
185 const char_type*
186 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
187 { return this->do_scan_is(__m, __lo, __hi); }
188
189 const char_type*
190 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
191 { return this->do_scan_not(__m, __lo, __hi); }
192
193 char_type
194 toupper(char_type __c) const
195 { return this->do_toupper(__c); }
196
197 const char_type*
198 toupper(char_type *__lo, const char_type* __hi) const
199 { return this->do_toupper(__lo, __hi); }
200
201 char_type
202 tolower(char_type __c) const
203 { return this->do_tolower(__c); }
204
205 const char_type*
206 tolower(char_type* __lo, const char_type* __hi) const
207 { return this->do_tolower(__lo, __hi); }
208
209 char_type
210 widen(char __c) const
211 { return this->do_widen(__c); }
212
213 const char*
214 widen(const char* __lo, const char* __hi, char_type* __to) const
215 { return this->do_widen(__lo, __hi, __to); }
216
217 char
218 narrow(char_type __c, char __dfault) const
219 { return this->do_narrow(__c, __dfault); }
220
221 const char_type*
222 narrow(const char_type* __lo, const char_type* __hi,
223 char __dfault, char *__to) const
224 { return this->do_narrow(__lo, __hi, __dfault, __to); }
225
226 protected:
227 explicit
228 __ctype_abstract_base(size_t __refs = 0): facet(__refs) { }
229
230 virtual
231 ~__ctype_abstract_base() { }
232
233 virtual bool
234 do_is(mask __m, char_type __c) const = 0;
235
236 virtual const char_type*
237 do_is(const char_type* __lo, const char_type* __hi,
238 mask* __vec) const = 0;
239
240 virtual const char_type*
241 do_scan_is(mask __m, const char_type* __lo,
242 const char_type* __hi) const = 0;
243
244 virtual const char_type*
245 do_scan_not(mask __m, const char_type* __lo,
246 const char_type* __hi) const = 0;
247
248 virtual char_type
249 do_toupper(char_type) const = 0;
250
251 virtual const char_type*
252 do_toupper(char_type* __lo, const char_type* __hi) const = 0;
253
254 virtual char_type
255 do_tolower(char_type) const = 0;
256
257 virtual const char_type*
258 do_tolower(char_type* __lo, const char_type* __hi) const = 0;
259
260 virtual char_type
261 do_widen(char) const = 0;
262
263 virtual const char*
264 do_widen(const char* __lo, const char* __hi,
265 char_type* __dest) const = 0;
266
267 virtual char
268 do_narrow(char_type, char __dfault) const = 0;
269
270 virtual const char_type*
271 do_narrow(const char_type* __lo, const char_type* __hi,
272 char __dfault, char* __dest) const = 0;
273 };
274
275 // NB: Generic, mostly useless implementation.
276 template<typename _CharT>
277 class ctype : public __ctype_abstract_base<_CharT>
278 {
279 public:
280 // Types:
281 typedef _CharT char_type;
282 typedef typename ctype::mask mask;
283
284 static locale::id id;
285
286 explicit
287 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
288
289 protected:
290 virtual
291 ~ctype();
292
293 virtual bool
294 do_is(mask __m, char_type __c) const;
295
296 virtual const char_type*
297 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
298
299 virtual const char_type*
300 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
301
302 virtual const char_type*
303 do_scan_not(mask __m, const char_type* __lo,
304 const char_type* __hi) const;
305
306 virtual char_type
307 do_toupper(char_type __c) const;
308
309 virtual const char_type*
310 do_toupper(char_type* __lo, const char_type* __hi) const;
311
312 virtual char_type
313 do_tolower(char_type __c) const;
314
315 virtual const char_type*
316 do_tolower(char_type* __lo, const char_type* __hi) const;
317
318 virtual char_type
319 do_widen(char __c) const;
320
321 virtual const char*
322 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
323
324 virtual char
325 do_narrow(char_type, char __dfault) const;
326
327 virtual const char_type*
328 do_narrow(const char_type* __lo, const char_type* __hi,
329 char __dfault, char* __dest) const;
330 };
331
332 template<typename _CharT>
333 locale::id ctype<_CharT>::id;
334
335 // 22.2.1.3 ctype<char> specialization.
336 template<>
337 class ctype<char> : public locale::facet, public ctype_base
338 {
339 public:
340 // Types:
341 typedef char char_type;
342
343 protected:
344 // Data Members:
345 __c_locale _M_c_locale_ctype;
346 bool _M_del;
347 __to_type _M_toupper;
348 __to_type _M_tolower;
349 const mask* _M_table;
350
351 public:
352 static locale::id id;
353 static const size_t table_size = 1 + static_cast<unsigned char>(-1);
354
355 explicit
356 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
357
358 explicit
359 ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
360 size_t __refs = 0);
361
362 inline bool
363 is(mask __m, char __c) const;
364
365 inline const char*
366 is(const char* __lo, const char* __hi, mask* __vec) const;
367
368 inline const char*
369 scan_is(mask __m, const char* __lo, const char* __hi) const;
370
371 inline const char*
372 scan_not(mask __m, const char* __lo, const char* __hi) const;
373
374 char_type
375 toupper(char_type __c) const
376 { return this->do_toupper(__c); }
377
378 const char_type*
379 toupper(char_type *__lo, const char_type* __hi) const
380 { return this->do_toupper(__lo, __hi); }
381
382 char_type
383 tolower(char_type __c) const
384 { return this->do_tolower(__c); }
385
386 const char_type*
387 tolower(char_type* __lo, const char_type* __hi) const
388 { return this->do_tolower(__lo, __hi); }
389
390 char_type
391 widen(char __c) const
392 { return this->do_widen(__c); }
393
394 const char*
395 widen(const char* __lo, const char* __hi, char_type* __to) const
396 { return this->do_widen(__lo, __hi, __to); }
397
398 char
399 narrow(char_type __c, char __dfault) const
400 { return this->do_narrow(__c, __dfault); }
401
402 const char_type*
403 narrow(const char_type* __lo, const char_type* __hi,
404 char __dfault, char *__to) const
405 { return this->do_narrow(__lo, __hi, __dfault, __to); }
406
407 protected:
408 const mask*
409 table() const throw()
410 { return _M_table; }
411
412 static const mask*
413 classic_table() throw();
414
415 virtual
416 ~ctype();
417
418 virtual char_type
419 do_toupper(char_type) const;
420
421 virtual const char_type*
422 do_toupper(char_type* __lo, const char_type* __hi) const;
423
424 virtual char_type
425 do_tolower(char_type) const;
426
427 virtual const char_type*
428 do_tolower(char_type* __lo, const char_type* __hi) const;
429
430 virtual char_type
431 do_widen(char __c) const
432 { return __c; }
433
434 virtual const char*
435 do_widen(const char* __lo, const char* __hi, char_type* __dest) const
436 {
437 memcpy(__dest, __lo, __hi - __lo);
438 return __hi;
439 }
440
441 virtual char
442 do_narrow(char_type __c, char) const
443 { return __c; }
444
445 virtual const char_type*
446 do_narrow(const char_type* __lo, const char_type* __hi,
447 char, char* __dest) const
448 {
449 memcpy(__dest, __lo, __hi - __lo);
450 return __hi;
451 }
452 };
453
454 template<>
455 const ctype<char>&
456 use_facet<ctype<char> >(const locale& __loc);
457
458 #ifdef _GLIBCXX_USE_WCHAR_T
459 // 22.2.1.3 ctype<wchar_t> specialization
460 template<>
461 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
462 {
463 public:
464 // Types:
465 typedef wchar_t char_type;
466 typedef wctype_t __wmask_type;
467
468 protected:
469 __c_locale _M_c_locale_ctype;
470
471 public:
472 // Data Members:
473 static locale::id id;
474
475 explicit
476 ctype(size_t __refs = 0);
477
478 explicit
479 ctype(__c_locale __cloc, size_t __refs = 0);
480
481 protected:
482 __wmask_type
483 _M_convert_to_wmask(const mask __m) const;
484
485 virtual
486 ~ctype();
487
488 virtual bool
489 do_is(mask __m, char_type __c) const;
490
491 virtual const char_type*
492 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
493
494 virtual const char_type*
495 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
496
497 virtual const char_type*
498 do_scan_not(mask __m, const char_type* __lo,
499 const char_type* __hi) const;
500
501 virtual char_type
502 do_toupper(char_type) const;
503
504 virtual const char_type*
505 do_toupper(char_type* __lo, const char_type* __hi) const;
506
507 virtual char_type
508 do_tolower(char_type) const;
509
510 virtual const char_type*
511 do_tolower(char_type* __lo, const char_type* __hi) const;
512
513 virtual char_type
514 do_widen(char) const;
515
516 virtual const char*
517 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
518
519 virtual char
520 do_narrow(char_type, char __dfault) const;
521
522 virtual const char_type*
523 do_narrow(const char_type* __lo, const char_type* __hi,
524 char __dfault, char* __dest) const;
525 };
526
527 template<>
528 const ctype<wchar_t>&
529 use_facet<ctype<wchar_t> >(const locale& __loc);
530 #endif //_GLIBCXX_USE_WCHAR_T
531
532 // Include host and configuration specific ctype inlines.
533 #include <bits/ctype_inline.h>
534
535 // 22.2.1.2 Template class ctype_byname
536 template<typename _CharT>
537 class ctype_byname : public ctype<_CharT>
538 {
539 public:
540 typedef _CharT char_type;
541
542 explicit
543 ctype_byname(const char* __s, size_t __refs = 0);
544
545 protected:
546 virtual
547 ~ctype_byname() { };
548 };
549
550 // 22.2.1.4 Class ctype_byname specializations.
551 template<>
552 ctype_byname<char>::ctype_byname(const char*, size_t refs);
553
554 template<>
555 ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs);
556
557 // 22.2.1.5 Template class codecvt
558 #include <bits/codecvt.h>
559
560 // 22.2.2 The numeric category.
561 class __num_base
562 {
563 public:
564 // NB: Code depends on the order of _S_atoms_out elements.
565 // Below are the indices into _S_atoms_out.
566 enum
567 {
568 _S_ominus,
569 _S_oplus,
570 _S_ox,
571 _S_oX,
572 _S_odigits,
573 _S_odigits_end = _S_odigits + 16,
574 _S_oudigits = _S_odigits_end,
575 _S_oudigits_end = _S_oudigits + 16,
576 _S_oe = _S_odigits + 14, // For scientific notation, 'e'
577 _S_oE = _S_oudigits + 14, // For scientific notation, 'E'
578 _S_oend = _S_oudigits_end
579 };
580
581 // A list of valid numeric literals for output. This array
582 // contains chars that will be passed through the current locale's
583 // ctype<_CharT>.widen() and then used to render numbers.
584 // For the standard "C" locale, this is
585 // "-+xX0123456789abcdef0123456789ABCDEF".
586 static const char* _S_atoms_out;
587
588 // String literal of acceptable (narrow) input, for num_get.
589 // "-+xX0123456789eEabcdfABCDF"
590 static const char* _S_atoms_in;
591
592 enum
593 {
594 _S_iminus,
595 _S_iplus,
596 _S_ix,
597 _S_iX,
598 _S_izero,
599 _S_ie = _S_izero + 10,
600 _S_iE = _S_izero + 11,
601 _S_iend = 26
602 };
603
604 // num_put
605 // Construct and return valid scanf format for floating point types.
606 static void
607 _S_format_float(const ios_base& __io, char* __fptr, char __mod);
608 };
609
610 template<typename _CharT>
611 struct __numpunct_cache : public locale::facet
612 {
613 const char* _M_grouping;
614 bool _M_use_grouping;
615 const _CharT* _M_truename;
616 const _CharT* _M_falsename;
617 _CharT _M_decimal_point;
618 _CharT _M_thousands_sep;
619
620 // A list of valid numeric literals for output: in the standard
621 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
622 // This array contains the chars after having been passed
623 // through the current locale's ctype<_CharT>.widen().
624 _CharT _M_atoms_out[__num_base::_S_oend + 1];
625
626 // A list of valid numeric literals for input: in the standard
627 // "C" locale, this is "-+xX0123456789eEabcdfABCDF"
628 // This array contains the chars after having been passed
629 // through the current locale's ctype<_CharT>.widen().
630 _CharT _M_atoms_in[__num_base::_S_iend + 1];
631
632 bool _M_allocated;
633
634 __numpunct_cache(size_t __refs = 0) : facet(__refs),
635 _M_grouping(NULL), _M_use_grouping(false), _M_truename(NULL),
636 _M_falsename(NULL), _M_decimal_point(_CharT()),
637 _M_thousands_sep(_CharT()), _M_allocated(false)
638 { }
639
640 ~__numpunct_cache();
641
642 void
643 _M_cache(const locale& __loc);
644 };
645
646 template<typename _CharT>
647 void
648 __numpunct_cache<_CharT>::_M_cache(const locale& __loc)
649 {
650 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
651 string __grouping = __np.grouping();
652 char* __group = new char[__grouping.length() + 1];
653 __grouping.copy(__group, __grouping.length());
654 __group[__grouping.length()] = char();
655 _M_grouping = __group;
656
657 _M_use_grouping = __grouping.length() != 0 && __grouping.data()[0] != 0;
658
659 typedef basic_string<_CharT> __string_type;
660
661 __string_type __true = __np.truename();
662 _CharT* __truename = new _CharT[__true.length() + 1];
663 __true.copy(__truename, __true.length());
664 __truename[__true.length()] = _CharT();
665 _M_truename = __truename;
666
667 __string_type __false = __np.falsename();
668 _CharT* __falsename = new _CharT[__false.length() + 1];
669 __false.copy(__falsename, __false.length());
670 __falsename[__false.length()] = _CharT();
671 _M_falsename = __falsename;
672
673 _M_decimal_point = __np.decimal_point();
674 _M_thousands_sep = __np.thousands_sep();
675
676 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
677 __ct.widen(__num_base::_S_atoms_out,
678 __num_base::_S_atoms_out + __num_base::_S_oend, _M_atoms_out);
679 _M_atoms_out[__num_base::_S_oend] = _CharT();
680 __ct.widen(__num_base::_S_atoms_in,
681 __num_base::_S_atoms_in + __num_base::_S_iend, _M_atoms_in);
682 _M_atoms_in[__num_base::_S_iend] = _CharT();
683
684 _M_allocated = true;
685 }
686
687 template<typename _CharT>
688 __numpunct_cache<_CharT>::~__numpunct_cache()
689 {
690 if (_M_allocated)
691 {
692 delete [] _M_grouping;
693 delete [] _M_truename;
694 delete [] _M_falsename;
695 }
696 }
697
698 template<typename _CharT>
699 class numpunct : public locale::facet
700 {
701 public:
702 // Types:
703 typedef _CharT char_type;
704 typedef basic_string<_CharT> string_type;
705 typedef __numpunct_cache<_CharT> __cache_type;
706
707 protected:
708 __cache_type* _M_data;
709
710 public:
711 static locale::id id;
712
713 explicit
714 numpunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
715 { _M_initialize_numpunct(); }
716
717 explicit
718 numpunct(__cache_type* __cache, size_t __refs = 0)
719 : facet(__refs), _M_data(__cache)
720 { _M_initialize_numpunct(); }
721
722 explicit
723 numpunct(__c_locale __cloc, size_t __refs = 0)
724 : facet(__refs), _M_data(NULL)
725 { _M_initialize_numpunct(__cloc); }
726
727 char_type
728 decimal_point() const
729 { return this->do_decimal_point(); }
730
731 char_type
732 thousands_sep() const
733 { return this->do_thousands_sep(); }
734
735 string
736 grouping() const
737 { return this->do_grouping(); }
738
739 string_type
740 truename() const
741 { return this->do_truename(); }
742
743 string_type
744 falsename() const
745 { return this->do_falsename(); }
746
747 protected:
748 virtual
749 ~numpunct();
750
751 virtual char_type
752 do_decimal_point() const
753 { return _M_data->_M_decimal_point; }
754
755 virtual char_type
756 do_thousands_sep() const
757 { return _M_data->_M_thousands_sep; }
758
759 virtual string
760 do_grouping() const
761 { return _M_data->_M_grouping; }
762
763 virtual string_type
764 do_truename() const
765 { return _M_data->_M_truename; }
766
767 virtual string_type
768 do_falsename() const
769 { return _M_data->_M_falsename; }
770
771 // For use at construction time only.
772 void
773 _M_initialize_numpunct(__c_locale __cloc = NULL);
774 };
775
776 template<typename _CharT>
777 locale::id numpunct<_CharT>::id;
778
779 template<>
780 numpunct<char>::~numpunct();
781
782 template<>
783 void
784 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
785
786 #ifdef _GLIBCXX_USE_WCHAR_T
787 template<>
788 numpunct<wchar_t>::~numpunct();
789
790 template<>
791 void
792 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
793 #endif
794
795 template<typename _CharT>
796 class numpunct_byname : public numpunct<_CharT>
797 {
798 public:
799 typedef _CharT char_type;
800 typedef basic_string<_CharT> string_type;
801
802 explicit
803 numpunct_byname(const char* __s, size_t __refs = 0)
804 : numpunct<_CharT>(__refs)
805 {
806 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
807 {
808 __c_locale __tmp;
809 this->_S_create_c_locale(__tmp, __s);
810 this->_M_initialize_numpunct(__tmp);
811 this->_S_destroy_c_locale(__tmp);
812 }
813 }
814
815 protected:
816 virtual
817 ~numpunct_byname() { }
818 };
819
820 template<typename _CharT, typename _InIter>
821 class num_get : public locale::facet, public __num_base
822 {
823 public:
824 // Types:
825 typedef _CharT char_type;
826 typedef _InIter iter_type;
827
828 static locale::id id;
829
830 explicit
831 num_get(size_t __refs = 0) : facet(__refs) { }
832
833 iter_type
834 get(iter_type __in, iter_type __end, ios_base& __io,
835 ios_base::iostate& __err, bool& __v) const
836 { return this->do_get(__in, __end, __io, __err, __v); }
837
838 iter_type
839 get(iter_type __in, iter_type __end, ios_base& __io,
840 ios_base::iostate& __err, long& __v) const
841 { return this->do_get(__in, __end, __io, __err, __v); }
842
843 iter_type
844 get(iter_type __in, iter_type __end, ios_base& __io,
845 ios_base::iostate& __err, unsigned short& __v) const
846 { return this->do_get(__in, __end, __io, __err, __v); }
847
848 iter_type
849 get(iter_type __in, iter_type __end, ios_base& __io,
850 ios_base::iostate& __err, unsigned int& __v) const
851 { return this->do_get(__in, __end, __io, __err, __v); }
852
853 iter_type
854 get(iter_type __in, iter_type __end, ios_base& __io,
855 ios_base::iostate& __err, unsigned long& __v) const
856 { return this->do_get(__in, __end, __io, __err, __v); }
857
858 #ifdef _GLIBCXX_USE_LONG_LONG
859 iter_type
860 get(iter_type __in, iter_type __end, ios_base& __io,
861 ios_base::iostate& __err, long long& __v) const
862 { return this->do_get(__in, __end, __io, __err, __v); }
863
864 iter_type
865 get(iter_type __in, iter_type __end, ios_base& __io,
866 ios_base::iostate& __err, unsigned long long& __v) const
867 { return this->do_get(__in, __end, __io, __err, __v); }
868 #endif
869
870 iter_type
871 get(iter_type __in, iter_type __end, ios_base& __io,
872 ios_base::iostate& __err, float& __v) const
873 { return this->do_get(__in, __end, __io, __err, __v); }
874
875 iter_type
876 get(iter_type __in, iter_type __end, ios_base& __io,
877 ios_base::iostate& __err, double& __v) const
878 { return this->do_get(__in, __end, __io, __err, __v); }
879
880 iter_type
881 get(iter_type __in, iter_type __end, ios_base& __io,
882 ios_base::iostate& __err, long double& __v) const
883 { return this->do_get(__in, __end, __io, __err, __v); }
884
885 iter_type
886 get(iter_type __in, iter_type __end, ios_base& __io,
887 ios_base::iostate& __err, void*& __v) const
888 { return this->do_get(__in, __end, __io, __err, __v); }
889
890 protected:
891 virtual ~num_get() { }
892
893 iter_type
894 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
895 string& __xtrc) const;
896
897 iter_type
898 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
899 string& __xtrc, int& __base) const;
900
901 virtual iter_type
902 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
903
904
905 virtual iter_type
906 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
907
908 virtual iter_type
909 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
910 unsigned short&) const;
911
912 virtual iter_type
913 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
914 unsigned int&) const;
915
916 virtual iter_type
917 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
918 unsigned long&) const;
919
920 #ifdef _GLIBCXX_USE_LONG_LONG
921 virtual iter_type
922 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
923 long long&) const;
924
925 virtual iter_type
926 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
927 unsigned long long&) const;
928 #endif
929
930 virtual iter_type
931 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
932 float&) const;
933
934 virtual iter_type
935 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
936 double&) const;
937
938 virtual iter_type
939 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
940 long double&) const;
941
942 virtual iter_type
943 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
944 void*&) const;
945 };
946
947 template<typename _CharT, typename _InIter>
948 locale::id num_get<_CharT, _InIter>::id;
949
950
951 template<typename _CharT, typename _OutIter>
952 class num_put : public locale::facet, public __num_base
953 {
954 public:
955 // Types:
956 typedef _CharT char_type;
957 typedef _OutIter iter_type;
958 static locale::id id;
959
960 explicit
961 num_put(size_t __refs = 0) : facet(__refs) { }
962
963 iter_type
964 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
965 { return this->do_put(__s, __f, __fill, __v); }
966
967 iter_type
968 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
969 { return this->do_put(__s, __f, __fill, __v); }
970
971 iter_type
972 put(iter_type __s, ios_base& __f, char_type __fill,
973 unsigned long __v) const
974 { return this->do_put(__s, __f, __fill, __v); }
975
976 #ifdef _GLIBCXX_USE_LONG_LONG
977 iter_type
978 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
979 { return this->do_put(__s, __f, __fill, __v); }
980
981 iter_type
982 put(iter_type __s, ios_base& __f, char_type __fill,
983 unsigned long long __v) const
984 { return this->do_put(__s, __f, __fill, __v); }
985 #endif
986
987 iter_type
988 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
989 { return this->do_put(__s, __f, __fill, __v); }
990
991 iter_type
992 put(iter_type __s, ios_base& __f, char_type __fill,
993 long double __v) const
994 { return this->do_put(__s, __f, __fill, __v); }
995
996 iter_type
997 put(iter_type __s, ios_base& __f, char_type __fill,
998 const void* __v) const
999 { return this->do_put(__s, __f, __fill, __v); }
1000
1001 protected:
1002 template<typename _ValueT>
1003 iter_type
1004 _M_insert_float(iter_type, ios_base& __io, char_type __fill,
1005 char __mod, _ValueT __v) const;
1006
1007 void
1008 _M_group_float(const string& __grouping, char_type __sep,
1009 const char_type* __p, char_type* __new, char_type* __cs,
1010 int& __len) const;
1011
1012 template<typename _ValueT>
1013 iter_type
1014 _M_insert_int(iter_type, ios_base& __io, char_type __fill,
1015 _ValueT __v) const;
1016
1017 void
1018 _M_group_int(const string& __grouping, char_type __sep,
1019 ios_base& __io, char_type* __new, char_type* __cs,
1020 int& __len) const;
1021
1022 void
1023 _M_pad(char_type __fill, streamsize __w, ios_base& __io,
1024 char_type* __new, const char_type* __cs, int& __len) const;
1025
1026 virtual
1027 ~num_put() { };
1028
1029 virtual iter_type
1030 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
1031
1032 virtual iter_type
1033 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
1034
1035 virtual iter_type
1036 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
1037
1038 #ifdef _GLIBCXX_USE_LONG_LONG
1039 virtual iter_type
1040 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
1041
1042 virtual iter_type
1043 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
1044 #endif
1045
1046 virtual iter_type
1047 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
1048
1049 virtual iter_type
1050 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
1051
1052 virtual iter_type
1053 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
1054 };
1055
1056 template <typename _CharT, typename _OutIter>
1057 locale::id num_put<_CharT, _OutIter>::id;
1058
1059
1060 template<typename _CharT>
1061 class collate : public locale::facet
1062 {
1063 public:
1064 // Types:
1065 typedef _CharT char_type;
1066 typedef basic_string<_CharT> string_type;
1067
1068 protected:
1069 // Underlying "C" library locale information saved from
1070 // initialization, needed by collate_byname as well.
1071 __c_locale _M_c_locale_collate;
1072
1073 public:
1074 static locale::id id;
1075
1076 explicit
1077 collate(size_t __refs = 0)
1078 : facet(__refs)
1079 { _M_c_locale_collate = _S_get_c_locale(); }
1080
1081 explicit
1082 collate(__c_locale __cloc, size_t __refs = 0)
1083 : facet(__refs)
1084 { _M_c_locale_collate = _S_clone_c_locale(__cloc); }
1085
1086 int
1087 compare(const _CharT* __lo1, const _CharT* __hi1,
1088 const _CharT* __lo2, const _CharT* __hi2) const
1089 { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
1090
1091 string_type
1092 transform(const _CharT* __lo, const _CharT* __hi) const
1093 { return this->do_transform(__lo, __hi); }
1094
1095 long
1096 hash(const _CharT* __lo, const _CharT* __hi) const
1097 { return this->do_hash(__lo, __hi); }
1098
1099 // Used to abstract out _CharT bits in virtual member functions, below.
1100 int
1101 _M_compare(const _CharT*, const _CharT*) const;
1102
1103 size_t
1104 _M_transform(_CharT*, const _CharT*, size_t) const;
1105
1106 protected:
1107 virtual
1108 ~collate()
1109 { _S_destroy_c_locale(_M_c_locale_collate); }
1110
1111 virtual int
1112 do_compare(const _CharT* __lo1, const _CharT* __hi1,
1113 const _CharT* __lo2, const _CharT* __hi2) const;
1114
1115 virtual string_type
1116 do_transform(const _CharT* __lo, const _CharT* __hi) const;
1117
1118 virtual long
1119 do_hash(const _CharT* __lo, const _CharT* __hi) const;
1120 };
1121
1122 template<typename _CharT>
1123 locale::id collate<_CharT>::id;
1124
1125 // Specializations.
1126 template<>
1127 int
1128 collate<char>::_M_compare(const char*, const char*) const;
1129
1130 template<>
1131 size_t
1132 collate<char>::_M_transform(char*, const char*, size_t) const;
1133
1134 #ifdef _GLIBCXX_USE_WCHAR_T
1135 template<>
1136 int
1137 collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
1138
1139 template<>
1140 size_t
1141 collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
1142 #endif
1143
1144 template<typename _CharT>
1145 class collate_byname : public collate<_CharT>
1146 {
1147 public:
1148 typedef _CharT char_type;
1149 typedef basic_string<_CharT> string_type;
1150
1151 explicit
1152 collate_byname(const char* __s, size_t __refs = 0)
1153 : collate<_CharT>(__refs)
1154 {
1155 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
1156 {
1157 this->_S_destroy_c_locale(this->_M_c_locale_collate);
1158 this->_S_create_c_locale(this->_M_c_locale_collate, __s);
1159 }
1160 }
1161
1162 protected:
1163 virtual
1164 ~collate_byname() { }
1165 };
1166
1167
1168 class time_base
1169 {
1170 public:
1171 enum dateorder { no_order, dmy, mdy, ymd, ydm };
1172 };
1173
1174 template<typename _CharT>
1175 struct __timepunct_cache : public locale::facet
1176 {
1177 // List of all known timezones, with GMT first.
1178 static const _CharT* _S_timezones[14];
1179
1180 const _CharT* _M_date_format;
1181 const _CharT* _M_date_era_format;
1182 const _CharT* _M_time_format;
1183 const _CharT* _M_time_era_format;
1184 const _CharT* _M_date_time_format;
1185 const _CharT* _M_date_time_era_format;
1186 const _CharT* _M_am;
1187 const _CharT* _M_pm;
1188 const _CharT* _M_am_pm_format;
1189
1190 // Day names, starting with "C"'s Sunday.
1191 const _CharT* _M_day1;
1192 const _CharT* _M_day2;
1193 const _CharT* _M_day3;
1194 const _CharT* _M_day4;
1195 const _CharT* _M_day5;
1196 const _CharT* _M_day6;
1197 const _CharT* _M_day7;
1198
1199 // Abbreviated day names, starting with "C"'s Sun.
1200 const _CharT* _M_aday1;
1201 const _CharT* _M_aday2;
1202 const _CharT* _M_aday3;
1203 const _CharT* _M_aday4;
1204 const _CharT* _M_aday5;
1205 const _CharT* _M_aday6;
1206 const _CharT* _M_aday7;
1207
1208 // Month names, starting with "C"'s January.
1209 const _CharT* _M_month01;
1210 const _CharT* _M_month02;
1211 const _CharT* _M_month03;
1212 const _CharT* _M_month04;
1213 const _CharT* _M_month05;
1214 const _CharT* _M_month06;
1215 const _CharT* _M_month07;
1216 const _CharT* _M_month08;
1217 const _CharT* _M_month09;
1218 const _CharT* _M_month10;
1219 const _CharT* _M_month11;
1220 const _CharT* _M_month12;
1221
1222 // Abbreviated month names, starting with "C"'s Jan.
1223 const _CharT* _M_amonth01;
1224 const _CharT* _M_amonth02;
1225 const _CharT* _M_amonth03;
1226 const _CharT* _M_amonth04;
1227 const _CharT* _M_amonth05;
1228 const _CharT* _M_amonth06;
1229 const _CharT* _M_amonth07;
1230 const _CharT* _M_amonth08;
1231 const _CharT* _M_amonth09;
1232 const _CharT* _M_amonth10;
1233 const _CharT* _M_amonth11;
1234 const _CharT* _M_amonth12;
1235
1236 bool _M_allocated;
1237
1238 __timepunct_cache(size_t __refs = 0) : facet(__refs),
1239 _M_date_format(NULL), _M_date_era_format(NULL), _M_time_format(NULL),
1240 _M_time_era_format(NULL), _M_date_time_format(NULL),
1241 _M_date_time_era_format(NULL), _M_am(NULL), _M_pm(NULL),
1242 _M_am_pm_format(NULL), _M_day1(NULL), _M_day2(NULL), _M_day3(NULL),
1243 _M_day4(NULL), _M_day5(NULL), _M_day6(NULL), _M_day7(NULL),
1244 _M_aday1(NULL), _M_aday2(NULL), _M_aday3(NULL), _M_aday4(NULL),
1245 _M_aday5(NULL), _M_aday6(NULL), _M_aday7(NULL), _M_month01(NULL),
1246 _M_month02(NULL), _M_month03(NULL), _M_month04(NULL), _M_month05(NULL),
1247 _M_month06(NULL), _M_month07(NULL), _M_month08(NULL), _M_month09(NULL),
1248 _M_month10(NULL), _M_month11(NULL), _M_month12(NULL), _M_amonth01(NULL),
1249 _M_amonth02(NULL), _M_amonth03(NULL), _M_amonth04(NULL),
1250 _M_amonth05(NULL), _M_amonth06(NULL), _M_amonth07(NULL),
1251 _M_amonth08(NULL), _M_amonth09(NULL), _M_amonth10(NULL),
1252 _M_amonth11(NULL), _M_amonth12(NULL), _M_allocated(false)
1253 { }
1254
1255 ~__timepunct_cache();
1256
1257 void
1258 _M_cache(const locale& __loc);
1259 };
1260
1261 template<typename _CharT>
1262 __timepunct_cache<_CharT>::~__timepunct_cache()
1263 {
1264 if (_M_allocated)
1265 {
1266 // XXX.
1267 }
1268 }
1269
1270 // Specializations.
1271 template<>
1272 const char*
1273 __timepunct_cache<char>::_S_timezones[14];
1274
1275 #ifdef _GLIBCXX_USE_WCHAR_T
1276 template<>
1277 const wchar_t*
1278 __timepunct_cache<wchar_t>::_S_timezones[14];
1279 #endif
1280
1281 // Generic.
1282 template<typename _CharT>
1283 const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
1284
1285 template<typename _CharT>
1286 class __timepunct : public locale::facet
1287 {
1288 public:
1289 // Types:
1290 typedef _CharT __char_type;
1291 typedef basic_string<_CharT> __string_type;
1292 typedef __timepunct_cache<_CharT> __cache_type;
1293
1294 protected:
1295 __cache_type* _M_data;
1296 __c_locale _M_c_locale_timepunct;
1297 const char* _M_name_timepunct;
1298
1299 public:
1300 static locale::id id;
1301
1302 explicit
1303 __timepunct(size_t __refs = 0);
1304
1305 explicit
1306 __timepunct(__cache_type* __cache, size_t __refs = 0);
1307
1308 explicit
1309 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
1310
1311 void
1312 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
1313 const tm* __tm) const;
1314
1315 void
1316 _M_date_formats(const _CharT** __date) const
1317 {
1318 // Always have default first.
1319 __date[0] = _M_data->_M_date_format;
1320 __date[1] = _M_data->_M_date_era_format;
1321 }
1322
1323 void
1324 _M_time_formats(const _CharT** __time) const
1325 {
1326 // Always have default first.
1327 __time[0] = _M_data->_M_time_format;
1328 __time[1] = _M_data->_M_time_era_format;
1329 }
1330
1331 void
1332 _M_ampm(const _CharT** __ampm) const
1333 {
1334 __ampm[0] = _M_data->_M_am;
1335 __ampm[1] = _M_data->_M_pm;
1336 }
1337
1338 void
1339 _M_date_time_formats(const _CharT** __dt) const
1340 {
1341 // Always have default first.
1342 __dt[0] = _M_data->_M_date_time_format;
1343 __dt[1] = _M_data->_M_date_time_era_format;
1344 }
1345
1346 void
1347 _M_days(const _CharT** __days) const
1348 {
1349 __days[0] = _M_data->_M_day1;
1350 __days[1] = _M_data->_M_day2;
1351 __days[2] = _M_data->_M_day3;
1352 __days[3] = _M_data->_M_day4;
1353 __days[4] = _M_data->_M_day5;
1354 __days[5] = _M_data->_M_day6;
1355 __days[6] = _M_data->_M_day7;
1356 }
1357
1358 void
1359 _M_days_abbreviated(const _CharT** __days) const
1360 {
1361 __days[0] = _M_data->_M_aday1;
1362 __days[1] = _M_data->_M_aday2;
1363 __days[2] = _M_data->_M_aday3;
1364 __days[3] = _M_data->_M_aday4;
1365 __days[4] = _M_data->_M_aday5;
1366 __days[5] = _M_data->_M_aday6;
1367 __days[6] = _M_data->_M_aday7;
1368 }
1369
1370 void
1371 _M_months(const _CharT** __months) const
1372 {
1373 __months[0] = _M_data->_M_month01;
1374 __months[1] = _M_data->_M_month02;
1375 __months[2] = _M_data->_M_month03;
1376 __months[3] = _M_data->_M_month04;
1377 __months[4] = _M_data->_M_month05;
1378 __months[5] = _M_data->_M_month06;
1379 __months[6] = _M_data->_M_month07;
1380 __months[7] = _M_data->_M_month08;
1381 __months[8] = _M_data->_M_month09;
1382 __months[9] = _M_data->_M_month10;
1383 __months[10] = _M_data->_M_month11;
1384 __months[11] = _M_data->_M_month12;
1385 }
1386
1387 void
1388 _M_months_abbreviated(const _CharT** __months) const
1389 {
1390 __months[0] = _M_data->_M_amonth01;
1391 __months[1] = _M_data->_M_amonth02;
1392 __months[2] = _M_data->_M_amonth03;
1393 __months[3] = _M_data->_M_amonth04;
1394 __months[4] = _M_data->_M_amonth05;
1395 __months[5] = _M_data->_M_amonth06;
1396 __months[6] = _M_data->_M_amonth07;
1397 __months[7] = _M_data->_M_amonth08;
1398 __months[8] = _M_data->_M_amonth09;
1399 __months[9] = _M_data->_M_amonth10;
1400 __months[10] = _M_data->_M_amonth11;
1401 __months[11] = _M_data->_M_amonth12;
1402 }
1403
1404 protected:
1405 virtual
1406 ~__timepunct();
1407
1408 // For use at construction time only.
1409 void
1410 _M_initialize_timepunct(__c_locale __cloc = NULL);
1411 };
1412
1413 template<typename _CharT>
1414 locale::id __timepunct<_CharT>::id;
1415
1416 // Specializations.
1417 template<>
1418 void
1419 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
1420
1421 template<>
1422 void
1423 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const;
1424
1425 #ifdef _GLIBCXX_USE_WCHAR_T
1426 template<>
1427 void
1428 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
1429
1430 template<>
1431 void
1432 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
1433 const tm*) const;
1434 #endif
1435
1436 // Include host and configuration specific timepunct functions.
1437 #include <bits/time_members.h>
1438
1439 template<typename _CharT, typename _InIter>
1440 class time_get : public locale::facet, public time_base
1441 {
1442 public:
1443 // Types:
1444 typedef _CharT char_type;
1445 typedef _InIter iter_type;
1446 typedef basic_string<_CharT> __string_type;
1447
1448 static locale::id id;
1449
1450 explicit
1451 time_get(size_t __refs = 0)
1452 : facet (__refs) { }
1453
1454 dateorder
1455 date_order() const
1456 { return this->do_date_order(); }
1457
1458 iter_type
1459 get_time(iter_type __beg, iter_type __end, ios_base& __io,
1460 ios_base::iostate& __err, tm* __tm) const
1461 { return this->do_get_time(__beg, __end, __io, __err, __tm); }
1462
1463 iter_type
1464 get_date(iter_type __beg, iter_type __end, ios_base& __io,
1465 ios_base::iostate& __err, tm* __tm) const
1466 { return this->do_get_date(__beg, __end, __io, __err, __tm); }
1467
1468 iter_type
1469 get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
1470 ios_base::iostate& __err, tm* __tm) const
1471 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
1472
1473 iter_type
1474 get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
1475 ios_base::iostate& __err, tm* __tm) const
1476 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
1477
1478 iter_type
1479 get_year(iter_type __beg, iter_type __end, ios_base& __io,
1480 ios_base::iostate& __err, tm* __tm) const
1481 { return this->do_get_year(__beg, __end, __io, __err, __tm); }
1482
1483 protected:
1484 virtual
1485 ~time_get() { }
1486
1487 virtual dateorder
1488 do_date_order() const;
1489
1490 virtual iter_type
1491 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
1492 ios_base::iostate& __err, tm* __tm) const;
1493
1494 virtual iter_type
1495 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
1496 ios_base::iostate& __err, tm* __tm) const;
1497
1498 virtual iter_type
1499 do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
1500 ios_base::iostate& __err, tm* __tm) const;
1501
1502 virtual iter_type
1503 do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
1504 ios_base::iostate& __err, tm* __tm) const;
1505
1506 virtual iter_type
1507 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
1508 ios_base::iostate& __err, tm* __tm) const;
1509
1510 // Extract numeric component of length __len.
1511 void
1512 _M_extract_num(iter_type& __beg, iter_type& __end, int& __member,
1513 int __min, int __max, size_t __len,
1514 const ctype<_CharT>& __ctype,
1515 ios_base::iostate& __err) const;
1516
1517 // Extract day or month name, or any unique array of string
1518 // literals in a const _CharT* array.
1519 void
1520 _M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
1521 const _CharT** __names, size_t __indexlen,
1522 const ctype<_CharT>& __ctype,
1523 ios_base::iostate& __err) const;
1524
1525 // Extract on a component-by-component basis, via __format argument.
1526 void
1527 _M_extract_via_format(iter_type& __beg, iter_type& __end, ios_base& __io,
1528 ios_base::iostate& __err, tm* __tm,
1529 const _CharT* __format) const;
1530 };
1531
1532 template<typename _CharT, typename _InIter>
1533 locale::id time_get<_CharT, _InIter>::id;
1534
1535 template<typename _CharT, typename _InIter>
1536 class time_get_byname : public time_get<_CharT, _InIter>
1537 {
1538 public:
1539 // Types:
1540 typedef _CharT char_type;
1541 typedef _InIter iter_type;
1542
1543 explicit
1544 time_get_byname(const char*, size_t __refs = 0)
1545 : time_get<_CharT, _InIter>(__refs) { }
1546
1547 protected:
1548 virtual
1549 ~time_get_byname() { }
1550 };
1551
1552 template<typename _CharT, typename _OutIter>
1553 class time_put : public locale::facet, public time_base
1554 {
1555 public:
1556 // Types:
1557 typedef _CharT char_type;
1558 typedef _OutIter iter_type;
1559
1560 static locale::id id;
1561
1562 explicit
1563 time_put(size_t __refs = 0)
1564 : facet(__refs) { }
1565
1566 iter_type
1567 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
1568 const _CharT* __beg, const _CharT* __end) const;
1569
1570 iter_type
1571 put(iter_type __s, ios_base& __io, char_type __fill,
1572 const tm* __tm, char __format, char __mod = 0) const
1573 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
1574
1575 protected:
1576 virtual
1577 ~time_put()
1578 { }
1579
1580 virtual iter_type
1581 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
1582 char __format, char __mod) const;
1583 };
1584
1585 template<typename _CharT, typename _OutIter>
1586 locale::id time_put<_CharT, _OutIter>::id;
1587
1588 template<typename _CharT, typename _OutIter>
1589 class time_put_byname : public time_put<_CharT, _OutIter>
1590 {
1591 public:
1592 // Types:
1593 typedef _CharT char_type;
1594 typedef _OutIter iter_type;
1595
1596 explicit
1597 time_put_byname(const char*, size_t __refs = 0)
1598 : time_put<_CharT, _OutIter>(__refs)
1599 { };
1600
1601 protected:
1602 virtual
1603 ~time_put_byname() { }
1604 };
1605
1606
1607 class money_base
1608 {
1609 public:
1610 enum part { none, space, symbol, sign, value };
1611 struct pattern { char field[4]; };
1612
1613 static const pattern _S_default_pattern;
1614
1615 // Construct and return valid pattern consisting of some combination of:
1616 // space none symbol sign value
1617 static pattern
1618 _S_construct_pattern(char __precedes, char __space, char __posn);
1619 };
1620
1621 template<typename _CharT>
1622 struct __moneypunct_cache : public locale::facet
1623 {
1624 const char* _M_grouping;
1625 bool _M_use_grouping;
1626 _CharT _M_decimal_point;
1627 _CharT _M_thousands_sep;
1628 const _CharT* _M_curr_symbol;
1629 const _CharT* _M_positive_sign;
1630 const _CharT* _M_negative_sign;
1631 int _M_frac_digits;
1632 money_base::pattern _M_pos_format;
1633 money_base::pattern _M_neg_format;
1634
1635 bool _M_allocated;
1636
1637 __moneypunct_cache(size_t __refs = 0) : facet(__refs),
1638 _M_grouping(NULL), _M_use_grouping(false), _M_decimal_point(_CharT()),
1639 _M_thousands_sep(_CharT()), _M_curr_symbol(NULL), _M_positive_sign(NULL),
1640 _M_negative_sign(NULL), _M_frac_digits(0),
1641 _M_pos_format(money_base::pattern()),
1642 _M_neg_format(money_base::pattern()), _M_allocated(false)
1643 { }
1644
1645 ~__moneypunct_cache();
1646
1647 void
1648 _M_cache(const locale& __loc);
1649 };
1650
1651 template<typename _CharT>
1652 __moneypunct_cache<_CharT>::~__moneypunct_cache()
1653 {
1654 if (_M_allocated)
1655 {
1656 // XXX.
1657 }
1658 }
1659
1660 template<typename _CharT, bool _Intl>
1661 class moneypunct : public locale::facet, public money_base
1662 {
1663 public:
1664 // Types:
1665 typedef _CharT char_type;
1666 typedef basic_string<_CharT> string_type;
1667 typedef __moneypunct_cache<_CharT> __cache_type;
1668
1669 private:
1670 __cache_type* _M_data;
1671
1672 public:
1673 static const bool intl = _Intl;
1674 static locale::id id;
1675
1676 explicit
1677 moneypunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
1678 { _M_initialize_moneypunct(); }
1679
1680 explicit
1681 moneypunct(__cache_type* __cache, size_t __refs = 0)
1682 : facet(__refs), _M_data(__cache)
1683 { _M_initialize_moneypunct(); }
1684
1685 explicit
1686 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
1687 : facet(__refs), _M_data(NULL)
1688 { _M_initialize_moneypunct(__cloc, __s); }
1689
1690 char_type
1691 decimal_point() const
1692 { return this->do_decimal_point(); }
1693
1694 char_type
1695 thousands_sep() const
1696 { return this->do_thousands_sep(); }
1697
1698 string
1699 grouping() const
1700 { return this->do_grouping(); }
1701
1702 string_type
1703 curr_symbol() const
1704 { return this->do_curr_symbol(); }
1705
1706 string_type
1707 positive_sign() const
1708 { return this->do_positive_sign(); }
1709
1710 string_type
1711 negative_sign() const
1712 { return this->do_negative_sign(); }
1713
1714 int
1715 frac_digits() const
1716 { return this->do_frac_digits(); }
1717
1718 pattern
1719 pos_format() const
1720 { return this->do_pos_format(); }
1721
1722 pattern
1723 neg_format() const
1724 { return this->do_neg_format(); }
1725
1726 protected:
1727 virtual
1728 ~moneypunct();
1729
1730 virtual char_type
1731 do_decimal_point() const
1732 { return _M_data->_M_decimal_point; }
1733
1734 virtual char_type
1735 do_thousands_sep() const
1736 { return _M_data->_M_thousands_sep; }
1737
1738 virtual string
1739 do_grouping() const
1740 { return _M_data->_M_grouping; }
1741
1742 virtual string_type
1743 do_curr_symbol() const
1744 { return _M_data->_M_curr_symbol; }
1745
1746 virtual string_type
1747 do_positive_sign() const
1748 { return _M_data->_M_positive_sign; }
1749
1750 virtual string_type
1751 do_negative_sign() const
1752 { return _M_data->_M_negative_sign; }
1753
1754 virtual int
1755 do_frac_digits() const
1756 { return _M_data->_M_frac_digits; }
1757
1758 virtual pattern
1759 do_pos_format() const
1760 { return _M_data->_M_pos_format; }
1761
1762 virtual pattern
1763 do_neg_format() const
1764 { return _M_data->_M_neg_format; }
1765
1766 // For use at construction time only.
1767 void
1768 _M_initialize_moneypunct(__c_locale __cloc = NULL,
1769 const char* __name = NULL);
1770 };
1771
1772 template<typename _CharT, bool _Intl>
1773 locale::id moneypunct<_CharT, _Intl>::id;
1774
1775 template<typename _CharT, bool _Intl>
1776 const bool moneypunct<_CharT, _Intl>::intl;
1777
1778 template<>
1779 moneypunct<char, true>::~moneypunct();
1780
1781 template<>
1782 moneypunct<char, false>::~moneypunct();
1783
1784 template<>
1785 void
1786 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
1787
1788 template<>
1789 void
1790 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
1791
1792 #ifdef _GLIBCXX_USE_WCHAR_T
1793 template<>
1794 moneypunct<wchar_t, true>::~moneypunct();
1795
1796 template<>
1797 moneypunct<wchar_t, false>::~moneypunct();
1798
1799 template<>
1800 void
1801 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
1802 const char*);
1803
1804 template<>
1805 void
1806 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
1807 const char*);
1808 #endif
1809
1810 template<typename _CharT, bool _Intl>
1811 class moneypunct_byname : public moneypunct<_CharT, _Intl>
1812 {
1813 public:
1814 typedef _CharT char_type;
1815 typedef basic_string<_CharT> string_type;
1816
1817 static const bool intl = _Intl;
1818
1819 explicit
1820 moneypunct_byname(const char* __s, size_t __refs = 0)
1821 : moneypunct<_CharT, _Intl>(__refs)
1822 {
1823 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
1824 {
1825 __c_locale __tmp;
1826 this->_S_create_c_locale(__tmp, __s);
1827 this->_M_initialize_moneypunct(__tmp);
1828 this->_S_destroy_c_locale(__tmp);
1829 }
1830 }
1831
1832 protected:
1833 virtual
1834 ~moneypunct_byname() { }
1835 };
1836
1837 template<typename _CharT, bool _Intl>
1838 const bool moneypunct_byname<_CharT, _Intl>::intl;
1839
1840 template<typename _CharT, typename _InIter>
1841 class money_get : public locale::facet
1842 {
1843 public:
1844 // Types:
1845 typedef _CharT char_type;
1846 typedef _InIter iter_type;
1847 typedef basic_string<_CharT> string_type;
1848
1849 static locale::id id;
1850
1851 explicit
1852 money_get(size_t __refs = 0) : facet(__refs) { }
1853
1854 iter_type
1855 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1856 ios_base::iostate& __err, long double& __units) const
1857 { return this->do_get(__s, __end, __intl, __io, __err, __units); }
1858
1859 iter_type
1860 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1861 ios_base::iostate& __err, string_type& __digits) const
1862 { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
1863
1864 protected:
1865 virtual
1866 ~money_get() { }
1867
1868 virtual iter_type
1869 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1870 ios_base::iostate& __err, long double& __units) const;
1871
1872 virtual iter_type
1873 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1874 ios_base::iostate& __err, string_type& __digits) const;
1875 };
1876
1877 template<typename _CharT, typename _InIter>
1878 locale::id money_get<_CharT, _InIter>::id;
1879
1880 template<typename _CharT, typename _OutIter>
1881 class money_put : public locale::facet
1882 {
1883 public:
1884 typedef _CharT char_type;
1885 typedef _OutIter iter_type;
1886 typedef basic_string<_CharT> string_type;
1887
1888 static locale::id id;
1889
1890 explicit
1891 money_put(size_t __refs = 0) : facet(__refs) { }
1892
1893 iter_type
1894 put(iter_type __s, bool __intl, ios_base& __io,
1895 char_type __fill, long double __units) const
1896 { return this->do_put(__s, __intl, __io, __fill, __units); }
1897
1898 iter_type
1899 put(iter_type __s, bool __intl, ios_base& __io,
1900 char_type __fill, const string_type& __digits) const
1901 { return this->do_put(__s, __intl, __io, __fill, __digits); }
1902
1903 protected:
1904 virtual
1905 ~money_put() { }
1906
1907 virtual iter_type
1908 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1909 long double __units) const;
1910
1911 virtual iter_type
1912 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1913 const string_type& __digits) const;
1914 };
1915
1916 template<typename _CharT, typename _OutIter>
1917 locale::id money_put<_CharT, _OutIter>::id;
1918
1919
1920 struct messages_base
1921 {
1922 typedef int catalog;
1923 };
1924
1925 template<typename _CharT>
1926 class messages : public locale::facet, public messages_base
1927 {
1928 public:
1929 // Types:
1930 typedef _CharT char_type;
1931 typedef basic_string<_CharT> string_type;
1932
1933 protected:
1934 // Underlying "C" library locale information saved from
1935 // initialization, needed by messages_byname as well.
1936 __c_locale _M_c_locale_messages;
1937 const char* _M_name_messages;
1938
1939 public:
1940 static locale::id id;
1941
1942 explicit
1943 messages(size_t __refs = 0);
1944
1945 // Non-standard.
1946 explicit
1947 messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
1948
1949 catalog
1950 open(const basic_string<char>& __s, const locale& __loc) const
1951 { return this->do_open(__s, __loc); }
1952
1953 // Non-standard and unorthodox, yet effective.
1954 catalog
1955 open(const basic_string<char>&, const locale&, const char*) const;
1956
1957 string_type
1958 get(catalog __c, int __set, int __msgid, const string_type& __s) const
1959 { return this->do_get(__c, __set, __msgid, __s); }
1960
1961 void
1962 close(catalog __c) const
1963 { return this->do_close(__c); }
1964
1965 protected:
1966 virtual
1967 ~messages();
1968
1969 virtual catalog
1970 do_open(const basic_string<char>&, const locale&) const;
1971
1972 virtual string_type
1973 do_get(catalog, int, int, const string_type& __dfault) const;
1974
1975 virtual void
1976 do_close(catalog) const;
1977
1978 // Returns a locale and codeset-converted string, given a char* message.
1979 char*
1980 _M_convert_to_char(const string_type& __msg) const
1981 {
1982 // XXX
1983 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
1984 }
1985
1986 // Returns a locale and codeset-converted string, given a char* message.
1987 string_type
1988 _M_convert_from_char(char* __msg) const
1989 {
1990 // Length of message string without terminating null.
1991 size_t __len = char_traits<char>::length(__msg) - 1;
1992
1993 // "everybody can easily convert the string using
1994 // mbsrtowcs/wcsrtombs or with iconv()"
1995 #if 0
1996 // Convert char* to _CharT in locale used to open catalog.
1997 // XXX need additional template parameter on messages class for this..
1998 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
1999 typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;
2000
2001 __codecvt_type::state_type __state;
2002 // XXX may need to initialize state.
2003 //initialize_state(__state._M_init());
2004
2005 char* __from_next;
2006 // XXX what size for this string?
2007 _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
2008 const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
2009 __cvt.out(__state, __msg, __msg + __len, __from_next,
2010 __to, __to + __len + 1, __to_next);
2011 return string_type(__to);
2012 #endif
2013 #if 0
2014 typedef ctype<_CharT> __ctype_type;
2015 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
2016 const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
2017 // XXX Again, proper length of converted string an issue here.
2018 // For now, assume the converted length is not larger.
2019 _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
2020 __cvt.widen(__msg, __msg + __len, __dest);
2021 return basic_string<_CharT>(__dest);
2022 #endif
2023 return string_type();
2024 }
2025 };
2026
2027 template<typename _CharT>
2028 locale::id messages<_CharT>::id;
2029
2030 // Specializations for required instantiations.
2031 template<>
2032 string
2033 messages<char>::do_get(catalog, int, int, const string&) const;
2034
2035 #ifdef _GLIBCXX_USE_WCHAR_T
2036 template<>
2037 wstring
2038 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
2039 #endif
2040
2041 template<typename _CharT>
2042 class messages_byname : public messages<_CharT>
2043 {
2044 public:
2045 typedef _CharT char_type;
2046 typedef basic_string<_CharT> string_type;
2047
2048 explicit
2049 messages_byname(const char* __s, size_t __refs = 0);
2050
2051 protected:
2052 virtual
2053 ~messages_byname()
2054 { }
2055 };
2056
2057 // Include host and configuration specific messages functions.
2058 #include <bits/messages_members.h>
2059
2060
2061 // Subclause convenience interfaces, inlines.
2062 // NB: These are inline because, when used in a loop, some compilers
2063 // can hoist the body out of the loop; then it's just as fast as the
2064 // C is*() function.
2065 template<typename _CharT>
2066 inline bool
2067 isspace(_CharT __c, const locale& __loc)
2068 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
2069
2070 template<typename _CharT>
2071 inline bool
2072 isprint(_CharT __c, const locale& __loc)
2073 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
2074
2075 template<typename _CharT>
2076 inline bool
2077 iscntrl(_CharT __c, const locale& __loc)
2078 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
2079
2080 template<typename _CharT>
2081 inline bool
2082 isupper(_CharT __c, const locale& __loc)
2083 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
2084
2085 template<typename _CharT>
2086 inline bool islower(_CharT __c, const locale& __loc)
2087 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
2088
2089 template<typename _CharT>
2090 inline bool
2091 isalpha(_CharT __c, const locale& __loc)
2092 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
2093
2094 template<typename _CharT>
2095 inline bool
2096 isdigit(_CharT __c, const locale& __loc)
2097 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
2098
2099 template<typename _CharT>
2100 inline bool
2101 ispunct(_CharT __c, const locale& __loc)
2102 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
2103
2104 template<typename _CharT>
2105 inline bool
2106 isxdigit(_CharT __c, const locale& __loc)
2107 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
2108
2109 template<typename _CharT>
2110 inline bool
2111 isalnum(_CharT __c, const locale& __loc)
2112 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
2113
2114 template<typename _CharT>
2115 inline bool
2116 isgraph(_CharT __c, const locale& __loc)
2117 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
2118
2119 template<typename _CharT>
2120 inline _CharT
2121 toupper(_CharT __c, const locale& __loc)
2122 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
2123
2124 template<typename _CharT>
2125 inline _CharT
2126 tolower(_CharT __c, const locale& __loc)
2127 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
2128 } // namespace std
2129
2130 #endif