1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 22.1 Locales
34 /** @file locale_facets.h
35 * This is an internal header file, included by other library headers.
36 * You should not attempt to use it directly.
39 #ifndef _CPP_BITS_LOCFACETS_H
40 #define _CPP_BITS_LOCFACETS_H 1
42 #pragma GCC system_header
44 #include <ctime> // For struct tm
45 #ifdef _GLIBCPP_USE_WCHAR_T
46 # include <cwctype> // For wctype_t
48 #include <ios> // For ios_base
52 // 22.2.1.1 Template class ctype
53 // Include host and configuration specific ctype enums for ctype_base.
54 #include <bits/ctype_base.h>
56 // __ctype_abstract_base is the common base for ctype<_CharT>.
57 template<typename _CharT>
58 class __ctype_abstract_base : public locale::facet, public ctype_base
62 typedef _CharT char_type;
65 is(mask __m, char_type __c) const
66 { return this->do_is(__m, __c); }
69 is(const char_type *__lo, const char_type *__hi, mask *__vec) const
70 { return this->do_is(__lo, __hi, __vec); }
73 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
74 { return this->do_scan_is(__m, __lo, __hi); }
77 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
78 { return this->do_scan_not(__m, __lo, __hi); }
81 toupper(char_type __c) const
82 { return this->do_toupper(__c); }
85 toupper(char_type *__lo, const char_type* __hi) const
86 { return this->do_toupper(__lo, __hi); }
89 tolower(char_type __c) const
90 { return this->do_tolower(__c); }
93 tolower(char_type* __lo, const char_type* __hi) const
94 { return this->do_tolower(__lo, __hi); }
98 { return this->do_widen(__c); }
101 widen(const char* __lo, const char* __hi, char_type* __to) const
102 { return this->do_widen(__lo, __hi, __to); }
105 narrow(char_type __c, char __dfault) const
106 { return this->do_narrow(__c, __dfault); }
109 narrow(const char_type* __lo, const char_type* __hi,
110 char __dfault, char *__to) const
111 { return this->do_narrow(__lo, __hi, __dfault, __to); }
115 __ctype_abstract_base(size_t __refs = 0): locale::facet(__refs) { }
118 ~__ctype_abstract_base() { }
121 do_is(mask __m, char_type __c) const = 0;
123 virtual const char_type*
124 do_is(const char_type* __lo, const char_type* __hi,
125 mask* __vec) const = 0;
127 virtual const char_type*
128 do_scan_is(mask __m, const char_type* __lo,
129 const char_type* __hi) const = 0;
131 virtual const char_type*
132 do_scan_not(mask __m, const char_type* __lo,
133 const char_type* __hi) const = 0;
136 do_toupper(char_type) const = 0;
138 virtual const char_type*
139 do_toupper(char_type* __lo, const char_type* __hi) const = 0;
142 do_tolower(char_type) const = 0;
144 virtual const char_type*
145 do_tolower(char_type* __lo, const char_type* __hi) const = 0;
148 do_widen(char) const = 0;
151 do_widen(const char* __lo, const char* __hi,
152 char_type* __dest) const = 0;
155 do_narrow(char_type, char __dfault) const = 0;
157 virtual const char_type*
158 do_narrow(const char_type* __lo, const char_type* __hi,
159 char __dfault, char* __dest) const = 0;
162 // NB: Generic, mostly useless implementation.
163 template<typename _CharT>
164 class ctype : public __ctype_abstract_base<_CharT>
168 typedef _CharT char_type;
169 typedef typename ctype::mask mask;
172 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
174 static locale::id id;
181 do_is(mask __m, char_type __c) const;
183 virtual const char_type*
184 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
186 virtual const char_type*
187 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
189 virtual const char_type*
190 do_scan_not(mask __m, const char_type* __lo,
191 const char_type* __hi) const;
194 do_toupper(char_type __c) const;
196 virtual const char_type*
197 do_toupper(char_type* __lo, const char_type* __hi) const;
200 do_tolower(char_type __c) const;
202 virtual const char_type*
203 do_tolower(char_type* __lo, const char_type* __hi) const;
206 do_widen(char __c) const;
209 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
212 do_narrow(char_type, char __dfault) const;
214 virtual const char_type*
215 do_narrow(const char_type* __lo, const char_type* __hi,
216 char __dfault, char* __dest) const;
219 template<typename _CharT>
220 locale::id ctype<_CharT>::id;
222 // 22.2.1.3 ctype<char> specialization.
224 class ctype<char> : public __ctype_abstract_base<char>
228 typedef char char_type;
232 __c_locale _M_c_locale_ctype;
234 __to_type _M_toupper;
235 __to_type _M_tolower;
236 const mask* _M_table;
239 static locale::id id;
240 static const size_t table_size = 1 + static_cast<unsigned char>(-1);
243 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
246 ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
250 is(mask __m, char __c) const;
253 is(const char* __lo, const char* __hi, mask* __vec) const;
256 scan_is(mask __m, const char* __lo, const char* __hi) const;
259 scan_not(mask __m, const char* __lo, const char* __hi) const;
263 table() const throw()
267 classic_table() throw();
273 do_is(mask __m, char_type __c) const;
275 virtual const char_type*
276 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
278 virtual const char_type*
279 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
281 virtual const char_type*
282 do_scan_not(mask __m, const char_type* __lo,
283 const char_type* __hi) const;
286 do_toupper(char_type) const;
288 virtual const char_type*
289 do_toupper(char_type* __lo, const char_type* __hi) const;
292 do_tolower(char_type) const;
294 virtual const char_type*
295 do_tolower(char_type* __lo, const char_type* __hi) const;
298 do_widen(char) const;
301 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
304 do_narrow(char_type, char __dfault) const;
306 virtual const char_type*
307 do_narrow(const char_type* __lo, const char_type* __hi,
308 char __dfault, char* __dest) const;
313 use_facet<ctype<char> >(const locale& __loc);
315 #ifdef _GLIBCPP_USE_WCHAR_T
316 // 22.2.1.3 ctype<wchar_t> specialization
318 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
322 typedef wchar_t char_type;
323 typedef wctype_t __wmask_type;
326 __c_locale _M_c_locale_ctype;
330 static locale::id id;
333 ctype(size_t __refs = 0);
336 ctype(__c_locale __cloc, size_t __refs = 0);
340 _M_convert_to_wmask(const mask __m) const;
346 do_is(mask __m, char_type __c) const;
348 virtual const char_type*
349 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
351 virtual const char_type*
352 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
354 virtual const char_type*
355 do_scan_not(mask __m, const char_type* __lo,
356 const char_type* __hi) const;
359 do_toupper(char_type) const;
361 virtual const char_type*
362 do_toupper(char_type* __lo, const char_type* __hi) const;
365 do_tolower(char_type) const;
367 virtual const char_type*
368 do_tolower(char_type* __lo, const char_type* __hi) const;
371 do_widen(char) const;
374 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
377 do_narrow(char_type, char __dfault) const;
379 virtual const char_type*
380 do_narrow(const char_type* __lo, const char_type* __hi,
381 char __dfault, char* __dest) const;
386 const ctype<wchar_t>&
387 use_facet<ctype<wchar_t> >(const locale& __loc);
388 #endif //_GLIBCPP_USE_WCHAR_T
390 // Include host and configuration specific ctype inlines.
391 #include <bits/ctype_inline.h>
393 // 22.2.1.2 Template class ctype_byname
394 template<typename _CharT>
395 class ctype_byname : public ctype<_CharT>
398 typedef _CharT char_type;
401 ctype_byname(const char* __s, size_t __refs = 0);
408 // 22.2.1.4 Class ctype_byname specializations.
410 ctype_byname<char>::ctype_byname(const char*, size_t refs);
413 ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs);
415 // 22.2.1.5 Template class codecvt
416 #include <bits/codecvt.h>
419 // 22.2.2 The numeric category.
423 // Used to establish gating factor for base 16 input.
424 static const double _S_scale_hex;
426 // Used to establish gating factor for base 8 input.
427 static const double _S_scale_oct;
429 // String literal of acceptable (narrow) input, for num_get.
430 // "0123456789eEabcdfABCDF"
431 static const char _S_atoms[];
441 // Construct and return valid scanf format for floating point types.
443 _S_format_float(const ios_base& __io, char* __fptr, char __mod,
446 // Construct and return valid scanf format for integer types.
448 _S_format_int(const ios_base& __io, char* __fptr, char __mod, char __modl);
451 template<typename _CharT>
452 class numpunct : public locale::facet
456 typedef _CharT char_type;
457 typedef basic_string<_CharT> string_type;
459 static locale::id id;
462 char_type _M_decimal_point;
463 char_type _M_thousands_sep;
465 string_type _M_truename;
466 string_type _M_falsename;
470 numpunct(size_t __refs = 0) : locale::facet(__refs)
471 { _M_initialize_numpunct(); }
474 numpunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs)
475 { _M_initialize_numpunct(__cloc); }
478 decimal_point() const
479 { return this->do_decimal_point(); }
482 thousands_sep() const
483 { return this->do_thousands_sep(); }
487 { return this->do_grouping(); }
491 { return this->do_truename(); }
495 { return this->do_falsename(); }
502 do_decimal_point() const
503 { return _M_decimal_point; }
506 do_thousands_sep() const
507 { return _M_thousands_sep; }
511 { return _M_grouping; }
515 { return _M_truename; }
519 { return _M_falsename; }
521 // For use at construction time only.
523 _M_initialize_numpunct(__c_locale __cloc = NULL);
526 template<typename _CharT>
527 locale::id numpunct<_CharT>::id;
529 // NB: Cannot be made generic.
530 template<typename _CharT>
532 numpunct<_CharT>::_M_initialize_numpunct(__c_locale)
537 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
539 #ifdef _GLIBCPP_USE_WCHAR_T
542 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
545 template<typename _CharT>
546 class numpunct_byname : public numpunct<_CharT>
549 __c_locale _M_c_locale_numpunct;
552 typedef _CharT char_type;
553 typedef basic_string<_CharT> string_type;
556 numpunct_byname(const char* __s, size_t __refs = 0)
557 : numpunct<_CharT>(__refs)
559 _S_create_c_locale(_M_c_locale_numpunct, __s);
560 _M_initialize_numpunct(_M_c_locale_numpunct);
566 { _S_destroy_c_locale(_M_c_locale_numpunct); }
569 template<typename _CharT, typename _InIter>
570 class num_get : public locale::facet, public __num_base
574 typedef _CharT char_type;
575 typedef _InIter iter_type;
577 static locale::id id;
580 num_get(size_t __refs = 0) : locale::facet(__refs) { }
583 get(iter_type __in, iter_type __end, ios_base& __io,
584 ios_base::iostate& __err, bool& __v) const
585 { return this->do_get(__in, __end, __io, __err, __v); }
588 get(iter_type __in, iter_type __end, ios_base& __io,
589 ios_base::iostate& __err, long& __v) const
590 { return this->do_get(__in, __end, __io, __err, __v); }
593 get(iter_type __in, iter_type __end, ios_base& __io,
594 ios_base::iostate& __err, unsigned short& __v) const
595 { return this->do_get(__in, __end, __io, __err, __v); }
598 get(iter_type __in, iter_type __end, ios_base& __io,
599 ios_base::iostate& __err, unsigned int& __v) const
600 { return this->do_get(__in, __end, __io, __err, __v); }
603 get(iter_type __in, iter_type __end, ios_base& __io,
604 ios_base::iostate& __err, unsigned long& __v) const
605 { return this->do_get(__in, __end, __io, __err, __v); }
607 #ifdef _GLIBCPP_USE_LONG_LONG
609 get(iter_type __in, iter_type __end, ios_base& __io,
610 ios_base::iostate& __err, long long& __v) const
611 { return this->do_get(__in, __end, __io, __err, __v); }
614 get(iter_type __in, iter_type __end, ios_base& __io,
615 ios_base::iostate& __err, unsigned long long& __v) const
616 { return this->do_get(__in, __end, __io, __err, __v); }
620 get(iter_type __in, iter_type __end, ios_base& __io,
621 ios_base::iostate& __err, float& __v) const
622 { return this->do_get(__in, __end, __io, __err, __v); }
625 get(iter_type __in, iter_type __end, ios_base& __io,
626 ios_base::iostate& __err, double& __v) const
627 { return this->do_get(__in, __end, __io, __err, __v); }
630 get(iter_type __in, iter_type __end, ios_base& __io,
631 ios_base::iostate& __err, long double& __v) const
632 { return this->do_get(__in, __end, __io, __err, __v); }
635 get(iter_type __in, iter_type __end, ios_base& __io,
636 ios_base::iostate& __err, void*& __v) const
637 { return this->do_get(__in, __end, __io, __err, __v); }
640 virtual ~num_get() { }
643 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
644 string& __xtrc) const;
647 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
648 char* __xtrc, int __max, int& __base) const;
651 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
654 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
657 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
658 unsigned short&) const;
661 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
662 unsigned int&) const;
665 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
666 unsigned long&) const;
668 #ifdef _GLIBCPP_USE_LONG_LONG
670 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
674 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
675 unsigned long long&) const;
679 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
683 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
687 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
691 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
695 template<typename _CharT, typename _InIter>
696 locale::id num_get<_CharT, _InIter>::id;
698 template<typename _CharT, typename _OutIter>
699 class num_put : public locale::facet, public __num_base
703 typedef _CharT char_type;
704 typedef _OutIter iter_type;
706 static locale::id id;
709 num_put(size_t __refs = 0) : locale::facet(__refs) { }
712 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
713 { return this->do_put(__s, __f, __fill, __v); }
716 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
717 { return this->do_put(__s, __f, __fill, __v); }
720 put(iter_type __s, ios_base& __f, char_type __fill,
721 unsigned long __v) const
722 { return this->do_put(__s, __f, __fill, __v); }
724 #ifdef _GLIBCPP_USE_LONG_LONG
726 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
727 { return this->do_put(__s, __f, __fill, __v); }
730 put(iter_type __s, ios_base& __f, char_type __fill,
731 unsigned long long __v) const
732 { return this->do_put(__s, __f, __fill, __v); }
736 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
737 { return this->do_put(__s, __f, __fill, __v); }
740 put(iter_type __s, ios_base& __f, char_type __fill,
741 long double __v) const
742 { return this->do_put(__s, __f, __fill, __v); }
745 put(iter_type __s, ios_base& __f, char_type __fill,
746 const void* __v) const
747 { return this->do_put(__s, __f, __fill, __v); }
750 template<typename _ValueT>
752 _M_convert_float(iter_type, ios_base& __io, char_type __fill,
753 char __mod, _ValueT __v) const;
755 template<typename _ValueT>
757 _M_convert_int(iter_type, ios_base& __io, char_type __fill,
758 char __mod, char __modl, _ValueT __v) const;
761 _M_widen_float(iter_type, ios_base& __io, char_type __fill, char* __cs,
765 _M_widen_int(iter_type, ios_base& __io, char_type __fill, char* __cs,
769 _M_insert(iter_type, ios_base& __io, char_type __fill,
770 const char_type* __ws, int __len) const;
776 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
779 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
782 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
784 #ifdef _GLIBCPP_USE_LONG_LONG
786 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
789 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
793 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
796 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
799 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
802 template <typename _CharT, typename _OutIter>
803 locale::id num_put<_CharT, _OutIter>::id;
806 template<typename _CharT>
807 class collate : public locale::facet
811 typedef _CharT char_type;
812 typedef basic_string<_CharT> string_type;
815 // Underlying "C" library locale information saved from
816 // initialization, needed by collate_byname as well.
817 __c_locale _M_c_locale_collate;
820 static locale::id id;
823 collate(size_t __refs = 0)
824 : locale::facet(__refs)
825 { _M_c_locale_collate = _S_clone_c_locale(_S_c_locale); }
829 collate(__c_locale __cloc, size_t __refs = 0)
830 : locale::facet(__refs)
831 { _M_c_locale_collate = _S_clone_c_locale(__cloc); }
834 compare(const _CharT* __lo1, const _CharT* __hi1,
835 const _CharT* __lo2, const _CharT* __hi2) const
836 { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
839 transform(const _CharT* __lo, const _CharT* __hi) const
840 { return this->do_transform(__lo, __hi); }
843 hash(const _CharT* __lo, const _CharT* __hi) const
844 { return this->do_hash(__lo, __hi); }
846 // Used to abstract out _CharT bits in virtual member functions, below.
848 _M_compare_helper(const _CharT*, const _CharT*) const;
851 _M_transform_helper(_CharT*, const _CharT*, size_t) const;
856 { _S_destroy_c_locale(_M_c_locale_collate); }
859 do_compare(const _CharT* __lo1, const _CharT* __hi1,
860 const _CharT* __lo2, const _CharT* __hi2) const;
863 do_transform(const _CharT* __lo, const _CharT* __hi) const;
866 do_hash(const _CharT* __lo, const _CharT* __hi) const;
869 template<typename _CharT>
870 locale::id collate<_CharT>::id;
875 collate<char>::_M_compare_helper(const char*, const char*) const;
879 collate<char>::_M_transform_helper(char*, const char*, size_t) const;
881 #ifdef _GLIBCPP_USE_WCHAR_T
884 collate<wchar_t>::_M_compare_helper(const wchar_t*, const wchar_t*) const;
888 collate<wchar_t>::_M_transform_helper(wchar_t*, const wchar_t*,
892 template<typename _CharT>
893 class collate_byname : public collate<_CharT>
896 typedef _CharT char_type;
897 typedef basic_string<_CharT> string_type;
900 collate_byname(const char* __s, size_t __refs = 0)
901 : collate<_CharT>(__refs)
903 _S_destroy_c_locale(_M_c_locale_collate);
904 _S_create_c_locale(_M_c_locale_collate, __s);
909 ~collate_byname() { }
916 enum dateorder { no_order, dmy, mdy, ymd, ydm };
919 template<typename _CharT>
920 class __timepunct : public locale::facet
924 typedef _CharT __char_type;
925 typedef basic_string<_CharT> __string_type;
927 static locale::id id;
929 // List of all known timezones, with GMT first.
930 static const _CharT* _S_timezones[14];
933 __c_locale _M_c_locale_timepunct;
934 const char* _M_name_timepunct;
935 const _CharT* _M_date_format;
936 const _CharT* _M_date_era_format;
937 const _CharT* _M_time_format;
938 const _CharT* _M_time_era_format;
939 const _CharT* _M_date_time_format;
940 const _CharT* _M_date_time_era_format;
943 const _CharT* _M_am_pm_format;
945 // Day names, starting with "C"'s Sunday.
946 const _CharT* _M_day1;
947 const _CharT* _M_day2;
948 const _CharT* _M_day3;
949 const _CharT* _M_day4;
950 const _CharT* _M_day5;
951 const _CharT* _M_day6;
952 const _CharT* _M_day7;
954 // Abbreviated day names, starting with "C"'s Sun.
955 const _CharT* _M_day_a1;
956 const _CharT* _M_day_a2;
957 const _CharT* _M_day_a3;
958 const _CharT* _M_day_a4;
959 const _CharT* _M_day_a5;
960 const _CharT* _M_day_a6;
961 const _CharT* _M_day_a7;
963 // Month names, starting with "C"'s January.
964 const _CharT* _M_month01;
965 const _CharT* _M_month02;
966 const _CharT* _M_month03;
967 const _CharT* _M_month04;
968 const _CharT* _M_month05;
969 const _CharT* _M_month06;
970 const _CharT* _M_month07;
971 const _CharT* _M_month08;
972 const _CharT* _M_month09;
973 const _CharT* _M_month10;
974 const _CharT* _M_month11;
975 const _CharT* _M_month12;
977 // Abbreviated month names, starting with "C"'s Jan.
978 const _CharT* _M_month_a01;
979 const _CharT* _M_month_a02;
980 const _CharT* _M_month_a03;
981 const _CharT* _M_month_a04;
982 const _CharT* _M_month_a05;
983 const _CharT* _M_month_a06;
984 const _CharT* _M_month_a07;
985 const _CharT* _M_month_a08;
986 const _CharT* _M_month_a09;
987 const _CharT* _M_month_a10;
988 const _CharT* _M_month_a11;
989 const _CharT* _M_month_a12;
993 __timepunct(size_t __refs = 0)
994 : locale::facet(__refs), _M_name_timepunct("C")
995 { _M_initialize_timepunct(); }
998 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
999 : locale::facet(__refs), _M_name_timepunct(__s)
1000 { _M_initialize_timepunct(__cloc); }
1003 _M_put_helper(_CharT* __s, size_t __maxlen, const _CharT* __format,
1004 const tm* __tm) const;
1007 _M_date_formats(const _CharT** __date) const
1009 // Always have default first.
1010 __date[0] = _M_date_format;
1011 __date[1] = _M_date_era_format;
1015 _M_time_formats(const _CharT** __time) const
1017 // Always have default first.
1018 __time[0] = _M_time_format;
1019 __time[1] = _M_time_era_format;
1023 _M_ampm(const _CharT** __ampm) const
1030 _M_date_time_formats(const _CharT** __dt) const
1032 // Always have default first.
1033 __dt[0] = _M_date_time_format;
1034 __dt[1] = _M_date_time_era_format;
1038 _M_days(const _CharT** __days) const
1040 __days[0] = _M_day1;
1041 __days[1] = _M_day2;
1042 __days[2] = _M_day3;
1043 __days[3] = _M_day4;
1044 __days[4] = _M_day5;
1045 __days[5] = _M_day6;
1046 __days[6] = _M_day7;
1050 _M_days_abbreviated(const _CharT** __days) const
1052 __days[0] = _M_day_a1;
1053 __days[1] = _M_day_a2;
1054 __days[2] = _M_day_a3;
1055 __days[3] = _M_day_a4;
1056 __days[4] = _M_day_a5;
1057 __days[5] = _M_day_a6;
1058 __days[6] = _M_day_a7;
1062 _M_months(const _CharT** __months) const
1064 __months[0] = _M_month01;
1065 __months[1] = _M_month02;
1066 __months[2] = _M_month03;
1067 __months[3] = _M_month04;
1068 __months[4] = _M_month05;
1069 __months[5] = _M_month06;
1070 __months[6] = _M_month07;
1071 __months[7] = _M_month08;
1072 __months[8] = _M_month09;
1073 __months[9] = _M_month10;
1074 __months[10] = _M_month11;
1075 __months[11] = _M_month12;
1079 _M_months_abbreviated(const _CharT** __months) const
1081 __months[0] = _M_month_a01;
1082 __months[1] = _M_month_a02;
1083 __months[2] = _M_month_a03;
1084 __months[3] = _M_month_a04;
1085 __months[4] = _M_month_a05;
1086 __months[5] = _M_month_a06;
1087 __months[6] = _M_month_a07;
1088 __months[7] = _M_month_a08;
1089 __months[8] = _M_month_a09;
1090 __months[9] = _M_month_a10;
1091 __months[10] = _M_month_a11;
1092 __months[11] = _M_month_a12;
1099 if (_M_c_locale_timepunct)
1100 _S_destroy_c_locale(_M_c_locale_timepunct);
1103 // For use at construction time only.
1105 _M_initialize_timepunct(__c_locale __cloc = NULL);
1108 template<typename _CharT>
1109 locale::id __timepunct<_CharT>::id;
1114 __timepunct<char>::_S_timezones[14];
1118 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
1122 __timepunct<char>::_M_put_helper(char*, size_t, const char*,
1125 #ifdef _GLIBCPP_USE_WCHAR_T
1128 __timepunct<wchar_t>::_S_timezones[14];
1132 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
1136 __timepunct<wchar_t>::_M_put_helper(wchar_t*, size_t, const wchar_t*,
1141 template<typename _CharT>
1142 const _CharT* __timepunct<_CharT>::_S_timezones[14];
1144 // NB: Cannot be made generic.
1145 template<typename _CharT>
1147 __timepunct<_CharT>::_M_initialize_timepunct(__c_locale)
1150 // NB: Cannot be made generic.
1151 template<typename _CharT>
1153 __timepunct<_CharT>::_M_put_helper(_CharT*, size_t, const _CharT*,
1157 template<typename _CharT, typename _InIter>
1158 class time_get : public locale::facet, public time_base
1162 typedef _CharT char_type;
1163 typedef _InIter iter_type;
1164 typedef basic_string<_CharT> __string_type;
1166 static locale::id id;
1169 time_get(size_t __refs = 0)
1170 : locale::facet (__refs) { }
1174 { return this->do_date_order(); }
1177 get_time(iter_type __beg, iter_type __end, ios_base& __io,
1178 ios_base::iostate& __err, tm* __tm) const
1179 { return this->do_get_time(__beg, __end, __io, __err, __tm); }
1182 get_date(iter_type __beg, iter_type __end, ios_base& __io,
1183 ios_base::iostate& __err, tm* __tm) const
1184 { return this->do_get_date(__beg, __end, __io, __err, __tm); }
1187 get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
1188 ios_base::iostate& __err, tm* __tm) const
1189 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
1192 get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
1193 ios_base::iostate& __err, tm* __tm) const
1194 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
1197 get_year(iter_type __beg, iter_type __end, ios_base& __io,
1198 ios_base::iostate& __err, tm* __tm) const
1199 { return this->do_get_year(__beg, __end, __io, __err, __tm); }
1206 do_date_order() const;
1209 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
1210 ios_base::iostate& __err, tm* __tm) const;
1213 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
1214 ios_base::iostate& __err, tm* __tm) const;
1217 do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
1218 ios_base::iostate& __err, tm* __tm) const;
1221 do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
1222 ios_base::iostate& __err, tm* __tm) const;
1225 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
1226 ios_base::iostate& __err, tm* __tm) const;
1228 // Extract numeric component of length __len.
1230 _M_extract_num(iter_type& __beg, iter_type& __end, int& __member,
1231 int __min, int __max, size_t __len,
1232 const ctype<_CharT>& __ctype,
1233 ios_base::iostate& __err) const;
1235 // Extract day or month name, or any unique array of string
1236 // literals in a const _CharT* array.
1238 _M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
1239 const _CharT** __names, size_t __indexlen,
1240 ios_base::iostate& __err) const;
1242 // Extract on a component-by-component basis, via __format argument.
1244 _M_extract_via_format(iter_type& __beg, iter_type& __end, ios_base& __io,
1245 ios_base::iostate& __err, tm* __tm,
1246 const _CharT* __format) const;
1249 template<typename _CharT, typename _InIter>
1250 locale::id time_get<_CharT, _InIter>::id;
1252 template<typename _CharT, typename _InIter>
1253 class time_get_byname : public time_get<_CharT, _InIter>
1257 typedef _CharT char_type;
1258 typedef _InIter iter_type;
1261 time_get_byname(const char*, size_t __refs = 0)
1262 : time_get<_CharT, _InIter>(__refs) { }
1266 ~time_get_byname() { }
1269 template<typename _CharT, typename _OutIter>
1270 class time_put : public locale::facet, public time_base
1274 typedef _CharT char_type;
1275 typedef _OutIter iter_type;
1277 static locale::id id;
1280 time_put(size_t __refs = 0)
1281 : locale::facet(__refs) { }
1284 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
1285 const _CharT* __beg, const _CharT* __end) const;
1288 put(iter_type __s, ios_base& __io, char_type __fill,
1289 const tm* __tm, char __format, char __mod = 0) const
1290 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
1298 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
1299 char __format, char __mod) const;
1302 template<typename _CharT, typename _OutIter>
1303 locale::id time_put<_CharT, _OutIter>::id;
1305 template<typename _CharT, typename _OutIter>
1306 class time_put_byname : public time_put<_CharT, _OutIter>
1310 typedef _CharT char_type;
1311 typedef _OutIter iter_type;
1314 time_put_byname(const char* /*__s*/, size_t __refs = 0)
1315 : time_put<_CharT, _OutIter>(__refs)
1320 ~time_put_byname() { }
1327 enum part { none, space, symbol, sign, value };
1328 struct pattern { char field[4]; };
1330 static const pattern _S_default_pattern;
1332 // Construct and return valid pattern consisting of some combination of:
1333 // space none symbol sign value
1335 _S_construct_pattern(char __precedes, char __space, char __posn);
1338 template<typename _CharT, bool _Intl>
1339 class moneypunct : public locale::facet, public money_base
1343 typedef _CharT char_type;
1344 typedef basic_string<_CharT> string_type;
1346 static const bool intl = _Intl;
1347 static locale::id id;
1350 char_type _M_decimal_point;
1351 char_type _M_thousands_sep;
1353 string_type _M_curr_symbol;
1354 string_type _M_positive_sign;
1355 string_type _M_negative_sign;
1357 pattern _M_pos_format;
1358 pattern _M_neg_format;
1362 moneypunct(size_t __refs = 0) : locale::facet(__refs)
1363 { _M_initialize_moneypunct(); }
1366 moneypunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs)
1367 { _M_initialize_moneypunct(__cloc); }
1370 decimal_point() const
1371 { return this->do_decimal_point(); }
1374 thousands_sep() const
1375 { return this->do_thousands_sep(); }
1379 { return this->do_grouping(); }
1383 { return this->do_curr_symbol(); }
1386 positive_sign() const
1387 { return this->do_positive_sign(); }
1390 negative_sign() const
1391 { return this->do_negative_sign(); }
1395 { return this->do_frac_digits(); }
1399 { return this->do_pos_format(); }
1403 { return this->do_neg_format(); }
1410 do_decimal_point() const
1411 { return _M_decimal_point; }
1414 do_thousands_sep() const
1415 { return _M_thousands_sep; }
1419 { return _M_grouping; }
1422 do_curr_symbol() const
1423 { return _M_curr_symbol; }
1426 do_positive_sign() const
1427 { return _M_positive_sign; }
1430 do_negative_sign() const
1431 { return _M_negative_sign; }
1434 do_frac_digits() const
1435 { return _M_frac_digits; }
1438 do_pos_format() const
1439 { return _M_pos_format; }
1442 do_neg_format() const
1443 { return _M_neg_format; }
1445 // For use at construction time only.
1447 _M_initialize_moneypunct(__c_locale __cloc = NULL);
1450 template<typename _CharT, bool _Intl>
1451 locale::id moneypunct<_CharT, _Intl>::id;
1453 template<typename _CharT, bool _Intl>
1454 const bool moneypunct<_CharT, _Intl>::intl;
1456 // NB: Cannot be made generic.
1457 template<typename _CharT, bool _Intl>
1459 moneypunct<_CharT, _Intl>::_M_initialize_moneypunct(__c_locale)
1464 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale __cloc);
1468 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale __cloc);
1470 #ifdef _GLIBCPP_USE_WCHAR_T
1473 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale __cloc);
1477 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale __cloc);
1480 template<typename _CharT, bool _Intl>
1481 class moneypunct_byname : public moneypunct<_CharT, _Intl>
1483 __c_locale _M_c_locale_moneypunct;
1486 typedef _CharT char_type;
1487 typedef basic_string<_CharT> string_type;
1489 static const bool intl = _Intl;
1492 moneypunct_byname(const char* __s, size_t __refs = 0)
1493 : moneypunct<_CharT, _Intl>(__refs)
1495 _S_create_c_locale(_M_c_locale_moneypunct, __s);
1496 _M_initialize_moneypunct(_M_c_locale_moneypunct);
1501 ~moneypunct_byname()
1502 { _S_destroy_c_locale(_M_c_locale_moneypunct); }
1505 template<typename _CharT, bool _Intl>
1506 const bool moneypunct_byname<_CharT, _Intl>::intl;
1508 template<typename _CharT, typename _InIter>
1509 class money_get : public locale::facet
1513 typedef _CharT char_type;
1514 typedef _InIter iter_type;
1515 typedef basic_string<_CharT> string_type;
1517 static locale::id id;
1520 money_get(size_t __refs = 0) : locale::facet(__refs) { }
1523 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1524 ios_base::iostate& __err, long double& __units) const
1525 { return this->do_get(__s, __end, __intl, __io, __err, __units); }
1528 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1529 ios_base::iostate& __err, string_type& __digits) const
1530 { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
1537 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1538 ios_base::iostate& __err, long double& __units) const;
1541 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
1542 ios_base::iostate& __err, string_type& __digits) const;
1545 template<typename _CharT, typename _InIter>
1546 locale::id money_get<_CharT, _InIter>::id;
1548 template<typename _CharT, typename _OutIter>
1549 class money_put : public locale::facet
1552 typedef _CharT char_type;
1553 typedef _OutIter iter_type;
1554 typedef basic_string<_CharT> string_type;
1556 static locale::id id;
1559 money_put(size_t __refs = 0) : locale::facet(__refs) { }
1562 put(iter_type __s, bool __intl, ios_base& __io,
1563 char_type __fill, long double __units) const
1564 { return this->do_put(__s, __intl, __io, __fill, __units); }
1567 put(iter_type __s, bool __intl, ios_base& __io,
1568 char_type __fill, const string_type& __digits) const
1569 { return this->do_put(__s, __intl, __io, __fill, __digits); }
1576 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1577 long double __units) const;
1580 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1581 const string_type& __digits) const;
1584 template<typename _CharT, typename _OutIter>
1585 locale::id money_put<_CharT, _OutIter>::id;
1588 struct messages_base
1590 typedef int catalog;
1593 template<typename _CharT>
1594 class messages : public locale::facet, public messages_base
1598 typedef _CharT char_type;
1599 typedef basic_string<_CharT> string_type;
1602 // Underlying "C" library locale information saved from
1603 // initialization, needed by messages_byname as well.
1604 __c_locale _M_c_locale_messages;
1606 // Only needed if glibc < 2.3
1607 const char* _M_name_messages;
1611 static locale::id id;
1614 messages(size_t __refs = 0)
1615 : locale::facet(__refs), _M_name_messages("C")
1616 { _M_c_locale_messages = _S_clone_c_locale(_S_c_locale); }
1620 messages(__c_locale __cloc, const char* __name, size_t __refs = 0)
1621 : locale::facet(__refs)
1623 _M_name_messages = __name;
1624 _M_c_locale_messages = _S_clone_c_locale(__cloc);
1628 open(const basic_string<char>& __s, const locale& __loc) const
1629 { return this->do_open(__s, __loc); }
1631 // Non-standard and unorthodox, yet effective.
1633 open(const basic_string<char>&, const locale&, const char*) const;
1636 get(catalog __c, int __set, int __msgid, const string_type& __s) const
1637 { return this->do_get(__c, __set, __msgid, __s); }
1640 close(catalog __c) const
1641 { return this->do_close(__c); }
1646 { _S_destroy_c_locale(_M_c_locale_messages); }
1649 do_open(const basic_string<char>&, const locale&) const;
1652 do_get(catalog, int, int, const string_type& __dfault) const;
1655 do_close(catalog) const;
1657 // Returns a locale and codeset-converted string, given a char* message.
1659 _M_convert_to_char(const string_type& __msg) const
1662 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
1665 // Returns a locale and codeset-converted string, given a char* message.
1667 _M_convert_from_char(char* __msg) const
1669 // Length of message string without terminating null.
1670 size_t __len = char_traits<char>::length(__msg) - 1;
1672 // "everybody can easily convert the string using
1673 // mbsrtowcs/wcsrtombs or with iconv()"
1675 // Convert char* to _CharT in locale used to open catalog.
1676 // XXX need additional template parameter on messages class for this..
1677 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
1678 typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;
1680 __codecvt_type::state_type __state;
1681 // XXX may need to initialize state.
1682 //initialize_state(__state._M_init());
1685 // XXX what size for this string?
1686 _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
1687 const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
1688 __cvt.out(__state, __msg, __msg + __len, __from_next,
1689 __to, __to + __len + 1, __to_next);
1690 return string_type(__to);
1693 typedef ctype<_CharT> __ctype_type;
1694 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
1695 const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
1696 // XXX Again, proper length of converted string an issue here.
1697 // For now, assume the converted length is not larger.
1698 _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
1699 __cvt.widen(__msg, __msg + __len, __dest);
1700 return basic_string<_CharT>(__dest);
1702 return string_type();
1706 template<typename _CharT>
1707 locale::id messages<_CharT>::id;
1709 // Specializations for required instantiations.
1712 messages<char>::do_get(catalog, int, int, const string&) const;
1714 // Include host and configuration specific messages virtual functions.
1715 #include <bits/messages_members.h>
1717 template<typename _CharT>
1718 class messages_byname : public messages<_CharT>
1721 typedef _CharT char_type;
1722 typedef basic_string<_CharT> string_type;
1725 messages_byname(const char* __s, size_t __refs = 0)
1726 : messages<_CharT>(__refs)
1728 _M_name_messages = __s;
1729 _S_destroy_c_locale(_M_c_locale_messages);
1730 _S_create_c_locale(_M_c_locale_messages, __s);
1740 // Subclause convenience interfaces, inlines.
1741 // NB: These are inline because, when used in a loop, some compilers
1742 // can hoist the body out of the loop; then it's just as fast as the
1743 // C is*() function.
1744 template<typename _CharT>
1746 isspace(_CharT __c, const locale& __loc)
1747 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
1749 template<typename _CharT>
1751 isprint(_CharT __c, const locale& __loc)
1752 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
1754 template<typename _CharT>
1756 iscntrl(_CharT __c, const locale& __loc)
1757 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
1759 template<typename _CharT>
1761 isupper(_CharT __c, const locale& __loc)
1762 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
1764 template<typename _CharT>
1765 inline bool islower(_CharT __c, const locale& __loc)
1766 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
1768 template<typename _CharT>
1770 isalpha(_CharT __c, const locale& __loc)
1771 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
1773 template<typename _CharT>
1775 isdigit(_CharT __c, const locale& __loc)
1776 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
1778 template<typename _CharT>
1780 ispunct(_CharT __c, const locale& __loc)
1781 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
1783 template<typename _CharT>
1785 isxdigit(_CharT __c, const locale& __loc)
1786 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
1788 template<typename _CharT>
1790 isalnum(_CharT __c, const locale& __loc)
1791 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
1793 template<typename _CharT>
1795 isgraph(_CharT __c, const locale& __loc)
1796 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
1798 template<typename _CharT>
1800 toupper(_CharT __c, const locale& __loc)
1801 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
1803 template<typename _CharT>
1805 tolower(_CharT __c, const locale& __loc)
1806 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }