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