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