1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 22.1 Locales
35 /** @file locale_facets.h
36 * This is an internal header file, included by other library headers.
37 * You should not attempt to use it directly.
40 #ifndef _LOCALE_FACETS_H
41 #define _LOCALE_FACETS_H 1
43 #pragma GCC system_header
45 #include <ctime> // For struct tm
46 #include <cwctype> // For wctype_t
48 #include <bits/ios_base.h> // For ios_base, ios_base::iostate
53 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
54 #ifdef _GLIBCXX_USE_WCHAR_T
55 # define _GLIBCXX_NUM_FACETS 28
57 # define _GLIBCXX_NUM_FACETS 14
60 // Convert string to numeric value of type _Tv and store results.
61 // NB: This is specialized for all required types, there is no
62 // generic definition.
63 template<typename _Tv
>
65 __convert_to_v(const char* __in
, _Tv
& __out
, ios_base::iostate
& __err
,
66 const __c_locale
& __cloc
);
68 // Explicit specializations for required types.
71 __convert_to_v(const char*, float&, ios_base::iostate
&,
76 __convert_to_v(const char*, double&, ios_base::iostate
&,
81 __convert_to_v(const char*, long double&, ios_base::iostate
&,
84 // NB: __pad is a struct, rather than a function, so it can be
85 // partially-specialized.
86 template<typename _CharT
, typename _Traits
>
90 _S_pad(ios_base
& __io
, _CharT __fill
, _CharT
* __news
,
91 const _CharT
* __olds
, const streamsize __newlen
,
92 const streamsize __oldlen
, const bool __num
);
95 // Used by both numeric and monetary facets.
96 // Inserts "group separator" characters into an array of characters.
97 // It's recursive, one iteration per group. It moves the characters
98 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
99 // only with __glen != 0.
100 template<typename _CharT
>
102 __add_grouping(_CharT
* __s
, _CharT __sep
,
103 const char* __gbeg
, size_t __gsize
,
104 const _CharT
* __first
, const _CharT
* __last
);
106 // This template permits specializing facet output code for
107 // ostreambuf_iterator. For ostreambuf_iterator, sputn is
108 // significantly more efficient than incrementing iterators.
109 template<typename _CharT
>
111 ostreambuf_iterator
<_CharT
>
112 __write(ostreambuf_iterator
<_CharT
> __s
, const _CharT
* __ws
, int __len
)
114 __s
._M_put(__ws
, __len
);
118 // This is the unspecialized form of the template.
119 template<typename _CharT
, typename _OutIter
>
122 __write(_OutIter __s
, const _CharT
* __ws
, int __len
)
124 for (int __j
= 0; __j
< __len
; __j
++, ++__s
)
130 // 22.2.1.1 Template class ctype
131 // Include host and configuration specific ctype enums for ctype_base.
132 #include <bits/ctype_base.h>
134 // Common base for ctype<_CharT>.
136 * @brief Common base for ctype facet
138 * This template class provides implementations of the public functions
139 * that forward to the protected virtual functions.
141 * This template also provides abtract stubs for the protected virtual
144 template<typename _CharT
>
145 class __ctype_abstract_base
: public locale::facet
, public ctype_base
149 /// Typedef for the template parameter
150 typedef _CharT char_type
;
153 * @brief Test char_type classification.
155 * This function finds a mask M for @a c and compares it to mask @a m.
156 * It does so by returning the value of ctype<char_type>::do_is().
158 * @param c The char_type to compare the mask of.
159 * @param m The mask to compare against.
160 * @return (M & m) != 0.
163 is(mask __m
, char_type __c
) const
164 { return this->do_is(__m
, __c
); }
167 * @brief Return a mask array.
169 * This function finds the mask for each char_type in the range [lo,hi)
170 * and successively writes it to vec. vec must have as many elements
171 * as the char array. It does so by returning the value of
172 * ctype<char_type>::do_is().
174 * @param lo Pointer to start of range.
175 * @param hi Pointer to end of range.
176 * @param vec Pointer to an array of mask storage.
180 is(const char_type
*__lo
, const char_type
*__hi
, mask
*__vec
) const
181 { return this->do_is(__lo
, __hi
, __vec
); }
184 * @brief Find char_type matching a mask
186 * This function searches for and returns the first char_type c in
187 * [lo,hi) for which is(m,c) is true. It does so by returning
188 * ctype<char_type>::do_scan_is().
190 * @param m The mask to compare against.
191 * @param lo Pointer to start of range.
192 * @param hi Pointer to end of range.
193 * @return Pointer to matching char_type if found, else @a hi.
196 scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
197 { return this->do_scan_is(__m
, __lo
, __hi
); }
200 * @brief Find char_type not matching a mask
202 * This function searches for and returns the first char_type c in
203 * [lo,hi) for which is(m,c) is false. It does so by returning
204 * ctype<char_type>::do_scan_not().
206 * @param m The mask to compare against.
207 * @param lo Pointer to first char in range.
208 * @param hi Pointer to end of range.
209 * @return Pointer to non-matching char if found, else @a hi.
212 scan_not(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
213 { return this->do_scan_not(__m
, __lo
, __hi
); }
216 * @brief Convert to uppercase.
218 * This function converts the argument to uppercase if possible.
219 * If not possible (for example, '2'), returns the argument. It does
220 * so by returning ctype<char_type>::do_toupper().
222 * @param c The char_type to convert.
223 * @return The uppercase char_type if convertible, else @a c.
226 toupper(char_type __c
) const
227 { return this->do_toupper(__c
); }
230 * @brief Convert array to uppercase.
232 * This function converts each char_type in the range [lo,hi) to
233 * uppercase if possible. Other elements remain untouched. It does so
234 * by returning ctype<char_type>:: do_toupper(lo, hi).
236 * @param lo Pointer to start of range.
237 * @param hi Pointer to end of range.
241 toupper(char_type
*__lo
, const char_type
* __hi
) const
242 { return this->do_toupper(__lo
, __hi
); }
245 * @brief Convert to lowercase.
247 * This function converts the argument to lowercase if possible. If
248 * not possible (for example, '2'), returns the argument. It does so
249 * by returning ctype<char_type>::do_tolower(c).
251 * @param c The char_type to convert.
252 * @return The lowercase char_type if convertible, else @a c.
255 tolower(char_type __c
) const
256 { return this->do_tolower(__c
); }
259 * @brief Convert array to lowercase.
261 * This function converts each char_type in the range [lo,hi) to
262 * lowercase if possible. Other elements remain untouched. It does so
263 * by returning ctype<char_type>:: do_tolower(lo, hi).
265 * @param lo Pointer to start of range.
266 * @param hi Pointer to end of range.
270 tolower(char_type
* __lo
, const char_type
* __hi
) const
271 { return this->do_tolower(__lo
, __hi
); }
274 * @brief Widen char to char_type
276 * This function converts the char argument to char_type using the
277 * simplest reasonable transformation. It does so by returning
278 * ctype<char_type>::do_widen(c).
280 * Note: this is not what you want for codepage conversions. See
283 * @param c The char to convert.
284 * @return The converted char_type.
287 widen(char __c
) const
288 { return this->do_widen(__c
); }
291 * @brief Widen array to char_type
293 * This function converts each char in the input to char_type using the
294 * simplest reasonable transformation. It does so by returning
295 * ctype<char_type>::do_widen(c).
297 * Note: this is not what you want for codepage conversions. See
300 * @param lo Pointer to start of range.
301 * @param hi Pointer to end of range.
302 * @param to Pointer to the destination array.
306 widen(const char* __lo
, const char* __hi
, char_type
* __to
) const
307 { return this->do_widen(__lo
, __hi
, __to
); }
310 * @brief Narrow char_type to char
312 * This function converts the char_type to char using the simplest
313 * reasonable transformation. If the conversion fails, dfault is
314 * returned instead. It does so by returning
315 * ctype<char_type>::do_narrow(c).
317 * Note: this is not what you want for codepage conversions. See
320 * @param c The char_type to convert.
321 * @param dfault Char to return if conversion fails.
322 * @return The converted char.
325 narrow(char_type __c
, char __dfault
) const
326 { return this->do_narrow(__c
, __dfault
); }
329 * @brief Narrow array to char array
331 * This function converts each char_type in the input to char using the
332 * simplest reasonable transformation and writes the results to the
333 * destination array. For any char_type in the input that cannot be
334 * converted, @a dfault is used instead. It does so by returning
335 * ctype<char_type>::do_narrow(lo, hi, dfault, to).
337 * Note: this is not what you want for codepage conversions. See
340 * @param lo Pointer to start of range.
341 * @param hi Pointer to end of range.
342 * @param dfault Char to use if conversion fails.
343 * @param to Pointer to the destination array.
347 narrow(const char_type
* __lo
, const char_type
* __hi
,
348 char __dfault
, char *__to
) const
349 { return this->do_narrow(__lo
, __hi
, __dfault
, __to
); }
353 __ctype_abstract_base(size_t __refs
= 0): facet(__refs
) { }
356 ~__ctype_abstract_base() { }
359 * @brief Test char_type classification.
361 * This function finds a mask M for @a c and compares it to mask @a m.
363 * do_is() is a hook for a derived facet to change the behavior of
364 * classifying. do_is() must always return the same result for the
367 * @param c The char_type to find the mask of.
368 * @param m The mask to compare against.
369 * @return (M & m) != 0.
372 do_is(mask __m
, char_type __c
) const = 0;
375 * @brief Return a mask array.
377 * This function finds the mask for each char_type in the range [lo,hi)
378 * and successively writes it to vec. vec must have as many elements
381 * do_is() is a hook for a derived facet to change the behavior of
382 * classifying. do_is() must always return the same result for the
385 * @param lo Pointer to start of range.
386 * @param hi Pointer to end of range.
387 * @param vec Pointer to an array of mask storage.
390 virtual const char_type
*
391 do_is(const char_type
* __lo
, const char_type
* __hi
,
392 mask
* __vec
) const = 0;
395 * @brief Find char_type matching mask
397 * This function searches for and returns the first char_type c in
398 * [lo,hi) for which is(m,c) is true.
400 * do_scan_is() is a hook for a derived facet to change the behavior of
401 * match searching. do_is() must always return the same result for the
404 * @param m The mask to compare against.
405 * @param lo Pointer to start of range.
406 * @param hi Pointer to end of range.
407 * @return Pointer to a matching char_type if found, else @a hi.
409 virtual const char_type
*
410 do_scan_is(mask __m
, const char_type
* __lo
,
411 const char_type
* __hi
) const = 0;
414 * @brief Find char_type not matching mask
416 * This function searches for and returns a pointer to the first
417 * char_type c of [lo,hi) for which is(m,c) is false.
419 * do_scan_is() is a hook for a derived facet to change the behavior of
420 * match searching. do_is() must always return the same result for the
423 * @param m The mask to compare against.
424 * @param lo Pointer to start of range.
425 * @param hi Pointer to end of range.
426 * @return Pointer to a non-matching char_type if found, else @a hi.
428 virtual const char_type
*
429 do_scan_not(mask __m
, const char_type
* __lo
,
430 const char_type
* __hi
) const = 0;
433 * @brief Convert to uppercase.
435 * This virtual function converts the char_type argument to uppercase
436 * if possible. If not possible (for example, '2'), returns the
439 * do_toupper() is a hook for a derived facet to change the behavior of
440 * uppercasing. do_toupper() must always return the same result for
443 * @param c The char_type to convert.
444 * @return The uppercase char_type if convertible, else @a c.
447 do_toupper(char_type
) const = 0;
450 * @brief Convert array to uppercase.
452 * This virtual function converts each char_type in the range [lo,hi)
453 * to uppercase if possible. Other elements remain untouched.
455 * do_toupper() is a hook for a derived facet to change the behavior of
456 * uppercasing. do_toupper() must always return the same result for
459 * @param lo Pointer to start of range.
460 * @param hi Pointer to end of range.
463 virtual const char_type
*
464 do_toupper(char_type
* __lo
, const char_type
* __hi
) const = 0;
467 * @brief Convert to lowercase.
469 * This virtual function converts the argument to lowercase if
470 * possible. If not possible (for example, '2'), returns the argument.
472 * do_tolower() is a hook for a derived facet to change the behavior of
473 * lowercasing. do_tolower() must always return the same result for
476 * @param c The char_type to convert.
477 * @return The lowercase char_type if convertible, else @a c.
480 do_tolower(char_type
) const = 0;
483 * @brief Convert array to lowercase.
485 * This virtual function converts each char_type in the range [lo,hi)
486 * to lowercase if possible. Other elements remain untouched.
488 * do_tolower() is a hook for a derived facet to change the behavior of
489 * lowercasing. do_tolower() must always return the same result for
492 * @param lo Pointer to start of range.
493 * @param hi Pointer to end of range.
496 virtual const char_type
*
497 do_tolower(char_type
* __lo
, const char_type
* __hi
) const = 0;
502 * This virtual function converts the char to char_type using the
503 * simplest reasonable transformation.
505 * do_widen() is a hook for a derived facet to change the behavior of
506 * widening. do_widen() must always return the same result for the
509 * Note: this is not what you want for codepage conversions. See
512 * @param c The char to convert.
513 * @return The converted char_type
516 do_widen(char) const = 0;
519 * @brief Widen char array
521 * This function converts each char in the input to char_type using the
522 * simplest reasonable transformation.
524 * do_widen() is a hook for a derived facet to change the behavior of
525 * widening. do_widen() must always return the same result for the
528 * Note: this is not what you want for codepage conversions. See
531 * @param lo Pointer to start range.
532 * @param hi Pointer to end of range.
533 * @param to Pointer to the destination array.
537 do_widen(const char* __lo
, const char* __hi
,
538 char_type
* __dest
) const = 0;
541 * @brief Narrow char_type to char
543 * This virtual function converts the argument to char using the
544 * simplest reasonable transformation. If the conversion fails, dfault
545 * is returned instead.
547 * do_narrow() is a hook for a derived facet to change the behavior of
548 * narrowing. do_narrow() must always return the same result for the
551 * Note: this is not what you want for codepage conversions. See
554 * @param c The char_type to convert.
555 * @param dfault Char to return if conversion fails.
556 * @return The converted char.
559 do_narrow(char_type
, char __dfault
) const = 0;
562 * @brief Narrow char_type array to char
564 * This virtual function converts each char_type in the range [lo,hi) to
565 * char using the simplest reasonable transformation and writes the
566 * results to the destination array. For any element in the input that
567 * cannot be converted, @a dfault is used instead.
569 * do_narrow() is a hook for a derived facet to change the behavior of
570 * narrowing. do_narrow() must always return the same result for the
573 * Note: this is not what you want for codepage conversions. See
576 * @param lo Pointer to start of range.
577 * @param hi Pointer to end of range.
578 * @param dfault Char to use if conversion fails.
579 * @param to Pointer to the destination array.
582 virtual const char_type
*
583 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
584 char __dfault
, char* __dest
) const = 0;
587 // NB: Generic, mostly useless implementation.
589 * @brief Template ctype facet
591 * This template class defines classification and conversion functions for
592 * character sets. It wraps <cctype> functionality. Ctype gets used by
593 * streams for many I/O operations.
595 * This template provides the protected virtual functions the developer
596 * will have to replace in a derived class or specialization to make a
597 * working facet. The public functions that access them are defined in
598 * __ctype_abstract_base, to allow for implementation flexibility. See
599 * ctype<wchar_t> for an example. The functions are documented in
600 * __ctype_abstract_base.
602 * Note: implementations are provided for all the protected virtual
603 * functions, but will likely not be useful.
605 template<typename _CharT
>
606 class ctype
: public __ctype_abstract_base
<_CharT
>
610 typedef _CharT char_type
;
611 typedef typename __ctype_abstract_base
<_CharT
>::mask mask
;
613 /// The facet id for ctype<char_type>
614 static locale::id id
;
617 ctype(size_t __refs
= 0) : __ctype_abstract_base
<_CharT
>(__refs
) { }
624 do_is(mask __m
, char_type __c
) const;
626 virtual const char_type
*
627 do_is(const char_type
* __lo
, const char_type
* __hi
, mask
* __vec
) const;
629 virtual const char_type
*
630 do_scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const;
632 virtual const char_type
*
633 do_scan_not(mask __m
, const char_type
* __lo
,
634 const char_type
* __hi
) const;
637 do_toupper(char_type __c
) const;
639 virtual const char_type
*
640 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
643 do_tolower(char_type __c
) const;
645 virtual const char_type
*
646 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
649 do_widen(char __c
) const;
652 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const;
655 do_narrow(char_type
, char __dfault
) const;
657 virtual const char_type
*
658 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
659 char __dfault
, char* __dest
) const;
662 template<typename _CharT
>
663 locale::id ctype
<_CharT
>::id
;
665 // 22.2.1.3 ctype<char> specialization.
667 * @brief The ctype<char> specialization.
669 * This class defines classification and conversion functions for
670 * the char type. It gets used by char streams for many I/O
671 * operations. The char specialization provides a number of
672 * optimizations as well.
675 class ctype
<char> : public locale::facet
, public ctype_base
679 /// Typedef for the template parameter char.
680 typedef char char_type
;
684 __c_locale _M_c_locale_ctype
;
686 __to_type _M_toupper
;
687 __to_type _M_tolower
;
688 const mask
* _M_table
;
689 mutable char _M_widen_ok
;
690 mutable char _M_widen
[1 + static_cast<unsigned char>(-1)];
691 mutable char _M_narrow
[1 + static_cast<unsigned char>(-1)];
692 mutable char _M_narrow_ok
; // 0 uninitialized, 1 init,
696 /// The facet id for ctype<char>
697 static locale::id id
;
698 /// The size of the mask table. It is SCHAR_MAX + 1.
699 static const size_t table_size
= 1 + static_cast<unsigned char>(-1);
702 * @brief Constructor performs initialization.
704 * This is the constructor provided by the standard.
706 * @param table If non-zero, table is used as the per-char mask.
707 * Else classic_table() is used.
708 * @param del If true, passes ownership of table to this facet.
709 * @param refs Passed to the base facet class.
712 ctype(const mask
* __table
= 0, bool __del
= false, size_t __refs
= 0);
715 * @brief Constructor performs static initialization.
717 * This constructor is used to construct the initial C locale facet.
719 * @param cloc Handle to C locale data.
720 * @param table If non-zero, table is used as the per-char mask.
721 * @param del If true, passes ownership of table to this facet.
722 * @param refs Passed to the base facet class.
725 ctype(__c_locale __cloc
, const mask
* __table
= 0, bool __del
= false,
729 * @brief Test char classification.
731 * This function compares the mask table[c] to @a m.
733 * @param c The char to compare the mask of.
734 * @param m The mask to compare against.
735 * @return True if m & table[c] is true, false otherwise.
738 is(mask __m
, char __c
) const;
741 * @brief Return a mask array.
743 * This function finds the mask for each char in the range [lo, hi) and
744 * successively writes it to vec. vec must have as many elements as
747 * @param lo Pointer to start of range.
748 * @param hi Pointer to end of range.
749 * @param vec Pointer to an array of mask storage.
753 is(const char* __lo
, const char* __hi
, mask
* __vec
) const;
756 * @brief Find char matching a mask
758 * This function searches for and returns the first char in [lo,hi) for
759 * which is(m,char) is true.
761 * @param m The mask to compare against.
762 * @param lo Pointer to start of range.
763 * @param hi Pointer to end of range.
764 * @return Pointer to a matching char if found, else @a hi.
767 scan_is(mask __m
, const char* __lo
, const char* __hi
) const;
770 * @brief Find char not matching a mask
772 * This function searches for and returns a pointer to the first char
773 * in [lo,hi) for which is(m,char) is false.
775 * @param m The mask to compare against.
776 * @param lo Pointer to start of range.
777 * @param hi Pointer to end of range.
778 * @return Pointer to a non-matching char if found, else @a hi.
781 scan_not(mask __m
, const char* __lo
, const char* __hi
) const;
784 * @brief Convert to uppercase.
786 * This function converts the char argument to uppercase if possible.
787 * If not possible (for example, '2'), returns the argument.
789 * toupper() acts as if it returns ctype<char>::do_toupper(c).
790 * do_toupper() must always return the same result for the same input.
792 * @param c The char to convert.
793 * @return The uppercase char if convertible, else @a c.
796 toupper(char_type __c
) const
797 { return this->do_toupper(__c
); }
800 * @brief Convert array to uppercase.
802 * This function converts each char in the range [lo,hi) to uppercase
803 * if possible. Other chars remain untouched.
805 * toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi).
806 * do_toupper() must always return the same result for the same input.
808 * @param lo Pointer to first char in range.
809 * @param hi Pointer to end of range.
813 toupper(char_type
*__lo
, const char_type
* __hi
) const
814 { return this->do_toupper(__lo
, __hi
); }
817 * @brief Convert to lowercase.
819 * This function converts the char argument to lowercase if possible.
820 * If not possible (for example, '2'), returns the argument.
822 * tolower() acts as if it returns ctype<char>::do_tolower(c).
823 * do_tolower() must always return the same result for the same input.
825 * @param c The char to convert.
826 * @return The lowercase char if convertible, else @a c.
829 tolower(char_type __c
) const
830 { return this->do_tolower(__c
); }
833 * @brief Convert array to lowercase.
835 * This function converts each char in the range [lo,hi) to lowercase
836 * if possible. Other chars remain untouched.
838 * tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi).
839 * do_tolower() must always return the same result for the same input.
841 * @param lo Pointer to first char in range.
842 * @param hi Pointer to end of range.
846 tolower(char_type
* __lo
, const char_type
* __hi
) const
847 { return this->do_tolower(__lo
, __hi
); }
852 * This function converts the char to char_type using the simplest
853 * reasonable transformation. For an underived ctype<char> facet, the
854 * argument will be returned unchanged.
856 * This function works as if it returns ctype<char>::do_widen(c).
857 * do_widen() must always return the same result for the same input.
859 * Note: this is not what you want for codepage conversions. See
862 * @param c The char to convert.
863 * @return The converted character.
866 widen(char __c
) const
868 if (_M_widen_ok
) return _M_widen
[static_cast<unsigned char>(__c
)];
869 this->_M_widen_init();
870 return this->do_widen(__c
);
874 * @brief Widen char array
876 * This function converts each char in the input to char using the
877 * simplest reasonable transformation. For an underived ctype<char>
878 * facet, the argument will be copied unchanged.
880 * This function works as if it returns ctype<char>::do_widen(c).
881 * do_widen() must always return the same result for the same input.
883 * Note: this is not what you want for codepage conversions. See
886 * @param lo Pointer to first char in range.
887 * @param hi Pointer to end of range.
888 * @param to Pointer to the destination array.
892 widen(const char* __lo
, const char* __hi
, char_type
* __to
) const
894 if (_M_widen_ok
== 1)
896 memcpy(__to
, __lo
, __hi
- __lo
);
899 if (!_M_widen_ok
) _M_widen_init();
900 return this->do_widen(__lo
, __hi
, __to
);
906 * This function converts the char to char using the simplest
907 * reasonable transformation. If the conversion fails, dfault is
908 * returned instead. For an underived ctype<char> facet, @a c
909 * will be returned unchanged.
911 * This function works as if it returns ctype<char>::do_narrow(c).
912 * do_narrow() must always return the same result for the same input.
914 * Note: this is not what you want for codepage conversions. See
917 * @param c The char to convert.
918 * @param dfault Char to return if conversion fails.
919 * @return The converted character.
922 narrow(char_type __c
, char __dfault
) const
924 if (_M_narrow
[static_cast<unsigned char>(__c
)])
925 return _M_narrow
[static_cast<unsigned char>(__c
)];
926 const char __t
= do_narrow(__c
, __dfault
);
927 if (__t
!= __dfault
) _M_narrow
[static_cast<unsigned char>(__c
)] = __t
;
932 * @brief Narrow char array
934 * This function converts each char in the input to char using the
935 * simplest reasonable transformation and writes the results to the
936 * destination array. For any char in the input that cannot be
937 * converted, @a dfault is used instead. For an underived ctype<char>
938 * facet, the argument will be copied unchanged.
940 * This function works as if it returns ctype<char>::do_narrow(lo, hi,
941 * dfault, to). do_narrow() must always return the same result for the
944 * Note: this is not what you want for codepage conversions. See
947 * @param lo Pointer to start of range.
948 * @param hi Pointer to end of range.
949 * @param dfault Char to use if conversion fails.
950 * @param to Pointer to the destination array.
954 narrow(const char_type
* __lo
, const char_type
* __hi
,
955 char __dfault
, char *__to
) const
957 if (__builtin_expect(_M_narrow_ok
== 1,true))
959 memcpy(__to
, __lo
, __hi
- __lo
);
964 return this->do_narrow(__lo
, __hi
, __dfault
, __to
);
968 /// Returns a pointer to the mask table provided to the constructor, or
969 /// the default from classic_table() if none was provided.
971 table() const throw()
974 /// Returns a pointer to the C locale mask table.
976 classic_table() throw();
981 * This function deletes table() if @a del was true in the
988 * @brief Convert to uppercase.
990 * This virtual function converts the char argument to uppercase if
991 * possible. If not possible (for example, '2'), returns the argument.
993 * do_toupper() is a hook for a derived facet to change the behavior of
994 * uppercasing. do_toupper() must always return the same result for
997 * @param c The char to convert.
998 * @return The uppercase char if convertible, else @a c.
1001 do_toupper(char_type
) const;
1004 * @brief Convert array to uppercase.
1006 * This virtual function converts each char in the range [lo,hi) to
1007 * uppercase if possible. Other chars remain untouched.
1009 * do_toupper() is a hook for a derived facet to change the behavior of
1010 * uppercasing. do_toupper() must always return the same result for
1013 * @param lo Pointer to start of range.
1014 * @param hi Pointer to end of range.
1017 virtual const char_type
*
1018 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
1021 * @brief Convert to lowercase.
1023 * This virtual function converts the char argument to lowercase if
1024 * possible. If not possible (for example, '2'), returns the argument.
1026 * do_tolower() is a hook for a derived facet to change the behavior of
1027 * lowercasing. do_tolower() must always return the same result for
1030 * @param c The char to convert.
1031 * @return The lowercase char if convertible, else @a c.
1034 do_tolower(char_type
) const;
1037 * @brief Convert array to lowercase.
1039 * This virtual function converts each char in the range [lo,hi) to
1040 * lowercase if possible. Other chars remain untouched.
1042 * do_tolower() is a hook for a derived facet to change the behavior of
1043 * lowercasing. do_tolower() must always return the same result for
1046 * @param lo Pointer to first char in range.
1047 * @param hi Pointer to end of range.
1050 virtual const char_type
*
1051 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
1056 * This virtual function converts the char to char using the simplest
1057 * reasonable transformation. For an underived ctype<char> facet, the
1058 * argument will be returned unchanged.
1060 * do_widen() is a hook for a derived facet to change the behavior of
1061 * widening. do_widen() must always return the same result for the
1064 * Note: this is not what you want for codepage conversions. See
1067 * @param c The char to convert.
1068 * @return The converted character.
1071 do_widen(char __c
) const
1075 * @brief Widen char array
1077 * This function converts each char in the range [lo,hi) to char using
1078 * the simplest reasonable transformation. For an underived
1079 * ctype<char> facet, the argument will be copied unchanged.
1081 * do_widen() is a hook for a derived facet to change the behavior of
1082 * widening. do_widen() must always return the same result for the
1085 * Note: this is not what you want for codepage conversions. See
1088 * @param lo Pointer to start of range.
1089 * @param hi Pointer to end of range.
1090 * @param to Pointer to the destination array.
1094 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const
1096 memcpy(__dest
, __lo
, __hi
- __lo
);
1101 * @brief Narrow char
1103 * This virtual function converts the char to char using the simplest
1104 * reasonable transformation. If the conversion fails, dfault is
1105 * returned instead. For an underived ctype<char> facet, @a c will be
1106 * returned unchanged.
1108 * do_narrow() is a hook for a derived facet to change the behavior of
1109 * narrowing. do_narrow() must always return the same result for the
1112 * Note: this is not what you want for codepage conversions. See
1115 * @param c The char to convert.
1116 * @param dfault Char to return if conversion fails.
1117 * @return The converted char.
1120 do_narrow(char_type __c
, char) const
1124 * @brief Narrow char array to char array
1126 * This virtual function converts each char in the range [lo,hi) to
1127 * char using the simplest reasonable transformation and writes the
1128 * results to the destination array. For any char in the input that
1129 * cannot be converted, @a dfault is used instead. For an underived
1130 * ctype<char> facet, the argument will be copied unchanged.
1132 * do_narrow() is a hook for a derived facet to change the behavior of
1133 * narrowing. do_narrow() must always return the same result for the
1136 * Note: this is not what you want for codepage conversions. See
1139 * @param lo Pointer to start of range.
1140 * @param hi Pointer to end of range.
1141 * @param dfault Char to use if conversion fails.
1142 * @param to Pointer to the destination array.
1145 virtual const char_type
*
1146 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
1147 char, char* __dest
) const
1149 memcpy(__dest
, __lo
, __hi
- __lo
);
1155 void _M_widen_init() const
1157 char __tmp
[sizeof(_M_widen
)];
1158 for (size_t __i
= 0; __i
< sizeof(_M_widen
); ++__i
)
1160 do_widen(__tmp
, __tmp
+ sizeof(__tmp
), _M_widen
);
1163 // Set _M_widen_ok to 2 if memcpy can't be used.
1164 for (size_t __i
= 0; __i
< sizeof(_M_widen
); ++__i
)
1165 if (__tmp
[__i
] != _M_widen
[__i
])
1172 // Fill in the narrowing cache and flag whether all values are
1173 // valid or not. _M_narrow_ok is set to 1 if the whole table is
1174 // narrowed, 2 if only some values could be narrowed.
1175 void _M_narrow_init() const
1177 char __tmp
[sizeof(_M_narrow
)];
1178 for (size_t __i
= 0; __i
< sizeof(_M_narrow
); ++__i
)
1180 do_narrow(__tmp
, __tmp
+ sizeof(__tmp
), 0, _M_narrow
);
1182 // Check if any default values were created. Do this by
1183 // renarrowing with a different default value and comparing.
1184 bool __consecutive
= true;
1185 for (size_t __i
= 0; __i
< sizeof(_M_narrow
); ++__i
)
1186 if (!_M_narrow
[__i
])
1189 do_narrow(__tmp
+ __i
, __tmp
+ __i
+ 1, 1, &__c
);
1192 __consecutive
= false;
1196 _M_narrow_ok
= __consecutive
? 1 : 2;
1202 use_facet
<ctype
<char> >(const locale
& __loc
);
1204 #ifdef _GLIBCXX_USE_WCHAR_T
1205 // 22.2.1.3 ctype<wchar_t> specialization
1207 * @brief The ctype<wchar_t> specialization.
1209 * This class defines classification and conversion functions for the
1210 * wchar_t type. It gets used by wchar_t streams for many I/O operations.
1211 * The wchar_t specialization provides a number of optimizations as well.
1213 * ctype<wchar_t> inherits its public methods from
1214 * __ctype_abstract_base<wchar_t>.
1217 class ctype
<wchar_t> : public __ctype_abstract_base
<wchar_t>
1221 /// Typedef for the template parameter wchar_t.
1222 typedef wchar_t char_type
;
1223 typedef wctype_t __wmask_type
;
1226 __c_locale _M_c_locale_ctype
;
1228 // Pre-computed narrowed and widened chars.
1230 char _M_narrow
[128];
1231 wint_t _M_widen
[1 + static_cast<unsigned char>(-1)];
1233 // Pre-computed elements for do_is.
1235 __wmask_type _M_wmask
[16];
1239 /// The facet id for ctype<wchar_t>
1240 static locale::id id
;
1243 * @brief Constructor performs initialization.
1245 * This is the constructor provided by the standard.
1247 * @param refs Passed to the base facet class.
1250 ctype(size_t __refs
= 0);
1253 * @brief Constructor performs static initialization.
1255 * This constructor is used to construct the initial C locale facet.
1257 * @param cloc Handle to C locale data.
1258 * @param refs Passed to the base facet class.
1261 ctype(__c_locale __cloc
, size_t __refs
= 0);
1265 _M_convert_to_wmask(const mask __m
) const;
1272 * @brief Test wchar_t classification.
1274 * This function finds a mask M for @a c and compares it to mask @a m.
1276 * do_is() is a hook for a derived facet to change the behavior of
1277 * classifying. do_is() must always return the same result for the
1280 * @param c The wchar_t to find the mask of.
1281 * @param m The mask to compare against.
1282 * @return (M & m) != 0.
1285 do_is(mask __m
, char_type __c
) const;
1288 * @brief Return a mask array.
1290 * This function finds the mask for each wchar_t in the range [lo,hi)
1291 * and successively writes it to vec. vec must have as many elements
1294 * do_is() is a hook for a derived facet to change the behavior of
1295 * classifying. do_is() must always return the same result for the
1298 * @param lo Pointer to start of range.
1299 * @param hi Pointer to end of range.
1300 * @param vec Pointer to an array of mask storage.
1303 virtual const char_type
*
1304 do_is(const char_type
* __lo
, const char_type
* __hi
, mask
* __vec
) const;
1307 * @brief Find wchar_t matching mask
1309 * This function searches for and returns the first wchar_t c in
1310 * [lo,hi) for which is(m,c) is true.
1312 * do_scan_is() is a hook for a derived facet to change the behavior of
1313 * match searching. do_is() must always return the same result for the
1316 * @param m The mask to compare against.
1317 * @param lo Pointer to start of range.
1318 * @param hi Pointer to end of range.
1319 * @return Pointer to a matching wchar_t if found, else @a hi.
1321 virtual const char_type
*
1322 do_scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const;
1325 * @brief Find wchar_t not matching mask
1327 * This function searches for and returns a pointer to the first
1328 * wchar_t c of [lo,hi) for which is(m,c) is false.
1330 * do_scan_is() is a hook for a derived facet to change the behavior of
1331 * match searching. do_is() must always return the same result for the
1334 * @param m The mask to compare against.
1335 * @param lo Pointer to start of range.
1336 * @param hi Pointer to end of range.
1337 * @return Pointer to a non-matching wchar_t if found, else @a hi.
1339 virtual const char_type
*
1340 do_scan_not(mask __m
, const char_type
* __lo
,
1341 const char_type
* __hi
) const;
1344 * @brief Convert to uppercase.
1346 * This virtual function converts the wchar_t argument to uppercase if
1347 * possible. If not possible (for example, '2'), returns the argument.
1349 * do_toupper() is a hook for a derived facet to change the behavior of
1350 * uppercasing. do_toupper() must always return the same result for
1353 * @param c The wchar_t to convert.
1354 * @return The uppercase wchar_t if convertible, else @a c.
1357 do_toupper(char_type
) const;
1360 * @brief Convert array to uppercase.
1362 * This virtual function converts each wchar_t in the range [lo,hi) to
1363 * uppercase if possible. Other elements remain untouched.
1365 * do_toupper() is a hook for a derived facet to change the behavior of
1366 * uppercasing. do_toupper() must always return the same result for
1369 * @param lo Pointer to start of range.
1370 * @param hi Pointer to end of range.
1373 virtual const char_type
*
1374 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
1377 * @brief Convert to lowercase.
1379 * This virtual function converts the argument to lowercase if
1380 * possible. If not possible (for example, '2'), returns the argument.
1382 * do_tolower() is a hook for a derived facet to change the behavior of
1383 * lowercasing. do_tolower() must always return the same result for
1386 * @param c The wchar_t to convert.
1387 * @return The lowercase wchar_t if convertible, else @a c.
1390 do_tolower(char_type
) const;
1393 * @brief Convert array to lowercase.
1395 * This virtual function converts each wchar_t in the range [lo,hi) to
1396 * lowercase if possible. Other elements remain untouched.
1398 * do_tolower() is a hook for a derived facet to change the behavior of
1399 * lowercasing. do_tolower() must always return the same result for
1402 * @param lo Pointer to start of range.
1403 * @param hi Pointer to end of range.
1406 virtual const char_type
*
1407 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
1410 * @brief Widen char to wchar_t
1412 * This virtual function converts the char to wchar_t using the
1413 * simplest reasonable transformation. For an underived ctype<wchar_t>
1414 * facet, the argument will be cast to wchar_t.
1416 * do_widen() is a hook for a derived facet to change the behavior of
1417 * widening. do_widen() must always return the same result for the
1420 * Note: this is not what you want for codepage conversions. See
1423 * @param c The char to convert.
1424 * @return The converted wchar_t.
1427 do_widen(char) const;
1430 * @brief Widen char array to wchar_t array
1432 * This function converts each char in the input to wchar_t using the
1433 * simplest reasonable transformation. For an underived ctype<wchar_t>
1434 * facet, the argument will be copied, casting each element to wchar_t.
1436 * do_widen() is a hook for a derived facet to change the behavior of
1437 * widening. do_widen() must always return the same result for the
1440 * Note: this is not what you want for codepage conversions. See
1443 * @param lo Pointer to start range.
1444 * @param hi Pointer to end of range.
1445 * @param to Pointer to the destination array.
1449 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const;
1452 * @brief Narrow wchar_t to char
1454 * This virtual function converts the argument to char using the
1455 * simplest reasonable transformation. If the conversion fails, dfault
1456 * is returned instead. For an underived ctype<wchar_t> facet, @a c will
1457 * be cast to char and returned.
1459 * do_narrow() is a hook for a derived facet to change the behavior of
1460 * narrowing. do_narrow() must always return the same result for the
1463 * Note: this is not what you want for codepage conversions. See
1466 * @param c The wchar_t to convert.
1467 * @param dfault Char to return if conversion fails.
1468 * @return The converted char.
1471 do_narrow(char_type
, char __dfault
) const;
1474 * @brief Narrow wchar_t array to char array
1476 * This virtual function converts each wchar_t in the range [lo,hi) to
1477 * char using the simplest reasonable transformation and writes the
1478 * results to the destination array. For any wchar_t in the input that
1479 * cannot be converted, @a dfault is used instead. For an underived
1480 * ctype<wchar_t> facet, the argument will be copied, casting each
1483 * do_narrow() is a hook for a derived facet to change the behavior of
1484 * narrowing. do_narrow() must always return the same result for the
1487 * Note: this is not what you want for codepage conversions. See
1490 * @param lo Pointer to start of range.
1491 * @param hi Pointer to end of range.
1492 * @param dfault Char to use if conversion fails.
1493 * @param to Pointer to the destination array.
1496 virtual const char_type
*
1497 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
1498 char __dfault
, char* __dest
) const;
1500 // For use at construction time only.
1502 _M_initialize_ctype();
1506 const ctype
<wchar_t>&
1507 use_facet
<ctype
<wchar_t> >(const locale
& __loc
);
1508 #endif //_GLIBCXX_USE_WCHAR_T
1510 // Include host and configuration specific ctype inlines.
1511 #include <bits/ctype_inline.h>
1513 // 22.2.1.2 Template class ctype_byname
1514 template<typename _CharT
>
1515 class ctype_byname
: public ctype
<_CharT
>
1518 typedef _CharT char_type
;
1521 ctype_byname(const char* __s
, size_t __refs
= 0);
1525 ~ctype_byname() { };
1528 // 22.2.1.4 Class ctype_byname specializations.
1530 ctype_byname
<char>::ctype_byname(const char*, size_t refs
);
1533 ctype_byname
<wchar_t>::ctype_byname(const char*, size_t refs
);
1535 // 22.2.1.5 Template class codecvt
1536 #include <bits/codecvt.h>
1538 // 22.2.2 The numeric category.
1542 // NB: Code depends on the order of _S_atoms_out elements.
1543 // Below are the indices into _S_atoms_out.
1551 _S_odigits_end
= _S_odigits
+ 16,
1552 _S_oudigits
= _S_odigits_end
,
1553 _S_oudigits_end
= _S_oudigits
+ 16,
1554 _S_oe
= _S_odigits
+ 14, // For scientific notation, 'e'
1555 _S_oE
= _S_oudigits
+ 14, // For scientific notation, 'E'
1556 _S_oend
= _S_oudigits_end
1559 // A list of valid numeric literals for output. This array
1560 // contains chars that will be passed through the current locale's
1561 // ctype<_CharT>.widen() and then used to render numbers.
1562 // For the standard "C" locale, this is
1563 // "-+xX0123456789abcdef0123456789ABCDEF".
1564 static const char* _S_atoms_out
;
1566 // String literal of acceptable (narrow) input, for num_get.
1567 // "-+xX0123456789abcdefABCDEF"
1568 static const char* _S_atoms_in
;
1577 _S_ie
= _S_izero
+ 14,
1578 _S_iE
= _S_izero
+ 20,
1583 // Construct and return valid scanf format for floating point types.
1585 _S_format_float(const ios_base
& __io
, char* __fptr
, char __mod
);
1588 template<typename _CharT
>
1589 struct __numpunct_cache
: public locale::facet
1591 const char* _M_grouping
;
1592 size_t _M_grouping_size
;
1593 bool _M_use_grouping
;
1594 const _CharT
* _M_truename
;
1595 size_t _M_truename_size
;
1596 const _CharT
* _M_falsename
;
1597 size_t _M_falsename_size
;
1598 _CharT _M_decimal_point
;
1599 _CharT _M_thousands_sep
;
1601 // A list of valid numeric literals for output: in the standard
1602 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1603 // This array contains the chars after having been passed
1604 // through the current locale's ctype<_CharT>.widen().
1605 _CharT _M_atoms_out
[__num_base::_S_oend
];
1607 // A list of valid numeric literals for input: in the standard
1608 // "C" locale, this is "-+xX0123456789abcdefABCDEF"
1609 // This array contains the chars after having been passed
1610 // through the current locale's ctype<_CharT>.widen().
1611 _CharT _M_atoms_in
[__num_base::_S_iend
];
1615 __numpunct_cache(size_t __refs
= 0) : facet(__refs
),
1616 _M_grouping(NULL
), _M_grouping_size(0), _M_use_grouping(false),
1617 _M_truename(NULL
), _M_truename_size(0), _M_falsename(NULL
),
1618 _M_falsename_size(0), _M_decimal_point(_CharT()),
1619 _M_thousands_sep(_CharT()), _M_allocated(false)
1622 ~__numpunct_cache();
1625 _M_cache(const locale
& __loc
);
1628 template<typename _CharT
>
1630 __numpunct_cache
<_CharT
>::_M_cache(const locale
& __loc
)
1632 _M_allocated
= true;
1634 const numpunct
<_CharT
>& __np
= use_facet
<numpunct
<_CharT
> >(__loc
);
1636 _M_grouping_size
= __np
.grouping().size();
1637 char* __grouping
= new char[_M_grouping_size
];
1638 __np
.grouping().copy(__grouping
, _M_grouping_size
);
1639 _M_grouping
= __grouping
;
1640 _M_use_grouping
= _M_grouping_size
&& __np
.grouping()[0] != 0;
1642 _M_truename_size
= __np
.truename().size();
1643 _CharT
* __truename
= new _CharT
[_M_truename_size
];
1644 __np
.truename().copy(__truename
, _M_truename_size
);
1645 _M_truename
= __truename
;
1647 _M_falsename_size
= __np
.falsename().size();
1648 _CharT
* __falsename
= new _CharT
[_M_falsename_size
];
1649 __np
.falsename().copy(__falsename
, _M_falsename_size
);
1650 _M_falsename
= __falsename
;
1652 _M_decimal_point
= __np
.decimal_point();
1653 _M_thousands_sep
= __np
.thousands_sep();
1655 const ctype
<_CharT
>& __ct
= use_facet
<ctype
<_CharT
> >(__loc
);
1656 __ct
.widen(__num_base::_S_atoms_out
,
1657 __num_base::_S_atoms_out
+ __num_base::_S_oend
, _M_atoms_out
);
1658 __ct
.widen(__num_base::_S_atoms_in
,
1659 __num_base::_S_atoms_in
+ __num_base::_S_iend
, _M_atoms_in
);
1662 template<typename _CharT
>
1663 __numpunct_cache
<_CharT
>::~__numpunct_cache()
1667 delete [] _M_grouping
;
1668 delete [] _M_truename
;
1669 delete [] _M_falsename
;
1674 * @brief Numpunct facet.
1676 * This facet stores several pieces of information related to printing and
1677 * scanning numbers, such as the decimal point character. It takes a
1678 * template parameter specifying the char type. The numpunct facet is
1679 * used by streams for many I/O operations involving numbers.
1681 * The numpunct template uses protected virtual functions to provide the
1682 * actual results. The public accessors forward the call to the virtual
1683 * functions. These virtual functions are hooks for developers to
1684 * implement the behavior they require from a numpunct facet.
1686 template<typename _CharT
>
1687 class numpunct
: public locale::facet
1693 typedef _CharT char_type
;
1694 typedef basic_string
<_CharT
> string_type
;
1696 typedef __numpunct_cache
<_CharT
> __cache_type
;
1699 __cache_type
* _M_data
;
1702 /// Numpunct facet id.
1703 static locale::id id
;
1706 * @brief Numpunct constructor.
1708 * @param refs Refcount to pass to the base class.
1711 numpunct(size_t __refs
= 0) : facet(__refs
), _M_data(NULL
)
1712 { _M_initialize_numpunct(); }
1715 * @brief Internal constructor. Not for general use.
1717 * This is a constructor for use by the library itself to set up the
1718 * predefined locale facets.
1720 * @param cache __numpunct_cache object.
1721 * @param refs Refcount to pass to the base class.
1724 numpunct(__cache_type
* __cache
, size_t __refs
= 0)
1725 : facet(__refs
), _M_data(__cache
)
1726 { _M_initialize_numpunct(); }
1729 * @brief Internal constructor. Not for general use.
1731 * This is a constructor for use by the library itself to set up new
1734 * @param cloc The "C" locale.
1735 * @param refs Refcount to pass to the base class.
1738 numpunct(__c_locale __cloc
, size_t __refs
= 0)
1739 : facet(__refs
), _M_data(NULL
)
1740 { _M_initialize_numpunct(__cloc
); }
1743 * @brief Return decimal point character.
1745 * This function returns a char_type to use as a decimal point. It
1746 * does so by returning returning
1747 * numpunct<char_type>::do_decimal_point().
1749 * @return @a char_type representing a decimal point.
1752 decimal_point() const
1753 { return this->do_decimal_point(); }
1756 * @brief Return thousands separator character.
1758 * This function returns a char_type to use as a thousands separator. It
1759 * does so by returning returning
1760 * numpunct<char_type>::do_thousands_sep().
1762 * @return char_type representing a thousands separator.
1765 thousands_sep() const
1766 { return this->do_thousands_sep(); }
1769 * @brief Return grouping specification.
1771 * This function returns a string representing groupings for the
1772 * integer part of a number. Groupings indicate where thousands
1773 * separators should be inserted in the integer part of a number.
1775 * Each char in the return string is interpret as an integer rather
1776 * than a character. These numbers represent the number of digits in a
1777 * group. The first char in the string represents the number of digits
1778 * in the least significant group. If a char is negative, it indicates
1779 * an unlimited number of digits for the group. If more chars from the
1780 * string are required to group a number, the last char is used
1783 * For example, if the grouping() returns "\003\002" and is applied to
1784 * the number 123456789, this corresponds to 12,34,56,789. Note that
1785 * if the string was "32", this would put more than 50 digits into the
1786 * least significant group if the character set is ASCII.
1788 * The string is returned by calling
1789 * numpunct<char_type>::do_grouping().
1791 * @return string representing grouping specification.
1795 { return this->do_grouping(); }
1798 * @brief Return string representation of bool true.
1800 * This function returns a string_type containing the text
1801 * representation for true bool variables. It does so by calling
1802 * numpunct<char_type>::do_truename().
1804 * @return string_type representing printed form of true.
1808 { return this->do_truename(); }
1811 * @brief Return string representation of bool false.
1813 * This function returns a string_type containing the text
1814 * representation for false bool variables. It does so by calling
1815 * numpunct<char_type>::do_falsename().
1817 * @return string_type representing printed form of false.
1821 { return this->do_falsename(); }
1829 * @brief Return decimal point character.
1831 * Returns a char_type to use as a decimal point. This function is a
1832 * hook for derived classes to change the value returned.
1834 * @return @a char_type representing a decimal point.
1837 do_decimal_point() const
1838 { return _M_data
->_M_decimal_point
; }
1841 * @brief Return thousands separator character.
1843 * Returns a char_type to use as a thousands separator. This function
1844 * is a hook for derived classes to change the value returned.
1846 * @return @a char_type representing a thousands separator.
1849 do_thousands_sep() const
1850 { return _M_data
->_M_thousands_sep
; }
1853 * @brief Return grouping specification.
1855 * Returns a string representing groupings for the integer part of a
1856 * number. This function is a hook for derived classes to change the
1857 * value returned. @see grouping() for details.
1859 * @return String representing grouping specification.
1863 { return _M_data
->_M_grouping
; }
1866 * @brief Return string representation of bool true.
1868 * Returns a string_type containing the text representation for true
1869 * bool variables. This function is a hook for derived classes to
1870 * change the value returned.
1872 * @return string_type representing printed form of true.
1876 { return _M_data
->_M_truename
; }
1879 * @brief Return string representation of bool false.
1881 * Returns a string_type containing the text representation for false
1882 * bool variables. This function is a hook for derived classes to
1883 * change the value returned.
1885 * @return string_type representing printed form of false.
1888 do_falsename() const
1889 { return _M_data
->_M_falsename
; }
1891 // For use at construction time only.
1893 _M_initialize_numpunct(__c_locale __cloc
= NULL
);
1896 template<typename _CharT
>
1897 locale::id numpunct
<_CharT
>::id
;
1900 numpunct
<char>::~numpunct();
1904 numpunct
<char>::_M_initialize_numpunct(__c_locale __cloc
);
1906 #ifdef _GLIBCXX_USE_WCHAR_T
1908 numpunct
<wchar_t>::~numpunct();
1912 numpunct
<wchar_t>::_M_initialize_numpunct(__c_locale __cloc
);
1915 template<typename _CharT
>
1916 class numpunct_byname
: public numpunct
<_CharT
>
1919 typedef _CharT char_type
;
1920 typedef basic_string
<_CharT
> string_type
;
1923 numpunct_byname(const char* __s
, size_t __refs
= 0)
1924 : numpunct
<_CharT
>(__refs
)
1926 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
1929 this->_S_create_c_locale(__tmp
, __s
);
1930 this->_M_initialize_numpunct(__tmp
);
1931 this->_S_destroy_c_locale(__tmp
);
1937 ~numpunct_byname() { }
1941 * @brief Facet for parsing number strings.
1943 * This facet encapsulates the code to parse and return a number
1944 * from a string. It is used by the istream numeric extraction
1947 * The num_get template uses protected virtual functions to provide the
1948 * actual results. The public accessors forward the call to the virtual
1949 * functions. These virtual functions are hooks for developers to
1950 * implement the behavior they require from the num_get facet.
1952 template<typename _CharT
, typename _InIter
>
1953 class num_get
: public locale::facet
, public __num_base
1959 typedef _CharT char_type
;
1960 typedef _InIter iter_type
;
1963 /// Numpunct facet id.
1964 static locale::id id
;
1967 * @brief Constructor performs initialization.
1969 * This is the constructor provided by the standard.
1971 * @param refs Passed to the base facet class.
1974 num_get(size_t __refs
= 0) : facet(__refs
) { }
1977 * @brief Numeric parsing.
1979 * Parses the input stream into the bool @a v. It does so by calling
1980 * num_put::do_put().
1982 * If ios_base::boolalpha is set, attempts to read ctype<CharT>::truename() or
1983 * ctype<CharT>::falsename(). Sets @a v to true or false if
1984 * successful. Sets err to ios_base::failbit if reading the string
1985 * fails. Sets err to ios_base::eofbit if the stream is emptied.
1987 * If ios_base::boolalpha is not set, proceeds as with reading a long,
1988 * except if the value is 1, sets @a v to true, if the value is 0, sets
1989 * @a v to false, and otherwise set err to ios_base::failbit.
1991 * @param in Start of input stream.
1992 * @param end End of input stream.
1993 * @param io Source of locale and flags.
1994 * @param err Error flags to set.
1995 * @param v Value to format and insert.
1996 * @return Iterator after reading.
1999 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2000 ios_base::iostate
& __err
, bool& __v
) const
2001 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2005 * @brief Numeric parsing.
2007 * Parses the input stream into the integral variable @a v. It does so
2008 * by calling num_put::do_put().
2010 * Parsing is affected by the flag settings in @a io.
2012 * The basic parse is affected by the value of io.flags() &
2013 * ios_base::basefield. If equal to ios_base::oct, parses like the
2014 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X
2015 * specifier. Else if basefield equal to 0, parses like the %i
2016 * specifier. Otherwise, parses like %d for signed and %u for unsigned
2017 * types. The matching type length modifier is also used.
2019 * Digit grouping is intrepreted according to numpunct::grouping() and
2020 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2021 * consistent, sets err to ios_base::failbit.
2023 * If parsing the string yields a valid value for @a v, @a v is set.
2024 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2025 * Sets err to ios_base::eofbit if the stream is emptied.
2027 * @param in Start of input stream.
2028 * @param end End of input stream.
2029 * @param io Source of locale and flags.
2030 * @param err Error flags to set.
2031 * @param v Value to format and insert.
2032 * @return Iterator after reading.
2035 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2036 ios_base::iostate
& __err
, long& __v
) const
2037 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2040 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2041 ios_base::iostate
& __err
, unsigned short& __v
) const
2042 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2045 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2046 ios_base::iostate
& __err
, unsigned int& __v
) const
2047 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2050 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2051 ios_base::iostate
& __err
, unsigned long& __v
) const
2052 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2054 #ifdef _GLIBCXX_USE_LONG_LONG
2056 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2057 ios_base::iostate
& __err
, long long& __v
) const
2058 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2061 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2062 ios_base::iostate
& __err
, unsigned long long& __v
) const
2063 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2069 * @brief Numeric parsing.
2071 * Parses the input stream into the integral variable @a v. It does so
2072 * by calling num_put::do_put().
2074 * The input characters are parsed like the scanf %g specifier. The
2075 * matching type length modifier is also used.
2077 * The decimal point character used is numpunct::decimal_point().
2078 * Digit grouping is intrepreted according to numpunct::grouping() and
2079 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2080 * consistent, sets err to ios_base::failbit.
2082 * If parsing the string yields a valid value for @a v, @a v is set.
2083 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2084 * Sets err to ios_base::eofbit if the stream is emptied.
2086 * @param in Start of input stream.
2087 * @param end End of input stream.
2088 * @param io Source of locale and flags.
2089 * @param err Error flags to set.
2090 * @param v Value to format and insert.
2091 * @return Iterator after reading.
2094 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2095 ios_base::iostate
& __err
, float& __v
) const
2096 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2099 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2100 ios_base::iostate
& __err
, double& __v
) const
2101 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2104 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2105 ios_base::iostate
& __err
, long double& __v
) const
2106 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2110 * @brief Numeric parsing.
2112 * Parses the input stream into the pointer variable @a v. It does so
2113 * by calling num_put::do_put().
2115 * The input characters are parsed like the scanf %p specifier.
2117 * Digit grouping is intrepreted according to numpunct::grouping() and
2118 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2119 * consistent, sets err to ios_base::failbit.
2121 * Note that the digit grouping effect for pointers is a bit ambiguous
2122 * in the standard and shouldn't be relied on. See DR 344.
2124 * If parsing the string yields a valid value for @a v, @a v is set.
2125 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2126 * Sets err to ios_base::eofbit if the stream is emptied.
2128 * @param in Start of input stream.
2129 * @param end End of input stream.
2130 * @param io Source of locale and flags.
2131 * @param err Error flags to set.
2132 * @param v Value to format and insert.
2133 * @return Iterator after reading.
2136 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2137 ios_base::iostate
& __err
, void*& __v
) const
2138 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2142 virtual ~num_get() { }
2145 _M_extract_float(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2146 string
& __xtrc
) const;
2148 template<typename _ValueT
>
2150 _M_extract_int(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2151 _ValueT
& __v
) const;
2155 * @brief Numeric parsing.
2157 * Parses the input stream into the variable @a v. This function is a
2158 * hook for derived classes to change the value returned. @see get()
2161 * @param in Start of input stream.
2162 * @param end End of input stream.
2163 * @param io Source of locale and flags.
2164 * @param err Error flags to set.
2165 * @param v Value to format and insert.
2166 * @return Iterator after reading.
2169 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, bool&) const;
2173 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, long&) const;
2176 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2177 unsigned short&) const;
2180 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2181 unsigned int&) const;
2184 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2185 unsigned long&) const;
2187 #ifdef _GLIBCXX_USE_LONG_LONG
2189 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2193 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2194 unsigned long long&) const;
2198 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2202 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2206 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2207 long double&) const;
2210 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2215 template<typename _CharT
, typename _InIter
>
2216 locale::id num_get
<_CharT
, _InIter
>::id
;
2220 * @brief Facet for converting numbers to strings.
2222 * This facet encapsulates the code to convert a number to a string. It is
2223 * used by the ostream numeric insertion operators.
2225 * The num_put template uses protected virtual functions to provide the
2226 * actual results. The public accessors forward the call to the virtual
2227 * functions. These virtual functions are hooks for developers to
2228 * implement the behavior they require from the num_put facet.
2230 template<typename _CharT
, typename _OutIter
>
2231 class num_put
: public locale::facet
, public __num_base
2237 typedef _CharT char_type
;
2238 typedef _OutIter iter_type
;
2241 /// Numpunct facet id.
2242 static locale::id id
;
2245 * @brief Constructor performs initialization.
2247 * This is the constructor provided by the standard.
2249 * @param refs Passed to the base facet class.
2252 num_put(size_t __refs
= 0) : facet(__refs
) { }
2255 * @brief Numeric formatting.
2257 * Formats the boolean @a v and inserts it into a stream. It does so
2258 * by calling num_put::do_put().
2260 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2261 * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
2263 * @param s Stream to write to.
2264 * @param io Source of locale and flags.
2265 * @param fill Char_type to use for filling.
2266 * @param v Value to format and insert.
2267 * @return Iterator after writing.
2270 put(iter_type __s
, ios_base
& __f
, char_type __fill
, bool __v
) const
2271 { return this->do_put(__s
, __f
, __fill
, __v
); }
2275 * @brief Numeric formatting.
2277 * Formats the integral value @a v and inserts it into a stream. It does so
2278 * by calling num_put::do_put().
2280 * Formatting is affected by the flag settings in @a io.
2282 * The basic format is affected by the value of io.flags() &
2283 * ios_base::basefield. If equal to ios_base::oct, formats like the
2284 * printf %o specifier. Else if equal to ios_base::hex, formats like
2285 * %x or %X with ios_base::uppercase unset or set respectively.
2286 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2287 * for unsigned values. Note that if both oct and hex are set, neither
2290 * If ios_base::showpos is set, '+' is output before positive values.
2291 * If ios_base::showbase is set, '0' precedes octal values (except 0)
2292 * and '0[xX]' precedes hex values.
2294 * Thousands separators are inserted according to numpunct::grouping()
2295 * and numpunct::thousands_sep(). The decimal point character used is
2296 * numpunct::decimal_point().
2298 * If io.width() is non-zero, enough @a fill characters are inserted to
2299 * make the result at least that wide. If
2300 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2301 * padded at the end. If ios_base::internal, then padding occurs
2302 * immediately after either a '+' or '-' or after '0x' or '0X'.
2303 * Otherwise, padding occurs at the beginning.
2305 * @param s Stream to write to.
2306 * @param io Source of locale and flags.
2307 * @param fill Char_type to use for filling.
2308 * @param v Value to format and insert.
2309 * @return Iterator after writing.
2312 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long __v
) const
2313 { return this->do_put(__s
, __f
, __fill
, __v
); }
2316 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2317 unsigned long __v
) const
2318 { return this->do_put(__s
, __f
, __fill
, __v
); }
2320 #ifdef _GLIBCXX_USE_LONG_LONG
2322 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long long __v
) const
2323 { return this->do_put(__s
, __f
, __fill
, __v
); }
2326 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2327 unsigned long long __v
) const
2328 { return this->do_put(__s
, __f
, __fill
, __v
); }
2334 * @brief Numeric formatting.
2336 * Formats the floating point value @a v and inserts it into a stream.
2337 * It does so by calling num_put::do_put().
2339 * Formatting is affected by the flag settings in @a io.
2341 * The basic format is affected by the value of io.flags() &
2342 * ios_base::floatfield. If equal to ios_base::fixed, formats like the
2343 * printf %f specifier. Else if equal to ios_base::scientific, formats
2344 * like %e or %E with ios_base::uppercase unset or set respectively.
2345 * Otherwise, formats like %g or %G depending on uppercase. Note that
2346 * if both fixed and scientific are set, the effect will also be like
2349 * The output precision is given by io.precision(). This precision is
2350 * capped at numeric_limits::digits10 + 2 (different for double and
2351 * long double). The default precision is 6.
2353 * If ios_base::showpos is set, '+' is output before positive values.
2354 * If ios_base::showpoint is set, a decimal point will always be
2357 * Thousands separators are inserted according to numpunct::grouping()
2358 * and numpunct::thousands_sep(). The decimal point character used is
2359 * numpunct::decimal_point().
2361 * If io.width() is non-zero, enough @a fill characters are inserted to
2362 * make the result at least that wide. If
2363 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2364 * padded at the end. If ios_base::internal, then padding occurs
2365 * immediately after either a '+' or '-' or after '0x' or '0X'.
2366 * Otherwise, padding occurs at the beginning.
2368 * @param s Stream to write to.
2369 * @param io Source of locale and flags.
2370 * @param fill Char_type to use for filling.
2371 * @param v Value to format and insert.
2372 * @return Iterator after writing.
2375 put(iter_type __s
, ios_base
& __f
, char_type __fill
, double __v
) const
2376 { return this->do_put(__s
, __f
, __fill
, __v
); }
2379 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2380 long double __v
) const
2381 { return this->do_put(__s
, __f
, __fill
, __v
); }
2385 * @brief Numeric formatting.
2387 * Formats the pointer value @a v and inserts it into a stream. It
2388 * does so by calling num_put::do_put().
2390 * This function formats @a v as an unsigned long with ios_base::hex
2391 * and ios_base::showbase set.
2393 * @param s Stream to write to.
2394 * @param io Source of locale and flags.
2395 * @param fill Char_type to use for filling.
2396 * @param v Value to format and insert.
2397 * @return Iterator after writing.
2400 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2401 const void* __v
) const
2402 { return this->do_put(__s
, __f
, __fill
, __v
); }
2405 template<typename _ValueT
>
2407 _M_insert_float(iter_type
, ios_base
& __io
, char_type __fill
,
2408 char __mod
, _ValueT __v
) const;
2411 _M_group_float(const char* __grouping
, size_t __grouping_size
,
2412 char_type __sep
, const char_type
* __p
, char_type
* __new
,
2413 char_type
* __cs
, int& __len
) const;
2415 template<typename _ValueT
>
2417 _M_insert_int(iter_type
, ios_base
& __io
, char_type __fill
,
2421 _M_group_int(const char* __grouping
, size_t __grouping_size
,
2422 char_type __sep
, ios_base
& __io
, char_type
* __new
,
2423 char_type
* __cs
, int& __len
) const;
2426 _M_pad(char_type __fill
, streamsize __w
, ios_base
& __io
,
2427 char_type
* __new
, const char_type
* __cs
, int& __len
) const;
2435 * @brief Numeric formatting.
2437 * These functions do the work of formatting numeric values and
2438 * inserting them into a stream. This function is a hook for derived
2439 * classes to change the value returned.
2441 * @param s Stream to write to.
2442 * @param io Source of locale and flags.
2443 * @param fill Char_type to use for filling.
2444 * @param v Value to format and insert.
2445 * @return Iterator after writing.
2448 do_put(iter_type
, ios_base
&, char_type __fill
, bool __v
) const;
2451 do_put(iter_type
, ios_base
&, char_type __fill
, long __v
) const;
2454 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long) const;
2456 #ifdef _GLIBCXX_USE_LONG_LONG
2458 do_put(iter_type
, ios_base
&, char_type __fill
, long long __v
) const;
2461 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long long) const;
2465 do_put(iter_type
, ios_base
&, char_type __fill
, double __v
) const;
2468 do_put(iter_type
, ios_base
&, char_type __fill
, long double __v
) const;
2471 do_put(iter_type
, ios_base
&, char_type __fill
, const void* __v
) const;
2475 template <typename _CharT
, typename _OutIter
>
2476 locale::id num_put
<_CharT
, _OutIter
>::id
;
2480 * @brief Facet for localized string comparison.
2482 * This facet encapsulates the code to compare strings in a localized
2485 * The collate template uses protected virtual functions to provide
2486 * the actual results. The public accessors forward the call to
2487 * the virtual functions. These virtual functions are hooks for
2488 * developers to implement the behavior they require from the
2491 template<typename _CharT
>
2492 class collate
: public locale::facet
2498 typedef _CharT char_type
;
2499 typedef basic_string
<_CharT
> string_type
;
2503 // Underlying "C" library locale information saved from
2504 // initialization, needed by collate_byname as well.
2505 __c_locale _M_c_locale_collate
;
2508 /// Numpunct facet id.
2509 static locale::id id
;
2512 * @brief Constructor performs initialization.
2514 * This is the constructor provided by the standard.
2516 * @param refs Passed to the base facet class.
2519 collate(size_t __refs
= 0)
2521 { _M_c_locale_collate
= _S_get_c_locale(); }
2524 * @brief Internal constructor. Not for general use.
2526 * This is a constructor for use by the library itself to set up new
2529 * @param cloc The "C" locale.
2530 * @param refs Passed to the base facet class.
2533 collate(__c_locale __cloc
, size_t __refs
= 0)
2535 { _M_c_locale_collate
= _S_clone_c_locale(__cloc
); }
2538 * @brief Compare two strings.
2540 * This function compares two strings and returns the result by calling
2541 * collate::do_compare().
2543 * @param lo1 Start of string 1.
2544 * @param hi1 End of string 1.
2545 * @param lo2 Start of string 2.
2546 * @param hi2 End of string 2.
2547 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2550 compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
2551 const _CharT
* __lo2
, const _CharT
* __hi2
) const
2552 { return this->do_compare(__lo1
, __hi1
, __lo2
, __hi2
); }
2555 * @brief Transform string to comparable form.
2557 * This function is a wrapper for strxfrm functionality. It takes the
2558 * input string and returns a modified string that can be directly
2559 * compared to other transformed strings. In the "C" locale, this
2560 * function just returns a copy of the input string. In some other
2561 * locales, it may replace two chars with one, change a char for
2562 * another, etc. It does so by returning collate::do_transform().
2564 * @param lo Start of string.
2565 * @param hi End of string.
2566 * @return Transformed string_type.
2569 transform(const _CharT
* __lo
, const _CharT
* __hi
) const
2570 { return this->do_transform(__lo
, __hi
); }
2573 * @brief Return hash of a string.
2575 * This function computes and returns a hash on the input string. It
2576 * does so by returning collate::do_hash().
2578 * @param lo Start of string.
2579 * @param hi End of string.
2580 * @return Hash value.
2583 hash(const _CharT
* __lo
, const _CharT
* __hi
) const
2584 { return this->do_hash(__lo
, __hi
); }
2586 // Used to abstract out _CharT bits in virtual member functions, below.
2588 _M_compare(const _CharT
*, const _CharT
*) const;
2591 _M_transform(_CharT
*, const _CharT
*, size_t) const;
2597 { _S_destroy_c_locale(_M_c_locale_collate
); }
2600 * @brief Compare two strings.
2602 * This function is a hook for derived classes to change the value
2603 * returned. @see compare().
2605 * @param lo1 Start of string 1.
2606 * @param hi1 End of string 1.
2607 * @param lo2 Start of string 2.
2608 * @param hi2 End of string 2.
2609 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2612 do_compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
2613 const _CharT
* __lo2
, const _CharT
* __hi2
) const;
2616 * @brief Transform string to comparable form.
2618 * This function is a hook for derived classes to change the value
2621 * @param lo1 Start of string 1.
2622 * @param hi1 End of string 1.
2623 * @param lo2 Start of string 2.
2624 * @param hi2 End of string 2.
2625 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2628 do_transform(const _CharT
* __lo
, const _CharT
* __hi
) const;
2631 * @brief Return hash of a string.
2633 * This function computes and returns a hash on the input string. This
2634 * function is a hook for derived classes to change the value returned.
2636 * @param lo Start of string.
2637 * @param hi End of string.
2638 * @return Hash value.
2641 do_hash(const _CharT
* __lo
, const _CharT
* __hi
) const;
2644 template<typename _CharT
>
2645 locale::id collate
<_CharT
>::id
;
2650 collate
<char>::_M_compare(const char*, const char*) const;
2654 collate
<char>::_M_transform(char*, const char*, size_t) const;
2656 #ifdef _GLIBCXX_USE_WCHAR_T
2659 collate
<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
2663 collate
<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
2666 template<typename _CharT
>
2667 class collate_byname
: public collate
<_CharT
>
2672 typedef _CharT char_type
;
2673 typedef basic_string
<_CharT
> string_type
;
2677 collate_byname(const char* __s
, size_t __refs
= 0)
2678 : collate
<_CharT
>(__refs
)
2680 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
2682 this->_S_destroy_c_locale(this->_M_c_locale_collate
);
2683 this->_S_create_c_locale(this->_M_c_locale_collate
, __s
);
2689 ~collate_byname() { }
2694 * @brief Time format ordering data.
2696 * This class provides an enum representing different orderings of day,
2702 enum dateorder
{ no_order
, dmy
, mdy
, ymd
, ydm
};
2705 template<typename _CharT
>
2706 struct __timepunct_cache
: public locale::facet
2708 // List of all known timezones, with GMT first.
2709 static const _CharT
* _S_timezones
[14];
2711 const _CharT
* _M_date_format
;
2712 const _CharT
* _M_date_era_format
;
2713 const _CharT
* _M_time_format
;
2714 const _CharT
* _M_time_era_format
;
2715 const _CharT
* _M_date_time_format
;
2716 const _CharT
* _M_date_time_era_format
;
2717 const _CharT
* _M_am
;
2718 const _CharT
* _M_pm
;
2719 const _CharT
* _M_am_pm_format
;
2721 // Day names, starting with "C"'s Sunday.
2722 const _CharT
* _M_day1
;
2723 const _CharT
* _M_day2
;
2724 const _CharT
* _M_day3
;
2725 const _CharT
* _M_day4
;
2726 const _CharT
* _M_day5
;
2727 const _CharT
* _M_day6
;
2728 const _CharT
* _M_day7
;
2730 // Abbreviated day names, starting with "C"'s Sun.
2731 const _CharT
* _M_aday1
;
2732 const _CharT
* _M_aday2
;
2733 const _CharT
* _M_aday3
;
2734 const _CharT
* _M_aday4
;
2735 const _CharT
* _M_aday5
;
2736 const _CharT
* _M_aday6
;
2737 const _CharT
* _M_aday7
;
2739 // Month names, starting with "C"'s January.
2740 const _CharT
* _M_month01
;
2741 const _CharT
* _M_month02
;
2742 const _CharT
* _M_month03
;
2743 const _CharT
* _M_month04
;
2744 const _CharT
* _M_month05
;
2745 const _CharT
* _M_month06
;
2746 const _CharT
* _M_month07
;
2747 const _CharT
* _M_month08
;
2748 const _CharT
* _M_month09
;
2749 const _CharT
* _M_month10
;
2750 const _CharT
* _M_month11
;
2751 const _CharT
* _M_month12
;
2753 // Abbreviated month names, starting with "C"'s Jan.
2754 const _CharT
* _M_amonth01
;
2755 const _CharT
* _M_amonth02
;
2756 const _CharT
* _M_amonth03
;
2757 const _CharT
* _M_amonth04
;
2758 const _CharT
* _M_amonth05
;
2759 const _CharT
* _M_amonth06
;
2760 const _CharT
* _M_amonth07
;
2761 const _CharT
* _M_amonth08
;
2762 const _CharT
* _M_amonth09
;
2763 const _CharT
* _M_amonth10
;
2764 const _CharT
* _M_amonth11
;
2765 const _CharT
* _M_amonth12
;
2769 __timepunct_cache(size_t __refs
= 0) : facet(__refs
),
2770 _M_date_format(NULL
), _M_date_era_format(NULL
), _M_time_format(NULL
),
2771 _M_time_era_format(NULL
), _M_date_time_format(NULL
),
2772 _M_date_time_era_format(NULL
), _M_am(NULL
), _M_pm(NULL
),
2773 _M_am_pm_format(NULL
), _M_day1(NULL
), _M_day2(NULL
), _M_day3(NULL
),
2774 _M_day4(NULL
), _M_day5(NULL
), _M_day6(NULL
), _M_day7(NULL
),
2775 _M_aday1(NULL
), _M_aday2(NULL
), _M_aday3(NULL
), _M_aday4(NULL
),
2776 _M_aday5(NULL
), _M_aday6(NULL
), _M_aday7(NULL
), _M_month01(NULL
),
2777 _M_month02(NULL
), _M_month03(NULL
), _M_month04(NULL
), _M_month05(NULL
),
2778 _M_month06(NULL
), _M_month07(NULL
), _M_month08(NULL
), _M_month09(NULL
),
2779 _M_month10(NULL
), _M_month11(NULL
), _M_month12(NULL
), _M_amonth01(NULL
),
2780 _M_amonth02(NULL
), _M_amonth03(NULL
), _M_amonth04(NULL
),
2781 _M_amonth05(NULL
), _M_amonth06(NULL
), _M_amonth07(NULL
),
2782 _M_amonth08(NULL
), _M_amonth09(NULL
), _M_amonth10(NULL
),
2783 _M_amonth11(NULL
), _M_amonth12(NULL
), _M_allocated(false)
2786 ~__timepunct_cache();
2789 _M_cache(const locale
& __loc
);
2792 template<typename _CharT
>
2793 __timepunct_cache
<_CharT
>::~__timepunct_cache()
2804 __timepunct_cache
<char>::_S_timezones
[14];
2806 #ifdef _GLIBCXX_USE_WCHAR_T
2809 __timepunct_cache
<wchar_t>::_S_timezones
[14];
2813 template<typename _CharT
>
2814 const _CharT
* __timepunct_cache
<_CharT
>::_S_timezones
[14];
2816 template<typename _CharT
>
2817 class __timepunct
: public locale::facet
2821 typedef _CharT __char_type
;
2822 typedef basic_string
<_CharT
> __string_type
;
2823 typedef __timepunct_cache
<_CharT
> __cache_type
;
2826 __cache_type
* _M_data
;
2827 __c_locale _M_c_locale_timepunct
;
2828 const char* _M_name_timepunct
;
2831 /// Numpunct facet id.
2832 static locale::id id
;
2835 __timepunct(size_t __refs
= 0);
2838 __timepunct(__cache_type
* __cache
, size_t __refs
= 0);
2841 * @brief Internal constructor. Not for general use.
2843 * This is a constructor for use by the library itself to set up new
2846 * @param cloc The "C" locale.
2847 * @param s The name of a locale.
2848 * @param refs Passed to the base facet class.
2851 __timepunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
2854 _M_put(_CharT
* __s
, size_t __maxlen
, const _CharT
* __format
,
2855 const tm
* __tm
) const;
2858 _M_date_formats(const _CharT
** __date
) const
2860 // Always have default first.
2861 __date
[0] = _M_data
->_M_date_format
;
2862 __date
[1] = _M_data
->_M_date_era_format
;
2866 _M_time_formats(const _CharT
** __time
) const
2868 // Always have default first.
2869 __time
[0] = _M_data
->_M_time_format
;
2870 __time
[1] = _M_data
->_M_time_era_format
;
2874 _M_ampm(const _CharT
** __ampm
) const
2876 __ampm
[0] = _M_data
->_M_am
;
2877 __ampm
[1] = _M_data
->_M_pm
;
2881 _M_date_time_formats(const _CharT
** __dt
) const
2883 // Always have default first.
2884 __dt
[0] = _M_data
->_M_date_time_format
;
2885 __dt
[1] = _M_data
->_M_date_time_era_format
;
2889 _M_days(const _CharT
** __days
) const
2891 __days
[0] = _M_data
->_M_day1
;
2892 __days
[1] = _M_data
->_M_day2
;
2893 __days
[2] = _M_data
->_M_day3
;
2894 __days
[3] = _M_data
->_M_day4
;
2895 __days
[4] = _M_data
->_M_day5
;
2896 __days
[5] = _M_data
->_M_day6
;
2897 __days
[6] = _M_data
->_M_day7
;
2901 _M_days_abbreviated(const _CharT
** __days
) const
2903 __days
[0] = _M_data
->_M_aday1
;
2904 __days
[1] = _M_data
->_M_aday2
;
2905 __days
[2] = _M_data
->_M_aday3
;
2906 __days
[3] = _M_data
->_M_aday4
;
2907 __days
[4] = _M_data
->_M_aday5
;
2908 __days
[5] = _M_data
->_M_aday6
;
2909 __days
[6] = _M_data
->_M_aday7
;
2913 _M_months(const _CharT
** __months
) const
2915 __months
[0] = _M_data
->_M_month01
;
2916 __months
[1] = _M_data
->_M_month02
;
2917 __months
[2] = _M_data
->_M_month03
;
2918 __months
[3] = _M_data
->_M_month04
;
2919 __months
[4] = _M_data
->_M_month05
;
2920 __months
[5] = _M_data
->_M_month06
;
2921 __months
[6] = _M_data
->_M_month07
;
2922 __months
[7] = _M_data
->_M_month08
;
2923 __months
[8] = _M_data
->_M_month09
;
2924 __months
[9] = _M_data
->_M_month10
;
2925 __months
[10] = _M_data
->_M_month11
;
2926 __months
[11] = _M_data
->_M_month12
;
2930 _M_months_abbreviated(const _CharT
** __months
) const
2932 __months
[0] = _M_data
->_M_amonth01
;
2933 __months
[1] = _M_data
->_M_amonth02
;
2934 __months
[2] = _M_data
->_M_amonth03
;
2935 __months
[3] = _M_data
->_M_amonth04
;
2936 __months
[4] = _M_data
->_M_amonth05
;
2937 __months
[5] = _M_data
->_M_amonth06
;
2938 __months
[6] = _M_data
->_M_amonth07
;
2939 __months
[7] = _M_data
->_M_amonth08
;
2940 __months
[8] = _M_data
->_M_amonth09
;
2941 __months
[9] = _M_data
->_M_amonth10
;
2942 __months
[10] = _M_data
->_M_amonth11
;
2943 __months
[11] = _M_data
->_M_amonth12
;
2950 // For use at construction time only.
2952 _M_initialize_timepunct(__c_locale __cloc
= NULL
);
2955 template<typename _CharT
>
2956 locale::id __timepunct
<_CharT
>::id
;
2961 __timepunct
<char>::_M_initialize_timepunct(__c_locale __cloc
);
2965 __timepunct
<char>::_M_put(char*, size_t, const char*, const tm
*) const;
2967 #ifdef _GLIBCXX_USE_WCHAR_T
2970 __timepunct
<wchar_t>::_M_initialize_timepunct(__c_locale __cloc
);
2974 __timepunct
<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
2978 // Include host and configuration specific timepunct functions.
2979 #include <bits/time_members.h>
2982 * @brief Facet for parsing dates and times.
2984 * This facet encapsulates the code to parse and return a date or
2985 * time from a string. It is used by the istream numeric
2986 * extraction operators.
2988 * The time_get template uses protected virtual functions to provide the
2989 * actual results. The public accessors forward the call to the virtual
2990 * functions. These virtual functions are hooks for developers to
2991 * implement the behavior they require from the time_get facet.
2993 template<typename _CharT
, typename _InIter
>
2994 class time_get
: public locale::facet
, public time_base
3000 typedef _CharT char_type
;
3001 typedef _InIter iter_type
;
3003 typedef basic_string
<_CharT
> __string_type
;
3005 /// Numpunct facet id.
3006 static locale::id id
;
3009 * @brief Constructor performs initialization.
3011 * This is the constructor provided by the standard.
3013 * @param refs Passed to the base facet class.
3016 time_get(size_t __refs
= 0)
3017 : facet (__refs
) { }
3020 * @brief Return preferred order of month, day, and year.
3022 * This function returns an enum from timebase::dateorder giving the
3023 * preferred ordering if the format "x" given to time_put::put() only
3024 * uses month, day, and year. If the format "x" for the associated
3025 * locale uses other fields, this function returns
3026 * timebase::dateorder::noorder.
3028 * NOTE: The library always returns noorder at the moment.
3030 * @return A member of timebase::dateorder.
3034 { return this->do_date_order(); }
3037 * @brief Parse input time string.
3039 * This function parses a time according to the format "x" and puts the
3040 * results into a user-supplied struct tm. The result is returned by
3041 * calling time_get::do_get_time().
3043 * If there is a valid time string according to format "x", @a tm will
3044 * be filled in accordingly and the returned iterator will point to the
3045 * first character beyond the time string. If an error occurs before
3046 * the end, err |= ios_base::failbit. If parsing reads all the
3047 * characters, err |= ios_base::eofbit.
3049 * @param beg Start of string to parse.
3050 * @param end End of string to parse.
3051 * @param io Source of the locale.
3052 * @param err Error flags to set.
3053 * @param tm Pointer to struct tm to fill in.
3054 * @return Iterator to first char beyond time string.
3057 get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3058 ios_base::iostate
& __err
, tm
* __tm
) const
3059 { return this->do_get_time(__beg
, __end
, __io
, __err
, __tm
); }
3062 * @brief Parse input date string.
3064 * This function parses a date according to the format "X" and puts the
3065 * results into a user-supplied struct tm. The result is returned by
3066 * calling time_get::do_get_date().
3068 * If there is a valid date string according to format "X", @a tm will
3069 * be filled in accordingly and the returned iterator will point to the
3070 * first character beyond the date string. If an error occurs before
3071 * the end, err |= ios_base::failbit. If parsing reads all the
3072 * characters, err |= ios_base::eofbit.
3074 * @param beg Start of string to parse.
3075 * @param end End of string to parse.
3076 * @param io Source of the locale.
3077 * @param err Error flags to set.
3078 * @param tm Pointer to struct tm to fill in.
3079 * @return Iterator to first char beyond date string.
3082 get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3083 ios_base::iostate
& __err
, tm
* __tm
) const
3084 { return this->do_get_date(__beg
, __end
, __io
, __err
, __tm
); }
3087 * @brief Parse input weekday string.
3089 * This function parses a weekday name and puts the results into a
3090 * user-supplied struct tm. The result is returned by calling
3091 * time_get::do_get_weekday().
3093 * Parsing starts by parsing an abbreviated weekday name. If a valid
3094 * abbreviation is followed by a character that would lead to the full
3095 * weekday name, parsing continues until the full name is found or an
3096 * error occurs. Otherwise parsing finishes at the end of the
3099 * If an error occurs before the end, err |= ios_base::failbit. If
3100 * parsing reads all the characters, err |= ios_base::eofbit.
3102 * @param beg Start of string to parse.
3103 * @param end End of string to parse.
3104 * @param io Source of the locale.
3105 * @param err Error flags to set.
3106 * @param tm Pointer to struct tm to fill in.
3107 * @return Iterator to first char beyond weekday name.
3110 get_weekday(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3111 ios_base::iostate
& __err
, tm
* __tm
) const
3112 { return this->do_get_weekday(__beg
, __end
, __io
, __err
, __tm
); }
3115 * @brief Parse input month string.
3117 * This function parses a month name and puts the results into a
3118 * user-supplied struct tm. The result is returned by calling
3119 * time_get::do_get_monthname().
3121 * Parsing starts by parsing an abbreviated month name. If a valid
3122 * abbreviation is followed by a character that would lead to the full
3123 * month name, parsing continues until the full name is found or an
3124 * error occurs. Otherwise parsing finishes at the end of the
3127 * If an error occurs before the end, err |= ios_base::failbit. If
3128 * parsing reads all the characters, err |=
3131 * @param beg Start of string to parse.
3132 * @param end End of string to parse.
3133 * @param io Source of the locale.
3134 * @param err Error flags to set.
3135 * @param tm Pointer to struct tm to fill in.
3136 * @return Iterator to first char beyond month name.
3139 get_monthname(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3140 ios_base::iostate
& __err
, tm
* __tm
) const
3141 { return this->do_get_monthname(__beg
, __end
, __io
, __err
, __tm
); }
3144 * @brief Parse input year string.
3146 * This function reads up to 4 characters to parse a year string and
3147 * puts the results into a user-supplied struct tm. The result is
3148 * returned by calling time_get::do_get_year().
3150 * 4 consecutive digits are interpreted as a full year. If there are
3151 * exactly 2 consecutive digits, the library interprets this as the
3152 * number of years since 1900.
3154 * If an error occurs before the end, err |= ios_base::failbit. If
3155 * parsing reads all the characters, err |= ios_base::eofbit.
3157 * @param beg Start of string to parse.
3158 * @param end End of string to parse.
3159 * @param io Source of the locale.
3160 * @param err Error flags to set.
3161 * @param tm Pointer to struct tm to fill in.
3162 * @return Iterator to first char beyond year.
3165 get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3166 ios_base::iostate
& __err
, tm
* __tm
) const
3167 { return this->do_get_year(__beg
, __end
, __io
, __err
, __tm
); }
3175 * @brief Return preferred order of month, day, and year.
3177 * This function returns an enum from timebase::dateorder giving the
3178 * preferred ordering if the format "x" given to time_put::put() only
3179 * uses month, day, and year. This function is a hook for derived
3180 * classes to change the value returned.
3182 * @return A member of timebase::dateorder.
3185 do_date_order() const;
3188 * @brief Parse input time string.
3190 * This function parses a time according to the format "x" and puts the
3191 * results into a user-supplied struct tm. This function is a hook for
3192 * derived classes to change the value returned. @see get_time() for
3195 * @param beg Start of string to parse.
3196 * @param end End of string to parse.
3197 * @param io Source of the locale.
3198 * @param err Error flags to set.
3199 * @param tm Pointer to struct tm to fill in.
3200 * @return Iterator to first char beyond time string.
3203 do_get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3204 ios_base::iostate
& __err
, tm
* __tm
) const;
3207 * @brief Parse input date string.
3209 * This function parses a date according to the format "X" and puts the
3210 * results into a user-supplied struct tm. This function is a hook for
3211 * derived classes to change the value returned. @see get_date() for
3214 * @param beg Start of string to parse.
3215 * @param end End of string to parse.
3216 * @param io Source of the locale.
3217 * @param err Error flags to set.
3218 * @param tm Pointer to struct tm to fill in.
3219 * @return Iterator to first char beyond date string.
3222 do_get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3223 ios_base::iostate
& __err
, tm
* __tm
) const;
3226 * @brief Parse input weekday string.
3228 * This function parses a weekday name and puts the results into a
3229 * user-supplied struct tm. This function is a hook for derived
3230 * classes to change the value returned. @see get_weekday() for
3233 * @param beg Start of string to parse.
3234 * @param end End of string to parse.
3235 * @param io Source of the locale.
3236 * @param err Error flags to set.
3237 * @param tm Pointer to struct tm to fill in.
3238 * @return Iterator to first char beyond weekday name.
3241 do_get_weekday(iter_type __beg
, iter_type __end
, ios_base
&,
3242 ios_base::iostate
& __err
, tm
* __tm
) const;
3245 * @brief Parse input month string.
3247 * This function parses a month name and puts the results into a
3248 * user-supplied struct tm. This function is a hook for derived
3249 * classes to change the value returned. @see get_monthname() for
3252 * @param beg Start of string to parse.
3253 * @param end End of string to parse.
3254 * @param io Source of the locale.
3255 * @param err Error flags to set.
3256 * @param tm Pointer to struct tm to fill in.
3257 * @return Iterator to first char beyond month name.
3260 do_get_monthname(iter_type __beg
, iter_type __end
, ios_base
&,
3261 ios_base::iostate
& __err
, tm
* __tm
) const;
3264 * @brief Parse input year string.
3266 * This function reads up to 4 characters to parse a year string and
3267 * puts the results into a user-supplied struct tm. This function is a
3268 * hook for derived classes to change the value returned. @see
3269 * get_year() for details.
3271 * @param beg Start of string to parse.
3272 * @param end End of string to parse.
3273 * @param io Source of the locale.
3274 * @param err Error flags to set.
3275 * @param tm Pointer to struct tm to fill in.
3276 * @return Iterator to first char beyond year.
3279 do_get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3280 ios_base::iostate
& __err
, tm
* __tm
) const;
3282 // Extract numeric component of length __len.
3284 _M_extract_num(iter_type
& __beg
, iter_type
& __end
, int& __member
,
3285 int __min
, int __max
, size_t __len
,
3286 const ctype
<_CharT
>& __ctype
,
3287 ios_base::iostate
& __err
) const;
3289 // Extract day or month name, or any unique array of string
3290 // literals in a const _CharT* array.
3292 _M_extract_name(iter_type
& __beg
, iter_type
& __end
, int& __member
,
3293 const _CharT
** __names
, size_t __indexlen
,
3294 const ctype
<_CharT
>& __ctype
,
3295 ios_base::iostate
& __err
) const;
3297 // Extract on a component-by-component basis, via __format argument.
3299 _M_extract_via_format(iter_type
& __beg
, iter_type
& __end
, ios_base
& __io
,
3300 ios_base::iostate
& __err
, tm
* __tm
,
3301 const _CharT
* __format
) const;
3304 template<typename _CharT
, typename _InIter
>
3305 locale::id time_get
<_CharT
, _InIter
>::id
;
3307 template<typename _CharT
, typename _InIter
>
3308 class time_get_byname
: public time_get
<_CharT
, _InIter
>
3312 typedef _CharT char_type
;
3313 typedef _InIter iter_type
;
3316 time_get_byname(const char*, size_t __refs
= 0)
3317 : time_get
<_CharT
, _InIter
>(__refs
) { }
3321 ~time_get_byname() { }
3325 * @brief Facet for outputting dates and times.
3327 * This facet encapsulates the code to format and output dates and times
3328 * according to formats used by strftime().
3330 * The time_put template uses protected virtual functions to provide the
3331 * actual results. The public accessors forward the call to the virtual
3332 * functions. These virtual functions are hooks for developers to
3333 * implement the behavior they require from the time_put facet.
3335 template<typename _CharT
, typename _OutIter
>
3336 class time_put
: public locale::facet
, public time_base
3342 typedef _CharT char_type
;
3343 typedef _OutIter iter_type
;
3346 /// Numpunct facet id.
3347 static locale::id id
;
3350 * @brief Constructor performs initialization.
3352 * This is the constructor provided by the standard.
3354 * @param refs Passed to the base facet class.
3357 time_put(size_t __refs
= 0)
3361 * @brief Format and output a time or date.
3363 * This function formats the data in struct tm according to the
3364 * provided format string. The format string is interpreted as by
3367 * @param s The stream to write to.
3368 * @param io Source of locale.
3369 * @param fill char_type to use for padding.
3370 * @param tm Struct tm with date and time info to format.
3371 * @param beg Start of format string.
3372 * @param end End of format string.
3373 * @return Iterator after writing.
3376 put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
3377 const _CharT
* __beg
, const _CharT
* __end
) const;
3380 * @brief Format and output a time or date.
3382 * This function formats the data in struct tm according to the
3383 * provided format char and optional modifier. The format and modifier
3384 * are interpreted as by strftime(). It does so by returning
3385 * time_put::do_put().
3387 * @param s The stream to write to.
3388 * @param io Source of locale.
3389 * @param fill char_type to use for padding.
3390 * @param tm Struct tm with date and time info to format.
3391 * @param format Format char.
3392 * @param mod Optional modifier char.
3393 * @return Iterator after writing.
3396 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
3397 const tm
* __tm
, char __format
, char __mod
= 0) const
3398 { return this->do_put(__s
, __io
, __fill
, __tm
, __format
, __mod
); }
3407 * @brief Format and output a time or date.
3409 * This function formats the data in struct tm according to the
3410 * provided format char and optional modifier. This function is a hook
3411 * for derived classes to change the value returned. @see put() for
3414 * @param s The stream to write to.
3415 * @param io Source of locale.
3416 * @param fill char_type to use for padding.
3417 * @param tm Struct tm with date and time info to format.
3418 * @param format Format char.
3419 * @param mod Optional modifier char.
3420 * @return Iterator after writing.
3423 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
3424 char __format
, char __mod
) const;
3427 template<typename _CharT
, typename _OutIter
>
3428 locale::id time_put
<_CharT
, _OutIter
>::id
;
3430 template<typename _CharT
, typename _OutIter
>
3431 class time_put_byname
: public time_put
<_CharT
, _OutIter
>
3435 typedef _CharT char_type
;
3436 typedef _OutIter iter_type
;
3439 time_put_byname(const char*, size_t __refs
= 0)
3440 : time_put
<_CharT
, _OutIter
>(__refs
)
3445 ~time_put_byname() { }
3450 * @brief Money format ordering data.
3452 * This class contains an ordered array of 4 fields to represent the
3453 * pattern for formatting a money amount. Each field may contain one entry
3454 * from the part enum. symbol, sign, and value must be present and the
3455 * remaining field must contain either none or space. @see
3456 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
3457 * these fields are interpreted.
3462 enum part
{ none
, space
, symbol
, sign
, value
};
3463 struct pattern
{ char field
[4]; };
3465 static const pattern _S_default_pattern
;
3467 // Construct and return valid pattern consisting of some combination of:
3468 // space none symbol sign value
3470 _S_construct_pattern(char __precedes
, char __space
, char __posn
);
3473 template<typename _CharT
>
3474 struct __moneypunct_cache
: public locale::facet
3476 const char* _M_grouping
;
3477 bool _M_use_grouping
;
3478 _CharT _M_decimal_point
;
3479 _CharT _M_thousands_sep
;
3480 const _CharT
* _M_curr_symbol
;
3481 const _CharT
* _M_positive_sign
;
3482 const _CharT
* _M_negative_sign
;
3484 money_base::pattern _M_pos_format
;
3485 money_base::pattern _M_neg_format
;
3489 __moneypunct_cache(size_t __refs
= 0) : facet(__refs
),
3490 _M_grouping(NULL
), _M_use_grouping(false), _M_decimal_point(_CharT()),
3491 _M_thousands_sep(_CharT()), _M_curr_symbol(NULL
), _M_positive_sign(NULL
),
3492 _M_negative_sign(NULL
), _M_frac_digits(0),
3493 _M_pos_format(money_base::pattern()),
3494 _M_neg_format(money_base::pattern()), _M_allocated(false)
3497 ~__moneypunct_cache();
3500 _M_cache(const locale
& __loc
);
3503 template<typename _CharT
>
3504 __moneypunct_cache
<_CharT
>::~__moneypunct_cache()
3513 * @brief Facet for formatting data for money amounts.
3515 * This facet encapsulates the punctuation, grouping and other formatting
3516 * features of money amount string representations.
3518 template<typename _CharT
, bool _Intl
>
3519 class moneypunct
: public locale::facet
, public money_base
3525 typedef _CharT char_type
;
3526 typedef basic_string
<_CharT
> string_type
;
3528 typedef __moneypunct_cache
<_CharT
> __cache_type
;
3531 __cache_type
* _M_data
;
3534 /// This value is provided by the standard, but no reason for its
3536 static const bool intl
= _Intl
;
3537 /// Numpunct facet id.
3538 static locale::id id
;
3541 * @brief Constructor performs initialization.
3543 * This is the constructor provided by the standard.
3545 * @param refs Passed to the base facet class.
3548 moneypunct(size_t __refs
= 0) : facet(__refs
), _M_data(NULL
)
3549 { _M_initialize_moneypunct(); }
3552 * @brief Constructor performs initialization.
3554 * This is an internal constructor.
3556 * @param cache Cache for optimization.
3557 * @param refs Passed to the base facet class.
3560 moneypunct(__cache_type
* __cache
, size_t __refs
= 0)
3561 : facet(__refs
), _M_data(__cache
)
3562 { _M_initialize_moneypunct(); }
3565 * @brief Internal constructor. Not for general use.
3567 * This is a constructor for use by the library itself to set up new
3570 * @param cloc The "C" locale.
3571 * @param s The name of a locale.
3572 * @param refs Passed to the base facet class.
3575 moneypunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0)
3576 : facet(__refs
), _M_data(NULL
)
3577 { _M_initialize_moneypunct(__cloc
, __s
); }
3580 * @brief Return decimal point character.
3582 * This function returns a char_type to use as a decimal point. It
3583 * does so by returning returning
3584 * moneypunct<char_type>::do_decimal_point().
3586 * @return @a char_type representing a decimal point.
3589 decimal_point() const
3590 { return this->do_decimal_point(); }
3593 * @brief Return thousands separator character.
3595 * This function returns a char_type to use as a thousands separator. It
3596 * does so by returning returning
3597 * moneypunct<char_type>::do_thousands_sep().
3599 * @return char_type representing a thousands separator.
3602 thousands_sep() const
3603 { return this->do_thousands_sep(); }
3606 * @brief Return grouping specification.
3608 * This function returns a string representing groupings for the
3609 * integer part of an amount. Groupings indicate where thousands
3610 * separators should be inserted.
3612 * Each char in the return string is interpret as an integer rather
3613 * than a character. These numbers represent the number of digits in a
3614 * group. The first char in the string represents the number of digits
3615 * in the least significant group. If a char is negative, it indicates
3616 * an unlimited number of digits for the group. If more chars from the
3617 * string are required to group a number, the last char is used
3620 * For example, if the grouping() returns "\003\002" and is applied to
3621 * the number 123456789, this corresponds to 12,34,56,789. Note that
3622 * if the string was "32", this would put more than 50 digits into the
3623 * least significant group if the character set is ASCII.
3625 * The string is returned by calling
3626 * moneypunct<char_type>::do_grouping().
3628 * @return string representing grouping specification.
3632 { return this->do_grouping(); }
3635 * @brief Return currency symbol string.
3637 * This function returns a string_type to use as a currency symbol. It
3638 * does so by returning returning
3639 * moneypunct<char_type>::do_curr_symbol().
3641 * @return @a string_type representing a currency symbol.
3645 { return this->do_curr_symbol(); }
3648 * @brief Return positive sign string.
3650 * This function returns a string_type to use as a sign for positive
3651 * amounts. It does so by returning returning
3652 * moneypunct<char_type>::do_positive_sign().
3654 * If the return value contains more than one character, the first
3655 * character appears in the position indicated by pos_format() and the
3656 * remainder appear at the end of the formatted string.
3658 * @return @a string_type representing a positive sign.
3661 positive_sign() const
3662 { return this->do_positive_sign(); }
3665 * @brief Return negative sign string.
3667 * This function returns a string_type to use as a sign for negative
3668 * amounts. It does so by returning returning
3669 * moneypunct<char_type>::do_negative_sign().
3671 * If the return value contains more than one character, the first
3672 * character appears in the position indicated by neg_format() and the
3673 * remainder appear at the end of the formatted string.
3675 * @return @a string_type representing a negative sign.
3678 negative_sign() const
3679 { return this->do_negative_sign(); }
3682 * @brief Return number of digits in fraction.
3684 * This function returns the exact number of digits that make up the
3685 * fractional part of a money amount. It does so by returning
3686 * returning moneypunct<char_type>::do_frac_digits().
3688 * The fractional part of a money amount is optional. But if it is
3689 * present, there must be frac_digits() digits.
3691 * @return Number of digits in amount fraction.
3695 { return this->do_frac_digits(); }
3699 * @brief Return pattern for money values.
3701 * This function returns a pattern describing the formatting of a
3702 * positive or negative valued money amount. It does so by returning
3703 * returning moneypunct<char_type>::do_pos_format() or
3704 * moneypunct<char_type>::do_neg_format().
3706 * The pattern has 4 fields describing the ordering of symbol, sign,
3707 * value, and none or space. There must be one of each in the pattern.
3708 * The none and space enums may not appear in the first field and space
3709 * may not appear in the final field.
3711 * The parts of a money string must appear in the order indicated by
3712 * the fields of the pattern. The symbol field indicates that the
3713 * value of curr_symbol() may be present. The sign field indicates
3714 * that the value of positive_sign() or negative_sign() must be
3715 * present. The value field indicates that the absolute value of the
3716 * money amount is present. none indicates 0 or more whitespace
3717 * characters, except at the end, where it permits no whitespace.
3718 * space indicates that 1 or more whitespace characters must be
3721 * For example, for the US locale and pos_format() pattern
3722 * {symbol,sign,value,none}, curr_symbol() == '$' positive_sign() ==
3723 * '+', and value 10.01, and options set to force the symbol, the
3724 * corresponding string is "$+10.01".
3726 * @return Pattern for money values.
3730 { return this->do_pos_format(); }
3734 { return this->do_neg_format(); }
3743 * @brief Return decimal point character.
3745 * Returns a char_type to use as a decimal point. This function is a
3746 * hook for derived classes to change the value returned.
3748 * @return @a char_type representing a decimal point.
3751 do_decimal_point() const
3752 { return _M_data
->_M_decimal_point
; }
3755 * @brief Return thousands separator character.
3757 * Returns a char_type to use as a thousands separator. This function
3758 * is a hook for derived classes to change the value returned.
3760 * @return @a char_type representing a thousands separator.
3763 do_thousands_sep() const
3764 { return _M_data
->_M_thousands_sep
; }
3767 * @brief Return grouping specification.
3769 * Returns a string representing groupings for the integer part of a
3770 * number. This function is a hook for derived classes to change the
3771 * value returned. @see grouping() for details.
3773 * @return String representing grouping specification.
3777 { return _M_data
->_M_grouping
; }
3780 * @brief Return currency symbol string.
3782 * This function returns a string_type to use as a currency symbol.
3783 * This function is a hook for derived classes to change the value
3784 * returned. @see curr_symbol() for details.
3786 * @return @a string_type representing a currency symbol.
3789 do_curr_symbol() const
3790 { return _M_data
->_M_curr_symbol
; }
3793 * @brief Return positive sign string.
3795 * This function returns a string_type to use as a sign for positive
3796 * amounts. This function is a hook for derived classes to change the
3797 * value returned. @see positive_sign() for details.
3799 * @return @a string_type representing a positive sign.
3802 do_positive_sign() const
3803 { return _M_data
->_M_positive_sign
; }
3806 * @brief Return negative sign string.
3808 * This function returns a string_type to use as a sign for negative
3809 * amounts. This function is a hook for derived classes to change the
3810 * value returned. @see negative_sign() for details.
3812 * @return @a string_type representing a negative sign.
3815 do_negative_sign() const
3816 { return _M_data
->_M_negative_sign
; }
3819 * @brief Return number of digits in fraction.
3821 * This function returns the exact number of digits that make up the
3822 * fractional part of a money amount. This function is a hook for
3823 * derived classes to change the value returned. @see frac_digits()
3826 * @return Number of digits in amount fraction.
3829 do_frac_digits() const
3830 { return _M_data
->_M_frac_digits
; }
3833 * @brief Return pattern for money values.
3835 * This function returns a pattern describing the formatting of a
3836 * positive valued money amount. This function is a hook for derived
3837 * classes to change the value returned. @see pos_format() for
3840 * @return Pattern for money values.
3843 do_pos_format() const
3844 { return _M_data
->_M_pos_format
; }
3847 * @brief Return pattern for money values.
3849 * This function returns a pattern describing the formatting of a
3850 * negative valued money amount. This function is a hook for derived
3851 * classes to change the value returned. @see neg_format() for
3854 * @return Pattern for money values.
3857 do_neg_format() const
3858 { return _M_data
->_M_neg_format
; }
3860 // For use at construction time only.
3862 _M_initialize_moneypunct(__c_locale __cloc
= NULL
,
3863 const char* __name
= NULL
);
3866 template<typename _CharT
, bool _Intl
>
3867 locale::id moneypunct
<_CharT
, _Intl
>::id
;
3869 template<typename _CharT
, bool _Intl
>
3870 const bool moneypunct
<_CharT
, _Intl
>::intl
;
3873 moneypunct
<char, true>::~moneypunct();
3876 moneypunct
<char, false>::~moneypunct();
3880 moneypunct
<char, true>::_M_initialize_moneypunct(__c_locale
, const char*);
3884 moneypunct
<char, false>::_M_initialize_moneypunct(__c_locale
, const char*);
3886 #ifdef _GLIBCXX_USE_WCHAR_T
3888 moneypunct
<wchar_t, true>::~moneypunct();
3891 moneypunct
<wchar_t, false>::~moneypunct();
3895 moneypunct
<wchar_t, true>::_M_initialize_moneypunct(__c_locale
,
3900 moneypunct
<wchar_t, false>::_M_initialize_moneypunct(__c_locale
,
3904 template<typename _CharT
, bool _Intl
>
3905 class moneypunct_byname
: public moneypunct
<_CharT
, _Intl
>
3908 typedef _CharT char_type
;
3909 typedef basic_string
<_CharT
> string_type
;
3911 static const bool intl
= _Intl
;
3914 moneypunct_byname(const char* __s
, size_t __refs
= 0)
3915 : moneypunct
<_CharT
, _Intl
>(__refs
)
3917 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
3920 this->_S_create_c_locale(__tmp
, __s
);
3921 this->_M_initialize_moneypunct(__tmp
);
3922 this->_S_destroy_c_locale(__tmp
);
3928 ~moneypunct_byname() { }
3931 template<typename _CharT
, bool _Intl
>
3932 const bool moneypunct_byname
<_CharT
, _Intl
>::intl
;
3935 * @brief Facet for parsing monetary amounts.
3937 * This facet encapsulates the code to parse and return a monetary
3938 * amount from a string.
3940 * The money_get template uses protected virtual functions to
3941 * provide the actual results. The public accessors forward the
3942 * call to the virtual functions. These virtual functions are
3943 * hooks for developers to implement the behavior they require from
3944 * the money_get facet.
3946 template<typename _CharT
, typename _InIter
>
3947 class money_get
: public locale::facet
3953 typedef _CharT char_type
;
3954 typedef _InIter iter_type
;
3955 typedef basic_string
<_CharT
> string_type
;
3958 /// Numpunct facet id.
3959 static locale::id id
;
3962 * @brief Constructor performs initialization.
3964 * This is the constructor provided by the standard.
3966 * @param refs Passed to the base facet class.
3969 money_get(size_t __refs
= 0) : facet(__refs
) { }
3972 * @brief Read and parse a monetary value.
3974 * This function reads characters from @a s, interprets them as a
3975 * monetary value according to moneypunct and ctype facets retrieved
3976 * from io.getloc(), and returns the result in @a units as an integral
3977 * value moneypunct::frac_digits() * the actual amount. For example,
3978 * the string $10.01 in a US locale would store 1001 in @a units.
3980 * Any characters not part of a valid money amount are not consumed.
3982 * If a money value cannot be parsed from the input stream, sets
3983 * err=(err|io.failbit). If the stream is consumed before finishing
3984 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
3985 * unchanged if parsing fails.
3987 * This function works by returning the result of do_get().
3989 * @param s Start of characters to parse.
3990 * @param end End of characters to parse.
3991 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
3992 * @param io Source of facets and io state.
3993 * @param err Error field to set if parsing fails.
3994 * @param units Place to store result of parsing.
3995 * @return Iterator referencing first character beyond valid money
3999 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4000 ios_base::iostate
& __err
, long double& __units
) const
4001 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __units
); }
4004 * @brief Read and parse a monetary value.
4006 * This function reads characters from @a s, interprets them as a
4007 * monetary value according to moneypunct and ctype facets retrieved
4008 * from io.getloc(), and returns the result in @a digits. For example,
4009 * the string $10.01 in a US locale would store "1001" in @a digits.
4011 * Any characters not part of a valid money amount are not consumed.
4013 * If a money value cannot be parsed from the input stream, sets
4014 * err=(err|io.failbit). If the stream is consumed before finishing
4015 * parsing, sets err=(err|io.failbit|io.eofbit).
4017 * This function works by returning the result of do_get().
4019 * @param s Start of characters to parse.
4020 * @param end End of characters to parse.
4021 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4022 * @param io Source of facets and io state.
4023 * @param err Error field to set if parsing fails.
4024 * @param digits Place to store result of parsing.
4025 * @return Iterator referencing first character beyond valid money
4029 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4030 ios_base::iostate
& __err
, string_type
& __digits
) const
4031 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __digits
); }
4039 * @brief Read and parse a monetary value.
4041 * This function reads and parses characters representing a monetary
4042 * value. This function is a hook for derived classes to change the
4043 * value returned. @see get() for details.
4046 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4047 ios_base::iostate
& __err
, long double& __units
) const;
4050 * @brief Read and parse a monetary value.
4052 * This function reads and parses characters representing a monetary
4053 * value. This function is a hook for derived classes to change the
4054 * value returned. @see get() for details.
4057 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4058 ios_base::iostate
& __err
, string_type
& __digits
) const;
4061 template<typename _CharT
, typename _InIter
>
4062 locale::id money_get
<_CharT
, _InIter
>::id
;
4065 * @brief Facet for outputting monetary amounts.
4067 * This facet encapsulates the code to format and output a monetary
4070 * The money_put template uses protected virtual functions to
4071 * provide the actual results. The public accessors forward the
4072 * call to the virtual functions. These virtual functions are
4073 * hooks for developers to implement the behavior they require from
4074 * the money_put facet.
4076 template<typename _CharT
, typename _OutIter
>
4077 class money_put
: public locale::facet
4082 typedef _CharT char_type
;
4083 typedef _OutIter iter_type
;
4084 typedef basic_string
<_CharT
> string_type
;
4087 /// Numpunct facet id.
4088 static locale::id id
;
4091 * @brief Constructor performs initialization.
4093 * This is the constructor provided by the standard.
4095 * @param refs Passed to the base facet class.
4098 money_put(size_t __refs
= 0) : facet(__refs
) { }
4101 * @brief Format and output a monetary value.
4103 * This function formats @a units as a monetary value according to
4104 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4105 * the resulting characters to @a s. For example, the value 1001 in a
4106 * US locale would write "$10.01" to @a s.
4108 * This function works by returning the result of do_put().
4110 * @param s The stream to write to.
4111 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4112 * @param io Source of facets and io state.
4113 * @param fill char_type to use for padding.
4114 * @param units Place to store result of parsing.
4115 * @return Iterator after writing.
4118 put(iter_type __s
, bool __intl
, ios_base
& __io
,
4119 char_type __fill
, long double __units
) const
4120 { return this->do_put(__s
, __intl
, __io
, __fill
, __units
); }
4123 * @brief Format and output a monetary value.
4125 * This function formats @a digits as a monetary value according to
4126 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4127 * the resulting characters to @a s. For example, the string "1001" in
4128 * a US locale would write "$10.01" to @a s.
4130 * This function works by returning the result of do_put().
4132 * @param s The stream to write to.
4133 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4134 * @param io Source of facets and io state.
4135 * @param fill char_type to use for padding.
4136 * @param units Place to store result of parsing.
4137 * @return Iterator after writing.
4140 put(iter_type __s
, bool __intl
, ios_base
& __io
,
4141 char_type __fill
, const string_type
& __digits
) const
4142 { return this->do_put(__s
, __intl
, __io
, __fill
, __digits
); }
4150 * @brief Format and output a monetary value.
4152 * This function formats @a units as a monetary value according to
4153 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4154 * the resulting characters to @a s. For example, the value 1001 in a
4155 * US locale would write "$10.01" to @a s.
4157 * This function is a hook for derived classes to change the value
4158 * returned. @see put().
4160 * @param s The stream to write to.
4161 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4162 * @param io Source of facets and io state.
4163 * @param fill char_type to use for padding.
4164 * @param units Place to store result of parsing.
4165 * @return Iterator after writing.
4168 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4169 long double __units
) const;
4172 * @brief Format and output a monetary value.
4174 * This function formats @a digits as a monetary value according to
4175 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4176 * the resulting characters to @a s. For example, the string "1001" in
4177 * a US locale would write "$10.01" to @a s.
4179 * This function is a hook for derived classes to change the value
4180 * returned. @see put().
4182 * @param s The stream to write to.
4183 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4184 * @param io Source of facets and io state.
4185 * @param fill char_type to use for padding.
4186 * @param units Place to store result of parsing.
4187 * @return Iterator after writing.
4190 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4191 const string_type
& __digits
) const;
4194 template<typename _CharT
, typename _OutIter
>
4195 locale::id money_put
<_CharT
, _OutIter
>::id
;
4198 * @brief Messages facet base class providing catalog typedef.
4200 struct messages_base
4202 typedef int catalog
;
4206 * @brief Facet for handling message catalogs
4208 * This facet encapsulates the code to retrieve messages from
4209 * message catalogs. The only thing defined by the standard for this facet
4210 * is the interface. All underlying functionality is
4211 * implementation-defined.
4213 * This library currently implements 3 versions of the message facet. The
4214 * first version (gnu) is a wrapper around gettext, provided by libintl.
4215 * The second version (ieee) is a wrapper around catgets. The final
4216 * version (default) does no actual translation. These implementations are
4217 * only provided for char and wchar_t instantiations.
4219 * The messages template uses protected virtual functions to
4220 * provide the actual results. The public accessors forward the
4221 * call to the virtual functions. These virtual functions are
4222 * hooks for developers to implement the behavior they require from
4223 * the messages facet.
4225 template<typename _CharT
>
4226 class messages
: public locale::facet
, public messages_base
4232 typedef _CharT char_type
;
4233 typedef basic_string
<_CharT
> string_type
;
4237 // Underlying "C" library locale information saved from
4238 // initialization, needed by messages_byname as well.
4239 __c_locale _M_c_locale_messages
;
4240 const char* _M_name_messages
;
4243 /// Numpunct facet id.
4244 static locale::id id
;
4247 * @brief Constructor performs initialization.
4249 * This is the constructor provided by the standard.
4251 * @param refs Passed to the base facet class.
4254 messages(size_t __refs
= 0);
4258 * @brief Internal constructor. Not for general use.
4260 * This is a constructor for use by the library itself to set up new
4263 * @param cloc The "C" locale.
4264 * @param s The name of a locale.
4265 * @param refs Refcount to pass to the base class.
4268 messages(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
4271 * @brief Open a message catalog.
4273 * This function opens and returns a handle to a message catalog by
4274 * returning do_open(s, loc).
4276 * @param s The catalog to open.
4277 * @param loc Locale to use for character set conversions.
4278 * @return Handle to the catalog or value < 0 if open fails.
4281 open(const basic_string
<char>& __s
, const locale
& __loc
) const
4282 { return this->do_open(__s
, __loc
); }
4284 // Non-standard and unorthodox, yet effective.
4286 * @brief Open a message catalog.
4288 * This non-standard function opens and returns a handle to a message
4289 * catalog by returning do_open(s, loc). The third argument provides a
4290 * message catalog root directory for gnu gettext and is ignored
4293 * @param s The catalog to open.
4294 * @param loc Locale to use for character set conversions.
4295 * @param dir Message catalog root directory.
4296 * @return Handle to the catalog or value < 0 if open fails.
4299 open(const basic_string
<char>&, const locale
&, const char*) const;
4302 * @brief Look up a string in a message catalog.
4304 * This function retrieves and returns a message from a catalog by
4305 * returning do_get(c, set, msgid, s).
4307 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4308 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4310 * @param c The catalog to access.
4311 * @param set Implementation-defined.
4312 * @param msgid Implementation-defined.
4313 * @param s Default return value if retrieval fails.
4314 * @return Retrieved message or @a s if get fails.
4317 get(catalog __c
, int __set
, int __msgid
, const string_type
& __s
) const
4318 { return this->do_get(__c
, __set
, __msgid
, __s
); }
4321 * @brief Close a message catalog.
4323 * Closes catalog @a c by calling do_close(c).
4325 * @param c The catalog to close.
4328 close(catalog __c
) const
4329 { return this->do_close(__c
); }
4337 * @brief Open a message catalog.
4339 * This function opens and returns a handle to a message catalog in an
4340 * implementation-defined manner. This function is a hook for derived
4341 * classes to change the value returned.
4343 * @param s The catalog to open.
4344 * @param loc Locale to use for character set conversions.
4345 * @return Handle to the opened catalog, value < 0 if open failed.
4348 do_open(const basic_string
<char>&, const locale
&) const;
4351 * @brief Look up a string in a message catalog.
4353 * This function retrieves and returns a message from a catalog in an
4354 * implementation-defined manner. This function is a hook for derived
4355 * classes to change the value returned.
4357 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4358 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4360 * @param c The catalog to access.
4361 * @param set Implementation-defined.
4362 * @param msgid Implementation-defined.
4363 * @param s Default return value if retrieval fails.
4364 * @return Retrieved message or @a s if get fails.
4367 do_get(catalog
, int, int, const string_type
& __dfault
) const;
4370 * @brief Close a message catalog.
4372 * @param c The catalog to close.
4375 do_close(catalog
) const;
4377 // Returns a locale and codeset-converted string, given a char* message.
4379 _M_convert_to_char(const string_type
& __msg
) const
4382 return reinterpret_cast<char*>(const_cast<_CharT
*>(__msg
.c_str()));
4385 // Returns a locale and codeset-converted string, given a char* message.
4387 _M_convert_from_char(char*) const
4390 // Length of message string without terminating null.
4391 size_t __len
= char_traits
<char>::length(__msg
) - 1;
4393 // "everybody can easily convert the string using
4394 // mbsrtowcs/wcsrtombs or with iconv()"
4396 // Convert char* to _CharT in locale used to open catalog.
4397 // XXX need additional template parameter on messages class for this..
4398 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
4399 typedef typename codecvt
<char, _CharT
, mbstate_t> __codecvt_type
;
4401 __codecvt_type::state_type __state
;
4402 // XXX may need to initialize state.
4403 //initialize_state(__state._M_init());
4406 // XXX what size for this string?
4407 _CharT
* __to
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
4408 const __codecvt_type
& __cvt
= use_facet
<__codecvt_type
>(_M_locale_conv
);
4409 __cvt
.out(__state
, __msg
, __msg
+ __len
, __from_next
,
4410 __to
, __to
+ __len
+ 1, __to_next
);
4411 return string_type(__to
);
4414 typedef ctype
<_CharT
> __ctype_type
;
4415 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
4416 const __ctype_type
& __cvt
= use_facet
<__ctype_type
>(locale());
4417 // XXX Again, proper length of converted string an issue here.
4418 // For now, assume the converted length is not larger.
4419 _CharT
* __dest
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
4420 __cvt
.widen(__msg
, __msg
+ __len
, __dest
);
4421 return basic_string
<_CharT
>(__dest
);
4423 return string_type();
4427 template<typename _CharT
>
4428 locale::id messages
<_CharT
>::id
;
4430 // Specializations for required instantiations.
4433 messages
<char>::do_get(catalog
, int, int, const string
&) const;
4435 #ifdef _GLIBCXX_USE_WCHAR_T
4438 messages
<wchar_t>::do_get(catalog
, int, int, const wstring
&) const;
4441 template<typename _CharT
>
4442 class messages_byname
: public messages
<_CharT
>
4445 typedef _CharT char_type
;
4446 typedef basic_string
<_CharT
> string_type
;
4449 messages_byname(const char* __s
, size_t __refs
= 0);
4457 // Include host and configuration specific messages functions.
4458 #include <bits/messages_members.h>
4461 // Subclause convenience interfaces, inlines.
4462 // NB: These are inline because, when used in a loop, some compilers
4463 // can hoist the body out of the loop; then it's just as fast as the
4464 // C is*() function.
4466 /// Convenience interface to ctype.is().
4467 template<typename _CharT
>
4469 isspace(_CharT __c
, const locale
& __loc
)
4470 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::space
, __c
); }
4472 template<typename _CharT
>
4474 isprint(_CharT __c
, const locale
& __loc
)
4475 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::print
, __c
); }
4477 template<typename _CharT
>
4479 iscntrl(_CharT __c
, const locale
& __loc
)
4480 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::cntrl
, __c
); }
4482 template<typename _CharT
>
4484 isupper(_CharT __c
, const locale
& __loc
)
4485 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::upper
, __c
); }
4487 template<typename _CharT
>
4488 inline bool islower(_CharT __c
, const locale
& __loc
)
4489 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::lower
, __c
); }
4491 template<typename _CharT
>
4493 isalpha(_CharT __c
, const locale
& __loc
)
4494 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alpha
, __c
); }
4496 template<typename _CharT
>
4498 isdigit(_CharT __c
, const locale
& __loc
)
4499 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::digit
, __c
); }
4501 template<typename _CharT
>
4503 ispunct(_CharT __c
, const locale
& __loc
)
4504 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::punct
, __c
); }
4506 template<typename _CharT
>
4508 isxdigit(_CharT __c
, const locale
& __loc
)
4509 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::xdigit
, __c
); }
4511 template<typename _CharT
>
4513 isalnum(_CharT __c
, const locale
& __loc
)
4514 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alnum
, __c
); }
4516 template<typename _CharT
>
4518 isgraph(_CharT __c
, const locale
& __loc
)
4519 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::graph
, __c
); }
4521 template<typename _CharT
>
4523 toupper(_CharT __c
, const locale
& __loc
)
4524 { return use_facet
<ctype
<_CharT
> >(__loc
).toupper(__c
); }
4526 template<typename _CharT
>
4528 tolower(_CharT __c
, const locale
& __loc
)
4529 { return use_facet
<ctype
<_CharT
> >(__loc
).tolower(__c
); }