]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/locale_facets.h
c_locale.h: Include <cstdlib> and <cstring>.
[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, 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 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): locale::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 __ctype_abstract_base<char>
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 protected:
375 const mask*
376 table() const throw()
377 { return _M_table; }
378
379 static const mask*
380 classic_table() throw();
381
382 virtual
383 ~ctype();
384
385 virtual bool
386 do_is(mask __m, char_type __c) const;
387
388 virtual const char_type*
389 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
390
391 virtual const char_type*
392 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
393
394 virtual const char_type*
395 do_scan_not(mask __m, const char_type* __lo,
396 const char_type* __hi) const;
397
398 virtual char_type
399 do_toupper(char_type) const;
400
401 virtual const char_type*
402 do_toupper(char_type* __lo, const char_type* __hi) const;
403
404 virtual char_type
405 do_tolower(char_type) const;
406
407 virtual const char_type*
408 do_tolower(char_type* __lo, const char_type* __hi) const;
409
410 virtual char_type
411 do_widen(char) const;
412
413 virtual const char*
414 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
415
416 virtual char
417 do_narrow(char_type, char __dfault) const;
418
419 virtual const char_type*
420 do_narrow(const char_type* __lo, const char_type* __hi,
421 char __dfault, char* __dest) const;
422 };
423
424 template<>
425 const ctype<char>&
426 use_facet<ctype<char> >(const locale& __loc);
427
428 #ifdef _GLIBCXX_USE_WCHAR_T
429 // 22.2.1.3 ctype<wchar_t> specialization
430 template<>
431 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
432 {
433 public:
434 // Types:
435 typedef wchar_t char_type;
436 typedef wctype_t __wmask_type;
437
438 protected:
439 __c_locale _M_c_locale_ctype;
440
441 public:
442 // Data Members:
443 static locale::id id;
444
445 explicit
446 ctype(size_t __refs = 0);
447
448 explicit
449 ctype(__c_locale __cloc, size_t __refs = 0);
450
451 protected:
452 __wmask_type
453 _M_convert_to_wmask(const mask __m) const;
454
455 virtual
456 ~ctype();
457
458 virtual bool
459 do_is(mask __m, char_type __c) const;
460
461 virtual const char_type*
462 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
463
464 virtual const char_type*
465 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
466
467 virtual const char_type*
468 do_scan_not(mask __m, const char_type* __lo,
469 const char_type* __hi) const;
470
471 virtual char_type
472 do_toupper(char_type) const;
473
474 virtual const char_type*
475 do_toupper(char_type* __lo, const char_type* __hi) const;
476
477 virtual char_type
478 do_tolower(char_type) const;
479
480 virtual const char_type*
481 do_tolower(char_type* __lo, const char_type* __hi) const;
482
483 virtual char_type
484 do_widen(char) const;
485
486 virtual const char*
487 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
488
489 virtual char
490 do_narrow(char_type, char __dfault) const;
491
492 virtual const char_type*
493 do_narrow(const char_type* __lo, const char_type* __hi,
494 char __dfault, char* __dest) const;
495
496 };
497
498 template<>
499 const ctype<wchar_t>&
500 use_facet<ctype<wchar_t> >(const locale& __loc);
501 #endif //_GLIBCXX_USE_WCHAR_T
502
503 // Include host and configuration specific ctype inlines.
504 #include <bits/ctype_inline.h>
505
506 // 22.2.1.2 Template class ctype_byname
507 template<typename _CharT>
508 class ctype_byname : public ctype<_CharT>
509 {
510 public:
511 typedef _CharT char_type;
512
513 explicit
514 ctype_byname(const char* __s, size_t __refs = 0);
515
516 protected:
517 virtual
518 ~ctype_byname() { };
519 };
520
521 // 22.2.1.4 Class ctype_byname specializations.
522 template<>
523 ctype_byname<char>::ctype_byname(const char*, size_t refs);
524
525 template<>
526 ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs);
527
528 // 22.2.1.5 Template class codecvt
529 #include <bits/codecvt.h>
530
531 // 22.2.2 The numeric category.
532 class __num_base
533 {
534 public:
535 // NB: Code depends on the order of _S_atoms_out elements.
536 // Below are the indices into _S_atoms_out.
537 enum
538 {
539 _S_ominus,
540 _S_oplus,
541 _S_ox,
542 _S_oX,
543 _S_odigits,
544 _S_odigits_end = _S_odigits + 16,
545 _S_oudigits = _S_odigits_end,
546 _S_oudigits_end = _S_oudigits + 16,
547 _S_oe = _S_odigits + 14, // For scientific notation, 'e'
548 _S_oE = _S_oudigits + 14, // For scientific notation, 'E'
549 _S_oend = _S_oudigits_end
550 };
551
552 // A list of valid numeric literals for output. This array
553 // contains chars that will be passed through the current locale's
554 // ctype<_CharT>.widen() and then used to render numbers.
555 // For the standard "C" locale, this is
556 // "-+xX0123456789abcdef0123456789ABCDEF".
557 static const char* _S_atoms_out;
558
559 // String literal of acceptable (narrow) input, for num_get.
560 // "0123456789eEabcdfABCDF"
561 static const char* _S_atoms_in;
562
563 enum
564 {
565 _S_izero,
566 _S_ie = _S_izero + 10,
567 _S_iE = _S_izero + 11,
568 _S_iend = 21 + 1
569 };
570
571 // num_put
572 // Construct and return valid scanf format for floating point types.
573 static void
574 _S_format_float(const ios_base& __io, char* __fptr, char __mod);
575 };
576
577 template<typename _CharT>
578 struct __numpunct_cache : public locale::facet
579 {
580 const char* _M_grouping;
581 bool _M_use_grouping;
582 const _CharT* _M_truename;
583 const _CharT* _M_falsename;
584 _CharT _M_decimal_point;
585 _CharT _M_thousands_sep;
586
587 // A list of valid numeric literals for output: in the standard
588 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
589 // This array contains the chars after having been passed
590 // through the current locale's ctype<_CharT>.widen().
591 _CharT _M_atoms_out[__num_base::_S_oend + 1];
592
593 // A list of valid numeric literals for output: in the standard
594 // "C" locale, this is "0123456789eEabcdfABCDF"
595 // This array contains the chars after having been passed
596 // through the current locale's ctype<_CharT>.widen().
597 _CharT _M_atoms_in[__num_base::_S_iend + 1];
598
599 bool _M_allocated;
600
601 __numpunct_cache(size_t __refs = 0) : locale::facet(__refs),
602 _M_grouping(NULL), _M_use_grouping(false), _M_truename(NULL),
603 _M_falsename(NULL), _M_decimal_point(_CharT()),
604 _M_thousands_sep(_CharT()), _M_allocated(false)
605 { }
606
607 ~__numpunct_cache();
608
609 void
610 _M_cache(const locale& __loc);
611 };
612
613 template<typename _CharT>
614 void
615 __numpunct_cache<_CharT>::_M_cache(const locale& __loc)
616 {
617 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
618 string __grouping = __np.grouping();
619 char* __group = new char[__grouping.length() + 1];
620 __grouping.copy(__group, __grouping.length());
621 __group[__grouping.length()] = char();
622 _M_grouping = __group;
623
624 _M_use_grouping = __grouping.length() != 0 && __grouping.data()[0] != 0;
625
626 typedef basic_string<_CharT> __string_type;
627
628 __string_type __true = __np.truename();
629 _CharT* __truename = new _CharT[__true.length() + 1];
630 __true.copy(__truename, __true.length());
631 __truename[__true.length()] = _CharT();
632 _M_truename = __truename;
633
634 __string_type __false = __np.falsename();
635 _CharT* __falsename = new _CharT[__false.length() + 1];
636 __false.copy(__falsename, __false.length());
637 __falsename[__false.length()] = _CharT();
638 _M_falsename = __falsename;
639
640 _M_decimal_point = __np.decimal_point();
641 _M_thousands_sep = __np.thousands_sep();
642
643 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
644 __ct.widen(__num_base::_S_atoms_out,
645 __num_base::_S_atoms_out + __num_base::_S_oend, _M_atoms_out);
646 _M_atoms_out[__num_base::_S_oend] = _CharT();
647 __ct.widen(__num_base::_S_atoms_in,
648 __num_base::_S_atoms_in + __num_base::_S_iend, _M_atoms_in);
649 _M_atoms_in[__num_base::_S_iend] = _CharT();
650
651 _M_allocated = true;
652 }
653
654 template<typename _CharT>
655 __numpunct_cache<_CharT>::~__numpunct_cache()
656 {
657 if (_M_allocated)
658 {
659 delete [] _M_grouping;
660 delete [] _M_truename;
661 delete [] _M_falsename;
662 }
663 }
664
665 template<typename _CharT>
666 class numpunct : public locale::facet
667 {
668 public:
669 // Types:
670 typedef _CharT char_type;
671 typedef basic_string<_CharT> string_type;
672 typedef __numpunct_cache<_CharT> __cache_type;
673
674 protected:
675 __cache_type* _M_data;
676
677 public:
678 static locale::id id;
679
680 explicit
681 numpunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
682 { _M_initialize_numpunct(); }
683
684 explicit
685 numpunct(__cache_type* __cache, size_t __refs = 0)
686 : facet(__refs), _M_data(__cache)
687 { _M_initialize_numpunct(); }
688
689 explicit
690 numpunct(__c_locale __cloc, size_t __refs = 0)
691 : locale::facet(__refs), _M_data(NULL)
692 { _M_initialize_numpunct(__cloc); }
693
694 char_type
695 decimal_point() const
696 { return this->do_decimal_point(); }
697
698 char_type
699 thousands_sep() const
700 { return this->do_thousands_sep(); }
701
702 string
703 grouping() const
704 { return this->do_grouping(); }
705
706 string_type
707 truename() const
708 { return this->do_truename(); }
709
710 string_type
711 falsename() const
712 { return this->do_falsename(); }
713
714 protected:
715 virtual
716 ~numpunct();
717
718 virtual char_type
719 do_decimal_point() const
720 { return _M_data->_M_decimal_point; }
721
722 virtual char_type
723 do_thousands_sep() const
724 { return _M_data->_M_thousands_sep; }
725
726 virtual string
727 do_grouping() const
728 { return _M_data->_M_grouping; }
729
730 virtual string_type
731 do_truename() const
732 { return _M_data->_M_truename; }
733
734 virtual string_type
735 do_falsename() const
736 { return _M_data->_M_falsename; }
737
738 // For use at construction time only.
739 void
740 _M_initialize_numpunct(__c_locale __cloc = NULL);
741 };
742
743 template<typename _CharT>
744 locale::id numpunct<_CharT>::id;
745
746 template<>
747 numpunct<char>::~numpunct();
748
749 template<>
750 void
751 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
752
753 #ifdef _GLIBCXX_USE_WCHAR_T
754 template<>
755 numpunct<wchar_t>::~numpunct();
756
757 template<>
758 void
759 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
760 #endif
761
762 template<typename _CharT>
763 class numpunct_byname : public numpunct<_CharT>
764 {
765 // Data Member.
766 __c_locale _M_c_locale_numpunct;
767
768 public:
769 typedef _CharT char_type;
770 typedef basic_string<_CharT> string_type;
771
772 explicit
773 numpunct_byname(const char* __s, size_t __refs = 0)
774 : numpunct<_CharT>(__refs)
775 {
776 this->_S_create_c_locale(_M_c_locale_numpunct, __s);
777 this->_M_initialize_numpunct(_M_c_locale_numpunct);
778 }
779
780 protected:
781 virtual
782 ~numpunct_byname()
783 { this->_S_destroy_c_locale(_M_c_locale_numpunct); }
784 };
785
786 template<typename _CharT, typename _InIter>
787 class num_get : public locale::facet, public __num_base
788 {
789 public:
790 // Types:
791 typedef _CharT char_type;
792 typedef _InIter iter_type;
793
794 static locale::id id;
795
796 explicit
797 num_get(size_t __refs = 0) : locale::facet(__refs) { }
798
799 iter_type
800 get(iter_type __in, iter_type __end, ios_base& __io,
801 ios_base::iostate& __err, bool& __v) const
802 { return this->do_get(__in, __end, __io, __err, __v); }
803
804 iter_type
805 get(iter_type __in, iter_type __end, ios_base& __io,
806 ios_base::iostate& __err, long& __v) const
807 { return this->do_get(__in, __end, __io, __err, __v); }
808
809 iter_type
810 get(iter_type __in, iter_type __end, ios_base& __io,
811 ios_base::iostate& __err, unsigned short& __v) const
812 { return this->do_get(__in, __end, __io, __err, __v); }
813
814 iter_type
815 get(iter_type __in, iter_type __end, ios_base& __io,
816 ios_base::iostate& __err, unsigned int& __v) const
817 { return this->do_get(__in, __end, __io, __err, __v); }
818
819 iter_type
820 get(iter_type __in, iter_type __end, ios_base& __io,
821 ios_base::iostate& __err, unsigned long& __v) const
822 { return this->do_get(__in, __end, __io, __err, __v); }
823
824 #ifdef _GLIBCXX_USE_LONG_LONG
825 iter_type
826 get(iter_type __in, iter_type __end, ios_base& __io,
827 ios_base::iostate& __err, long long& __v) const
828 { return this->do_get(__in, __end, __io, __err, __v); }
829
830 iter_type
831 get(iter_type __in, iter_type __end, ios_base& __io,
832 ios_base::iostate& __err, unsigned long long& __v) const
833 { return this->do_get(__in, __end, __io, __err, __v); }
834 #endif
835
836 iter_type
837 get(iter_type __in, iter_type __end, ios_base& __io,
838 ios_base::iostate& __err, float& __v) const
839 { return this->do_get(__in, __end, __io, __err, __v); }
840
841 iter_type
842 get(iter_type __in, iter_type __end, ios_base& __io,
843 ios_base::iostate& __err, double& __v) const
844 { return this->do_get(__in, __end, __io, __err, __v); }
845
846 iter_type
847 get(iter_type __in, iter_type __end, ios_base& __io,
848 ios_base::iostate& __err, long double& __v) const
849 { return this->do_get(__in, __end, __io, __err, __v); }
850
851 iter_type
852 get(iter_type __in, iter_type __end, ios_base& __io,
853 ios_base::iostate& __err, void*& __v) const
854 { return this->do_get(__in, __end, __io, __err, __v); }
855
856 protected:
857 virtual ~num_get() { }
858
859 iter_type
860 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
861 string& __xtrc) const;
862
863 iter_type
864 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
865 string& __xtrc, int& __base) const;
866
867 virtual iter_type
868 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
869
870
871 virtual iter_type
872 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
873
874 virtual iter_type
875 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
876 unsigned short&) const;
877
878 virtual iter_type
879 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
880 unsigned int&) const;
881
882 virtual iter_type
883 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
884 unsigned long&) const;
885
886 #ifdef _GLIBCXX_USE_LONG_LONG
887 virtual iter_type
888 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
889 long long&) const;
890
891 virtual iter_type
892 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
893 unsigned long long&) const;
894 #endif
895
896 virtual iter_type
897 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
898 float&) const;
899
900 virtual iter_type
901 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
902 double&) const;
903
904 virtual iter_type
905 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
906 long double&) const;
907
908 virtual iter_type
909 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
910 void*&) const;
911 };
912
913 template<typename _CharT, typename _InIter>
914 locale::id num_get<_CharT, _InIter>::id;
915
916 #if 0
917 // Partial specialization for istreambuf_iterator, so can use traits_type.
918 template<typename _CharT>
919 class num_get<_CharT, istreambuf_iterator<_CharT> >;
920
921 iter_type
922 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
923 string& __xtrc) const;
924
925 iter_type
926 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
927 string& __xtrc, int& __base) const;
928
929 virtual iter_type
930 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
931 #endif
932
933 template<typename _CharT, typename _OutIter>
934 class num_put : public locale::facet, public __num_base
935 {
936 public:
937 // Types:
938 typedef _CharT char_type;
939 typedef _OutIter iter_type;
940 static locale::id id;
941
942 explicit
943 num_put(size_t __refs = 0) : locale::facet(__refs) { }
944
945 iter_type
946 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
947 { return this->do_put(__s, __f, __fill, __v); }
948
949 iter_type
950 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
951 { return this->do_put(__s, __f, __fill, __v); }
952
953 iter_type
954 put(iter_type __s, ios_base& __f, char_type __fill,
955 unsigned long __v) const
956 { return this->do_put(__s, __f, __fill, __v); }
957
958 #ifdef _GLIBCXX_USE_LONG_LONG
959 iter_type
960 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
961 { return this->do_put(__s, __f, __fill, __v); }
962
963 iter_type
964 put(iter_type __s, ios_base& __f, char_type __fill,
965 unsigned long long __v) const
966 { return this->do_put(__s, __f, __fill, __v); }
967 #endif
968
969 iter_type
970 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
971 { return this->do_put(__s, __f, __fill, __v); }
972
973 iter_type
974 put(iter_type __s, ios_base& __f, char_type __fill,
975 long 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 const void* __v) const
981 { return this->do_put(__s, __f, __fill, __v); }
982
983 protected:
984 template<typename _ValueT>
985 iter_type
986 _M_convert_float(iter_type, ios_base& __io, char_type __fill,
987 char __mod, _ValueT __v) const;
988
989 void
990 _M_group_float(const string& __grouping, char_type __sep,
991 const char_type* __p, char_type* __new, char_type* __cs,
992 int& __len) const;
993
994 template<typename _ValueT>
995 iter_type
996 _M_convert_int(iter_type, ios_base& __io, char_type __fill,
997 _ValueT __v) const;
998
999 void
1000 _M_group_int(const string& __grouping, char_type __sep,
1001 ios_base& __io, char_type* __new, char_type* __cs,
1002 int& __len) const;
1003
1004 void
1005 _M_pad(char_type __fill, streamsize __w, ios_base& __io,
1006 char_type* __new, const char_type* __cs, int& __len) const;
1007
1008 virtual
1009 ~num_put() { };
1010
1011 virtual iter_type
1012 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
1013
1014 virtual iter_type
1015 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
1016
1017 virtual iter_type
1018 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
1019
1020 #ifdef _GLIBCXX_USE_LONG_LONG
1021 virtual iter_type
1022 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
1023
1024 virtual iter_type
1025 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
1026 #endif
1027
1028 virtual iter_type
1029 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
1030
1031 virtual iter_type
1032 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
1033
1034 virtual iter_type
1035 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
1036 };
1037
1038 template <typename _CharT, typename _OutIter>
1039 locale::id num_put<_CharT, _OutIter>::id;
1040
1041
1042 template<typename _CharT>
1043 class collate : public locale::facet
1044 {
1045 public:
1046 // Types:
1047 typedef _CharT char_type;
1048 typedef basic_string<_CharT> string_type;
1049
1050 protected:
1051 // Underlying "C" library locale information saved from
1052 // initialization, needed by collate_byname as well.
1053 __c_locale _M_c_locale_collate;
1054
1055 public:
1056 static locale::id id;
1057
1058 explicit
1059 collate(size_t __refs = 0)
1060 : locale::facet(__refs)
1061 { _M_c_locale_collate = _S_c_locale; }
1062
1063 explicit
1064 collate(__c_locale __cloc, size_t __refs = 0)
1065 : locale::facet(__refs)
1066 { _M_c_locale_collate = _S_clone_c_locale(__cloc); }
1067
1068 int
1069 compare(const _CharT* __lo1, const _CharT* __hi1,
1070 const _CharT* __lo2, const _CharT* __hi2) const
1071 { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
1072
1073 string_type
1074 transform(const _CharT* __lo, const _CharT* __hi) const
1075 { return this->do_transform(__lo, __hi); }
1076
1077 long
1078 hash(const _CharT* __lo, const _CharT* __hi) const
1079 { return this->do_hash(__lo, __hi); }
1080
1081 // Used to abstract out _CharT bits in virtual member functions, below.
1082 int
1083 _M_compare(const _CharT*, const _CharT*) const;
1084
1085 size_t
1086 _M_transform(_CharT*, const _CharT*, size_t) const;
1087
1088 protected:
1089 virtual
1090 ~collate()
1091 { _S_destroy_c_locale(_M_c_locale_collate); }
1092
1093 virtual int
1094 do_compare(const _CharT* __lo1, const _CharT* __hi1,
1095 const _CharT* __lo2, const _CharT* __hi2) const;
1096
1097 virtual string_type
1098 do_transform(const _CharT* __lo, const _CharT* __hi) const;
1099
1100 virtual long
1101 do_hash(const _CharT* __lo, const _CharT* __hi) const;
1102 };
1103
1104 template<typename _CharT>
1105 locale::id collate<_CharT>::id;
1106
1107 // Specializations.
1108 template<>
1109 int
1110 collate<char>::_M_compare(const char*, const char*) const;
1111
1112 template<>
1113 size_t
1114 collate<char>::_M_transform(char*, const char*, size_t) const;
1115
1116 #ifdef _GLIBCXX_USE_WCHAR_T
1117 template<>
1118 int
1119 collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
1120
1121 template<>
1122 size_t
1123 collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
1124 #endif
1125
1126 template<typename _CharT>
1127 class collate_byname : public collate<_CharT>
1128 {
1129 public:
1130 typedef _CharT char_type;
1131 typedef basic_string<_CharT> string_type;
1132
1133 explicit
1134 collate_byname(const char* __s, size_t __refs = 0)
1135 : collate<_CharT>(__refs)
1136 {
1137 this->_S_destroy_c_locale(this->_M_c_locale_collate);
1138 this->_S_create_c_locale(this->_M_c_locale_collate, __s);
1139 }
1140
1141 protected:
1142 virtual
1143 ~collate_byname() { }
1144 };
1145
1146
1147 class time_base
1148 {
1149 public:
1150 enum dateorder { no_order, dmy, mdy, ymd, ydm };
1151 };
1152
1153 template<typename _CharT>
1154 class __timepunct : public locale::facet
1155 {
1156 public:
1157 // Types:
1158 typedef _CharT __char_type;
1159 typedef basic_string<_CharT> __string_type;
1160
1161 static locale::id id;
1162
1163 // List of all known timezones, with GMT first.
1164 static const _CharT* _S_timezones[14];
1165
1166 protected:
1167 __c_locale _M_c_locale_timepunct;
1168 char* _M_name_timepunct;
1169 const _CharT* _M_date_format;
1170 const _CharT* _M_date_era_format;
1171 const _CharT* _M_time_format;
1172 const _CharT* _M_time_era_format;
1173 const _CharT* _M_date_time_format;
1174 const _CharT* _M_date_time_era_format;
1175 const _CharT* _M_am;
1176 const _CharT* _M_pm;
1177 const _CharT* _M_am_pm_format;
1178
1179 // Day names, starting with "C"'s Sunday.
1180 const _CharT* _M_day1;
1181 const _CharT* _M_day2;
1182 const _CharT* _M_day3;
1183 const _CharT* _M_day4;
1184 const _CharT* _M_day5;
1185 const _CharT* _M_day6;
1186 const _CharT* _M_day7;
1187
1188 // Abbreviated day names, starting with "C"'s Sun.
1189 const _CharT* _M_day_a1;
1190 const _CharT* _M_day_a2;
1191 const _CharT* _M_day_a3;
1192 const _CharT* _M_day_a4;
1193 const _CharT* _M_day_a5;
1194 const _CharT* _M_day_a6;
1195 const _CharT* _M_day_a7;
1196
1197 // Month names, starting with "C"'s January.
1198 const _CharT* _M_month01;
1199 const _CharT* _M_month02;
1200 const _CharT* _M_month03;
1201 const _CharT* _M_month04;
1202 const _CharT* _M_month05;
1203 const _CharT* _M_month06;
1204 const _CharT* _M_month07;
1205 const _CharT* _M_month08;
1206 const _CharT* _M_month09;
1207 const _CharT* _M_month10;
1208 const _CharT* _M_month11;
1209 const _CharT* _M_month12;
1210
1211 // Abbreviated month names, starting with "C"'s Jan.
1212 const _CharT* _M_month_a01;
1213 const _CharT* _M_month_a02;
1214 const _CharT* _M_month_a03;
1215 const _CharT* _M_month_a04;
1216 const _CharT* _M_month_a05;
1217 const _CharT* _M_month_a06;
1218 const _CharT* _M_month_a07;
1219 const _CharT* _M_month_a08;
1220 const _CharT* _M_month_a09;
1221 const _CharT* _M_month_a10;
1222 const _CharT* _M_month_a11;
1223 const _CharT* _M_month_a12;
1224
1225 public:
1226 explicit
1227 __timepunct(size_t __refs = 0);
1228
1229 explicit
1230 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
1231
1232 void
1233 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
1234 const tm* __tm) const;
1235
1236 void
1237 _M_date_formats(const _CharT** __date) const
1238 {
1239 // Always have default first.
1240 __date[0] = _M_date_format;
1241 __date[1] = _M_date_era_format;
1242 }
1243
1244 void
1245 _M_time_formats(const _CharT** __time) const
1246 {
1247 // Always have default first.
1248 __time[0] = _M_time_format;
1249 __time[1] = _M_time_era_format;
1250 }
1251
1252 void
1253 _M_ampm(const _CharT** __ampm) const
1254 {
1255 __ampm[0] = _M_am;
1256 __ampm[1] = _M_pm;
1257 }
1258
1259 void
1260 _M_date_time_formats(const _CharT** __dt) const
1261 {
1262 // Always have default first.
1263 __dt[0] = _M_date_time_format;
1264 __dt[1] = _M_date_time_era_format;
1265 }
1266
1267 void
1268 _M_days(const _CharT** __days) const
1269 {
1270 __days[0] = _M_day1;
1271 __days[1] = _M_day2;
1272 __days[2] = _M_day3;
1273 __days[3] = _M_day4;
1274 __days[4] = _M_day5;
1275 __days[5] = _M_day6;
1276 __days[6] = _M_day7;
1277 }
1278
1279 void
1280 _M_days_abbreviated(const _CharT** __days) const
1281 {
1282 __days[0] = _M_day_a1;
1283 __days[1] = _M_day_a2;
1284 __days[2] = _M_day_a3;
1285 __days[3] = _M_day_a4;
1286 __days[4] = _M_day_a5;
1287 __days[5] = _M_day_a6;
1288 __days[6] = _M_day_a7;
1289 }
1290
1291 void
1292 _M_months(const _CharT** __months) const
1293 {
1294 __months[0] = _M_month01;
1295 __months[1] = _M_month02;
1296 __months[2] = _M_month03;
1297 __months[3] = _M_month04;
1298 __months[4] = _M_month05;
1299 __months[5] = _M_month06;
1300 __months[6] = _M_month07;
1301 __months[7] = _M_month08;
1302 __months[8] = _M_month09;
1303 __months[9] = _M_month10;
1304 __months[10] = _M_month11;
1305 __months[11] = _M_month12;
1306 }
1307
1308 void
1309 _M_months_abbreviated(const _CharT** __months) const
1310 {
1311 __months[0] = _M_month_a01;
1312 __months[1] = _M_month_a02;
1313 __months[2] = _M_month_a03;
1314 __months[3] = _M_month_a04;
1315 __months[4] = _M_month_a05;
1316 __months[5] = _M_month_a06;
1317 __months[6] = _M_month_a07;
1318 __months[7] = _M_month_a08;
1319 __months[8] = _M_month_a09;
1320 __months[9] = _M_month_a10;
1321 __months[10] = _M_month_a11;
1322 __months[11] = _M_month_a12;
1323 }
1324
1325 protected:
1326 virtual
1327 ~__timepunct();
1328
1329 // For use at construction time only.
1330 void
1331 _M_initialize_timepunct(__c_locale __cloc = NULL);
1332 };
1333
1334 template<typename _CharT>
1335 locale::id __timepunct<_CharT>::id;
1336
1337 // Specializations.
1338 template<>
1339 const char*
1340 __timepunct<char>::_S_timezones[14];
1341
1342 template<>
1343 void
1344 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
1345
1346 template<>
1347 void
1348 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const;
1349
1350 #ifdef _GLIBCXX_USE_WCHAR_T
1351 template<>
1352 const wchar_t*
1353 __timepunct<wchar_t>::_S_timezones[14];
1354
1355 template<>
1356 void
1357 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
1358
1359 template<>
1360 void
1361 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
1362 const tm*) const;
1363 #endif
1364
1365 // Generic.
1366 template<typename _CharT>
1367 const _CharT* __timepunct<_CharT>::_S_timezones[14];
1368
1369 // Include host and configuration specific timepunct functions.
1370 #include <bits/time_members.h>
1371
1372 template<typename _CharT, typename _InIter>
1373 class time_get : public locale::facet, public time_base
1374 {
1375 public:
1376 // Types:
1377 typedef _CharT char_type;
1378 typedef _InIter iter_type;
1379 typedef basic_string<_CharT> __string_type;
1380
1381 static locale::id id;
1382
1383 explicit
1384 time_get(size_t __refs = 0)
1385 : locale::facet (__refs) { }
1386
1387 dateorder
1388 date_order() const
1389 { return this->do_date_order(); }
1390
1391 iter_type
1392 get_time(iter_type __beg, iter_type __end, ios_base& __io,
1393 ios_base::iostate& __err, tm* __tm) const
1394 { return this->do_get_time(__beg, __end, __io, __err, __tm); }
1395
1396 iter_type
1397 get_date(iter_type __beg, iter_type __end, ios_base& __io,
1398 ios_base::iostate& __err, tm* __tm) const
1399 { return this->do_get_date(__beg, __end, __io, __err, __tm); }
1400
1401 iter_type
1402 get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
1403 ios_base::iostate& __err, tm* __tm) const
1404 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
1405
1406 iter_type
1407 get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
1408 ios_base::iostate& __err, tm* __tm) const
1409 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
1410
1411 iter_type
1412 get_year(iter_type __beg, iter_type __end, ios_base& __io,
1413 ios_base::iostate& __err, tm* __tm) const
1414 { return this->do_get_year(__beg, __end, __io, __err, __tm); }
1415
1416 protected:
1417 virtual
1418 ~time_get() { }
1419
1420 virtual dateorder
1421 do_date_order() const;
1422
1423 virtual iter_type
1424 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
1425 ios_base::iostate& __err, tm* __tm) const;
1426
1427 virtual iter_type
1428 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
1429 ios_base::iostate& __err, tm* __tm) const;
1430
1431 virtual iter_type
1432 do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
1433 ios_base::iostate& __err, tm* __tm) const;
1434
1435 virtual iter_type
1436 do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
1437 ios_base::iostate& __err, tm* __tm) const;
1438
1439 virtual iter_type
1440 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
1441 ios_base::iostate& __err, tm* __tm) const;
1442
1443 // Extract numeric component of length __len.
1444 void
1445 _M_extract_num(iter_type& __beg, iter_type& __end, int& __member,
1446 int __min, int __max, size_t __len,
1447 const ctype<_CharT>& __ctype,
1448 ios_base::iostate& __err) const;
1449
1450 // Extract day or month name, or any unique array of string
1451 // literals in a const _CharT* array.
1452 void
1453 _M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
1454 const _CharT** __names, size_t __indexlen,
1455 ios_base::iostate& __err) const;
1456
1457 // Extract on a component-by-component basis, via __format argument.
1458 void
1459 _M_extract_via_format(iter_type& __beg, iter_type& __end, ios_base& __io,
1460 ios_base::iostate& __err, tm* __tm,
1461 const _CharT* __format) const;
1462 };
1463
1464 template<typename _CharT, typename _InIter>
1465 locale::id time_get<_CharT, _InIter>::id;
1466
1467 template<typename _CharT, typename _InIter>
1468 class time_get_byname : public time_get<_CharT, _InIter>
1469 {
1470 public:
1471 // Types:
1472 typedef _CharT char_type;
1473 typedef _InIter iter_type;
1474
1475 explicit
1476 time_get_byname(const char*, size_t __refs = 0)
1477 : time_get<_CharT, _InIter>(__refs) { }
1478
1479 protected:
1480 virtual
1481 ~time_get_byname() { }
1482 };
1483
1484 template<typename _CharT, typename _OutIter>
1485 class time_put : public locale::facet, public time_base
1486 {
1487 public:
1488 // Types:
1489 typedef _CharT char_type;
1490 typedef _OutIter iter_type;
1491
1492 static locale::id id;
1493
1494 explicit
1495 time_put(size_t __refs = 0)
1496 : locale::facet(__refs) { }
1497
1498 iter_type
1499 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
1500 const _CharT* __beg, const _CharT* __end) const;
1501
1502 iter_type
1503 put(iter_type __s, ios_base& __io, char_type __fill,
1504 const tm* __tm, char __format, char __mod = 0) const
1505 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
1506
1507 protected:
1508 virtual
1509 ~time_put()
1510 { }
1511
1512 virtual iter_type
1513 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
1514 char __format, char __mod) const;
1515 };
1516
1517 template<typename _CharT, typename _OutIter>
1518 locale::id time_put<_CharT, _OutIter>::id;
1519
1520 template<typename _CharT, typename _OutIter>
1521 class time_put_byname : public time_put<_CharT, _OutIter>
1522 {
1523 public:
1524 // Types:
1525 typedef _CharT char_type;
1526 typedef _OutIter iter_type;
1527
1528 explicit
1529 time_put_byname(const char* /*__s*/, size_t __refs = 0)
1530 : time_put<_CharT, _OutIter>(__refs)
1531 { };
1532
1533 protected:
1534 virtual
1535 ~time_put_byname() { }
1536 };
1537
1538
1539 class money_base
1540 {
1541 public:
1542 enum part { none, space, symbol, sign, value };
1543 struct pattern { char field[4]; };
1544
1545 static const pattern _S_default_pattern;
1546
1547 // Construct and return valid pattern consisting of some combination of:
1548 // space none symbol sign value
1549 static pattern
1550 _S_construct_pattern(char __precedes, char __space, char __posn);
1551 };
1552
1553 template<typename _CharT, bool _Intl>
1554 class moneypunct : public locale::facet, public money_base
1555 {
1556 public:
1557 // Types:
1558 typedef _CharT char_type;
1559 typedef basic_string<_CharT> string_type;
1560
1561 static const bool intl = _Intl;
1562 static locale::id id;
1563
1564 private:
1565 const char* _M_grouping;
1566 char_type _M_decimal_point;
1567 char_type _M_thousands_sep;
1568 const char_type* _M_curr_symbol;
1569 const char_type* _M_positive_sign;
1570 const char_type* _M_negative_sign;
1571 int _M_frac_digits;
1572 pattern _M_pos_format;
1573 pattern _M_neg_format;
1574
1575 public:
1576 explicit
1577 moneypunct(size_t __refs = 0) : locale::facet(__refs)
1578 { _M_initialize_moneypunct(); }
1579
1580 explicit
1581 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
1582 : locale::facet(__refs)
1583 { _M_initialize_moneypunct(__cloc, __s); }
1584
1585 char_type
1586 decimal_point() const
1587 { return this->do_decimal_point(); }
1588
1589 char_type
1590 thousands_sep() const
1591 { return this->do_thousands_sep(); }
1592
1593 string
1594 grouping() const
1595 { return this->do_grouping(); }
1596
1597 string_type
1598 curr_symbol() const
1599 { return this->do_curr_symbol(); }
1600
1601 string_type
1602 positive_sign() const
1603 { return this->do_positive_sign(); }
1604
1605 string_type
1606 negative_sign() const
1607 { return this->do_negative_sign(); }
1608
1609 int
1610 frac_digits() const
1611 { return this->do_frac_digits(); }
1612
1613 pattern
1614 pos_format() const
1615 { return this->do_pos_format(); }
1616
1617 pattern
1618 neg_format() const
1619 { return this->do_neg_format(); }
1620
1621 protected:
1622 virtual
1623 ~moneypunct();
1624
1625 virtual char_type
1626 do_decimal_point() const
1627 { return _M_decimal_point; }
1628
1629 virtual char_type
1630 do_thousands_sep() const
1631 { return _M_thousands_sep; }
1632
1633 virtual string
1634 do_grouping() const
1635 { return _M_grouping; }
1636
1637 virtual string_type
1638 do_curr_symbol() const
1639 { return _M_curr_symbol; }
1640
1641 virtual string_type
1642 do_positive_sign() const
1643 { return _M_positive_sign; }
1644
1645 virtual string_type
1646 do_negative_sign() const
1647 { return _M_negative_sign; }
1648
1649 virtual int
1650 do_frac_digits() const
1651 { return _M_frac_digits; }
1652
1653 virtual pattern
1654 do_pos_format() const
1655 { return _M_pos_format; }
1656
1657 virtual pattern
1658 do_neg_format() const
1659 { return _M_neg_format; }
1660
1661 // For use at construction time only.
1662 void
1663 _M_initialize_moneypunct(__c_locale __cloc = NULL,
1664 const char* __name = NULL);
1665 };
1666
1667 template<typename _CharT, bool _Intl>
1668 locale::id moneypunct<_CharT, _Intl>::id;
1669
1670 template<typename _CharT, bool _Intl>
1671 const bool moneypunct<_CharT, _Intl>::intl;
1672
1673 template<>
1674 moneypunct<char, true>::~moneypunct();
1675
1676 template<>
1677 moneypunct<char, false>::~moneypunct();
1678
1679 template<>
1680 void
1681 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
1682
1683 template<>
1684 void
1685 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
1686
1687 #ifdef _GLIBCXX_USE_WCHAR_T
1688 template<>
1689 moneypunct<wchar_t, true>::~moneypunct();
1690
1691 template<>
1692 moneypunct<wchar_t, false>::~moneypunct();
1693
1694 template<>
1695 void
1696 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
1697 const char*);
1698
1699 template<>
1700 void
1701 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
1702 const char*);
1703 #endif
1704
1705 template<typename _CharT, bool _Intl>
1706 class moneypunct_byname : public moneypunct<_CharT, _Intl>
1707 {
1708 __c_locale _M_c_locale_moneypunct;
1709
1710 public:
1711 typedef _CharT char_type;
1712 typedef basic_string<_CharT> string_type;
1713
1714 static const bool intl = _Intl;
1715
1716 explicit
1717 moneypunct_byname(const char* __s, size_t __refs = 0)
1718 : moneypunct<_CharT, _Intl>(__refs)
1719 {
1720 this->_S_create_c_locale(_M_c_locale_moneypunct, __s);
1721 this->_M_initialize_moneypunct(_M_c_locale_moneypunct);
1722 }
1723
1724 protected:
1725 virtual
1726 ~moneypunct_byname()
1727 { this->_S_destroy_c_locale(_M_c_locale_moneypunct); }
1728 };
1729
1730 template<typename _CharT, bool _Intl>
1731 const bool moneypunct_byname<_CharT, _Intl>::intl;
1732
1733 template<typename _CharT, typename _InIter>
1734 class money_get : public locale::facet
1735 {
1736 public:
1737 // Types:
1738 typedef _CharT char_type;
1739 typedef _InIter iter_type;
1740 typedef basic_string<_CharT> string_type;
1741
1742 static locale::id id;
1743
1744 explicit
1745 money_get(size_t __refs = 0) : locale::facet(__refs) { }
1746
1747 iter_type
1748 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1749 ios_base::iostate& __err, long double& __units) const
1750 { return this->do_get(__s, __end, __intl, __io, __err, __units); }
1751
1752 iter_type
1753 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1754 ios_base::iostate& __err, string_type& __digits) const
1755 { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
1756
1757 protected:
1758 virtual
1759 ~money_get() { }
1760
1761 virtual iter_type
1762 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1763 ios_base::iostate& __err, long double& __units) const;
1764
1765 virtual iter_type
1766 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1767 ios_base::iostate& __err, string_type& __digits) const;
1768 };
1769
1770 template<typename _CharT, typename _InIter>
1771 locale::id money_get<_CharT, _InIter>::id;
1772
1773 template<typename _CharT, typename _OutIter>
1774 class money_put : public locale::facet
1775 {
1776 public:
1777 typedef _CharT char_type;
1778 typedef _OutIter iter_type;
1779 typedef basic_string<_CharT> string_type;
1780
1781 static locale::id id;
1782
1783 explicit
1784 money_put(size_t __refs = 0) : locale::facet(__refs) { }
1785
1786 iter_type
1787 put(iter_type __s, bool __intl, ios_base& __io,
1788 char_type __fill, long double __units) const
1789 { return this->do_put(__s, __intl, __io, __fill, __units); }
1790
1791 iter_type
1792 put(iter_type __s, bool __intl, ios_base& __io,
1793 char_type __fill, const string_type& __digits) const
1794 { return this->do_put(__s, __intl, __io, __fill, __digits); }
1795
1796 protected:
1797 virtual
1798 ~money_put() { }
1799
1800 virtual iter_type
1801 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1802 long double __units) const;
1803
1804 virtual iter_type
1805 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1806 const string_type& __digits) const;
1807 };
1808
1809 template<typename _CharT, typename _OutIter>
1810 locale::id money_put<_CharT, _OutIter>::id;
1811
1812
1813 struct messages_base
1814 {
1815 typedef int catalog;
1816 };
1817
1818 template<typename _CharT>
1819 class messages : public locale::facet, public messages_base
1820 {
1821 public:
1822 // Types:
1823 typedef _CharT char_type;
1824 typedef basic_string<_CharT> string_type;
1825
1826 protected:
1827 // Underlying "C" library locale information saved from
1828 // initialization, needed by messages_byname as well.
1829 __c_locale _M_c_locale_messages;
1830 char* _M_name_messages;
1831
1832 public:
1833 static locale::id id;
1834
1835 explicit
1836 messages(size_t __refs = 0);
1837
1838 // Non-standard.
1839 explicit
1840 messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
1841
1842 catalog
1843 open(const basic_string<char>& __s, const locale& __loc) const
1844 { return this->do_open(__s, __loc); }
1845
1846 // Non-standard and unorthodox, yet effective.
1847 catalog
1848 open(const basic_string<char>&, const locale&, const char*) const;
1849
1850 string_type
1851 get(catalog __c, int __set, int __msgid, const string_type& __s) const
1852 { return this->do_get(__c, __set, __msgid, __s); }
1853
1854 void
1855 close(catalog __c) const
1856 { return this->do_close(__c); }
1857
1858 protected:
1859 virtual
1860 ~messages();
1861
1862 virtual catalog
1863 do_open(const basic_string<char>&, const locale&) const;
1864
1865 virtual string_type
1866 do_get(catalog, int, int, const string_type& __dfault) const;
1867
1868 virtual void
1869 do_close(catalog) const;
1870
1871 // Returns a locale and codeset-converted string, given a char* message.
1872 char*
1873 _M_convert_to_char(const string_type& __msg) const
1874 {
1875 // XXX
1876 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
1877 }
1878
1879 // Returns a locale and codeset-converted string, given a char* message.
1880 string_type
1881 _M_convert_from_char(char* __msg) const
1882 {
1883 // Length of message string without terminating null.
1884 size_t __len = char_traits<char>::length(__msg) - 1;
1885
1886 // "everybody can easily convert the string using
1887 // mbsrtowcs/wcsrtombs or with iconv()"
1888 #if 0
1889 // Convert char* to _CharT in locale used to open catalog.
1890 // XXX need additional template parameter on messages class for this..
1891 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
1892 typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;
1893
1894 __codecvt_type::state_type __state;
1895 // XXX may need to initialize state.
1896 //initialize_state(__state._M_init());
1897
1898 char* __from_next;
1899 // XXX what size for this string?
1900 _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
1901 const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
1902 __cvt.out(__state, __msg, __msg + __len, __from_next,
1903 __to, __to + __len + 1, __to_next);
1904 return string_type(__to);
1905 #endif
1906 #if 0
1907 typedef ctype<_CharT> __ctype_type;
1908 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
1909 const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
1910 // XXX Again, proper length of converted string an issue here.
1911 // For now, assume the converted length is not larger.
1912 _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
1913 __cvt.widen(__msg, __msg + __len, __dest);
1914 return basic_string<_CharT>(__dest);
1915 #endif
1916 return string_type();
1917 }
1918 };
1919
1920 template<typename _CharT>
1921 locale::id messages<_CharT>::id;
1922
1923 // Specializations for required instantiations.
1924 template<>
1925 string
1926 messages<char>::do_get(catalog, int, int, const string&) const;
1927
1928 #ifdef _GLIBCXX_USE_WCHAR_T
1929 template<>
1930 wstring
1931 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
1932 #endif
1933
1934 template<typename _CharT>
1935 class messages_byname : public messages<_CharT>
1936 {
1937 public:
1938 typedef _CharT char_type;
1939 typedef basic_string<_CharT> string_type;
1940
1941 explicit
1942 messages_byname(const char* __s, size_t __refs = 0);
1943
1944 protected:
1945 virtual
1946 ~messages_byname()
1947 { }
1948 };
1949
1950 // Include host and configuration specific messages functions.
1951 #include <bits/messages_members.h>
1952
1953
1954 // Subclause convenience interfaces, inlines.
1955 // NB: These are inline because, when used in a loop, some compilers
1956 // can hoist the body out of the loop; then it's just as fast as the
1957 // C is*() function.
1958 template<typename _CharT>
1959 inline bool
1960 isspace(_CharT __c, const locale& __loc)
1961 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
1962
1963 template<typename _CharT>
1964 inline bool
1965 isprint(_CharT __c, const locale& __loc)
1966 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
1967
1968 template<typename _CharT>
1969 inline bool
1970 iscntrl(_CharT __c, const locale& __loc)
1971 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
1972
1973 template<typename _CharT>
1974 inline bool
1975 isupper(_CharT __c, const locale& __loc)
1976 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
1977
1978 template<typename _CharT>
1979 inline bool islower(_CharT __c, const locale& __loc)
1980 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
1981
1982 template<typename _CharT>
1983 inline bool
1984 isalpha(_CharT __c, const locale& __loc)
1985 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
1986
1987 template<typename _CharT>
1988 inline bool
1989 isdigit(_CharT __c, const locale& __loc)
1990 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
1991
1992 template<typename _CharT>
1993 inline bool
1994 ispunct(_CharT __c, const locale& __loc)
1995 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
1996
1997 template<typename _CharT>
1998 inline bool
1999 isxdigit(_CharT __c, const locale& __loc)
2000 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
2001
2002 template<typename _CharT>
2003 inline bool
2004 isalnum(_CharT __c, const locale& __loc)
2005 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
2006
2007 template<typename _CharT>
2008 inline bool
2009 isgraph(_CharT __c, const locale& __loc)
2010 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
2011
2012 template<typename _CharT>
2013 inline _CharT
2014 toupper(_CharT __c, const locale& __loc)
2015 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
2016
2017 template<typename _CharT>
2018 inline _CharT
2019 tolower(_CharT __c, const locale& __loc)
2020 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
2021 } // namespace std
2022
2023 #endif