1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997-2000 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 // Warning: this file is not meant for user inclusion. Use <locale>.
36 #ifndef _CPP_BITS_LOCFACETS_H
37 #define _CPP_BITS_LOCFACETS_H 1
39 #include <bits/std_ctime.h> // For struct tm
40 #include <typeinfo> // For bad_cast, which shouldn't be here.
41 #include <bits/std_ios.h> // For ios_base
42 #ifdef _GLIBCPP_USE_WCHAR_T
43 #include <bits/std_cwctype.h> // For wctype_t
44 #endif /* _GLIBCPP_USE_WCHAR_T */
48 // XXX This function is to be specialized for the "required" facets to
49 // be constructed lazily. The specializations must be declared after
50 // the definitions of the facets themselves; but they shouldn't be
51 // inline. Corresponding new's in locale::classic() should then be
52 // eliminated. Note that ctype<> should not get this treatment;
53 // see the use_facet<> specializations below.
55 struct _Bad_use_facet : public bad_cast
57 _Bad_use_facet() throw() {}
59 _Bad_use_facet(_Bad_use_facet const& __b) throw()
63 operator=(_Bad_use_facet const& __b) throw()
65 static_cast<bad_cast*>(this)->operator=(__b);
73 ~_Bad_use_facet() throw();
76 template<typename _Facet>
78 _Use_facet_failure_handler(const locale&)
79 { throw _Bad_use_facet(); }
81 // 22.2.1 The ctype category
82 // Include host-specific ctype enums for ctype_base.
83 #include <bits/ctype_base.h>
85 // 22.2.1.1 Template class ctype
86 // _Ctype_nois is the common base for ctype<char>. It lacks "do_is"
87 // and related virtuals. These are filled in by _Ctype, below.
88 template<typename _CharT>
89 class _Ctype_nois : public locale::facet, public ctype_base
93 typedef _CharT char_type;
96 toupper(char_type __c) const
97 { return this->do_toupper(__c); }
100 toupper(char_type *__low, const char_type* __high) const
101 { return this->do_toupper(__low, __high); }
104 tolower(char_type __c) const
105 { return this->do_tolower(__c); }
108 tolower(char_type* __low, const char_type* __high) const
109 { return this->do_tolower(__low, __high); }
112 widen(char __c) const
113 { return this->do_widen(__c); }
116 widen(const char* __low, const char* __high, char_type* __to) const
117 { return this->do_widen(__low, __high, __to); }
120 narrow(char_type __c, char __dfault) const
121 { return this->do_narrow(__c, __dfault); }
124 narrow(const char_type* __low, const char_type* __high,
125 char __dfault, char *__to) const
126 { return this->do_narrow(__low, __high, __dfault, __to); }
130 _Ctype_nois(size_t __refs = 0): locale::facet(__refs) { }
136 do_toupper(char_type) const = 0;
138 virtual const char_type*
139 do_toupper(char_type* __low, const char_type* __high) const = 0;
142 do_tolower(char_type) const = 0;
144 virtual const char_type*
145 do_tolower(char_type* __low, const char_type* __high) const = 0;
148 do_widen(char) const = 0;
151 do_widen(const char* __low, const char* __high,
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* __low, const char_type* __high,
159 char __dfault, char* __dest) const = 0;
163 template<typename _CharT>
164 class _Ctype : public _Ctype_nois<_CharT>
168 typedef _CharT char_type;
169 typedef typename _Ctype_nois<_CharT>::mask mask;
172 is(mask __m, char_type __c) const
173 { return this->do_is(__m, __c); }
176 is(const char_type *__lo, const char_type *__hi, mask *__vec) const
177 { return this->do_is(__lo, __hi, __vec); }
180 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
181 { return this->do_scan_is(__m, __lo, __hi); }
184 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
185 { return this->do_scan_not(__m, __lo, __hi); }
189 _Ctype(size_t __refs = 0) : _Ctype_nois<_CharT>(__refs) { }
195 do_is(mask __m, char_type __c) const = 0;
197 virtual const char_type*
198 do_is(const char_type* __lo, const char_type* __hi,
199 mask* __vec) const = 0;
201 virtual const char_type*
202 do_scan_is(mask __m, const char_type* __lo,
203 const char_type* __hi) const = 0;
205 virtual const char_type*
206 do_scan_not(mask __m, const char_type* __lo,
207 const char_type* __hi) const = 0;
210 template<typename _CharT>
211 class ctype : public _Ctype<_CharT>
215 typedef _CharT char_type;
216 typedef typename ctype::mask mask;
219 ctype(size_t __refs = 0) : _Ctype<_CharT>(__refs) { }
221 static locale::id id;
228 do_is(mask, char_type) const
230 // XXX Need definitions for these abstract mf's.
234 virtual const char_type*
235 do_is(const char_type* __lo, const char_type*, mask*) const
237 // XXX Need definitions for these abstract mf's.
241 virtual const char_type*
242 do_scan_is(mask, const char_type* __lo, const char_type*) const
244 // XXX Need definitions for these abstract mf's.
248 virtual const char_type*
249 do_scan_not(mask, const char_type* __lo, const char_type*) const
251 // XXX Need definitions for these abstract mf's.
256 do_toupper(char_type __c) const
258 // XXX Need definitions for these abstract mf's.
262 virtual const char_type*
263 do_toupper(char_type* __lo, const char_type*) const
265 // XXX Need definitions for these abstract mf's.
270 do_tolower(char_type __c) const
272 // XXX Need definitions for these abstract mf's.
276 virtual const char_type*
277 do_tolower(char_type* __lo, const char_type*) const
279 // XXX Need definitions for these abstract mf's.
284 do_widen(char __c) const
286 // XXX Need definitions for these abstract mf's.
291 do_widen(const char* __lo, const char*, char_type*) const
293 // XXX Need definitions for these abstract mf's.
298 do_narrow(char_type, char __c) const
300 // XXX Need definitions for these abstract mf's.
304 virtual const char_type*
305 do_narrow(const char_type* __lo, const char_type*, char, char*) const
307 // XXX Need definitions for these abstract mf's.
313 // 22.2.1.3 ctype specializations
314 // NB: Can use _Ctype_nois to actually implement the "is"
315 // functionality in the non-virtual (thus inline-able) member
318 class ctype<char> : public _Ctype_nois<char>
322 typedef char char_type;
323 typedef ctype::mask mask;
328 __to_type const& _M_toupper;
329 __to_type const& _M_tolower;
330 const mask* const& _M_ctable;
331 const mask* _M_table;
334 static locale::id id;
335 static const size_t table_size = 1 + static_cast<unsigned char>(-1);
338 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
341 is(mask __m, char __c) const throw();
344 is(const char* __low, const char* __high, mask* __vec) const throw();
347 scan_is(mask __m, const char* __low, const char* __high) const throw();
350 scan_not(mask __m, const char* __low, const char* __high) const throw();
358 table() const throw()
363 classic_table() throw()
364 { return _M_ctable; }
367 do_toupper(char_type) const;
369 virtual const char_type*
370 do_toupper(char_type* __low, const char_type* __high) const;
373 do_tolower(char_type) const;
375 virtual const char_type*
376 do_tolower(char_type* __low, const char_type* __high) const;
379 do_widen(char) const;
382 do_widen(const char* __low, const char* __high,
383 char_type* __dest) const;
386 do_narrow(char_type, char __dfault) const;
388 virtual const char_type*
389 do_narrow(const char_type* __low, const char_type* __high,
390 char __dfault, char* __dest) const;
395 use_facet<ctype<char> >(const locale& __loc);
397 #ifdef _GLIBCPP_USE_WCHAR_T
398 // ctype<wchar_t> specialization
400 class ctype<wchar_t> : public _Ctype<wchar_t>
404 typedef wchar_t char_type;
405 typedef ctype::mask mask;
406 typedef wctype_t __wmask_type;
409 static locale::id id;
412 ctype(size_t __refs = 0);
416 _M_convert_to_wmask(const mask __m) const
422 __ret = wctype("space");
425 __ret = wctype("print");
428 __ret = wctype("cntrl");
431 __ret = wctype("upper");
434 __ret = wctype("lower");
437 __ret = wctype("alpha");
440 __ret = wctype("digit");
443 __ret = wctype("punct");
446 __ret = wctype("xdigit");
449 __ret = wctype("alnum");
452 __ret = wctype("graph");
464 do_is(mask __m, char_type __c) const;
466 virtual const char_type*
467 do_is(const char_type* __lo, const char_type* __hi,
470 virtual const char_type*
471 do_scan_is(mask __m, const char_type* __lo,
472 const char_type* __hi) const;
474 virtual const char_type*
475 do_scan_not(mask __m, const char_type* __lo,
476 const char_type* __hi) const;
479 do_toupper(char_type) const;
481 virtual const char_type*
482 do_toupper(char_type* __low, const char_type* __high) const;
485 do_tolower(char_type) const;
487 virtual const char_type*
488 do_tolower(char_type* __low, const char_type* __high) const;
491 do_widen(char) const;
494 do_widen(const char* __low, const char* __high,
495 char_type* __dest) const;
498 do_narrow(char_type, char __dfault) const;
500 virtual const char_type*
501 do_narrow(const char_type* __low, const char_type* __high,
502 char __dfault, char* __dest) const;
507 const ctype<wchar_t>&
508 use_facet<ctype<wchar_t> >(const locale& __loc);
509 #endif //_GLIBCPP_USE_WCHAR_T
511 // Include host-specific ctype inlines.
512 #include <bits/ctype_inline.h>
514 // 22.2.1.2 Template class ctype_byname
515 template<typename _CharT>
516 class ctype_byname : public ctype<_CharT>
519 typedef _CharT char_type;
522 ctype_byname(const char*, size_t __refs = 0);
529 // 22.2.1.4 Class ctype_byname specializations
531 ctype_byname<char>::ctype_byname(const char*, size_t refs);
532 #ifdef _GLIBCPP_USE_WCHAR_T
534 ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs);
538 template<typename _CharT, typename _InIter>
539 class _Numeric_get; // forward
541 // _Format_cache holds the information extracted from the numpunct<>
542 // and moneypunct<> facets in a form optimized for parsing and
543 // formatting. It is stored via a void* pointer in the pword()
544 // array of an iosbase object passed to the _get and _put facets.
545 // NB: contains no user-serviceable parts.
546 template<typename _CharT>
551 typedef _CharT char_type;
552 typedef char_traits<_CharT> traits_type;
553 typedef basic_string<_CharT> string_type;
554 typedef typename string_type::size_type size_type;
556 // Forward decls and Friends:
558 template<typename _Char, typename _InIter>
559 friend class _Numeric_get;
560 friend class num_get<_CharT>;
561 friend class num_put<_CharT>;
562 friend class time_get<_CharT>;
563 friend class money_get<_CharT>;
564 friend class time_put<_CharT>;
565 friend class money_put<_CharT>;
569 // ios_base::pword() reserved cell
570 static int _S_pword_ix;
572 // True iff data members are consistent with the current locale,
573 // ie imbue sets this to false.
576 // A list of valid numeric literals: for the standard "C" locale,
577 // this would usually be: "-+xX0123456789abcdef0123456789ABCDEF"
578 static const char _S_literals[];
580 // NB: Code depends on the order of definitions of the names
581 // these are indices into _S_literals, above.
582 // This string is formatted for putting, not getting. (output, not input)
590 _S_digits_end = _S_digits + 16,
591 _S_udigits = _S_digits_end,
592 _S_udigits_end = _S_udigits + 16,
593 _S_ee = _S_digits + 14, // For scientific notation, 'E'
594 _S_Ee = _S_udigits + 14 // For scientific notation, 'e'
597 // The sign used to separate decimal values: for standard US
598 // locales, this would usually be: "."
599 // Abstracted from numpunct::decimal_point().
600 char_type _M_decimal_point;
602 // The sign used to separate groups of digits into smaller
603 // strings that the eye can parse with less difficulty: for
604 // standard US locales, this would usually be: ","
605 // Abstracted from numpunct::thousands_sep().
606 char_type _M_thousands_sep;
608 // However the US's "false" and "true" are translated.
609 // From numpunct::truename() and numpunct::falsename(), respectively.
610 string_type _M_truename;
611 string_type _M_falsename;
613 // If we are checking groupings. This should be equivalent to
614 // numpunct::groupings().size() != 0
615 bool _M_use_grouping;
617 // If we are using numpunct's groupings, this is the current
618 // grouping string in effect (from numpunct::grouping()).
623 ~_Format_cache() throw() { }
625 // Given a member of the ios heirarchy as an argument, extract
626 // out all the current formatting information into a
627 // _Format_cache object and return a pointer to it.
628 static _Format_cache<_CharT>*
629 _S_get(ios_base& __ios);
632 _M_populate(ios_base&);
635 _S_callback(ios_base::event __event, ios_base& __ios, int __ix) throw();
638 template<> _Format_cache<char>::_Format_cache();
639 #ifdef _GLIBCPP_USE_WCHAR_T
640 template<> _Format_cache<wchar_t>::_Format_cache();
643 // _Numeric_get is used by num_get, money_get, and time_get to help
644 // in parsing out numbers.
645 template<typename _CharT, typename _InIter>
650 typedef _CharT char_type;
651 typedef _InIter iter_type;
653 // Forward decls and Friends:
654 template<typename _Char, typename _InIterT>
655 friend class num_get;
656 template<typename _Char, typename _InIterT>
657 friend class time_get;
658 template<typename _Char, typename _InIterT>
659 friend class money_get;
660 template<typename _Char, typename _InIterT>
661 friend class num_put;
662 template<typename _Char, typename _InIterT>
663 friend class time_put;
664 template<typename _Char, typename _InIterT>
665 friend class money_put;
675 _M_get_digits(iter_type __in, iter_type __end) const;
678 template<typename _CharT, typename _InIter>
679 class num_get : public locale::facet
683 typedef _CharT char_type;
684 typedef _InIter iter_type;
685 typedef char_traits<_CharT> __traits_type;
687 static locale::id id;
690 num_get(size_t __refs = 0) : locale::facet(__refs) { }
693 get(iter_type __in, iter_type __end, ios_base& __io,
694 ios_base::iostate& __err, bool& __v) const
695 { return do_get(__in, __end, __io, __err, __v); }
697 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
699 get(iter_type __in, iter_type __end, ios_base& __io,
700 ios_base::iostate& __err, short& __v) const
701 { return do_get(__in, __end, __io, __err, __v); }
704 get(iter_type __in, iter_type __end, ios_base& __io,
705 ios_base::iostate& __err, int& __v) const
706 { return do_get(__in, __end, __io, __err, __v); }
710 get(iter_type __in, iter_type __end, ios_base& __io,
711 ios_base::iostate& __err, long& __v) const
712 { return do_get(__in, __end, __io, __err, __v); }
714 #ifdef _GLIBCPP_USE_LONG_LONG
716 get(iter_type __in, iter_type __end, ios_base& __io,
717 ios_base::iostate& __err, long long& __v) const
718 { return do_get(__in, __end, __io, __err, __v); }
722 get(iter_type __in, iter_type __end, ios_base& __io,
723 ios_base::iostate& __err, unsigned short& __v) const
724 { return do_get(__in, __end, __io, __err, __v); }
727 get(iter_type __in, iter_type __end, ios_base& __io,
728 ios_base::iostate& __err, unsigned int& __v) const
729 { return do_get(__in, __end, __io, __err, __v); }
732 get(iter_type __in, iter_type __end, ios_base& __io,
733 ios_base::iostate& __err, unsigned long& __v) const
734 { return do_get(__in, __end, __io, __err, __v); }
736 #ifdef _GLIBCPP_USE_LONG_LONG
738 get(iter_type __in, iter_type __end, ios_base& __io,
739 ios_base::iostate& __err, unsigned long long& __v) const
740 { return do_get(__in, __end, __io, __err, __v); }
744 get(iter_type __in, iter_type __end, ios_base& __io,
745 ios_base::iostate& __err, float& __v) const
746 { return do_get(__in, __end, __io, __err, __v); }
749 get(iter_type __in, iter_type __end, ios_base& __io,
750 ios_base::iostate& __err, double& __v) const
751 { return do_get(__in, __end, __io, __err, __v); }
754 get(iter_type __in, iter_type __end, ios_base& __io,
755 ios_base::iostate& __err, long double& __v) const
756 { return do_get(__in, __end, __io, __err, __v); }
759 get(iter_type __in, iter_type __end, ios_base& __io,
760 ios_base::iostate& __err, void*& __v) const
761 { return do_get(__in, __end, __io, __err, __v); }
764 virtual ~num_get() { }
766 // This consolidates the extraction, storage and
767 // error-processing parts of the do_get(...) overloaded member
769 // NB: This is specialized for char.
771 _M_extract(iter_type __beg, iter_type __end, ios_base& __io,
772 ios_base::iostate& __err, char* __xtrc,
773 int& __base, bool __fp = true) const;
776 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
778 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
780 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, short&) const;
782 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, int&) const;
785 do_get (iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
786 #ifdef _GLIBCPP_USE_LONG_LONG
788 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
792 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
793 unsigned short&) const;
795 do_get(iter_type, iter_type, ios_base&,
796 ios_base::iostate& __err, unsigned int&) const;
798 do_get(iter_type, iter_type, ios_base&,
799 ios_base::iostate& __err, unsigned long&) const;
800 #ifdef _GLIBCPP_USE_LONG_LONG
802 do_get(iter_type, iter_type, ios_base&,
803 ios_base::iostate& __err, unsigned long long&) const;
806 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
810 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
814 do_get(iter_type, iter_type, ios_base&,
815 ios_base::iostate& __err, long double&) const;
818 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
822 // Declare specialized extraction member function.
825 num_get<char, istreambuf_iterator<char> >::
826 _M_extract(istreambuf_iterator<char> __beg,
827 istreambuf_iterator<char> __end, ios_base& __io,
828 ios_base::iostate& __err, char* __xtrc,
829 int& __base, bool __fp) const;
831 // _Numeric_put is used by num_put, money_put, and time_put
832 // to help in formatting out numbers.
833 template<typename _CharT, typename _OutIter>
837 typedef _CharT char_type;
838 typedef _OutIter iter_type;
847 template<typename _CharT, typename _OutIter>
848 class num_put : public locale::facet
852 typedef _CharT char_type;
853 typedef _OutIter iter_type;
855 static locale::id id;
858 num_put(size_t __refs = 0) : locale::facet(__refs) { }
861 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
862 { return do_put(__s, __f, __fill, __v); }
865 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
866 { return do_put(__s, __f, __fill, __v); }
869 put(iter_type __s, ios_base& __f, char_type __fill,
870 unsigned long __v) const
871 { return do_put(__s, __f, __fill, __v); }
873 #ifdef _GLIBCPP_USE_LONG_LONG
875 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
876 { return do_put(__s, __f, __fill, __v); }
879 put(iter_type __s, ios_base& __f, char_type __fill,
880 unsigned long long __v) const
881 { return do_put(__s, __f, __fill, __v); }
885 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
886 { return do_put(__s, __f, __fill, __v); }
889 put(iter_type __s, ios_base& __f, char_type __fill,
890 long double __v) const
891 { return do_put(__s, __f, __fill, __v); }
894 put(iter_type __s, ios_base& __f, char_type __fill,
895 const void* __v) const
896 { return do_put(__s, __f, __fill, __v); }
903 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
906 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
908 #ifdef _GLIBCPP_USE_LONG_LONG
910 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
914 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
916 #ifdef _GLIBCPP_USE_LONG_LONG
918 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
922 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
925 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
928 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
931 template<typename _CharT>
932 class _Punct : public locale::facet
936 typedef _CharT char_type;
937 typedef basic_string<_CharT> string_type;
940 decimal_point() const
941 { return do_decimal_point(); }
944 thousands_sep() const
945 { return do_thousands_sep(); }
949 { return do_grouping(); }
953 _Punct(size_t __refs = 0) : locale::facet(__refs) { }
959 do_decimal_point() const
960 { return _M_decimal_point; }
963 do_thousands_sep() const
964 { return _M_thousands_sep; }
968 { return _M_grouping; }
971 char_type _M_decimal_point;
972 char_type _M_thousands_sep;
976 // for use at construction time only:
978 _M_init(char_type __d, char_type __t, const string& __g)
980 _M_decimal_point = __d;
981 _M_thousands_sep = __t;
987 template<typename _CharT>
988 class _Numpunct : public _Punct<_CharT>
992 typedef _CharT char_type;
993 typedef basic_string<_CharT> string_type;
997 { return do_truename(); }
1001 { return do_falsename(); }
1005 _Numpunct(size_t __refs = 0) : _Punct<_CharT> (__refs) { }
1012 { return _M_truename; }
1015 do_falsename() const
1016 { return _M_falsename; }
1019 string_type _M_truename;
1020 string_type _M_falsename;
1023 // For use only during construction
1025 _M_boolnames_init(const string_type& __t, const string_type& __f)
1033 template<typename _CharT>
1034 class numpunct : public _Numpunct<_CharT>
1037 typedef _CharT char_type;
1038 typedef basic_string<_CharT> string_type;
1040 static locale::id id;
1043 numpunct(size_t __refs = 0) : _Numpunct<_CharT>(__refs) { }
1051 numpunct<char>::numpunct(size_t __refs): _Numpunct<char>(__refs)
1053 _M_init('.', ',', "");
1054 _M_boolnames_init("true", "false");
1057 #ifdef _GLIBCPP_USE_WCHAR_T
1059 numpunct<wchar_t>::numpunct(size_t __refs): _Numpunct<wchar_t>(__refs)
1061 _M_init(L'.', L',', "");
1062 _M_boolnames_init(L"true", L"false");
1066 template<typename _CharT>
1067 class numpunct_byname : public numpunct<_CharT>
1070 typedef _CharT char_type;
1071 typedef basic_string<_CharT> string_type;
1074 numpunct_byname(const char*, size_t __refs = 0);
1078 ~numpunct_byname() { }
1082 numpunct_byname<char>::numpunct_byname(const char*, size_t __refs);
1083 #ifdef _GLIBCPP_USE_WCHAR_T
1085 numpunct_byname<wchar_t>::numpunct_byname(const char*, size_t __refs);
1088 template<typename _CharT>
1089 class _Collate : public locale::facet
1093 typedef _CharT char_type;
1094 typedef basic_string<_CharT> string_type;
1097 compare(const _CharT* __lo1, const _CharT* __hi1,
1098 const _CharT* __lo2, const _CharT* __hi2) const
1099 { return do_compare(__lo1, __hi1, __lo2, __hi2); }
1102 transform(const _CharT* __lo, const _CharT* __hi) const
1103 { return do_transform(__lo, __hi); }
1106 hash(const _CharT* __lo, const _CharT* __hi) const
1107 { return do_hash(__lo, __hi); }
1111 _Collate(size_t __refs = 0) : locale::facet(__refs) { }
1113 ~_Collate() { } // virtual
1116 do_compare(const _CharT* __lo1, const _CharT* __hi1,
1117 const _CharT* __lo2, const _CharT* __hi2) const = 0;
1120 do_transform(const _CharT* __lo, const _CharT* __hi) const = 0;
1123 do_hash(const _CharT* __lo, const _CharT* __hi) const = 0;
1126 template<typename _CharT>
1127 class collate : public _Collate<_CharT>
1131 typedef _CharT char_type;
1132 typedef basic_string<_CharT> string_type;
1135 collate(size_t __refs = 0) : _Collate<_CharT> (__refs) { }
1137 static locale::id id;
1145 class collate<char> : public _Collate<char>
1149 typedef char char_type;
1150 typedef basic_string<char> string_type;
1153 collate(size_t __refs = 0);
1155 static locale::id id;
1162 do_compare(const char* __lo1, const char* __hi1,
1163 const char* __lo2, const char* __hi2) const;
1166 do_transform(const char* __lo, const char* __hi) const;
1169 do_hash(const char* __lo, const char* __hi) const;
1172 #ifdef _GLIBCPP_USE_WCHAR_T
1174 class collate<wchar_t> : public _Collate<wchar_t>
1178 typedef wchar_t char_type;
1179 typedef basic_string<wchar_t> string_type;
1182 collate(size_t __refs = 0);
1184 static locale::id id;
1191 do_compare(const wchar_t* __lo1, const wchar_t* __hi1,
1192 const wchar_t* __lo2, const wchar_t* __hi2) const;
1195 do_transform(const wchar_t* __lo, const wchar_t* __hi) const;
1198 do_hash(const wchar_t* __lo, const wchar_t* __hi) const;
1202 template<typename _CharT>
1203 class collate_byname : public collate<_CharT>
1207 typedef _CharT char_type;
1208 typedef basic_string<_CharT> string_type;
1211 collate_byname(const char*, size_t __refs = 0);
1215 ~collate_byname() { }
1219 collate_byname<char>::collate_byname(const char*, size_t __refs);
1220 #ifdef _GLIBCPP_USE_WCHAR_T
1222 collate_byname<wchar_t>::collate_byname(const char*, size_t __refs);
1228 enum dateorder { no_order, dmy, mdy, ymd, ydm };
1231 template<typename _CharT, typename _InIter>
1232 class time_get : public locale::facet, public time_base
1236 typedef _CharT char_type;
1237 typedef _InIter iter_type;
1239 static locale::id id;
1242 time_get(size_t __refs = 0)
1243 : locale::facet (__refs), _M_daynames(0), _M_monthnames(0) { }
1247 { return do_date_order(); }
1250 get_time(iter_type __s, iter_type __end, ios_base& __f,
1251 ios_base::iostate& __err, tm* __t) const
1252 { return do_get_time(__s, __end, __f, __err, __t); }
1255 get_date(iter_type __s, iter_type __end, ios_base& __f,
1256 ios_base::iostate& __err, tm* __t) const
1257 { return do_get_date(__s, __end, __f, __err, __t); }
1260 get_weekday(iter_type __s, iter_type __end, ios_base& __f,
1261 ios_base::iostate& __err, tm* __t) const
1262 { return do_get_weekday(__s,__end,__f,__err,__t); }
1265 get_monthname(iter_type __s, iter_type __end, ios_base& __f,
1266 ios_base::iostate& __err, tm* __t) const
1267 { return do_get_monthname(__s,__end,__f,__err,__t); }
1270 get_year(iter_type __s, iter_type __end, ios_base& __f,
1271 ios_base::iostate& __err, tm* __t) const
1272 { return do_get_year(__s,__end,__f,__err,__t); }
1278 delete [] _M_monthnames;
1279 delete [] _M_daynames;
1283 do_date_order() const
1284 { return time_base::ymd; }
1287 do_get_time(iter_type __s, iter_type /*__end*/, ios_base&,
1288 ios_base::iostate& /*__err*/, tm* /*__t*/) const
1292 do_get_date(iter_type __s, iter_type /*__end*/, ios_base&,
1293 ios_base::iostate& /*__err*/, tm* /*__t*/) const
1297 do_get_weekday(iter_type __s, iter_type __end, ios_base&,
1298 ios_base::iostate& __err, tm* __t) const;
1301 do_get_monthname(iter_type __s, iter_type __end, ios_base&,
1302 ios_base::iostate& __err, tm* __t) const;
1305 do_get_year(iter_type __s, iter_type /*__end*/, ios_base&,
1306 ios_base::iostate& /*__err*/, tm* /*__t*/) const
1309 mutable basic_string<_CharT>* _M_daynames;
1310 mutable basic_string<_CharT>* _M_monthnames;
1313 template<typename _CharT, typename _InIter>
1314 class time_get_byname : public time_get<_CharT, _InIter>
1317 typedef _CharT char_type;
1318 typedef _InIter iter_type;
1321 time_get_byname(const char*, size_t __refs = 0)
1322 : time_get<_CharT, _InIter>(__refs) { }
1325 ~time_get_byname() { }
1328 template<typename _CharT, typename _OutIter>
1329 class time_put : public locale::facet, public time_base
1332 typedef _CharT char_type;
1333 typedef _OutIter iter_type;
1335 static locale::id id;
1338 time_put(size_t __refs = 0) : locale::facet (__refs) { }
1340 // NB: this is a nonvirtual, calls do_put in a loop.
1342 put(iter_type __s, ios_base& /*__f*/, char_type /*__fill*/,
1343 const tm* /*__tmb*/, const _CharT* /*__pattern*/,
1344 const _CharT* /*__pat_end*/) const
1348 put(iter_type __s, ios_base& __f, char_type __fill,
1349 const tm* __tmb, char __format, char __modifier = 0) const
1350 { return do_put(__s, __f, __fill, __tmb, __format, __modifier); }
1357 do_put(iter_type __s, ios_base&, char_type, const tm* /*__t*/,
1358 char /*__format*/, char /*__mod*/) const
1362 template<typename _CharT, typename _OutIter>
1363 class time_put_byname : public time_put<_CharT, _OutIter>
1366 typedef _CharT char_type;
1367 typedef _OutIter iter_type;
1370 time_put_byname(const char*, size_t __refs = 0)
1371 : time_put<_CharT, _OutIter> (__refs) { }
1375 ~time_put_byname() { }
1379 template<typename _CharT, typename _InIter>
1380 class money_get : public locale::facet
1383 typedef _CharT char_type;
1384 typedef _InIter iter_type;
1385 typedef basic_string<_CharT> string_type;
1387 static locale::id id;
1390 money_get(size_t __refs = 0) : locale::facet(__refs) { }
1393 get(iter_type __s, iter_type __end, bool __intl,
1394 ios_base& __f, ios_base::iostate& __err, long double& __units) const
1395 { return do_get(__s, __end, __intl, __f, __err, __units); }
1398 get(iter_type __s, iter_type __end, bool __intl, ios_base& __f,
1399 ios_base::iostate& __err, string_type& __digits) const
1400 { return do_get(__s, __end, __intl, __f, __err, __digits); }
1407 do_get(iter_type __s, iter_type /*__end*/, bool /*__intl*/,
1408 ios_base& /*__io*/, ios_base::iostate& /*__err*/,
1409 long double& /*__units*/) const
1413 do_get(iter_type __s, iter_type /*__end*/, bool /*__intl*/,
1414 ios_base& /*__io*/, ios_base::iostate& /*__err*/,
1415 string_type& /*__digits*/) const
1419 template<typename _CharT, typename _OutIter>
1420 class money_put : public locale::facet
1423 typedef _CharT char_type;
1424 typedef _OutIter iter_type;
1425 typedef basic_string<_CharT> string_type;
1427 static locale::id id;
1430 money_put(size_t __refs = 0) : locale::facet(__refs) { }
1433 put(iter_type __s, bool __intl, ios_base& __f,
1434 char_type __fill, long double __units) const
1435 { return do_put(__s, __intl, __f, __fill, __units); }
1438 put(iter_type __s, bool __intl, ios_base& __f,
1439 char_type __fill, const string_type& __digits) const
1440 { return do_put(__s, __intl, __f, __fill, __digits); }
1447 do_put(iter_type __s, bool, ios_base& /*__io*/, char_type /*__fill*/,
1448 long double /*__units*/) const
1452 do_put(iter_type __s, bool, ios_base& /*__io*/, char_type /*__fill*/,
1453 const string_type& /*__digits*/) const
1459 enum part { none, space, symbol, sign, value };
1460 struct pattern { char field[4]; };
1462 static const pattern _S_default_pattern;
1465 template<typename _CharT>
1466 class _Moneypunct : public _Punct<_CharT>, public money_base
1469 typedef _CharT char_type;
1470 typedef basic_string<_CharT> string_type;
1474 { return do_curr_symbol(); }
1477 positive_sign() const
1478 { return do_positive_sign(); }
1481 negative_sign() const
1482 { return do_negative_sign(); }
1486 { return do_frac_digits(); }
1490 { return do_pos_format(); }
1494 { return do_neg_format(); }
1498 _Moneypunct(size_t __refs = 0) : _Punct<_CharT> (__refs) { }
1504 do_curr_symbol() const
1505 { return basic_string<_CharT>(); }
1508 do_positive_sign() const
1509 { return basic_string<_CharT>(); }
1512 do_negative_sign() const
1513 { return basic_string<_CharT>(); }
1516 do_frac_digits() const
1520 do_pos_format() const
1521 { return money_base::_S_default_pattern; }
1524 do_neg_format() const
1525 { return money_base::_S_default_pattern; }
1528 template<typename _CharT, bool _Intl>
1529 class moneypunct : public _Moneypunct<_CharT>
1533 typedef _CharT char_type;
1534 typedef basic_string<_CharT> string_type;
1536 static const bool intl = _Intl;
1537 static locale::id id;
1540 moneypunct(size_t __refs = 0) : _Moneypunct<_CharT> (__refs) { }
1547 template<typename _CharT, bool _Intl>
1548 class moneypunct_byname : public moneypunct<_CharT,_Intl>
1551 typedef _CharT char_type;
1552 typedef basic_string<_CharT> string_type;
1553 static const bool intl = _Intl;
1556 moneypunct_byname(const char*, size_t __refs = 0);
1560 ~moneypunct_byname() { }
1564 moneypunct_byname<char, false>::
1565 moneypunct_byname(const char*, size_t __refs);
1567 moneypunct_byname<char, true>::
1568 moneypunct_byname(const char*, size_t __refs);
1569 #ifdef _GLIBCPP_USE_WCHAR_T
1571 moneypunct_byname<wchar_t,false>::
1572 moneypunct_byname(const char*, size_t __refs);
1574 moneypunct_byname<wchar_t,true>::
1575 moneypunct_byname (const char*, size_t __refs);
1578 struct messages_base
1580 typedef int catalog;
1583 template<typename _CharT>
1584 class _Messages : public locale::facet, public messages_base
1587 typedef _CharT char_type;
1588 typedef basic_string<_CharT> string_type;
1591 open(const basic_string<char>& __s, const locale& __loc) const
1592 { return do_open(__s, __loc); }
1595 get(catalog __c, int __set, int __msgid, const string_type& __s) const
1596 { return do_get(__c,__set,__msgid,__s); }
1599 close(catalog __c) const
1600 { return do_close(__c); }
1604 _Messages(size_t __refs = 0) : locale::facet(__refs) { }
1609 // NB: Probably these should be pure, and implemented only in
1610 // specializations of messages<>. But for now...
1612 do_open(const basic_string<char>&, const locale&) const
1616 do_get(catalog, int, int /*__msgid*/, const string_type& __dfault) const
1617 { return __dfault; }
1620 do_close (catalog) const { }
1623 template<typename _CharT>
1624 class messages : public _Messages<_CharT>
1627 typedef _CharT char_type;
1628 typedef basic_string<_CharT> string_type;
1629 static locale::id id;
1632 messages(size_t __refs = 0) : _Messages<_CharT> (__refs) { }
1638 template<typename _CharT>
1639 class messages_byname : public messages<_CharT>
1642 typedef _CharT char_type;
1643 typedef basic_string<_CharT> string_type;
1646 messages_byname(const char*, size_t __refs = 0);
1650 ~messages_byname() { }
1654 messages_byname<char>::messages_byname(const char*, size_t __refs);
1655 #ifdef _GLIBCPP_USE_WCHAR_T
1657 messages_byname<wchar_t>::messages_byname(const char*, size_t __refs);
1660 // Subclause convenience interfaces, inlines
1661 // NB: these are inline
1662 // because, when used in a loop, some compilers can hoist the body
1663 // out of the loop; then it's just as fast as the C is*() function.
1664 template<typename _CharT>
1666 isspace(_CharT __c, const locale& __loc)
1667 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
1669 template<typename _CharT>
1671 isprint(_CharT __c, const locale& __loc)
1672 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
1674 template<typename _CharT>
1676 iscntrl(_CharT __c, const locale& __loc)
1677 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
1679 template<typename _CharT>
1681 isupper(_CharT __c, const locale& __loc)
1682 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
1684 template<typename _CharT>
1685 inline bool islower(_CharT __c, const locale& __loc)
1686 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
1688 template<typename _CharT>
1690 isalpha(_CharT __c, const locale& __loc)
1691 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
1693 template<typename _CharT>
1695 isdigit(_CharT __c, const locale& __loc)
1696 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
1698 template<typename _CharT>
1700 ispunct(_CharT __c, const locale& __loc)
1701 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
1703 template<typename _CharT>
1705 isxdigit(_CharT __c, const locale& __loc)
1706 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
1708 template<typename _CharT>
1710 isalnum(_CharT __c, const locale& __loc)
1711 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
1713 template<typename _CharT>
1715 isgraph(_CharT __c, const locale& __loc)
1716 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
1718 template<typename _CharT>
1720 toupper(_CharT __c, const locale& __loc)
1721 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
1723 template<typename _CharT>
1725 tolower(_CharT __c, const locale& __loc)
1726 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
1730 #endif /* _CPP_BITS_LOCFACETS_H */