1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 22.1 Locales
34 // 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 <bits/std_ios.h> // For ios_base
41 #ifdef _GLIBCPP_USE_WCHAR_T
42 # include <langinfo.h> // For codecvt
43 # include <bits/std_cwctype.h> // For wctype_t
44 # include <iconv.h> // For codecvt using iconv, iconv_t
49 // 22.2.1.1 Template class ctype
50 // Include host-specific ctype enums for ctype_base.
51 #include <bits/ctype_base.h>
53 // __ctype_abstract_base is the common base for ctype<_CharT>.
54 template<typename _CharT
>
55 class __ctype_abstract_base
: public locale::facet
, public ctype_base
59 typedef _CharT char_type
;
62 is(mask __m
, char_type __c
) const
63 { return this->do_is(__m
, __c
); }
66 is(const char_type
*__lo
, const char_type
*__hi
, mask
*__vec
) const
67 { return this->do_is(__lo
, __hi
, __vec
); }
70 scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
71 { return this->do_scan_is(__m
, __lo
, __hi
); }
74 scan_not(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
75 { return this->do_scan_not(__m
, __lo
, __hi
); }
78 toupper(char_type __c
) const
79 { return this->do_toupper(__c
); }
82 toupper(char_type
*__low
, const char_type
* __high
) const
83 { return this->do_toupper(__low
, __high
); }
86 tolower(char_type __c
) const
87 { return this->do_tolower(__c
); }
90 tolower(char_type
* __low
, const char_type
* __high
) const
91 { return this->do_tolower(__low
, __high
); }
95 { return this->do_widen(__c
); }
98 widen(const char* __low
, const char* __high
, char_type
* __to
) const
99 { return this->do_widen(__low
, __high
, __to
); }
102 narrow(char_type __c
, char __dfault
) const
103 { return this->do_narrow(__c
, __dfault
); }
106 narrow(const char_type
* __low
, const char_type
* __high
,
107 char __dfault
, char *__to
) const
108 { return this->do_narrow(__low
, __high
, __dfault
, __to
); }
112 __ctype_abstract_base(size_t __refs
= 0): locale::facet(__refs
) { }
115 ~__ctype_abstract_base() { }
118 do_is(mask __m
, char_type __c
) const = 0;
120 virtual const char_type
*
121 do_is(const char_type
* __lo
, const char_type
* __hi
,
122 mask
* __vec
) const = 0;
124 virtual const char_type
*
125 do_scan_is(mask __m
, const char_type
* __lo
,
126 const char_type
* __hi
) const = 0;
128 virtual const char_type
*
129 do_scan_not(mask __m
, const char_type
* __lo
,
130 const char_type
* __hi
) const = 0;
133 do_toupper(char_type
) const = 0;
135 virtual const char_type
*
136 do_toupper(char_type
* __low
, const char_type
* __high
) const = 0;
139 do_tolower(char_type
) const = 0;
141 virtual const char_type
*
142 do_tolower(char_type
* __low
, const char_type
* __high
) const = 0;
145 do_widen(char) const = 0;
148 do_widen(const char* __low
, const char* __high
,
149 char_type
* __dest
) const = 0;
152 do_narrow(char_type
, char __dfault
) const = 0;
154 virtual const char_type
*
155 do_narrow(const char_type
* __low
, const char_type
* __high
,
156 char __dfault
, char* __dest
) const = 0;
159 // NB: Generic, mostly useless implementation.
160 template<typename _CharT
>
161 class ctype
: public __ctype_abstract_base
<_CharT
>
165 typedef _CharT char_type
;
166 typedef typename
ctype::mask mask
;
169 ctype(size_t __refs
= 0) : __ctype_abstract_base
<_CharT
>(__refs
) { }
171 static locale::id id
;
178 template<typename _CharT
>
179 locale::id ctype
<_CharT
>::id
;
181 // 22.2.1.3 ctype specializations
183 class ctype
<char> : public __ctype_abstract_base
<char>
187 typedef char char_type
;
192 __to_type
const& _M_toupper
;
193 __to_type
const& _M_tolower
;
194 const mask
* const& _M_ctable
;
195 const mask
* _M_table
;
198 static locale::id id
;
199 static const size_t table_size
= 1 + static_cast<unsigned char>(-1);
202 ctype(const mask
* __table
= 0, bool __del
= false, size_t __refs
= 0);
205 is(mask __m
, char __c
) const;
208 is(const char* __low
, const char* __high
, mask
* __vec
) const;
211 scan_is(mask __m
, const char* __low
, const char* __high
) const;
214 scan_not(mask __m
, const char* __low
, const char* __high
) const;
221 table() const throw()
225 classic_table() throw()
226 { return _M_ctable
; }
229 do_is(mask __m
, char_type __c
) const;
231 virtual const char_type
*
232 do_is(const char_type
* __lo
, const char_type
* __hi
,
235 virtual const char_type
*
236 do_scan_is(mask __m
, const char_type
* __lo
,
237 const char_type
* __hi
) const;
239 virtual const char_type
*
240 do_scan_not(mask __m
, const char_type
* __lo
,
241 const char_type
* __hi
) const;
244 do_toupper(char_type
) const;
246 virtual const char_type
*
247 do_toupper(char_type
* __low
, const char_type
* __high
) const;
250 do_tolower(char_type
) const;
252 virtual const char_type
*
253 do_tolower(char_type
* __low
, const char_type
* __high
) const;
256 do_widen(char) const;
259 do_widen(const char* __low
, const char* __high
,
260 char_type
* __dest
) const;
263 do_narrow(char_type
, char __dfault
) const;
265 virtual const char_type
*
266 do_narrow(const char_type
* __low
, const char_type
* __high
,
267 char __dfault
, char* __dest
) const;
272 use_facet
<ctype
<char> >(const locale
& __loc
);
274 #ifdef _GLIBCPP_USE_WCHAR_T
275 // ctype<wchar_t> specialization
277 class ctype
<wchar_t> : public __ctype_abstract_base
<wchar_t>
281 typedef wchar_t char_type
;
282 typedef wctype_t __wmask_type
;
285 static locale::id id
;
288 ctype(size_t __refs
= 0);
292 _M_convert_to_wmask(const mask __m
) const;
298 do_is(mask __m
, char_type __c
) const;
300 virtual const char_type
*
301 do_is(const char_type
* __lo
, const char_type
* __hi
,
304 virtual const char_type
*
305 do_scan_is(mask __m
, const char_type
* __lo
,
306 const char_type
* __hi
) const;
308 virtual const char_type
*
309 do_scan_not(mask __m
, const char_type
* __lo
,
310 const char_type
* __hi
) const;
313 do_toupper(char_type
) const;
315 virtual const char_type
*
316 do_toupper(char_type
* __low
, const char_type
* __high
) const;
319 do_tolower(char_type
) const;
321 virtual const char_type
*
322 do_tolower(char_type
* __low
, const char_type
* __high
) const;
325 do_widen(char) const;
328 do_widen(const char* __low
, const char* __high
,
329 char_type
* __dest
) const;
332 do_narrow(char_type
, char __dfault
) const;
334 virtual const char_type
*
335 do_narrow(const char_type
* __low
, const char_type
* __high
,
336 char __dfault
, char* __dest
) const;
341 const ctype
<wchar_t>&
342 use_facet
<ctype
<wchar_t> >(const locale
& __loc
);
343 #endif //_GLIBCPP_USE_WCHAR_T
345 // Include host-specific ctype inlines.
346 #include <bits/ctype_inline.h>
348 // 22.2.1.2 Template class ctype_byname
349 template<typename _CharT
>
350 class ctype_byname
: public ctype
<_CharT
>
353 typedef _CharT char_type
;
356 ctype_byname(const char*, size_t __refs
= 0);
363 // 22.2.1.4 Class ctype_byname specialization
365 ctype_byname
<char>::ctype_byname(const char*, size_t refs
);
368 // 22.2.1.5 Template class codecvt
369 #include <bits/codecvt.h>
371 template<typename _CharT
, typename _InIter
>
372 class _Numeric_get
; // forward
374 // _Format_cache holds the information extracted from the numpunct<>
375 // and moneypunct<> facets in a form optimized for parsing and
376 // formatting. It is stored via a void* pointer in the pword()
377 // array of an iosbase object passed to the _get and _put facets.
378 // NB: contains no user-serviceable parts.
379 template<typename _CharT
>
384 typedef _CharT char_type
;
385 typedef char_traits
<_CharT
> traits_type
;
386 typedef basic_string
<_CharT
> string_type
;
387 typedef typename
string_type::size_type size_type
;
389 // Forward decls and Friends:
391 template<typename _Char
, typename _InIter
>
392 friend class _Numeric_get
;
393 friend class num_get
<_CharT
>;
394 friend class num_put
<_CharT
>;
395 friend class time_get
<_CharT
>;
396 friend class money_get
<_CharT
>;
397 friend class time_put
<_CharT
>;
398 friend class money_put
<_CharT
>;
402 // ios_base::pword() reserved cell
403 static int _S_pword_ix
;
405 // True iff data members are consistent with the current locale,
406 // ie imbue sets this to false.
409 // A list of valid numeric literals: for the standard "C" locale,
410 // this would usually be: "-+xX0123456789abcdef0123456789ABCDEF"
411 static const char _S_literals
[];
413 // NB: Code depends on the order of definitions of the names
414 // these are indices into _S_literals, above.
415 // This string is formatted for putting, not getting. (output, not input)
423 _S_digits_end
= _S_digits
+ 16,
424 _S_udigits
= _S_digits_end
,
425 _S_udigits_end
= _S_udigits
+ 16,
426 _S_ee
= _S_digits
+ 14, // For scientific notation, 'E'
427 _S_Ee
= _S_udigits
+ 14 // For scientific notation, 'e'
430 // The sign used to separate decimal values: for standard US
431 // locales, this would usually be: "."
432 // Abstracted from numpunct::decimal_point().
433 char_type _M_decimal_point
;
435 // The sign used to separate groups of digits into smaller
436 // strings that the eye can parse with less difficulty: for
437 // standard US locales, this would usually be: ","
438 // Abstracted from numpunct::thousands_sep().
439 char_type _M_thousands_sep
;
441 // However the US's "false" and "true" are translated.
442 // From numpunct::truename() and numpunct::falsename(), respectively.
443 string_type _M_truename
;
444 string_type _M_falsename
;
446 // If we are checking groupings. This should be equivalent to
447 // numpunct::groupings().size() != 0
448 bool _M_use_grouping
;
450 // If we are using numpunct's groupings, this is the current
451 // grouping string in effect (from numpunct::grouping()).
456 ~_Format_cache() throw() { }
458 // Given a member of the ios heirarchy as an argument, extract
459 // out all the current formatting information into a
460 // _Format_cache object and return a pointer to it.
461 static _Format_cache
<_CharT
>*
462 _S_get(ios_base
& __ios
);
465 _M_populate(ios_base
&);
468 _S_callback(ios_base::event __event
, ios_base
& __ios
, int __ix
) throw();
471 template<typename _CharT
>
472 int _Format_cache
<_CharT
>::_S_pword_ix
;
474 template<typename _CharT
>
475 const char _Format_cache
<_CharT
>::
476 _S_literals
[] = "-+xX0123456789abcdef0123456789ABCDEF";
478 template<> _Format_cache
<char>::_Format_cache();
479 #ifdef _GLIBCPP_USE_WCHAR_T
480 template<> _Format_cache
<wchar_t>::_Format_cache();
483 // _Numeric_get is used by num_get, money_get, and time_get to help
484 // in parsing out numbers.
485 template<typename _CharT
, typename _InIter
>
490 typedef _CharT char_type
;
491 typedef _InIter iter_type
;
493 // Forward decls and Friends:
494 template<typename _Char
, typename _InIterT
>
495 friend class num_get
;
496 template<typename _Char
, typename _InIterT
>
497 friend class time_get
;
498 template<typename _Char
, typename _InIterT
>
499 friend class money_get
;
500 template<typename _Char
, typename _InIterT
>
501 friend class num_put
;
502 template<typename _Char
, typename _InIterT
>
503 friend class time_put
;
504 template<typename _Char
, typename _InIterT
>
505 friend class money_put
;
515 _M_get_digits(iter_type __in
, iter_type __end
) const;
518 template<typename _CharT
, typename _InIter
>
519 class num_get
: public locale::facet
523 typedef _CharT char_type
;
524 typedef _InIter iter_type
;
525 typedef char_traits
<_CharT
> __traits_type
;
527 static locale::id id
;
530 num_get(size_t __refs
= 0) : locale::facet(__refs
) { }
533 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
534 ios_base::iostate
& __err
, bool& __v
) const
535 { return do_get(__in
, __end
, __io
, __err
, __v
); }
537 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
539 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
540 ios_base::iostate
& __err
, short& __v
) const
541 { return do_get(__in
, __end
, __io
, __err
, __v
); }
544 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
545 ios_base::iostate
& __err
, int& __v
) const
546 { return do_get(__in
, __end
, __io
, __err
, __v
); }
550 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
551 ios_base::iostate
& __err
, long& __v
) const
552 { return do_get(__in
, __end
, __io
, __err
, __v
); }
554 #ifdef _GLIBCPP_USE_LONG_LONG
556 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
557 ios_base::iostate
& __err
, long long& __v
) const
558 { return do_get(__in
, __end
, __io
, __err
, __v
); }
562 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
563 ios_base::iostate
& __err
, unsigned short& __v
) const
564 { return do_get(__in
, __end
, __io
, __err
, __v
); }
567 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
568 ios_base::iostate
& __err
, unsigned int& __v
) const
569 { return do_get(__in
, __end
, __io
, __err
, __v
); }
572 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
573 ios_base::iostate
& __err
, unsigned long& __v
) const
574 { return do_get(__in
, __end
, __io
, __err
, __v
); }
576 #ifdef _GLIBCPP_USE_LONG_LONG
578 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
579 ios_base::iostate
& __err
, unsigned long long& __v
) const
580 { return do_get(__in
, __end
, __io
, __err
, __v
); }
584 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
585 ios_base::iostate
& __err
, float& __v
) const
586 { return do_get(__in
, __end
, __io
, __err
, __v
); }
589 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
590 ios_base::iostate
& __err
, double& __v
) const
591 { return do_get(__in
, __end
, __io
, __err
, __v
); }
594 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
595 ios_base::iostate
& __err
, long double& __v
) const
596 { return do_get(__in
, __end
, __io
, __err
, __v
); }
599 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
600 ios_base::iostate
& __err
, void*& __v
) const
601 { return do_get(__in
, __end
, __io
, __err
, __v
); }
604 virtual ~num_get() { }
606 // This consolidates the extraction, storage and
607 // error-processing parts of the do_get(...) overloaded member
609 // NB: This is specialized for char.
611 _M_extract(iter_type __beg
, iter_type __end
, ios_base
& __io
,
612 ios_base::iostate
& __err
, char* __xtrc
,
613 int& __base
, bool __fp
= true) const;
616 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, bool&) const;
618 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
620 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, short&) const;
622 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, int&) const;
625 do_get (iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, long&) const;
626 #ifdef _GLIBCPP_USE_LONG_LONG
628 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
632 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
633 unsigned short&) const;
635 do_get(iter_type
, iter_type
, ios_base
&,
636 ios_base::iostate
& __err
, unsigned int&) const;
638 do_get(iter_type
, iter_type
, ios_base
&,
639 ios_base::iostate
& __err
, unsigned long&) const;
640 #ifdef _GLIBCPP_USE_LONG_LONG
642 do_get(iter_type
, iter_type
, ios_base
&,
643 ios_base::iostate
& __err
, unsigned long long&) const;
646 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
650 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
654 do_get(iter_type
, iter_type
, ios_base
&,
655 ios_base::iostate
& __err
, long double&) const;
658 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
662 template<typename _CharT
, typename _InIter
>
663 locale::id num_get
<_CharT
, _InIter
>::id
;
665 // Declare specialized extraction member function.
668 num_get
<char, istreambuf_iterator
<char> >::
669 _M_extract(istreambuf_iterator
<char> __beg
,
670 istreambuf_iterator
<char> __end
, ios_base
& __io
,
671 ios_base::iostate
& __err
, char* __xtrc
,
672 int& __base
, bool __fp
) const;
674 // _Numeric_put is used by num_put, money_put, and time_put
675 // to help in formatting out numbers.
676 template<typename _CharT
, typename _OutIter
>
680 typedef _CharT char_type
;
681 typedef _OutIter iter_type
;
690 template<typename _CharT
, typename _OutIter
>
691 class num_put
: public locale::facet
695 typedef _CharT char_type
;
696 typedef _OutIter iter_type
;
698 static locale::id id
;
701 num_put(size_t __refs
= 0) : locale::facet(__refs
) { }
704 put(iter_type __s
, ios_base
& __f
, char_type __fill
, bool __v
) const
705 { return do_put(__s
, __f
, __fill
, __v
); }
708 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long __v
) const
709 { return do_put(__s
, __f
, __fill
, __v
); }
712 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
713 unsigned long __v
) const
714 { return do_put(__s
, __f
, __fill
, __v
); }
716 #ifdef _GLIBCPP_USE_LONG_LONG
718 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long long __v
) const
719 { return do_put(__s
, __f
, __fill
, __v
); }
722 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
723 unsigned long long __v
) const
724 { return do_put(__s
, __f
, __fill
, __v
); }
728 put(iter_type __s
, ios_base
& __f
, char_type __fill
, double __v
) const
729 { return do_put(__s
, __f
, __fill
, __v
); }
732 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
733 long double __v
) const
734 { return do_put(__s
, __f
, __fill
, __v
); }
737 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
738 const void* __v
) const
739 { return do_put(__s
, __f
, __fill
, __v
); }
746 do_put(iter_type
, ios_base
&, char_type __fill
, bool __v
) const;
749 do_put(iter_type
, ios_base
&, char_type __fill
, long __v
) const;
751 #ifdef _GLIBCPP_USE_LONG_LONG
753 do_put(iter_type
, ios_base
&, char_type __fill
, long long __v
) const;
757 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long) const;
759 #ifdef _GLIBCPP_USE_LONG_LONG
761 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long long) const;
765 do_put(iter_type
, ios_base
&, char_type __fill
, double __v
) const;
768 do_put(iter_type
, ios_base
&, char_type __fill
, long double __v
) const;
771 do_put(iter_type
, ios_base
&, char_type __fill
, const void* __v
) const;
774 template <typename _CharT
, typename _OutIter
>
775 locale::id num_put
<_CharT
, _OutIter
>::id
;
777 template<typename _CharT
>
778 class numpunct
: public locale::facet
782 typedef _CharT char_type
;
783 typedef basic_string
<_CharT
> string_type
;
785 static locale::id id
;
788 char_type _M_decimal_point
;
789 char_type _M_thousands_sep
;
791 string_type _M_truename
;
792 string_type _M_falsename
;
796 numpunct(size_t __refs
= 0) : locale::facet(__refs
)
797 { _M_initialize_numpunct(); }
800 numpunct(__c_locale __cloc
, size_t __refs
= 0) : locale::facet(__refs
)
801 { _M_initialize_numpunct(__cloc
); }
804 decimal_point() const
805 { return do_decimal_point(); }
808 thousands_sep() const
809 { return do_thousands_sep(); }
813 { return do_grouping(); }
817 { return do_truename(); }
821 { return do_falsename(); }
828 do_decimal_point() const
829 { return _M_decimal_point
; }
832 do_thousands_sep() const
833 { return _M_thousands_sep
; }
837 { return _M_grouping
; }
841 { return _M_truename
; }
845 { return _M_falsename
; }
847 // For use at construction time only.
849 _M_initialize_numpunct(__c_locale __cloc
= NULL
);
852 template<typename _CharT
>
853 locale::id numpunct
<_CharT
>::id
;
855 template<typename _CharT
>
857 numpunct
<_CharT
>::_M_initialize_numpunct(__c_locale
/*__cloc*/)
859 // NB: Cannot be made generic.
864 numpunct
<char>::_M_initialize_numpunct(__c_locale __cloc
);
865 #ifdef _GLIBCPP_USE_WCHAR_T
868 numpunct
<wchar_t>::_M_initialize_numpunct(__c_locale __cloc
);
872 template<typename _CharT
>
873 class numpunct_byname
: public numpunct
<_CharT
>
875 __c_locale _M_c_locale_numpunct
;
877 typedef _CharT char_type
;
878 typedef basic_string
<_CharT
> string_type
;
881 numpunct_byname(const char* __s
, size_t __refs
= 0)
882 : numpunct
<_CharT
>(__refs
)
884 _S_create_c_locale(_M_c_locale_numpunct
, __s
);
885 _M_initialize_numpunct(_M_c_locale_numpunct
);
891 { _S_destroy_c_locale(_M_c_locale_numpunct
); }
895 template<typename _CharT
>
896 class collate
: public locale::facet
900 typedef _CharT char_type
;
901 typedef basic_string
<_CharT
> string_type
;
903 static locale::id id
;
906 collate(size_t __refs
= 0) : locale::facet(__refs
) { }
909 compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
910 const _CharT
* __lo2
, const _CharT
* __hi2
) const
911 { return this->do_compare(__lo1
, __hi1
, __lo2
, __hi2
); }
914 transform(const _CharT
* __lo
, const _CharT
* __hi
) const
915 { return this->do_transform(__lo
, __hi
); }
918 hash(const _CharT
* __lo
, const _CharT
* __hi
) const
919 { return this->do_hash(__lo
, __hi
); }
922 ~collate() { } // virtual
925 do_compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
926 const _CharT
* __lo2
, const _CharT
* __hi2
) const;
929 do_transform(const _CharT
* __lo
, const _CharT
* __hi
) const;
932 do_hash(const _CharT
* __lo
, const _CharT
* __hi
) const;
935 template<typename _CharT
>
936 locale::id collate
<_CharT
>::id
;
938 // Required specializations.
941 collate
<char>::do_compare(const char* __lo1
, const char* __hi1
,
942 const char* __lo2
, const char* __hi2
) const;
946 collate
<char>::do_transform(const char* __lo
, const char* __hi
) const;
950 collate
<char>::do_hash(const char* __lo
, const char* __hi
) const;
951 #ifdef _GLIBCPP_USE_WCHAR_T
954 collate
<wchar_t>::do_compare(const wchar_t* __lo1
, const wchar_t* __hi1
,
955 const wchar_t* __lo2
,
956 const wchar_t* __hi2
) const;
960 collate
<wchar_t>::do_transform(const wchar_t* __lo
,
961 const wchar_t* __hi
) const;
965 collate
<wchar_t>::do_hash(const wchar_t* __lo
, const wchar_t* __hi
) const;
968 template<typename _CharT
>
969 class collate_byname
: public collate
<_CharT
>
973 typedef _CharT char_type
;
974 typedef basic_string
<_CharT
> string_type
;
977 collate_byname(const char*, size_t __refs
= 0);
981 ~collate_byname() { }
985 collate_byname
<char>::collate_byname(const char*, size_t __refs
);
986 #ifdef _GLIBCPP_USE_WCHAR_T
988 collate_byname
<wchar_t>::collate_byname(const char*, size_t __refs
);
994 enum dateorder
{ no_order
, dmy
, mdy
, ymd
, ydm
};
997 template<typename _CharT
, typename _InIter
>
998 class time_get
: public locale::facet
, public time_base
1002 typedef _CharT char_type
;
1003 typedef _InIter iter_type
;
1005 static locale::id id
;
1008 time_get(size_t __refs
= 0)
1009 : locale::facet (__refs
), _M_daynames(0), _M_monthnames(0) { }
1013 { return do_date_order(); }
1016 get_time(iter_type __s
, iter_type __end
, ios_base
& __f
,
1017 ios_base::iostate
& __err
, tm
* __t
) const
1018 { return do_get_time(__s
, __end
, __f
, __err
, __t
); }
1021 get_date(iter_type __s
, iter_type __end
, ios_base
& __f
,
1022 ios_base::iostate
& __err
, tm
* __t
) const
1023 { return do_get_date(__s
, __end
, __f
, __err
, __t
); }
1026 get_weekday(iter_type __s
, iter_type __end
, ios_base
& __f
,
1027 ios_base::iostate
& __err
, tm
* __t
) const
1028 { return do_get_weekday(__s
,__end
,__f
,__err
,__t
); }
1031 get_monthname(iter_type __s
, iter_type __end
, ios_base
& __f
,
1032 ios_base::iostate
& __err
, tm
* __t
) const
1033 { return do_get_monthname(__s
,__end
,__f
,__err
,__t
); }
1036 get_year(iter_type __s
, iter_type __end
, ios_base
& __f
,
1037 ios_base::iostate
& __err
, tm
* __t
) const
1038 { return do_get_year(__s
,__end
,__f
,__err
,__t
); }
1044 delete [] _M_monthnames
;
1045 delete [] _M_daynames
;
1049 do_date_order() const
1050 { return time_base::ymd
; }
1053 do_get_time(iter_type __s
, iter_type
/*__end*/, ios_base
&,
1054 ios_base::iostate
& /*__err*/, tm
* /*__t*/) const
1058 do_get_date(iter_type __s
, iter_type
/*__end*/, ios_base
&,
1059 ios_base::iostate
& /*__err*/, tm
* /*__t*/) const
1063 do_get_weekday(iter_type __s
, iter_type __end
, ios_base
&,
1064 ios_base::iostate
& __err
, tm
* __t
) const;
1067 do_get_monthname(iter_type __s
, iter_type __end
, ios_base
&,
1068 ios_base::iostate
& __err
, tm
* __t
) const;
1071 do_get_year(iter_type __s
, iter_type
/*__end*/, ios_base
&,
1072 ios_base::iostate
& /*__err*/, tm
* /*__t*/) const
1075 mutable basic_string
<_CharT
>* _M_daynames
;
1076 mutable basic_string
<_CharT
>* _M_monthnames
;
1079 template<typename _CharT
, typename _InIter
>
1080 locale::id time_get
<_CharT
, _InIter
>::id
;
1082 template<typename _CharT
, typename _InIter
>
1083 class time_get_byname
: public time_get
<_CharT
, _InIter
>
1086 typedef _CharT char_type
;
1087 typedef _InIter iter_type
;
1090 time_get_byname(const char*, size_t __refs
= 0)
1091 : time_get
<_CharT
, _InIter
>(__refs
) { }
1094 ~time_get_byname() { }
1097 template<typename _CharT
, typename _OutIter
>
1098 class time_put
: public locale::facet
, public time_base
1101 typedef _CharT char_type
;
1102 typedef _OutIter iter_type
;
1104 static locale::id id
;
1107 time_put(size_t __refs
= 0) : locale::facet (__refs
) { }
1109 // NB: this is a nonvirtual, calls do_put in a loop.
1111 put(iter_type __s
, ios_base
& /*__f*/, char_type
/*__fill*/,
1112 const tm
* /*__tmb*/, const _CharT
* /*__pattern*/,
1113 const _CharT
* /*__pat_end*/) const
1117 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
1118 const tm
* __tmb
, char __format
, char __modifier
= 0) const
1119 { return do_put(__s
, __f
, __fill
, __tmb
, __format
, __modifier
); }
1126 do_put(iter_type __s
, ios_base
&, char_type
, const tm
* /*__t*/,
1127 char /*__format*/, char /*__mod*/) const
1131 template<typename _CharT
, typename _OutIter
>
1132 locale::id time_put
<_CharT
, _OutIter
>::id
;
1134 template<typename _CharT
, typename _OutIter
>
1135 class time_put_byname
: public time_put
<_CharT
, _OutIter
>
1138 typedef _CharT char_type
;
1139 typedef _OutIter iter_type
;
1142 time_put_byname(const char*, size_t __refs
= 0)
1143 : time_put
<_CharT
, _OutIter
> (__refs
) { }
1147 ~time_put_byname() { }
1151 template<typename _CharT
, typename _InIter
>
1152 class money_get
: public locale::facet
1155 typedef _CharT char_type
;
1156 typedef _InIter iter_type
;
1157 typedef basic_string
<_CharT
> string_type
;
1159 static locale::id id
;
1162 money_get(size_t __refs
= 0) : locale::facet(__refs
) { }
1165 get(iter_type __s
, iter_type __end
, bool __intl
,
1166 ios_base
& __f
, ios_base::iostate
& __err
, long double& __units
) const
1167 { return do_get(__s
, __end
, __intl
, __f
, __err
, __units
); }
1170 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __f
,
1171 ios_base::iostate
& __err
, string_type
& __digits
) const
1172 { return do_get(__s
, __end
, __intl
, __f
, __err
, __digits
); }
1179 do_get(iter_type __s
, iter_type
/*__end*/, bool /*__intl*/,
1180 ios_base
& /*__io*/, ios_base::iostate
& /*__err*/,
1181 long double& /*__units*/) const
1185 do_get(iter_type __s
, iter_type
/*__end*/, bool /*__intl*/,
1186 ios_base
& /*__io*/, ios_base::iostate
& /*__err*/,
1187 string_type
& /*__digits*/) const
1191 template<typename _CharT
, typename _InIter
>
1192 locale::id money_get
<_CharT
, _InIter
>::id
;
1194 template<typename _CharT
, typename _OutIter
>
1195 class money_put
: public locale::facet
1198 typedef _CharT char_type
;
1199 typedef _OutIter iter_type
;
1200 typedef basic_string
<_CharT
> string_type
;
1202 static locale::id id
;
1205 money_put(size_t __refs
= 0) : locale::facet(__refs
) { }
1208 put(iter_type __s
, bool __intl
, ios_base
& __f
,
1209 char_type __fill
, long double __units
) const
1210 { return do_put(__s
, __intl
, __f
, __fill
, __units
); }
1213 put(iter_type __s
, bool __intl
, ios_base
& __f
,
1214 char_type __fill
, const string_type
& __digits
) const
1215 { return do_put(__s
, __intl
, __f
, __fill
, __digits
); }
1222 do_put(iter_type __s
, bool, ios_base
& /*__io*/, char_type
/*__fill*/,
1223 long double /*__units*/) const
1227 do_put(iter_type __s
, bool, ios_base
& /*__io*/, char_type
/*__fill*/,
1228 const string_type
& /*__digits*/) const
1232 template<typename _CharT
, typename _OutIter
>
1233 locale::id money_put
<_CharT
, _OutIter
>::id
;
1237 enum part
{ none
, space
, symbol
, sign
, value
};
1238 struct pattern
{ char field
[4]; };
1240 static const pattern _S_default_pattern
;
1242 // Construct and return valid pattern consisting of some combination of:
1243 // space none symbol sign value
1245 _S_construct_pattern(char __preceeds
, char __space
, char __posn
);
1248 template<typename _CharT
, bool _Intl
>
1249 class moneypunct
: public locale::facet
, public money_base
1253 typedef _CharT char_type
;
1254 typedef basic_string
<_CharT
> string_type
;
1256 static const bool intl
= _Intl
;
1257 static locale::id id
;
1260 char_type _M_decimal_point
;
1261 char_type _M_thousands_sep
;
1263 string_type _M_curr_symbol
;
1264 string_type _M_positive_sign
;
1265 string_type _M_negative_sign
;
1267 pattern _M_pos_format
;
1268 pattern _M_neg_format
;
1272 moneypunct(size_t __refs
= 0) : locale::facet(__refs
)
1273 { _M_initialize_moneypunct(); }
1276 moneypunct(__c_locale __cloc
, size_t __refs
= 0) : locale::facet(__refs
)
1277 { _M_initialize_moneypunct(__cloc
); }
1280 decimal_point() const
1281 { return this->do_decimal_point(); }
1284 thousands_sep() const
1285 { return this->do_thousands_sep(); }
1289 { return this->do_grouping(); }
1293 { return this->do_curr_symbol(); }
1296 positive_sign() const
1297 { return this->do_positive_sign(); }
1300 negative_sign() const
1301 { return this->do_negative_sign(); }
1305 { return this->do_frac_digits(); }
1309 { return this->do_pos_format(); }
1313 { return this->do_neg_format(); }
1320 do_decimal_point() const
1321 { return _M_decimal_point
; }
1324 do_thousands_sep() const
1325 { return _M_thousands_sep
; }
1329 { return _M_grouping
; }
1332 do_curr_symbol() const
1333 { return _M_curr_symbol
; }
1336 do_positive_sign() const
1337 { return _M_positive_sign
; }
1340 do_negative_sign() const
1341 { return _M_negative_sign
; }
1344 do_frac_digits() const
1345 { return _M_frac_digits
; }
1348 do_pos_format() const
1349 { return _M_pos_format
; }
1352 do_neg_format() const
1353 { return _M_neg_format
; }
1355 // For use at construction time only.
1357 _M_initialize_moneypunct(__c_locale __cloc
= NULL
);
1360 template<typename _CharT
, bool _Intl
>
1361 locale::id moneypunct
<_CharT
, _Intl
>::id
;
1363 template<typename _CharT
, bool _Intl
>
1364 const bool moneypunct
<_CharT
, _Intl
>::intl
;
1366 template<typename _CharT
, bool _Intl
>
1368 moneypunct
<_CharT
, _Intl
>::_M_initialize_moneypunct(__c_locale
/*__cloc*/)
1370 // NB: Cannot be made generic.
1375 moneypunct
<char>::_M_initialize_moneypunct(__c_locale __cloc
);
1376 #ifdef _GLIBCPP_USE_WCHAR_T
1379 moneypunct
<wchar_t>::_M_initialize_moneypunct(__c_locale __cloc
);
1382 template<typename _CharT
, bool _Intl
>
1383 class moneypunct_byname
: public moneypunct
<_CharT
, _Intl
>
1385 __c_locale _M_c_locale_moneypunct
;
1387 typedef _CharT char_type
;
1388 typedef basic_string
<_CharT
> string_type
;
1390 static const bool intl
= _Intl
;
1393 moneypunct_byname(const char* __s
, size_t __refs
= 0)
1394 : moneypunct
<_CharT
, _Intl
>(__refs
)
1396 _S_create_c_locale(_M_c_locale_moneypunct
, __s
);
1397 _M_initialize_moneypunct(_M_c_locale_moneypunct
);
1402 ~moneypunct_byname()
1403 { _S_destroy_c_locale(_M_c_locale_moneypunct
); }
1406 template<typename _CharT
, bool _Intl
>
1407 const bool moneypunct_byname
<_CharT
, _Intl
>::intl
;
1410 struct messages_base
1412 typedef int catalog
;
1415 template<typename _CharT
>
1416 class messages
: public locale::facet
, public messages_base
1419 typedef _CharT char_type
;
1420 typedef basic_string
<_CharT
> string_type
;
1422 static locale::id id
;
1425 messages(size_t __refs
= 0) : locale::facet(__refs
) { }
1428 open(const basic_string
<char>& __s
, const locale
& __loc
) const
1429 { return do_open(__s
, __loc
); }
1432 get(catalog __c
, int __set
, int __msgid
, const string_type
& __s
) const
1433 { return do_get(__c
,__set
,__msgid
,__s
); }
1436 close(catalog __c
) const
1437 { return do_close(__c
); }
1443 // NB: Probably these should be pure, and implemented only in
1444 // specializations of messages<>. But for now...
1446 do_open(const basic_string
<char>&, const locale
&) const
1450 do_get(catalog
, int, int /*__msgid*/, const string_type
& __dfault
) const
1451 { return __dfault
; }
1454 do_close(catalog
) const { }
1457 template<typename _CharT
>
1458 locale::id messages
<_CharT
>::id
;
1460 template<typename _CharT
>
1461 class messages_byname
: public messages
<_CharT
>
1464 typedef _CharT char_type
;
1465 typedef basic_string
<_CharT
> string_type
;
1468 messages_byname(const char*, size_t __refs
= 0);
1472 ~messages_byname() { }
1476 messages_byname
<char>::messages_byname(const char*, size_t __refs
);
1477 #ifdef _GLIBCPP_USE_WCHAR_T
1479 messages_byname
<wchar_t>::messages_byname(const char*, size_t __refs
);
1482 // Subclause convenience interfaces, inlines
1483 // NB: these are inline
1484 // because, when used in a loop, some compilers can hoist the body
1485 // out of the loop; then it's just as fast as the C is*() function.
1486 template<typename _CharT
>
1488 isspace(_CharT __c
, const locale
& __loc
)
1489 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::space
, __c
); }
1491 template<typename _CharT
>
1493 isprint(_CharT __c
, const locale
& __loc
)
1494 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::print
, __c
); }
1496 template<typename _CharT
>
1498 iscntrl(_CharT __c
, const locale
& __loc
)
1499 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::cntrl
, __c
); }
1501 template<typename _CharT
>
1503 isupper(_CharT __c
, const locale
& __loc
)
1504 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::upper
, __c
); }
1506 template<typename _CharT
>
1507 inline bool islower(_CharT __c
, const locale
& __loc
)
1508 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::lower
, __c
); }
1510 template<typename _CharT
>
1512 isalpha(_CharT __c
, const locale
& __loc
)
1513 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alpha
, __c
); }
1515 template<typename _CharT
>
1517 isdigit(_CharT __c
, const locale
& __loc
)
1518 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::digit
, __c
); }
1520 template<typename _CharT
>
1522 ispunct(_CharT __c
, const locale
& __loc
)
1523 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::punct
, __c
); }
1525 template<typename _CharT
>
1527 isxdigit(_CharT __c
, const locale
& __loc
)
1528 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::xdigit
, __c
); }
1530 template<typename _CharT
>
1532 isalnum(_CharT __c
, const locale
& __loc
)
1533 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alnum
, __c
); }
1535 template<typename _CharT
>
1537 isgraph(_CharT __c
, const locale
& __loc
)
1538 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::graph
, __c
); }
1540 template<typename _CharT
>
1542 toupper(_CharT __c
, const locale
& __loc
)
1543 { return use_facet
<ctype
<_CharT
> >(__loc
).toupper(__c
); }
1545 template<typename _CharT
>
1547 tolower(_CharT __c
, const locale
& __loc
)
1548 { return use_facet
<ctype
<_CharT
> >(__loc
).tolower(__c
); }
1551 #endif /* _CPP_BITS_LOCFACETS_H */