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
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_abstract_base is the common base for ctype<_CharT>.
87 template<typename _CharT>
88 class __ctype_abstract_base : public locale::facet, public ctype_base
92 typedef _CharT char_type;
95 is(mask __m, char_type __c) const
96 { return this->do_is(__m, __c); }
99 is(const char_type *__lo, const char_type *__hi, mask *__vec) const
100 { return this->do_is(__lo, __hi, __vec); }
103 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
104 { return this->do_scan_is(__m, __lo, __hi); }
107 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
108 { return this->do_scan_not(__m, __lo, __hi); }
111 toupper(char_type __c) const
112 { return this->do_toupper(__c); }
115 toupper(char_type *__low, const char_type* __high) const
116 { return this->do_toupper(__low, __high); }
119 tolower(char_type __c) const
120 { return this->do_tolower(__c); }
123 tolower(char_type* __low, const char_type* __high) const
124 { return this->do_tolower(__low, __high); }
127 widen(char __c) const
128 { return this->do_widen(__c); }
131 widen(const char* __low, const char* __high, char_type* __to) const
132 { return this->do_widen(__low, __high, __to); }
135 narrow(char_type __c, char __dfault) const
136 { return this->do_narrow(__c, __dfault); }
139 narrow(const char_type* __low, const char_type* __high,
140 char __dfault, char *__to) const
141 { return this->do_narrow(__low, __high, __dfault, __to); }
145 __ctype_abstract_base(size_t __refs = 0): locale::facet(__refs) { }
148 ~__ctype_abstract_base() { }
151 do_is(mask __m, char_type __c) const = 0;
153 virtual const char_type*
154 do_is(const char_type* __lo, const char_type* __hi,
155 mask* __vec) const = 0;
157 virtual const char_type*
158 do_scan_is(mask __m, const char_type* __lo,
159 const char_type* __hi) const = 0;
161 virtual const char_type*
162 do_scan_not(mask __m, const char_type* __lo,
163 const char_type* __hi) const = 0;
166 do_toupper(char_type) const = 0;
168 virtual const char_type*
169 do_toupper(char_type* __low, const char_type* __high) const = 0;
172 do_tolower(char_type) const = 0;
174 virtual const char_type*
175 do_tolower(char_type* __low, const char_type* __high) const = 0;
178 do_widen(char) const = 0;
181 do_widen(const char* __low, const char* __high,
182 char_type* __dest) const = 0;
185 do_narrow(char_type, char __dfault) const = 0;
187 virtual const char_type*
188 do_narrow(const char_type* __low, const char_type* __high,
189 char __dfault, char* __dest) const = 0;
192 // NB: Generic, mostly useless implementation.
193 template<typename _CharT>
194 class ctype : public __ctype_abstract_base<_CharT>
198 typedef _CharT char_type;
199 typedef typename ctype::mask mask;
202 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
204 static locale::id id;
211 // 22.2.1.3 ctype specializations
213 class ctype<char> : public __ctype_abstract_base<char>
217 typedef char char_type;
222 __to_type const& _M_toupper;
223 __to_type const& _M_tolower;
224 const mask* const& _M_ctable;
225 const mask* _M_table;
228 static locale::id id;
229 static const size_t table_size = 1 + static_cast<unsigned char>(-1);
232 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
235 is(mask __m, char __c) const throw();
238 is(const char* __low, const char* __high, mask* __vec) const throw();
241 scan_is(mask __m, const char* __low, const char* __high) const throw();
244 scan_not(mask __m, const char* __low, const char* __high) const throw();
251 table() const throw()
255 classic_table() throw()
256 { return _M_ctable; }
259 do_is(mask __m, char_type __c) const;
261 virtual const char_type*
262 do_is(const char_type* __lo, const char_type* __hi,
265 virtual const char_type*
266 do_scan_is(mask __m, const char_type* __lo,
267 const char_type* __hi) const;
269 virtual const char_type*
270 do_scan_not(mask __m, const char_type* __lo,
271 const char_type* __hi) const;
274 do_toupper(char_type) const;
276 virtual const char_type*
277 do_toupper(char_type* __low, const char_type* __high) const;
280 do_tolower(char_type) const;
282 virtual const char_type*
283 do_tolower(char_type* __low, const char_type* __high) const;
286 do_widen(char) const;
289 do_widen(const char* __low, const char* __high,
290 char_type* __dest) const;
293 do_narrow(char_type, char __dfault) const;
295 virtual const char_type*
296 do_narrow(const char_type* __low, const char_type* __high,
297 char __dfault, char* __dest) const;
302 use_facet<ctype<char> >(const locale& __loc);
304 #ifdef _GLIBCPP_USE_WCHAR_T
305 // ctype<wchar_t> specialization
307 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
311 typedef wchar_t char_type;
312 typedef wctype_t __wmask_type;
315 static locale::id id;
318 ctype(size_t __refs = 0);
322 _M_convert_to_wmask(const mask __m) const;
328 do_is(mask __m, char_type __c) const;
330 virtual const char_type*
331 do_is(const char_type* __lo, const char_type* __hi,
334 virtual const char_type*
335 do_scan_is(mask __m, const char_type* __lo,
336 const char_type* __hi) const;
338 virtual const char_type*
339 do_scan_not(mask __m, const char_type* __lo,
340 const char_type* __hi) const;
343 do_toupper(char_type) const;
345 virtual const char_type*
346 do_toupper(char_type* __low, const char_type* __high) const;
349 do_tolower(char_type) const;
351 virtual const char_type*
352 do_tolower(char_type* __low, const char_type* __high) const;
355 do_widen(char) const;
358 do_widen(const char* __low, const char* __high,
359 char_type* __dest) const;
362 do_narrow(char_type, char __dfault) const;
364 virtual const char_type*
365 do_narrow(const char_type* __low, const char_type* __high,
366 char __dfault, char* __dest) const;
371 const ctype<wchar_t>&
372 use_facet<ctype<wchar_t> >(const locale& __loc);
373 #endif //_GLIBCPP_USE_WCHAR_T
375 // Include host-specific ctype inlines.
376 #include <bits/ctype_inline.h>
378 // 22.2.1.2 Template class ctype_byname
379 template<typename _CharT>
380 class ctype_byname : public ctype<_CharT>
383 typedef _CharT char_type;
386 ctype_byname(const char*, size_t __refs = 0);
393 // 22.2.1.4 Class ctype_byname specialization
395 ctype_byname<char>::ctype_byname(const char*, size_t refs);
398 template<typename _CharT, typename _InIter>
399 class _Numeric_get; // forward
401 // _Format_cache holds the information extracted from the numpunct<>
402 // and moneypunct<> facets in a form optimized for parsing and
403 // formatting. It is stored via a void* pointer in the pword()
404 // array of an iosbase object passed to the _get and _put facets.
405 // NB: contains no user-serviceable parts.
406 template<typename _CharT>
411 typedef _CharT char_type;
412 typedef char_traits<_CharT> traits_type;
413 typedef basic_string<_CharT> string_type;
414 typedef typename string_type::size_type size_type;
416 // Forward decls and Friends:
418 template<typename _Char, typename _InIter>
419 friend class _Numeric_get;
420 friend class num_get<_CharT>;
421 friend class num_put<_CharT>;
422 friend class time_get<_CharT>;
423 friend class money_get<_CharT>;
424 friend class time_put<_CharT>;
425 friend class money_put<_CharT>;
429 // ios_base::pword() reserved cell
430 static int _S_pword_ix;
432 // True iff data members are consistent with the current locale,
433 // ie imbue sets this to false.
436 // A list of valid numeric literals: for the standard "C" locale,
437 // this would usually be: "-+xX0123456789abcdef0123456789ABCDEF"
438 static const char _S_literals[];
440 // NB: Code depends on the order of definitions of the names
441 // these are indices into _S_literals, above.
442 // This string is formatted for putting, not getting. (output, not input)
450 _S_digits_end = _S_digits + 16,
451 _S_udigits = _S_digits_end,
452 _S_udigits_end = _S_udigits + 16,
453 _S_ee = _S_digits + 14, // For scientific notation, 'E'
454 _S_Ee = _S_udigits + 14 // For scientific notation, 'e'
457 // The sign used to separate decimal values: for standard US
458 // locales, this would usually be: "."
459 // Abstracted from numpunct::decimal_point().
460 char_type _M_decimal_point;
462 // The sign used to separate groups of digits into smaller
463 // strings that the eye can parse with less difficulty: for
464 // standard US locales, this would usually be: ","
465 // Abstracted from numpunct::thousands_sep().
466 char_type _M_thousands_sep;
468 // However the US's "false" and "true" are translated.
469 // From numpunct::truename() and numpunct::falsename(), respectively.
470 string_type _M_truename;
471 string_type _M_falsename;
473 // If we are checking groupings. This should be equivalent to
474 // numpunct::groupings().size() != 0
475 bool _M_use_grouping;
477 // If we are using numpunct's groupings, this is the current
478 // grouping string in effect (from numpunct::grouping()).
483 ~_Format_cache() throw() { }
485 // Given a member of the ios heirarchy as an argument, extract
486 // out all the current formatting information into a
487 // _Format_cache object and return a pointer to it.
488 static _Format_cache<_CharT>*
489 _S_get(ios_base& __ios);
492 _M_populate(ios_base&);
495 _S_callback(ios_base::event __event, ios_base& __ios, int __ix) throw();
498 template<> _Format_cache<char>::_Format_cache();
499 #ifdef _GLIBCPP_USE_WCHAR_T
500 template<> _Format_cache<wchar_t>::_Format_cache();
503 // _Numeric_get is used by num_get, money_get, and time_get to help
504 // in parsing out numbers.
505 template<typename _CharT, typename _InIter>
510 typedef _CharT char_type;
511 typedef _InIter iter_type;
513 // Forward decls and Friends:
514 template<typename _Char, typename _InIterT>
515 friend class num_get;
516 template<typename _Char, typename _InIterT>
517 friend class time_get;
518 template<typename _Char, typename _InIterT>
519 friend class money_get;
520 template<typename _Char, typename _InIterT>
521 friend class num_put;
522 template<typename _Char, typename _InIterT>
523 friend class time_put;
524 template<typename _Char, typename _InIterT>
525 friend class money_put;
535 _M_get_digits(iter_type __in, iter_type __end) const;
538 template<typename _CharT, typename _InIter>
539 class num_get : public locale::facet
543 typedef _CharT char_type;
544 typedef _InIter iter_type;
545 typedef char_traits<_CharT> __traits_type;
547 static locale::id id;
550 num_get(size_t __refs = 0) : locale::facet(__refs) { }
553 get(iter_type __in, iter_type __end, ios_base& __io,
554 ios_base::iostate& __err, bool& __v) const
555 { return do_get(__in, __end, __io, __err, __v); }
557 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
559 get(iter_type __in, iter_type __end, ios_base& __io,
560 ios_base::iostate& __err, short& __v) const
561 { return do_get(__in, __end, __io, __err, __v); }
564 get(iter_type __in, iter_type __end, ios_base& __io,
565 ios_base::iostate& __err, int& __v) const
566 { return do_get(__in, __end, __io, __err, __v); }
570 get(iter_type __in, iter_type __end, ios_base& __io,
571 ios_base::iostate& __err, long& __v) const
572 { return do_get(__in, __end, __io, __err, __v); }
574 #ifdef _GLIBCPP_USE_LONG_LONG
576 get(iter_type __in, iter_type __end, ios_base& __io,
577 ios_base::iostate& __err, long long& __v) const
578 { return do_get(__in, __end, __io, __err, __v); }
582 get(iter_type __in, iter_type __end, ios_base& __io,
583 ios_base::iostate& __err, unsigned short& __v) const
584 { return do_get(__in, __end, __io, __err, __v); }
587 get(iter_type __in, iter_type __end, ios_base& __io,
588 ios_base::iostate& __err, unsigned int& __v) const
589 { return do_get(__in, __end, __io, __err, __v); }
592 get(iter_type __in, iter_type __end, ios_base& __io,
593 ios_base::iostate& __err, unsigned long& __v) const
594 { return do_get(__in, __end, __io, __err, __v); }
596 #ifdef _GLIBCPP_USE_LONG_LONG
598 get(iter_type __in, iter_type __end, ios_base& __io,
599 ios_base::iostate& __err, unsigned long long& __v) const
600 { return do_get(__in, __end, __io, __err, __v); }
604 get(iter_type __in, iter_type __end, ios_base& __io,
605 ios_base::iostate& __err, float& __v) const
606 { return do_get(__in, __end, __io, __err, __v); }
609 get(iter_type __in, iter_type __end, ios_base& __io,
610 ios_base::iostate& __err, double& __v) const
611 { return do_get(__in, __end, __io, __err, __v); }
614 get(iter_type __in, iter_type __end, ios_base& __io,
615 ios_base::iostate& __err, long double& __v) const
616 { return do_get(__in, __end, __io, __err, __v); }
619 get(iter_type __in, iter_type __end, ios_base& __io,
620 ios_base::iostate& __err, void*& __v) const
621 { return do_get(__in, __end, __io, __err, __v); }
624 virtual ~num_get() { }
626 // This consolidates the extraction, storage and
627 // error-processing parts of the do_get(...) overloaded member
629 // NB: This is specialized for char.
631 _M_extract(iter_type __beg, iter_type __end, ios_base& __io,
632 ios_base::iostate& __err, char* __xtrc,
633 int& __base, bool __fp = true) const;
636 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
638 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
640 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, short&) const;
642 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, int&) const;
645 do_get (iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
646 #ifdef _GLIBCPP_USE_LONG_LONG
648 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
652 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
653 unsigned short&) const;
655 do_get(iter_type, iter_type, ios_base&,
656 ios_base::iostate& __err, unsigned int&) const;
658 do_get(iter_type, iter_type, ios_base&,
659 ios_base::iostate& __err, unsigned long&) const;
660 #ifdef _GLIBCPP_USE_LONG_LONG
662 do_get(iter_type, iter_type, ios_base&,
663 ios_base::iostate& __err, unsigned long long&) const;
666 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
670 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
674 do_get(iter_type, iter_type, ios_base&,
675 ios_base::iostate& __err, long double&) const;
678 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
682 // Declare specialized extraction member function.
685 num_get<char, istreambuf_iterator<char> >::
686 _M_extract(istreambuf_iterator<char> __beg,
687 istreambuf_iterator<char> __end, ios_base& __io,
688 ios_base::iostate& __err, char* __xtrc,
689 int& __base, bool __fp) const;
691 // _Numeric_put is used by num_put, money_put, and time_put
692 // to help in formatting out numbers.
693 template<typename _CharT, typename _OutIter>
697 typedef _CharT char_type;
698 typedef _OutIter iter_type;
707 template<typename _CharT, typename _OutIter>
708 class num_put : public locale::facet
712 typedef _CharT char_type;
713 typedef _OutIter iter_type;
715 static locale::id id;
718 num_put(size_t __refs = 0) : locale::facet(__refs) { }
721 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
722 { return do_put(__s, __f, __fill, __v); }
725 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
726 { return do_put(__s, __f, __fill, __v); }
729 put(iter_type __s, ios_base& __f, char_type __fill,
730 unsigned long __v) const
731 { return do_put(__s, __f, __fill, __v); }
733 #ifdef _GLIBCPP_USE_LONG_LONG
735 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
736 { return do_put(__s, __f, __fill, __v); }
739 put(iter_type __s, ios_base& __f, char_type __fill,
740 unsigned long long __v) const
741 { return do_put(__s, __f, __fill, __v); }
745 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
746 { return do_put(__s, __f, __fill, __v); }
749 put(iter_type __s, ios_base& __f, char_type __fill,
750 long double __v) const
751 { return do_put(__s, __f, __fill, __v); }
754 put(iter_type __s, ios_base& __f, char_type __fill,
755 const void* __v) const
756 { return do_put(__s, __f, __fill, __v); }
763 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
766 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
768 #ifdef _GLIBCPP_USE_LONG_LONG
770 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
774 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
776 #ifdef _GLIBCPP_USE_LONG_LONG
778 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
782 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
785 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
788 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
791 template<typename _CharT>
792 class _Punct : public locale::facet
796 typedef _CharT char_type;
797 typedef basic_string<_CharT> string_type;
800 decimal_point() const
801 { return do_decimal_point(); }
804 thousands_sep() const
805 { return do_thousands_sep(); }
809 { return do_grouping(); }
813 _Punct(size_t __refs = 0) : locale::facet(__refs) { }
819 do_decimal_point() const
820 { return _M_decimal_point; }
823 do_thousands_sep() const
824 { return _M_thousands_sep; }
828 { return _M_grouping; }
831 char_type _M_decimal_point;
832 char_type _M_thousands_sep;
836 // for use at construction time only:
838 _M_init(char_type __d, char_type __t, const string& __g)
840 _M_decimal_point = __d;
841 _M_thousands_sep = __t;
847 template<typename _CharT>
848 class _Numpunct : public _Punct<_CharT>
852 typedef _CharT char_type;
853 typedef basic_string<_CharT> string_type;
857 { return do_truename(); }
861 { return do_falsename(); }
865 _Numpunct(size_t __refs = 0) : _Punct<_CharT> (__refs) { }
872 { return _M_truename; }
876 { return _M_falsename; }
879 string_type _M_truename;
880 string_type _M_falsename;
883 // For use only during construction
885 _M_boolnames_init(const string_type& __t, const string_type& __f)
893 template<typename _CharT>
894 class numpunct : public _Numpunct<_CharT>
897 typedef _CharT char_type;
898 typedef basic_string<_CharT> string_type;
900 static locale::id id;
903 numpunct(size_t __refs = 0) : _Numpunct<_CharT>(__refs) { }
911 numpunct<char>::numpunct(size_t __refs): _Numpunct<char>(__refs)
913 _M_init('.', ',', "");
914 _M_boolnames_init("true", "false");
917 #ifdef _GLIBCPP_USE_WCHAR_T
919 numpunct<wchar_t>::numpunct(size_t __refs): _Numpunct<wchar_t>(__refs)
921 _M_init(L'.', L',', "");
922 _M_boolnames_init(L"true", L"false");
926 template<typename _CharT>
927 class numpunct_byname : public numpunct<_CharT>
930 typedef _CharT char_type;
931 typedef basic_string<_CharT> string_type;
934 numpunct_byname(const char*, size_t __refs = 0);
938 ~numpunct_byname() { }
942 numpunct_byname<char>::numpunct_byname(const char*, size_t __refs);
943 #ifdef _GLIBCPP_USE_WCHAR_T
945 numpunct_byname<wchar_t>::numpunct_byname(const char*, size_t __refs);
948 template<typename _CharT>
949 class _Collate : public locale::facet
953 typedef _CharT char_type;
954 typedef basic_string<_CharT> string_type;
957 compare(const _CharT* __lo1, const _CharT* __hi1,
958 const _CharT* __lo2, const _CharT* __hi2) const
959 { return do_compare(__lo1, __hi1, __lo2, __hi2); }
962 transform(const _CharT* __lo, const _CharT* __hi) const
963 { return do_transform(__lo, __hi); }
966 hash(const _CharT* __lo, const _CharT* __hi) const
967 { return do_hash(__lo, __hi); }
971 _Collate(size_t __refs = 0) : locale::facet(__refs) { }
973 ~_Collate() { } // virtual
976 do_compare(const _CharT* __lo1, const _CharT* __hi1,
977 const _CharT* __lo2, const _CharT* __hi2) const = 0;
980 do_transform(const _CharT* __lo, const _CharT* __hi) const = 0;
983 do_hash(const _CharT* __lo, const _CharT* __hi) const = 0;
986 template<typename _CharT>
987 class collate : public _Collate<_CharT>
991 typedef _CharT char_type;
992 typedef basic_string<_CharT> string_type;
995 collate(size_t __refs = 0) : _Collate<_CharT> (__refs) { }
997 static locale::id id;
1005 class collate<char> : public _Collate<char>
1009 typedef char char_type;
1010 typedef basic_string<char> string_type;
1013 collate(size_t __refs = 0);
1015 static locale::id id;
1022 do_compare(const char* __lo1, const char* __hi1,
1023 const char* __lo2, const char* __hi2) const;
1026 do_transform(const char* __lo, const char* __hi) const;
1029 do_hash(const char* __lo, const char* __hi) const;
1032 #ifdef _GLIBCPP_USE_WCHAR_T
1034 class collate<wchar_t> : public _Collate<wchar_t>
1038 typedef wchar_t char_type;
1039 typedef basic_string<wchar_t> string_type;
1042 collate(size_t __refs = 0);
1044 static locale::id id;
1051 do_compare(const wchar_t* __lo1, const wchar_t* __hi1,
1052 const wchar_t* __lo2, const wchar_t* __hi2) const;
1055 do_transform(const wchar_t* __lo, const wchar_t* __hi) const;
1058 do_hash(const wchar_t* __lo, const wchar_t* __hi) const;
1062 template<typename _CharT>
1063 class collate_byname : public collate<_CharT>
1067 typedef _CharT char_type;
1068 typedef basic_string<_CharT> string_type;
1071 collate_byname(const char*, size_t __refs = 0);
1075 ~collate_byname() { }
1079 collate_byname<char>::collate_byname(const char*, size_t __refs);
1080 #ifdef _GLIBCPP_USE_WCHAR_T
1082 collate_byname<wchar_t>::collate_byname(const char*, size_t __refs);
1088 enum dateorder { no_order, dmy, mdy, ymd, ydm };
1091 template<typename _CharT, typename _InIter>
1092 class time_get : public locale::facet, public time_base
1096 typedef _CharT char_type;
1097 typedef _InIter iter_type;
1099 static locale::id id;
1102 time_get(size_t __refs = 0)
1103 : locale::facet (__refs), _M_daynames(0), _M_monthnames(0) { }
1107 { return do_date_order(); }
1110 get_time(iter_type __s, iter_type __end, ios_base& __f,
1111 ios_base::iostate& __err, tm* __t) const
1112 { return do_get_time(__s, __end, __f, __err, __t); }
1115 get_date(iter_type __s, iter_type __end, ios_base& __f,
1116 ios_base::iostate& __err, tm* __t) const
1117 { return do_get_date(__s, __end, __f, __err, __t); }
1120 get_weekday(iter_type __s, iter_type __end, ios_base& __f,
1121 ios_base::iostate& __err, tm* __t) const
1122 { return do_get_weekday(__s,__end,__f,__err,__t); }
1125 get_monthname(iter_type __s, iter_type __end, ios_base& __f,
1126 ios_base::iostate& __err, tm* __t) const
1127 { return do_get_monthname(__s,__end,__f,__err,__t); }
1130 get_year(iter_type __s, iter_type __end, ios_base& __f,
1131 ios_base::iostate& __err, tm* __t) const
1132 { return do_get_year(__s,__end,__f,__err,__t); }
1138 delete [] _M_monthnames;
1139 delete [] _M_daynames;
1143 do_date_order() const
1144 { return time_base::ymd; }
1147 do_get_time(iter_type __s, iter_type /*__end*/, ios_base&,
1148 ios_base::iostate& /*__err*/, tm* /*__t*/) const
1152 do_get_date(iter_type __s, iter_type /*__end*/, ios_base&,
1153 ios_base::iostate& /*__err*/, tm* /*__t*/) const
1157 do_get_weekday(iter_type __s, iter_type __end, ios_base&,
1158 ios_base::iostate& __err, tm* __t) const;
1161 do_get_monthname(iter_type __s, iter_type __end, ios_base&,
1162 ios_base::iostate& __err, tm* __t) const;
1165 do_get_year(iter_type __s, iter_type /*__end*/, ios_base&,
1166 ios_base::iostate& /*__err*/, tm* /*__t*/) const
1169 mutable basic_string<_CharT>* _M_daynames;
1170 mutable basic_string<_CharT>* _M_monthnames;
1173 template<typename _CharT, typename _InIter>
1174 class time_get_byname : public time_get<_CharT, _InIter>
1177 typedef _CharT char_type;
1178 typedef _InIter iter_type;
1181 time_get_byname(const char*, size_t __refs = 0)
1182 : time_get<_CharT, _InIter>(__refs) { }
1185 ~time_get_byname() { }
1188 template<typename _CharT, typename _OutIter>
1189 class time_put : public locale::facet, public time_base
1192 typedef _CharT char_type;
1193 typedef _OutIter iter_type;
1195 static locale::id id;
1198 time_put(size_t __refs = 0) : locale::facet (__refs) { }
1200 // NB: this is a nonvirtual, calls do_put in a loop.
1202 put(iter_type __s, ios_base& /*__f*/, char_type /*__fill*/,
1203 const tm* /*__tmb*/, const _CharT* /*__pattern*/,
1204 const _CharT* /*__pat_end*/) const
1208 put(iter_type __s, ios_base& __f, char_type __fill,
1209 const tm* __tmb, char __format, char __modifier = 0) const
1210 { return do_put(__s, __f, __fill, __tmb, __format, __modifier); }
1217 do_put(iter_type __s, ios_base&, char_type, const tm* /*__t*/,
1218 char /*__format*/, char /*__mod*/) const
1222 template<typename _CharT, typename _OutIter>
1223 class time_put_byname : public time_put<_CharT, _OutIter>
1226 typedef _CharT char_type;
1227 typedef _OutIter iter_type;
1230 time_put_byname(const char*, size_t __refs = 0)
1231 : time_put<_CharT, _OutIter> (__refs) { }
1235 ~time_put_byname() { }
1239 template<typename _CharT, typename _InIter>
1240 class money_get : public locale::facet
1243 typedef _CharT char_type;
1244 typedef _InIter iter_type;
1245 typedef basic_string<_CharT> string_type;
1247 static locale::id id;
1250 money_get(size_t __refs = 0) : locale::facet(__refs) { }
1253 get(iter_type __s, iter_type __end, bool __intl,
1254 ios_base& __f, ios_base::iostate& __err, long double& __units) const
1255 { return do_get(__s, __end, __intl, __f, __err, __units); }
1258 get(iter_type __s, iter_type __end, bool __intl, ios_base& __f,
1259 ios_base::iostate& __err, string_type& __digits) const
1260 { return do_get(__s, __end, __intl, __f, __err, __digits); }
1267 do_get(iter_type __s, iter_type /*__end*/, bool /*__intl*/,
1268 ios_base& /*__io*/, ios_base::iostate& /*__err*/,
1269 long double& /*__units*/) const
1273 do_get(iter_type __s, iter_type /*__end*/, bool /*__intl*/,
1274 ios_base& /*__io*/, ios_base::iostate& /*__err*/,
1275 string_type& /*__digits*/) const
1279 template<typename _CharT, typename _OutIter>
1280 class money_put : public locale::facet
1283 typedef _CharT char_type;
1284 typedef _OutIter iter_type;
1285 typedef basic_string<_CharT> string_type;
1287 static locale::id id;
1290 money_put(size_t __refs = 0) : locale::facet(__refs) { }
1293 put(iter_type __s, bool __intl, ios_base& __f,
1294 char_type __fill, long double __units) const
1295 { return do_put(__s, __intl, __f, __fill, __units); }
1298 put(iter_type __s, bool __intl, ios_base& __f,
1299 char_type __fill, const string_type& __digits) const
1300 { return do_put(__s, __intl, __f, __fill, __digits); }
1307 do_put(iter_type __s, bool, ios_base& /*__io*/, char_type /*__fill*/,
1308 long double /*__units*/) const
1312 do_put(iter_type __s, bool, ios_base& /*__io*/, char_type /*__fill*/,
1313 const string_type& /*__digits*/) const
1319 enum part { none, space, symbol, sign, value };
1320 struct pattern { char field[4]; };
1322 static const pattern _S_default_pattern;
1325 template<typename _CharT>
1326 class _Moneypunct : public _Punct<_CharT>, public money_base
1329 typedef _CharT char_type;
1330 typedef basic_string<_CharT> string_type;
1334 { return do_curr_symbol(); }
1337 positive_sign() const
1338 { return do_positive_sign(); }
1341 negative_sign() const
1342 { return do_negative_sign(); }
1346 { return do_frac_digits(); }
1350 { return do_pos_format(); }
1354 { return do_neg_format(); }
1358 _Moneypunct(size_t __refs = 0) : _Punct<_CharT> (__refs) { }
1364 do_curr_symbol() const
1365 { return basic_string<_CharT>(); }
1368 do_positive_sign() const
1369 { return basic_string<_CharT>(); }
1372 do_negative_sign() const
1373 { return basic_string<_CharT>(); }
1376 do_frac_digits() const
1380 do_pos_format() const
1381 { return money_base::_S_default_pattern; }
1384 do_neg_format() const
1385 { return money_base::_S_default_pattern; }
1388 template<typename _CharT, bool _Intl>
1389 class moneypunct : public _Moneypunct<_CharT>
1393 typedef _CharT char_type;
1394 typedef basic_string<_CharT> string_type;
1396 static const bool intl = _Intl;
1397 static locale::id id;
1400 moneypunct(size_t __refs = 0) : _Moneypunct<_CharT> (__refs) { }
1407 template<typename _CharT, bool _Intl>
1408 class moneypunct_byname : public moneypunct<_CharT,_Intl>
1411 typedef _CharT char_type;
1412 typedef basic_string<_CharT> string_type;
1413 static const bool intl = _Intl;
1416 moneypunct_byname(const char*, size_t __refs = 0);
1420 ~moneypunct_byname() { }
1424 moneypunct_byname<char, false>::
1425 moneypunct_byname(const char*, size_t __refs);
1427 moneypunct_byname<char, true>::
1428 moneypunct_byname(const char*, size_t __refs);
1429 #ifdef _GLIBCPP_USE_WCHAR_T
1431 moneypunct_byname<wchar_t,false>::
1432 moneypunct_byname(const char*, size_t __refs);
1434 moneypunct_byname<wchar_t,true>::
1435 moneypunct_byname (const char*, size_t __refs);
1438 struct messages_base
1440 typedef int catalog;
1443 template<typename _CharT>
1444 class _Messages : public locale::facet, public messages_base
1447 typedef _CharT char_type;
1448 typedef basic_string<_CharT> string_type;
1451 open(const basic_string<char>& __s, const locale& __loc) const
1452 { return do_open(__s, __loc); }
1455 get(catalog __c, int __set, int __msgid, const string_type& __s) const
1456 { return do_get(__c,__set,__msgid,__s); }
1459 close(catalog __c) const
1460 { return do_close(__c); }
1464 _Messages(size_t __refs = 0) : locale::facet(__refs) { }
1469 // NB: Probably these should be pure, and implemented only in
1470 // specializations of messages<>. But for now...
1472 do_open(const basic_string<char>&, const locale&) const
1476 do_get(catalog, int, int /*__msgid*/, const string_type& __dfault) const
1477 { return __dfault; }
1480 do_close (catalog) const { }
1483 template<typename _CharT>
1484 class messages : public _Messages<_CharT>
1487 typedef _CharT char_type;
1488 typedef basic_string<_CharT> string_type;
1489 static locale::id id;
1492 messages(size_t __refs = 0) : _Messages<_CharT> (__refs) { }
1498 template<typename _CharT>
1499 class messages_byname : public messages<_CharT>
1502 typedef _CharT char_type;
1503 typedef basic_string<_CharT> string_type;
1506 messages_byname(const char*, size_t __refs = 0);
1510 ~messages_byname() { }
1514 messages_byname<char>::messages_byname(const char*, size_t __refs);
1515 #ifdef _GLIBCPP_USE_WCHAR_T
1517 messages_byname<wchar_t>::messages_byname(const char*, size_t __refs);
1520 // Subclause convenience interfaces, inlines
1521 // NB: these are inline
1522 // because, when used in a loop, some compilers can hoist the body
1523 // out of the loop; then it's just as fast as the C is*() function.
1524 template<typename _CharT>
1526 isspace(_CharT __c, const locale& __loc)
1527 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
1529 template<typename _CharT>
1531 isprint(_CharT __c, const locale& __loc)
1532 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
1534 template<typename _CharT>
1536 iscntrl(_CharT __c, const locale& __loc)
1537 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
1539 template<typename _CharT>
1541 isupper(_CharT __c, const locale& __loc)
1542 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
1544 template<typename _CharT>
1545 inline bool islower(_CharT __c, const locale& __loc)
1546 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
1548 template<typename _CharT>
1550 isalpha(_CharT __c, const locale& __loc)
1551 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
1553 template<typename _CharT>
1555 isdigit(_CharT __c, const locale& __loc)
1556 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
1558 template<typename _CharT>
1560 ispunct(_CharT __c, const locale& __loc)
1561 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
1563 template<typename _CharT>
1565 isxdigit(_CharT __c, const locale& __loc)
1566 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
1568 template<typename _CharT>
1570 isalnum(_CharT __c, const locale& __loc)
1571 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
1573 template<typename _CharT>
1575 isgraph(_CharT __c, const locale& __loc)
1576 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
1578 template<typename _CharT>
1580 toupper(_CharT __c, const locale& __loc)
1581 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
1583 template<typename _CharT>
1585 tolower(_CharT __c, const locale& __loc)
1586 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
1590 #endif /* _CPP_BITS_LOCFACETS_H */