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
;
218 typedef ctype::mask mask
;
223 __to_type
const& _M_toupper
;
224 __to_type
const& _M_tolower
;
225 const mask
* const& _M_ctable
;
226 const mask
* _M_table
;
229 static locale::id id
;
230 static const size_t table_size
= 1 + static_cast<unsigned char>(-1);
233 ctype(const mask
* __table
= 0, bool __del
= false, size_t __refs
= 0);
236 is(mask __m
, char __c
) const throw();
239 is(const char* __low
, const char* __high
, mask
* __vec
) const throw();
242 scan_is(mask __m
, const char* __low
, const char* __high
) const throw();
245 scan_not(mask __m
, const char* __low
, const char* __high
) const throw();
253 table() const throw()
258 classic_table() throw()
259 { return _M_ctable
; }
262 do_is(mask __m
, char_type __c
) const;
264 virtual const char_type
*
265 do_is(const char_type
* __lo
, const char_type
* __hi
,
268 virtual const char_type
*
269 do_scan_is(mask __m
, const char_type
* __lo
,
270 const char_type
* __hi
) const;
272 virtual const char_type
*
273 do_scan_not(mask __m
, const char_type
* __lo
,
274 const char_type
* __hi
) const;
277 do_toupper(char_type
) const;
279 virtual const char_type
*
280 do_toupper(char_type
* __low
, const char_type
* __high
) const;
283 do_tolower(char_type
) const;
285 virtual const char_type
*
286 do_tolower(char_type
* __low
, const char_type
* __high
) const;
289 do_widen(char) const;
292 do_widen(const char* __low
, const char* __high
,
293 char_type
* __dest
) const;
296 do_narrow(char_type
, char __dfault
) const;
298 virtual const char_type
*
299 do_narrow(const char_type
* __low
, const char_type
* __high
,
300 char __dfault
, char* __dest
) const;
305 use_facet
<ctype
<char> >(const locale
& __loc
);
307 #ifdef _GLIBCPP_USE_WCHAR_T
308 // ctype<wchar_t> specialization
310 class ctype
<wchar_t> : public __ctype_abstract_base
<wchar_t>
314 typedef wchar_t char_type
;
315 typedef ctype::mask mask
;
316 typedef wctype_t __wmask_type
;
319 static locale::id id
;
322 ctype(size_t __refs
= 0);
326 _M_convert_to_wmask(const mask __m
) const;
332 do_is(mask __m
, char_type __c
) const;
334 virtual const char_type
*
335 do_is(const char_type
* __lo
, const char_type
* __hi
,
338 virtual const char_type
*
339 do_scan_is(mask __m
, const char_type
* __lo
,
340 const char_type
* __hi
) const;
342 virtual const char_type
*
343 do_scan_not(mask __m
, const char_type
* __lo
,
344 const char_type
* __hi
) const;
347 do_toupper(char_type
) const;
349 virtual const char_type
*
350 do_toupper(char_type
* __low
, const char_type
* __high
) const;
353 do_tolower(char_type
) const;
355 virtual const char_type
*
356 do_tolower(char_type
* __low
, const char_type
* __high
) const;
359 do_widen(char) const;
362 do_widen(const char* __low
, const char* __high
,
363 char_type
* __dest
) const;
366 do_narrow(char_type
, char __dfault
) const;
368 virtual const char_type
*
369 do_narrow(const char_type
* __low
, const char_type
* __high
,
370 char __dfault
, char* __dest
) const;
375 const ctype
<wchar_t>&
376 use_facet
<ctype
<wchar_t> >(const locale
& __loc
);
377 #endif //_GLIBCPP_USE_WCHAR_T
379 // Include host-specific ctype inlines.
380 #include <bits/ctype_inline.h>
382 // 22.2.1.2 Template class ctype_byname
383 template<typename _CharT
>
384 class ctype_byname
: public ctype
<_CharT
>
387 typedef _CharT char_type
;
390 ctype_byname(const char*, size_t __refs
= 0);
397 // 22.2.1.4 Class ctype_byname specialization
399 ctype_byname
<char>::ctype_byname(const char*, size_t refs
);
402 template<typename _CharT
, typename _InIter
>
403 class _Numeric_get
; // forward
405 // _Format_cache holds the information extracted from the numpunct<>
406 // and moneypunct<> facets in a form optimized for parsing and
407 // formatting. It is stored via a void* pointer in the pword()
408 // array of an iosbase object passed to the _get and _put facets.
409 // NB: contains no user-serviceable parts.
410 template<typename _CharT
>
415 typedef _CharT char_type
;
416 typedef char_traits
<_CharT
> traits_type
;
417 typedef basic_string
<_CharT
> string_type
;
418 typedef typename
string_type::size_type size_type
;
420 // Forward decls and Friends:
422 template<typename _Char
, typename _InIter
>
423 friend class _Numeric_get
;
424 friend class num_get
<_CharT
>;
425 friend class num_put
<_CharT
>;
426 friend class time_get
<_CharT
>;
427 friend class money_get
<_CharT
>;
428 friend class time_put
<_CharT
>;
429 friend class money_put
<_CharT
>;
433 // ios_base::pword() reserved cell
434 static int _S_pword_ix
;
436 // True iff data members are consistent with the current locale,
437 // ie imbue sets this to false.
440 // A list of valid numeric literals: for the standard "C" locale,
441 // this would usually be: "-+xX0123456789abcdef0123456789ABCDEF"
442 static const char _S_literals
[];
444 // NB: Code depends on the order of definitions of the names
445 // these are indices into _S_literals, above.
446 // This string is formatted for putting, not getting. (output, not input)
454 _S_digits_end
= _S_digits
+ 16,
455 _S_udigits
= _S_digits_end
,
456 _S_udigits_end
= _S_udigits
+ 16,
457 _S_ee
= _S_digits
+ 14, // For scientific notation, 'E'
458 _S_Ee
= _S_udigits
+ 14 // For scientific notation, 'e'
461 // The sign used to separate decimal values: for standard US
462 // locales, this would usually be: "."
463 // Abstracted from numpunct::decimal_point().
464 char_type _M_decimal_point
;
466 // The sign used to separate groups of digits into smaller
467 // strings that the eye can parse with less difficulty: for
468 // standard US locales, this would usually be: ","
469 // Abstracted from numpunct::thousands_sep().
470 char_type _M_thousands_sep
;
472 // However the US's "false" and "true" are translated.
473 // From numpunct::truename() and numpunct::falsename(), respectively.
474 string_type _M_truename
;
475 string_type _M_falsename
;
477 // If we are checking groupings. This should be equivalent to
478 // numpunct::groupings().size() != 0
479 bool _M_use_grouping
;
481 // If we are using numpunct's groupings, this is the current
482 // grouping string in effect (from numpunct::grouping()).
487 ~_Format_cache() throw() { }
489 // Given a member of the ios heirarchy as an argument, extract
490 // out all the current formatting information into a
491 // _Format_cache object and return a pointer to it.
492 static _Format_cache
<_CharT
>*
493 _S_get(ios_base
& __ios
);
496 _M_populate(ios_base
&);
499 _S_callback(ios_base::event __event
, ios_base
& __ios
, int __ix
) throw();
502 template<> _Format_cache
<char>::_Format_cache();
503 #ifdef _GLIBCPP_USE_WCHAR_T
504 template<> _Format_cache
<wchar_t>::_Format_cache();
507 // _Numeric_get is used by num_get, money_get, and time_get to help
508 // in parsing out numbers.
509 template<typename _CharT
, typename _InIter
>
514 typedef _CharT char_type
;
515 typedef _InIter iter_type
;
517 // Forward decls and Friends:
518 template<typename _Char
, typename _InIterT
>
519 friend class num_get
;
520 template<typename _Char
, typename _InIterT
>
521 friend class time_get
;
522 template<typename _Char
, typename _InIterT
>
523 friend class money_get
;
524 template<typename _Char
, typename _InIterT
>
525 friend class num_put
;
526 template<typename _Char
, typename _InIterT
>
527 friend class time_put
;
528 template<typename _Char
, typename _InIterT
>
529 friend class money_put
;
539 _M_get_digits(iter_type __in
, iter_type __end
) const;
542 template<typename _CharT
, typename _InIter
>
543 class num_get
: public locale::facet
547 typedef _CharT char_type
;
548 typedef _InIter iter_type
;
549 typedef char_traits
<_CharT
> __traits_type
;
551 static locale::id id
;
554 num_get(size_t __refs
= 0) : locale::facet(__refs
) { }
557 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
558 ios_base::iostate
& __err
, bool& __v
) const
559 { return do_get(__in
, __end
, __io
, __err
, __v
); }
561 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
563 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
564 ios_base::iostate
& __err
, short& __v
) const
565 { return do_get(__in
, __end
, __io
, __err
, __v
); }
568 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
569 ios_base::iostate
& __err
, int& __v
) const
570 { return do_get(__in
, __end
, __io
, __err
, __v
); }
574 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
575 ios_base::iostate
& __err
, long& __v
) const
576 { return do_get(__in
, __end
, __io
, __err
, __v
); }
578 #ifdef _GLIBCPP_USE_LONG_LONG
580 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
581 ios_base::iostate
& __err
, long long& __v
) const
582 { return do_get(__in
, __end
, __io
, __err
, __v
); }
586 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
587 ios_base::iostate
& __err
, unsigned short& __v
) const
588 { return do_get(__in
, __end
, __io
, __err
, __v
); }
591 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
592 ios_base::iostate
& __err
, unsigned int& __v
) const
593 { return do_get(__in
, __end
, __io
, __err
, __v
); }
596 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
597 ios_base::iostate
& __err
, unsigned long& __v
) const
598 { return do_get(__in
, __end
, __io
, __err
, __v
); }
600 #ifdef _GLIBCPP_USE_LONG_LONG
602 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
603 ios_base::iostate
& __err
, unsigned long long& __v
) const
604 { return do_get(__in
, __end
, __io
, __err
, __v
); }
608 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
609 ios_base::iostate
& __err
, float& __v
) const
610 { return do_get(__in
, __end
, __io
, __err
, __v
); }
613 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
614 ios_base::iostate
& __err
, double& __v
) const
615 { return do_get(__in
, __end
, __io
, __err
, __v
); }
618 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
619 ios_base::iostate
& __err
, long double& __v
) const
620 { return do_get(__in
, __end
, __io
, __err
, __v
); }
623 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
624 ios_base::iostate
& __err
, void*& __v
) const
625 { return do_get(__in
, __end
, __io
, __err
, __v
); }
628 virtual ~num_get() { }
630 // This consolidates the extraction, storage and
631 // error-processing parts of the do_get(...) overloaded member
633 // NB: This is specialized for char.
635 _M_extract(iter_type __beg
, iter_type __end
, ios_base
& __io
,
636 ios_base::iostate
& __err
, char* __xtrc
,
637 int& __base
, bool __fp
= true) const;
640 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, bool&) const;
642 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
644 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, short&) const;
646 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, int&) const;
649 do_get (iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, long&) const;
650 #ifdef _GLIBCPP_USE_LONG_LONG
652 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
656 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
657 unsigned short&) const;
659 do_get(iter_type
, iter_type
, ios_base
&,
660 ios_base::iostate
& __err
, unsigned int&) const;
662 do_get(iter_type
, iter_type
, ios_base
&,
663 ios_base::iostate
& __err
, unsigned long&) const;
664 #ifdef _GLIBCPP_USE_LONG_LONG
666 do_get(iter_type
, iter_type
, ios_base
&,
667 ios_base::iostate
& __err
, unsigned long long&) const;
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
,
678 do_get(iter_type
, iter_type
, ios_base
&,
679 ios_base::iostate
& __err
, long double&) const;
682 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
686 // Declare specialized extraction member function.
689 num_get
<char, istreambuf_iterator
<char> >::
690 _M_extract(istreambuf_iterator
<char> __beg
,
691 istreambuf_iterator
<char> __end
, ios_base
& __io
,
692 ios_base::iostate
& __err
, char* __xtrc
,
693 int& __base
, bool __fp
) const;
695 // _Numeric_put is used by num_put, money_put, and time_put
696 // to help in formatting out numbers.
697 template<typename _CharT
, typename _OutIter
>
701 typedef _CharT char_type
;
702 typedef _OutIter iter_type
;
711 template<typename _CharT
, typename _OutIter
>
712 class num_put
: public locale::facet
716 typedef _CharT char_type
;
717 typedef _OutIter iter_type
;
719 static locale::id id
;
722 num_put(size_t __refs
= 0) : locale::facet(__refs
) { }
725 put(iter_type __s
, ios_base
& __f
, char_type __fill
, bool __v
) const
726 { return do_put(__s
, __f
, __fill
, __v
); }
729 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long __v
) const
730 { return do_put(__s
, __f
, __fill
, __v
); }
733 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
734 unsigned long __v
) const
735 { return do_put(__s
, __f
, __fill
, __v
); }
737 #ifdef _GLIBCPP_USE_LONG_LONG
739 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long long __v
) const
740 { return do_put(__s
, __f
, __fill
, __v
); }
743 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
744 unsigned long long __v
) const
745 { return do_put(__s
, __f
, __fill
, __v
); }
749 put(iter_type __s
, ios_base
& __f
, char_type __fill
, double __v
) const
750 { return do_put(__s
, __f
, __fill
, __v
); }
753 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
754 long double __v
) const
755 { return do_put(__s
, __f
, __fill
, __v
); }
758 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
759 const void* __v
) const
760 { return do_put(__s
, __f
, __fill
, __v
); }
767 do_put(iter_type
, ios_base
&, char_type __fill
, bool __v
) const;
770 do_put(iter_type
, ios_base
&, char_type __fill
, long __v
) const;
772 #ifdef _GLIBCPP_USE_LONG_LONG
774 do_put(iter_type
, ios_base
&, char_type __fill
, long long __v
) const;
778 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long) const;
780 #ifdef _GLIBCPP_USE_LONG_LONG
782 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long long) const;
786 do_put(iter_type
, ios_base
&, char_type __fill
, double __v
) const;
789 do_put(iter_type
, ios_base
&, char_type __fill
, long double __v
) const;
792 do_put(iter_type
, ios_base
&, char_type __fill
, const void* __v
) const;
795 template<typename _CharT
>
796 class _Punct
: public locale::facet
800 typedef _CharT char_type
;
801 typedef basic_string
<_CharT
> string_type
;
804 decimal_point() const
805 { return do_decimal_point(); }
808 thousands_sep() const
809 { return do_thousands_sep(); }
813 { return do_grouping(); }
817 _Punct(size_t __refs
= 0) : locale::facet(__refs
) { }
823 do_decimal_point() const
824 { return _M_decimal_point
; }
827 do_thousands_sep() const
828 { return _M_thousands_sep
; }
832 { return _M_grouping
; }
835 char_type _M_decimal_point
;
836 char_type _M_thousands_sep
;
840 // for use at construction time only:
842 _M_init(char_type __d
, char_type __t
, const string
& __g
)
844 _M_decimal_point
= __d
;
845 _M_thousands_sep
= __t
;
851 template<typename _CharT
>
852 class _Numpunct
: public _Punct
<_CharT
>
856 typedef _CharT char_type
;
857 typedef basic_string
<_CharT
> string_type
;
861 { return do_truename(); }
865 { return do_falsename(); }
869 _Numpunct(size_t __refs
= 0) : _Punct
<_CharT
> (__refs
) { }
876 { return _M_truename
; }
880 { return _M_falsename
; }
883 string_type _M_truename
;
884 string_type _M_falsename
;
887 // For use only during construction
889 _M_boolnames_init(const string_type
& __t
, const string_type
& __f
)
897 template<typename _CharT
>
898 class numpunct
: public _Numpunct
<_CharT
>
901 typedef _CharT char_type
;
902 typedef basic_string
<_CharT
> string_type
;
904 static locale::id id
;
907 numpunct(size_t __refs
= 0) : _Numpunct
<_CharT
>(__refs
) { }
915 numpunct
<char>::numpunct(size_t __refs
): _Numpunct
<char>(__refs
)
917 _M_init('.', ',', "");
918 _M_boolnames_init("true", "false");
921 #ifdef _GLIBCPP_USE_WCHAR_T
923 numpunct
<wchar_t>::numpunct(size_t __refs
): _Numpunct
<wchar_t>(__refs
)
925 _M_init(L
'.', L
',', "");
926 _M_boolnames_init(L
"true", L
"false");
930 template<typename _CharT
>
931 class numpunct_byname
: public numpunct
<_CharT
>
934 typedef _CharT char_type
;
935 typedef basic_string
<_CharT
> string_type
;
938 numpunct_byname(const char*, size_t __refs
= 0);
942 ~numpunct_byname() { }
946 numpunct_byname
<char>::numpunct_byname(const char*, size_t __refs
);
947 #ifdef _GLIBCPP_USE_WCHAR_T
949 numpunct_byname
<wchar_t>::numpunct_byname(const char*, size_t __refs
);
952 template<typename _CharT
>
953 class _Collate
: public locale::facet
957 typedef _CharT char_type
;
958 typedef basic_string
<_CharT
> string_type
;
961 compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
962 const _CharT
* __lo2
, const _CharT
* __hi2
) const
963 { return do_compare(__lo1
, __hi1
, __lo2
, __hi2
); }
966 transform(const _CharT
* __lo
, const _CharT
* __hi
) const
967 { return do_transform(__lo
, __hi
); }
970 hash(const _CharT
* __lo
, const _CharT
* __hi
) const
971 { return do_hash(__lo
, __hi
); }
975 _Collate(size_t __refs
= 0) : locale::facet(__refs
) { }
977 ~_Collate() { } // virtual
980 do_compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
981 const _CharT
* __lo2
, const _CharT
* __hi2
) const = 0;
984 do_transform(const _CharT
* __lo
, const _CharT
* __hi
) const = 0;
987 do_hash(const _CharT
* __lo
, const _CharT
* __hi
) const = 0;
990 template<typename _CharT
>
991 class collate
: public _Collate
<_CharT
>
995 typedef _CharT char_type
;
996 typedef basic_string
<_CharT
> string_type
;
999 collate(size_t __refs
= 0) : _Collate
<_CharT
> (__refs
) { }
1001 static locale::id id
;
1009 class collate
<char> : public _Collate
<char>
1013 typedef char char_type
;
1014 typedef basic_string
<char> string_type
;
1017 collate(size_t __refs
= 0);
1019 static locale::id id
;
1026 do_compare(const char* __lo1
, const char* __hi1
,
1027 const char* __lo2
, const char* __hi2
) const;
1030 do_transform(const char* __lo
, const char* __hi
) const;
1033 do_hash(const char* __lo
, const char* __hi
) const;
1036 #ifdef _GLIBCPP_USE_WCHAR_T
1038 class collate
<wchar_t> : public _Collate
<wchar_t>
1042 typedef wchar_t char_type
;
1043 typedef basic_string
<wchar_t> string_type
;
1046 collate(size_t __refs
= 0);
1048 static locale::id id
;
1055 do_compare(const wchar_t* __lo1
, const wchar_t* __hi1
,
1056 const wchar_t* __lo2
, const wchar_t* __hi2
) const;
1059 do_transform(const wchar_t* __lo
, const wchar_t* __hi
) const;
1062 do_hash(const wchar_t* __lo
, const wchar_t* __hi
) const;
1066 template<typename _CharT
>
1067 class collate_byname
: public collate
<_CharT
>
1071 typedef _CharT char_type
;
1072 typedef basic_string
<_CharT
> string_type
;
1075 collate_byname(const char*, size_t __refs
= 0);
1079 ~collate_byname() { }
1083 collate_byname
<char>::collate_byname(const char*, size_t __refs
);
1084 #ifdef _GLIBCPP_USE_WCHAR_T
1086 collate_byname
<wchar_t>::collate_byname(const char*, size_t __refs
);
1092 enum dateorder
{ no_order
, dmy
, mdy
, ymd
, ydm
};
1095 template<typename _CharT
, typename _InIter
>
1096 class time_get
: public locale::facet
, public time_base
1100 typedef _CharT char_type
;
1101 typedef _InIter iter_type
;
1103 static locale::id id
;
1106 time_get(size_t __refs
= 0)
1107 : locale::facet (__refs
), _M_daynames(0), _M_monthnames(0) { }
1111 { return do_date_order(); }
1114 get_time(iter_type __s
, iter_type __end
, ios_base
& __f
,
1115 ios_base::iostate
& __err
, tm
* __t
) const
1116 { return do_get_time(__s
, __end
, __f
, __err
, __t
); }
1119 get_date(iter_type __s
, iter_type __end
, ios_base
& __f
,
1120 ios_base::iostate
& __err
, tm
* __t
) const
1121 { return do_get_date(__s
, __end
, __f
, __err
, __t
); }
1124 get_weekday(iter_type __s
, iter_type __end
, ios_base
& __f
,
1125 ios_base::iostate
& __err
, tm
* __t
) const
1126 { return do_get_weekday(__s
,__end
,__f
,__err
,__t
); }
1129 get_monthname(iter_type __s
, iter_type __end
, ios_base
& __f
,
1130 ios_base::iostate
& __err
, tm
* __t
) const
1131 { return do_get_monthname(__s
,__end
,__f
,__err
,__t
); }
1134 get_year(iter_type __s
, iter_type __end
, ios_base
& __f
,
1135 ios_base::iostate
& __err
, tm
* __t
) const
1136 { return do_get_year(__s
,__end
,__f
,__err
,__t
); }
1142 delete [] _M_monthnames
;
1143 delete [] _M_daynames
;
1147 do_date_order() const
1148 { return time_base::ymd
; }
1151 do_get_time(iter_type __s
, iter_type
/*__end*/, ios_base
&,
1152 ios_base::iostate
& /*__err*/, tm
* /*__t*/) const
1156 do_get_date(iter_type __s
, iter_type
/*__end*/, ios_base
&,
1157 ios_base::iostate
& /*__err*/, tm
* /*__t*/) const
1161 do_get_weekday(iter_type __s
, iter_type __end
, ios_base
&,
1162 ios_base::iostate
& __err
, tm
* __t
) const;
1165 do_get_monthname(iter_type __s
, iter_type __end
, ios_base
&,
1166 ios_base::iostate
& __err
, tm
* __t
) const;
1169 do_get_year(iter_type __s
, iter_type
/*__end*/, ios_base
&,
1170 ios_base::iostate
& /*__err*/, tm
* /*__t*/) const
1173 mutable basic_string
<_CharT
>* _M_daynames
;
1174 mutable basic_string
<_CharT
>* _M_monthnames
;
1177 template<typename _CharT
, typename _InIter
>
1178 class time_get_byname
: public time_get
<_CharT
, _InIter
>
1181 typedef _CharT char_type
;
1182 typedef _InIter iter_type
;
1185 time_get_byname(const char*, size_t __refs
= 0)
1186 : time_get
<_CharT
, _InIter
>(__refs
) { }
1189 ~time_get_byname() { }
1192 template<typename _CharT
, typename _OutIter
>
1193 class time_put
: public locale::facet
, public time_base
1196 typedef _CharT char_type
;
1197 typedef _OutIter iter_type
;
1199 static locale::id id
;
1202 time_put(size_t __refs
= 0) : locale::facet (__refs
) { }
1204 // NB: this is a nonvirtual, calls do_put in a loop.
1206 put(iter_type __s
, ios_base
& /*__f*/, char_type
/*__fill*/,
1207 const tm
* /*__tmb*/, const _CharT
* /*__pattern*/,
1208 const _CharT
* /*__pat_end*/) const
1212 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
1213 const tm
* __tmb
, char __format
, char __modifier
= 0) const
1214 { return do_put(__s
, __f
, __fill
, __tmb
, __format
, __modifier
); }
1221 do_put(iter_type __s
, ios_base
&, char_type
, const tm
* /*__t*/,
1222 char /*__format*/, char /*__mod*/) const
1226 template<typename _CharT
, typename _OutIter
>
1227 class time_put_byname
: public time_put
<_CharT
, _OutIter
>
1230 typedef _CharT char_type
;
1231 typedef _OutIter iter_type
;
1234 time_put_byname(const char*, size_t __refs
= 0)
1235 : time_put
<_CharT
, _OutIter
> (__refs
) { }
1239 ~time_put_byname() { }
1243 template<typename _CharT
, typename _InIter
>
1244 class money_get
: public locale::facet
1247 typedef _CharT char_type
;
1248 typedef _InIter iter_type
;
1249 typedef basic_string
<_CharT
> string_type
;
1251 static locale::id id
;
1254 money_get(size_t __refs
= 0) : locale::facet(__refs
) { }
1257 get(iter_type __s
, iter_type __end
, bool __intl
,
1258 ios_base
& __f
, ios_base::iostate
& __err
, long double& __units
) const
1259 { return do_get(__s
, __end
, __intl
, __f
, __err
, __units
); }
1262 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __f
,
1263 ios_base::iostate
& __err
, string_type
& __digits
) const
1264 { return do_get(__s
, __end
, __intl
, __f
, __err
, __digits
); }
1271 do_get(iter_type __s
, iter_type
/*__end*/, bool /*__intl*/,
1272 ios_base
& /*__io*/, ios_base::iostate
& /*__err*/,
1273 long double& /*__units*/) const
1277 do_get(iter_type __s
, iter_type
/*__end*/, bool /*__intl*/,
1278 ios_base
& /*__io*/, ios_base::iostate
& /*__err*/,
1279 string_type
& /*__digits*/) const
1283 template<typename _CharT
, typename _OutIter
>
1284 class money_put
: public locale::facet
1287 typedef _CharT char_type
;
1288 typedef _OutIter iter_type
;
1289 typedef basic_string
<_CharT
> string_type
;
1291 static locale::id id
;
1294 money_put(size_t __refs
= 0) : locale::facet(__refs
) { }
1297 put(iter_type __s
, bool __intl
, ios_base
& __f
,
1298 char_type __fill
, long double __units
) const
1299 { return do_put(__s
, __intl
, __f
, __fill
, __units
); }
1302 put(iter_type __s
, bool __intl
, ios_base
& __f
,
1303 char_type __fill
, const string_type
& __digits
) const
1304 { return do_put(__s
, __intl
, __f
, __fill
, __digits
); }
1311 do_put(iter_type __s
, bool, ios_base
& /*__io*/, char_type
/*__fill*/,
1312 long double /*__units*/) const
1316 do_put(iter_type __s
, bool, ios_base
& /*__io*/, char_type
/*__fill*/,
1317 const string_type
& /*__digits*/) const
1323 enum part
{ none
, space
, symbol
, sign
, value
};
1324 struct pattern
{ char field
[4]; };
1326 static const pattern _S_default_pattern
;
1329 template<typename _CharT
>
1330 class _Moneypunct
: public _Punct
<_CharT
>, public money_base
1333 typedef _CharT char_type
;
1334 typedef basic_string
<_CharT
> string_type
;
1338 { return do_curr_symbol(); }
1341 positive_sign() const
1342 { return do_positive_sign(); }
1345 negative_sign() const
1346 { return do_negative_sign(); }
1350 { return do_frac_digits(); }
1354 { return do_pos_format(); }
1358 { return do_neg_format(); }
1362 _Moneypunct(size_t __refs
= 0) : _Punct
<_CharT
> (__refs
) { }
1368 do_curr_symbol() const
1369 { return basic_string
<_CharT
>(); }
1372 do_positive_sign() const
1373 { return basic_string
<_CharT
>(); }
1376 do_negative_sign() const
1377 { return basic_string
<_CharT
>(); }
1380 do_frac_digits() const
1384 do_pos_format() const
1385 { return money_base::_S_default_pattern
; }
1388 do_neg_format() const
1389 { return money_base::_S_default_pattern
; }
1392 template<typename _CharT
, bool _Intl
>
1393 class moneypunct
: public _Moneypunct
<_CharT
>
1397 typedef _CharT char_type
;
1398 typedef basic_string
<_CharT
> string_type
;
1400 static const bool intl
= _Intl
;
1401 static locale::id id
;
1404 moneypunct(size_t __refs
= 0) : _Moneypunct
<_CharT
> (__refs
) { }
1411 template<typename _CharT
, bool _Intl
>
1412 class moneypunct_byname
: public moneypunct
<_CharT
,_Intl
>
1415 typedef _CharT char_type
;
1416 typedef basic_string
<_CharT
> string_type
;
1417 static const bool intl
= _Intl
;
1420 moneypunct_byname(const char*, size_t __refs
= 0);
1424 ~moneypunct_byname() { }
1428 moneypunct_byname
<char, false>::
1429 moneypunct_byname(const char*, size_t __refs
);
1431 moneypunct_byname
<char, true>::
1432 moneypunct_byname(const char*, size_t __refs
);
1433 #ifdef _GLIBCPP_USE_WCHAR_T
1435 moneypunct_byname
<wchar_t,false>::
1436 moneypunct_byname(const char*, size_t __refs
);
1438 moneypunct_byname
<wchar_t,true>::
1439 moneypunct_byname (const char*, size_t __refs
);
1442 struct messages_base
1444 typedef int catalog
;
1447 template<typename _CharT
>
1448 class _Messages
: public locale::facet
, public messages_base
1451 typedef _CharT char_type
;
1452 typedef basic_string
<_CharT
> string_type
;
1455 open(const basic_string
<char>& __s
, const locale
& __loc
) const
1456 { return do_open(__s
, __loc
); }
1459 get(catalog __c
, int __set
, int __msgid
, const string_type
& __s
) const
1460 { return do_get(__c
,__set
,__msgid
,__s
); }
1463 close(catalog __c
) const
1464 { return do_close(__c
); }
1468 _Messages(size_t __refs
= 0) : locale::facet(__refs
) { }
1473 // NB: Probably these should be pure, and implemented only in
1474 // specializations of messages<>. But for now...
1476 do_open(const basic_string
<char>&, const locale
&) const
1480 do_get(catalog
, int, int /*__msgid*/, const string_type
& __dfault
) const
1481 { return __dfault
; }
1484 do_close (catalog
) const { }
1487 template<typename _CharT
>
1488 class messages
: public _Messages
<_CharT
>
1491 typedef _CharT char_type
;
1492 typedef basic_string
<_CharT
> string_type
;
1493 static locale::id id
;
1496 messages(size_t __refs
= 0) : _Messages
<_CharT
> (__refs
) { }
1502 template<typename _CharT
>
1503 class messages_byname
: public messages
<_CharT
>
1506 typedef _CharT char_type
;
1507 typedef basic_string
<_CharT
> string_type
;
1510 messages_byname(const char*, size_t __refs
= 0);
1514 ~messages_byname() { }
1518 messages_byname
<char>::messages_byname(const char*, size_t __refs
);
1519 #ifdef _GLIBCPP_USE_WCHAR_T
1521 messages_byname
<wchar_t>::messages_byname(const char*, size_t __refs
);
1524 // Subclause convenience interfaces, inlines
1525 // NB: these are inline
1526 // because, when used in a loop, some compilers can hoist the body
1527 // out of the loop; then it's just as fast as the C is*() function.
1528 template<typename _CharT
>
1530 isspace(_CharT __c
, const locale
& __loc
)
1531 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::space
, __c
); }
1533 template<typename _CharT
>
1535 isprint(_CharT __c
, const locale
& __loc
)
1536 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::print
, __c
); }
1538 template<typename _CharT
>
1540 iscntrl(_CharT __c
, const locale
& __loc
)
1541 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::cntrl
, __c
); }
1543 template<typename _CharT
>
1545 isupper(_CharT __c
, const locale
& __loc
)
1546 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::upper
, __c
); }
1548 template<typename _CharT
>
1549 inline bool islower(_CharT __c
, const locale
& __loc
)
1550 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::lower
, __c
); }
1552 template<typename _CharT
>
1554 isalpha(_CharT __c
, const locale
& __loc
)
1555 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alpha
, __c
); }
1557 template<typename _CharT
>
1559 isdigit(_CharT __c
, const locale
& __loc
)
1560 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::digit
, __c
); }
1562 template<typename _CharT
>
1564 ispunct(_CharT __c
, const locale
& __loc
)
1565 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::punct
, __c
); }
1567 template<typename _CharT
>
1569 isxdigit(_CharT __c
, const locale
& __loc
)
1570 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::xdigit
, __c
); }
1572 template<typename _CharT
>
1574 isalnum(_CharT __c
, const locale
& __loc
)
1575 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alnum
, __c
); }
1577 template<typename _CharT
>
1579 isgraph(_CharT __c
, const locale
& __loc
)
1580 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::graph
, __c
); }
1582 template<typename _CharT
>
1584 toupper(_CharT __c
, const locale
& __loc
)
1585 { return use_facet
<ctype
<_CharT
> >(__loc
).toupper(__c
); }
1587 template<typename _CharT
>
1589 tolower(_CharT __c
, const locale
& __loc
)
1590 { return use_facet
<ctype
<_CharT
> >(__loc
).tolower(__c
); }
1594 #endif /* _CPP_BITS_LOCFACETS_H */