1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 // Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 2, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING. If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 // As a special exception, you may use this file as part of a free software
24 // library without restriction. Specifically, if other files instantiate
25 // templates or use macros or inline functions from this file, or you compile
26 // this file and link it with other files to produce an executable, this
27 // file does not by itself cause the resulting executable to be covered by
28 // the GNU General Public License. This exception does not however
29 // invalidate any other reasons why the executable file might be covered by
30 // the GNU General Public License.
32 /** @file locale_facets.h
33 * This is an internal header file, included by other library headers.
34 * You should not attempt to use it directly.
38 // ISO C++ 14882: 22.1 Locales
41 #ifndef _LOCALE_FACETS_H
42 #define _LOCALE_FACETS_H 1
44 #pragma GCC system_header
46 #include <ctime> // For struct tm
47 #include <cwctype> // For wctype_t
48 #include <bits/ctype_base.h>
50 #include <bits/ios_base.h> // For ios_base, ios_base::iostate
52 #include <bits/cpp_type_traits.h>
54 _GLIBCXX_BEGIN_NAMESPACE(std
)
56 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
57 #ifdef _GLIBCXX_USE_WCHAR_T
58 # define _GLIBCXX_NUM_FACETS 28
60 # define _GLIBCXX_NUM_FACETS 14
63 // Convert string to numeric value of type _Tv and store results.
64 // NB: This is specialized for all required types, there is no
65 // generic definition.
66 template<typename _Tv
>
68 __convert_to_v(const char* __in
, _Tv
& __out
, ios_base::iostate
& __err
,
69 const __c_locale
& __cloc
);
71 // Explicit specializations for required types.
74 __convert_to_v(const char*, float&, ios_base::iostate
&,
79 __convert_to_v(const char*, double&, ios_base::iostate
&,
84 __convert_to_v(const char*, long double&, ios_base::iostate
&,
87 // NB: __pad is a struct, rather than a function, so it can be
88 // partially-specialized.
89 template<typename _CharT
, typename _Traits
>
93 _S_pad(ios_base
& __io
, _CharT __fill
, _CharT
* __news
,
94 const _CharT
* __olds
, const streamsize __newlen
,
95 const streamsize __oldlen
, const bool __num
);
98 // Used by both numeric and monetary facets.
99 // Inserts "group separator" characters into an array of characters.
100 // It's recursive, one iteration per group. It moves the characters
101 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
102 // only with __glen != 0.
103 template<typename _CharT
>
105 __add_grouping(_CharT
* __s
, _CharT __sep
,
106 const char* __gbeg
, size_t __gsize
,
107 const _CharT
* __first
, const _CharT
* __last
);
109 // This template permits specializing facet output code for
110 // ostreambuf_iterator. For ostreambuf_iterator, sputn is
111 // significantly more efficient than incrementing iterators.
112 template<typename _CharT
>
114 ostreambuf_iterator
<_CharT
>
115 __write(ostreambuf_iterator
<_CharT
> __s
, const _CharT
* __ws
, int __len
)
117 __s
._M_put(__ws
, __len
);
121 // This is the unspecialized form of the template.
122 template<typename _CharT
, typename _OutIter
>
125 __write(_OutIter __s
, const _CharT
* __ws
, int __len
)
127 for (int __j
= 0; __j
< __len
; __j
++, ++__s
)
133 // 22.2.1.1 Template class ctype
134 // Include host and configuration specific ctype enums for ctype_base.
136 // Common base for ctype<_CharT>.
138 * @brief Common base for ctype facet
140 * This template class provides implementations of the public functions
141 * that forward to the protected virtual functions.
143 * This template also provides abtract stubs for the protected virtual
146 template<typename _CharT
>
147 class __ctype_abstract_base
: public locale::facet
, public ctype_base
151 /// Typedef for the template parameter
152 typedef _CharT char_type
;
155 * @brief Test char_type classification.
157 * This function finds a mask M for @a c and compares it to mask @a m.
158 * It does so by returning the value of ctype<char_type>::do_is().
160 * @param c The char_type to compare the mask of.
161 * @param m The mask to compare against.
162 * @return (M & m) != 0.
165 is(mask __m
, char_type __c
) const
166 { return this->do_is(__m
, __c
); }
169 * @brief Return a mask array.
171 * This function finds the mask for each char_type in the range [lo,hi)
172 * and successively writes it to vec. vec must have as many elements
173 * as the char array. It does so by returning the value of
174 * ctype<char_type>::do_is().
176 * @param lo Pointer to start of range.
177 * @param hi Pointer to end of range.
178 * @param vec Pointer to an array of mask storage.
182 is(const char_type
*__lo
, const char_type
*__hi
, mask
*__vec
) const
183 { return this->do_is(__lo
, __hi
, __vec
); }
186 * @brief Find char_type matching a mask
188 * This function searches for and returns the first char_type c in
189 * [lo,hi) for which is(m,c) is true. It does so by returning
190 * ctype<char_type>::do_scan_is().
192 * @param m The mask to compare against.
193 * @param lo Pointer to start of range.
194 * @param hi Pointer to end of range.
195 * @return Pointer to matching char_type if found, else @a hi.
198 scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
199 { return this->do_scan_is(__m
, __lo
, __hi
); }
202 * @brief Find char_type not matching a mask
204 * This function searches for and returns the first char_type c in
205 * [lo,hi) for which is(m,c) is false. It does so by returning
206 * ctype<char_type>::do_scan_not().
208 * @param m The mask to compare against.
209 * @param lo Pointer to first char in range.
210 * @param hi Pointer to end of range.
211 * @return Pointer to non-matching char if found, else @a hi.
214 scan_not(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
215 { return this->do_scan_not(__m
, __lo
, __hi
); }
218 * @brief Convert to uppercase.
220 * This function converts the argument to uppercase if possible.
221 * If not possible (for example, '2'), returns the argument. It does
222 * so by returning ctype<char_type>::do_toupper().
224 * @param c The char_type to convert.
225 * @return The uppercase char_type if convertible, else @a c.
228 toupper(char_type __c
) const
229 { return this->do_toupper(__c
); }
232 * @brief Convert array to uppercase.
234 * This function converts each char_type in the range [lo,hi) to
235 * uppercase if possible. Other elements remain untouched. It does so
236 * by returning ctype<char_type>:: do_toupper(lo, hi).
238 * @param lo Pointer to start of range.
239 * @param hi Pointer to end of range.
243 toupper(char_type
*__lo
, const char_type
* __hi
) const
244 { return this->do_toupper(__lo
, __hi
); }
247 * @brief Convert to lowercase.
249 * This function converts the argument to lowercase if possible. If
250 * not possible (for example, '2'), returns the argument. It does so
251 * by returning ctype<char_type>::do_tolower(c).
253 * @param c The char_type to convert.
254 * @return The lowercase char_type if convertible, else @a c.
257 tolower(char_type __c
) const
258 { return this->do_tolower(__c
); }
261 * @brief Convert array to lowercase.
263 * This function converts each char_type in the range [lo,hi) to
264 * lowercase if possible. Other elements remain untouched. It does so
265 * by returning ctype<char_type>:: do_tolower(lo, hi).
267 * @param lo Pointer to start of range.
268 * @param hi Pointer to end of range.
272 tolower(char_type
* __lo
, const char_type
* __hi
) const
273 { return this->do_tolower(__lo
, __hi
); }
276 * @brief Widen char to char_type
278 * This function converts the char argument to char_type using the
279 * simplest reasonable transformation. It does so by returning
280 * ctype<char_type>::do_widen(c).
282 * Note: this is not what you want for codepage conversions. See
285 * @param c The char to convert.
286 * @return The converted char_type.
289 widen(char __c
) const
290 { return this->do_widen(__c
); }
293 * @brief Widen array to char_type
295 * This function converts each char in the input to char_type using the
296 * simplest reasonable transformation. It does so by returning
297 * ctype<char_type>::do_widen(c).
299 * Note: this is not what you want for codepage conversions. See
302 * @param lo Pointer to start of range.
303 * @param hi Pointer to end of range.
304 * @param to Pointer to the destination array.
308 widen(const char* __lo
, const char* __hi
, char_type
* __to
) const
309 { return this->do_widen(__lo
, __hi
, __to
); }
312 * @brief Narrow char_type to char
314 * This function converts the char_type to char using the simplest
315 * reasonable transformation. If the conversion fails, dfault is
316 * returned instead. It does so by returning
317 * ctype<char_type>::do_narrow(c).
319 * Note: this is not what you want for codepage conversions. See
322 * @param c The char_type to convert.
323 * @param dfault Char to return if conversion fails.
324 * @return The converted char.
327 narrow(char_type __c
, char __dfault
) const
328 { return this->do_narrow(__c
, __dfault
); }
331 * @brief Narrow array to char array
333 * This function converts each char_type in the input to char using the
334 * simplest reasonable transformation and writes the results to the
335 * destination array. For any char_type in the input that cannot be
336 * converted, @a dfault is used instead. It does so by returning
337 * ctype<char_type>::do_narrow(lo, hi, dfault, to).
339 * Note: this is not what you want for codepage conversions. See
342 * @param lo Pointer to start of range.
343 * @param hi Pointer to end of range.
344 * @param dfault Char to use if conversion fails.
345 * @param to Pointer to the destination array.
349 narrow(const char_type
* __lo
, const char_type
* __hi
,
350 char __dfault
, char *__to
) const
351 { return this->do_narrow(__lo
, __hi
, __dfault
, __to
); }
355 __ctype_abstract_base(size_t __refs
= 0): facet(__refs
) { }
358 ~__ctype_abstract_base() { }
361 * @brief Test char_type classification.
363 * This function finds a mask M for @a c and compares it to mask @a m.
365 * do_is() is a hook for a derived facet to change the behavior of
366 * classifying. do_is() must always return the same result for the
369 * @param c The char_type to find the mask of.
370 * @param m The mask to compare against.
371 * @return (M & m) != 0.
374 do_is(mask __m
, char_type __c
) const = 0;
377 * @brief Return a mask array.
379 * This function finds the mask for each char_type in the range [lo,hi)
380 * and successively writes it to vec. vec must have as many elements
383 * do_is() is a hook for a derived facet to change the behavior of
384 * classifying. do_is() must always return the same result for the
387 * @param lo Pointer to start of range.
388 * @param hi Pointer to end of range.
389 * @param vec Pointer to an array of mask storage.
392 virtual const char_type
*
393 do_is(const char_type
* __lo
, const char_type
* __hi
,
394 mask
* __vec
) const = 0;
397 * @brief Find char_type matching mask
399 * This function searches for and returns the first char_type c in
400 * [lo,hi) for which is(m,c) is true.
402 * do_scan_is() is a hook for a derived facet to change the behavior of
403 * match searching. do_is() must always return the same result for the
406 * @param m The mask to compare against.
407 * @param lo Pointer to start of range.
408 * @param hi Pointer to end of range.
409 * @return Pointer to a matching char_type if found, else @a hi.
411 virtual const char_type
*
412 do_scan_is(mask __m
, const char_type
* __lo
,
413 const char_type
* __hi
) const = 0;
416 * @brief Find char_type not matching mask
418 * This function searches for and returns a pointer to the first
419 * char_type c of [lo,hi) for which is(m,c) is false.
421 * do_scan_is() is a hook for a derived facet to change the behavior of
422 * match searching. do_is() must always return the same result for the
425 * @param m The mask to compare against.
426 * @param lo Pointer to start of range.
427 * @param hi Pointer to end of range.
428 * @return Pointer to a non-matching char_type if found, else @a hi.
430 virtual const char_type
*
431 do_scan_not(mask __m
, const char_type
* __lo
,
432 const char_type
* __hi
) const = 0;
435 * @brief Convert to uppercase.
437 * This virtual function converts the char_type argument to uppercase
438 * if possible. If not possible (for example, '2'), returns the
441 * do_toupper() is a hook for a derived facet to change the behavior of
442 * uppercasing. do_toupper() must always return the same result for
445 * @param c The char_type to convert.
446 * @return The uppercase char_type if convertible, else @a c.
449 do_toupper(char_type
) const = 0;
452 * @brief Convert array to uppercase.
454 * This virtual function converts each char_type in the range [lo,hi)
455 * to uppercase if possible. Other elements remain untouched.
457 * do_toupper() is a hook for a derived facet to change the behavior of
458 * uppercasing. do_toupper() must always return the same result for
461 * @param lo Pointer to start of range.
462 * @param hi Pointer to end of range.
465 virtual const char_type
*
466 do_toupper(char_type
* __lo
, const char_type
* __hi
) const = 0;
469 * @brief Convert to lowercase.
471 * This virtual function converts the argument to lowercase if
472 * possible. If not possible (for example, '2'), returns the argument.
474 * do_tolower() is a hook for a derived facet to change the behavior of
475 * lowercasing. do_tolower() must always return the same result for
478 * @param c The char_type to convert.
479 * @return The lowercase char_type if convertible, else @a c.
482 do_tolower(char_type
) const = 0;
485 * @brief Convert array to lowercase.
487 * This virtual function converts each char_type in the range [lo,hi)
488 * to lowercase if possible. Other elements remain untouched.
490 * do_tolower() is a hook for a derived facet to change the behavior of
491 * lowercasing. do_tolower() must always return the same result for
494 * @param lo Pointer to start of range.
495 * @param hi Pointer to end of range.
498 virtual const char_type
*
499 do_tolower(char_type
* __lo
, const char_type
* __hi
) const = 0;
504 * This virtual function converts the char to char_type using the
505 * simplest reasonable transformation.
507 * do_widen() is a hook for a derived facet to change the behavior of
508 * widening. do_widen() must always return the same result for the
511 * Note: this is not what you want for codepage conversions. See
514 * @param c The char to convert.
515 * @return The converted char_type
518 do_widen(char) const = 0;
521 * @brief Widen char array
523 * This function converts each char in the input to char_type using the
524 * simplest reasonable transformation.
526 * do_widen() is a hook for a derived facet to change the behavior of
527 * widening. do_widen() must always return the same result for the
530 * Note: this is not what you want for codepage conversions. See
533 * @param lo Pointer to start range.
534 * @param hi Pointer to end of range.
535 * @param to Pointer to the destination array.
539 do_widen(const char* __lo
, const char* __hi
,
540 char_type
* __dest
) const = 0;
543 * @brief Narrow char_type to char
545 * This virtual function converts the argument to char using the
546 * simplest reasonable transformation. If the conversion fails, dfault
547 * is returned instead.
549 * do_narrow() is a hook for a derived facet to change the behavior of
550 * narrowing. do_narrow() must always return the same result for the
553 * Note: this is not what you want for codepage conversions. See
556 * @param c The char_type to convert.
557 * @param dfault Char to return if conversion fails.
558 * @return The converted char.
561 do_narrow(char_type
, char __dfault
) const = 0;
564 * @brief Narrow char_type array to char
566 * This virtual function converts each char_type in the range [lo,hi) to
567 * char using the simplest reasonable transformation and writes the
568 * results to the destination array. For any element in the input that
569 * cannot be converted, @a dfault is used instead.
571 * do_narrow() is a hook for a derived facet to change the behavior of
572 * narrowing. do_narrow() must always return the same result for the
575 * Note: this is not what you want for codepage conversions. See
578 * @param lo Pointer to start of range.
579 * @param hi Pointer to end of range.
580 * @param dfault Char to use if conversion fails.
581 * @param to Pointer to the destination array.
584 virtual const char_type
*
585 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
586 char __dfault
, char* __dest
) const = 0;
589 // NB: Generic, mostly useless implementation.
591 * @brief Template ctype facet
593 * This template class defines classification and conversion functions for
594 * character sets. It wraps <cctype> functionality. Ctype gets used by
595 * streams for many I/O operations.
597 * This template provides the protected virtual functions the developer
598 * will have to replace in a derived class or specialization to make a
599 * working facet. The public functions that access them are defined in
600 * __ctype_abstract_base, to allow for implementation flexibility. See
601 * ctype<wchar_t> for an example. The functions are documented in
602 * __ctype_abstract_base.
604 * Note: implementations are provided for all the protected virtual
605 * functions, but will likely not be useful.
607 template<typename _CharT
>
608 class ctype
: public __ctype_abstract_base
<_CharT
>
612 typedef _CharT char_type
;
613 typedef typename __ctype_abstract_base
<_CharT
>::mask mask
;
615 /// The facet id for ctype<char_type>
616 static locale::id id
;
619 ctype(size_t __refs
= 0) : __ctype_abstract_base
<_CharT
>(__refs
) { }
626 do_is(mask __m
, char_type __c
) const;
628 virtual const char_type
*
629 do_is(const char_type
* __lo
, const char_type
* __hi
, mask
* __vec
) const;
631 virtual const char_type
*
632 do_scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const;
634 virtual const char_type
*
635 do_scan_not(mask __m
, const char_type
* __lo
,
636 const char_type
* __hi
) const;
639 do_toupper(char_type __c
) const;
641 virtual const char_type
*
642 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
645 do_tolower(char_type __c
) const;
647 virtual const char_type
*
648 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
651 do_widen(char __c
) const;
654 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const;
657 do_narrow(char_type
, char __dfault
) const;
659 virtual const char_type
*
660 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
661 char __dfault
, char* __dest
) const;
664 template<typename _CharT
>
665 locale::id ctype
<_CharT
>::id
;
667 // 22.2.1.3 ctype<char> specialization.
669 * @brief The ctype<char> specialization.
671 * This class defines classification and conversion functions for
672 * the char type. It gets used by char streams for many I/O
673 * operations. The char specialization provides a number of
674 * optimizations as well.
677 class ctype
<char> : public locale::facet
, public ctype_base
681 /// Typedef for the template parameter char.
682 typedef char char_type
;
686 __c_locale _M_c_locale_ctype
;
688 __to_type _M_toupper
;
689 __to_type _M_tolower
;
690 const mask
* _M_table
;
691 mutable char _M_widen_ok
;
692 mutable char _M_widen
[1 + static_cast<unsigned char>(-1)];
693 mutable char _M_narrow
[1 + static_cast<unsigned char>(-1)];
694 mutable char _M_narrow_ok
; // 0 uninitialized, 1 init,
695 // 2 memcpy can't be used
698 /// The facet id for ctype<char>
699 static locale::id id
;
700 /// The size of the mask table. It is SCHAR_MAX + 1.
701 static const size_t table_size
= 1 + static_cast<unsigned char>(-1);
704 * @brief Constructor performs initialization.
706 * This is the constructor provided by the standard.
708 * @param table If non-zero, table is used as the per-char mask.
709 * Else classic_table() is used.
710 * @param del If true, passes ownership of table to this facet.
711 * @param refs Passed to the base facet class.
714 ctype(const mask
* __table
= 0, bool __del
= false, size_t __refs
= 0);
717 * @brief Constructor performs static initialization.
719 * This constructor is used to construct the initial C locale facet.
721 * @param cloc Handle to C locale data.
722 * @param table If non-zero, table is used as the per-char mask.
723 * @param del If true, passes ownership of table to this facet.
724 * @param refs Passed to the base facet class.
727 ctype(__c_locale __cloc
, const mask
* __table
= 0, bool __del
= false,
731 * @brief Test char classification.
733 * This function compares the mask table[c] to @a m.
735 * @param c The char to compare the mask of.
736 * @param m The mask to compare against.
737 * @return True if m & table[c] is true, false otherwise.
740 is(mask __m
, char __c
) const;
743 * @brief Return a mask array.
745 * This function finds the mask for each char in the range [lo, hi) and
746 * successively writes it to vec. vec must have as many elements as
749 * @param lo Pointer to start of range.
750 * @param hi Pointer to end of range.
751 * @param vec Pointer to an array of mask storage.
755 is(const char* __lo
, const char* __hi
, mask
* __vec
) const;
758 * @brief Find char matching a mask
760 * This function searches for and returns the first char in [lo,hi) for
761 * which is(m,char) is true.
763 * @param m The mask to compare against.
764 * @param lo Pointer to start of range.
765 * @param hi Pointer to end of range.
766 * @return Pointer to a matching char if found, else @a hi.
769 scan_is(mask __m
, const char* __lo
, const char* __hi
) const;
772 * @brief Find char not matching a mask
774 * This function searches for and returns a pointer to the first char
775 * in [lo,hi) for which is(m,char) is false.
777 * @param m The mask to compare against.
778 * @param lo Pointer to start of range.
779 * @param hi Pointer to end of range.
780 * @return Pointer to a non-matching char if found, else @a hi.
783 scan_not(mask __m
, const char* __lo
, const char* __hi
) const;
786 * @brief Convert to uppercase.
788 * This function converts the char argument to uppercase if possible.
789 * If not possible (for example, '2'), returns the argument.
791 * toupper() acts as if it returns ctype<char>::do_toupper(c).
792 * do_toupper() must always return the same result for the same input.
794 * @param c The char to convert.
795 * @return The uppercase char if convertible, else @a c.
798 toupper(char_type __c
) const
799 { return this->do_toupper(__c
); }
802 * @brief Convert array to uppercase.
804 * This function converts each char in the range [lo,hi) to uppercase
805 * if possible. Other chars remain untouched.
807 * toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi).
808 * do_toupper() must always return the same result for the same input.
810 * @param lo Pointer to first char in range.
811 * @param hi Pointer to end of range.
815 toupper(char_type
*__lo
, const char_type
* __hi
) const
816 { return this->do_toupper(__lo
, __hi
); }
819 * @brief Convert to lowercase.
821 * This function converts the char argument to lowercase if possible.
822 * If not possible (for example, '2'), returns the argument.
824 * tolower() acts as if it returns ctype<char>::do_tolower(c).
825 * do_tolower() must always return the same result for the same input.
827 * @param c The char to convert.
828 * @return The lowercase char if convertible, else @a c.
831 tolower(char_type __c
) const
832 { return this->do_tolower(__c
); }
835 * @brief Convert array to lowercase.
837 * This function converts each char in the range [lo,hi) to lowercase
838 * if possible. Other chars remain untouched.
840 * tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi).
841 * do_tolower() must always return the same result for the same input.
843 * @param lo Pointer to first char in range.
844 * @param hi Pointer to end of range.
848 tolower(char_type
* __lo
, const char_type
* __hi
) const
849 { return this->do_tolower(__lo
, __hi
); }
854 * This function converts the char to char_type using the simplest
855 * reasonable transformation. For an underived ctype<char> facet, the
856 * argument will be returned unchanged.
858 * This function works as if it returns ctype<char>::do_widen(c).
859 * do_widen() must always return the same result for the same input.
861 * Note: this is not what you want for codepage conversions. See
864 * @param c The char to convert.
865 * @return The converted character.
868 widen(char __c
) const
871 return _M_widen
[static_cast<unsigned char>(__c
)];
872 this->_M_widen_init();
873 return this->do_widen(__c
);
877 * @brief Widen char array
879 * This function converts each char in the input to char using the
880 * simplest reasonable transformation. For an underived ctype<char>
881 * facet, the argument will be copied unchanged.
883 * This function works as if it returns ctype<char>::do_widen(c).
884 * do_widen() must always return the same result for the same input.
886 * Note: this is not what you want for codepage conversions. See
889 * @param lo Pointer to first char in range.
890 * @param hi Pointer to end of range.
891 * @param to Pointer to the destination array.
895 widen(const char* __lo
, const char* __hi
, char_type
* __to
) const
897 if (_M_widen_ok
== 1)
899 memcpy(__to
, __lo
, __hi
- __lo
);
904 return this->do_widen(__lo
, __hi
, __to
);
910 * This function converts the char to char using the simplest
911 * reasonable transformation. If the conversion fails, dfault is
912 * returned instead. For an underived ctype<char> facet, @a c
913 * will be returned unchanged.
915 * This function works as if it returns ctype<char>::do_narrow(c).
916 * do_narrow() must always return the same result for the same input.
918 * Note: this is not what you want for codepage conversions. See
921 * @param c The char to convert.
922 * @param dfault Char to return if conversion fails.
923 * @return The converted character.
926 narrow(char_type __c
, char __dfault
) const
928 if (_M_narrow
[static_cast<unsigned char>(__c
)])
929 return _M_narrow
[static_cast<unsigned char>(__c
)];
930 const char __t
= do_narrow(__c
, __dfault
);
932 _M_narrow
[static_cast<unsigned char>(__c
)] = __t
;
937 * @brief Narrow char array
939 * This function converts each char in the input to char using the
940 * simplest reasonable transformation and writes the results to the
941 * destination array. For any char in the input that cannot be
942 * converted, @a dfault is used instead. For an underived ctype<char>
943 * facet, the argument will be copied unchanged.
945 * This function works as if it returns ctype<char>::do_narrow(lo, hi,
946 * dfault, to). do_narrow() must always return the same result for the
949 * Note: this is not what you want for codepage conversions. See
952 * @param lo Pointer to start of range.
953 * @param hi Pointer to end of range.
954 * @param dfault Char to use if conversion fails.
955 * @param to Pointer to the destination array.
959 narrow(const char_type
* __lo
, const char_type
* __hi
,
960 char __dfault
, char *__to
) const
962 if (__builtin_expect(_M_narrow_ok
== 1, true))
964 memcpy(__to
, __lo
, __hi
- __lo
);
969 return this->do_narrow(__lo
, __hi
, __dfault
, __to
);
973 /// Returns a pointer to the mask table provided to the constructor, or
974 /// the default from classic_table() if none was provided.
976 table() const throw()
979 /// Returns a pointer to the C locale mask table.
981 classic_table() throw();
986 * This function deletes table() if @a del was true in the
993 * @brief Convert to uppercase.
995 * This virtual function converts the char argument to uppercase if
996 * possible. If not possible (for example, '2'), returns the argument.
998 * do_toupper() is a hook for a derived facet to change the behavior of
999 * uppercasing. do_toupper() must always return the same result for
1002 * @param c The char to convert.
1003 * @return The uppercase char if convertible, else @a c.
1006 do_toupper(char_type
) const;
1009 * @brief Convert array to uppercase.
1011 * This virtual function converts each char in the range [lo,hi) to
1012 * uppercase if possible. Other chars remain untouched.
1014 * do_toupper() is a hook for a derived facet to change the behavior of
1015 * uppercasing. do_toupper() must always return the same result for
1018 * @param lo Pointer to start of range.
1019 * @param hi Pointer to end of range.
1022 virtual const char_type
*
1023 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
1026 * @brief Convert to lowercase.
1028 * This virtual function converts the char argument to lowercase if
1029 * possible. If not possible (for example, '2'), returns the argument.
1031 * do_tolower() is a hook for a derived facet to change the behavior of
1032 * lowercasing. do_tolower() must always return the same result for
1035 * @param c The char to convert.
1036 * @return The lowercase char if convertible, else @a c.
1039 do_tolower(char_type
) const;
1042 * @brief Convert array to lowercase.
1044 * This virtual function converts each char in the range [lo,hi) to
1045 * lowercase if possible. Other chars remain untouched.
1047 * do_tolower() is a hook for a derived facet to change the behavior of
1048 * lowercasing. do_tolower() must always return the same result for
1051 * @param lo Pointer to first char in range.
1052 * @param hi Pointer to end of range.
1055 virtual const char_type
*
1056 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
1061 * This virtual function converts the char to char using the simplest
1062 * reasonable transformation. For an underived ctype<char> facet, the
1063 * argument will be returned unchanged.
1065 * do_widen() is a hook for a derived facet to change the behavior of
1066 * widening. do_widen() must always return the same result for the
1069 * Note: this is not what you want for codepage conversions. See
1072 * @param c The char to convert.
1073 * @return The converted character.
1076 do_widen(char __c
) const
1080 * @brief Widen char array
1082 * This function converts each char in the range [lo,hi) to char using
1083 * the simplest reasonable transformation. For an underived
1084 * ctype<char> facet, the argument will be copied unchanged.
1086 * do_widen() is a hook for a derived facet to change the behavior of
1087 * widening. do_widen() must always return the same result for the
1090 * Note: this is not what you want for codepage conversions. See
1093 * @param lo Pointer to start of range.
1094 * @param hi Pointer to end of range.
1095 * @param to Pointer to the destination array.
1099 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const
1101 memcpy(__dest
, __lo
, __hi
- __lo
);
1106 * @brief Narrow char
1108 * This virtual function converts the char to char using the simplest
1109 * reasonable transformation. If the conversion fails, dfault is
1110 * returned instead. For an underived ctype<char> facet, @a c will be
1111 * returned unchanged.
1113 * do_narrow() is a hook for a derived facet to change the behavior of
1114 * narrowing. do_narrow() must always return the same result for the
1117 * Note: this is not what you want for codepage conversions. See
1120 * @param c The char to convert.
1121 * @param dfault Char to return if conversion fails.
1122 * @return The converted char.
1125 do_narrow(char_type __c
, char) const
1129 * @brief Narrow char array to char array
1131 * This virtual function converts each char in the range [lo,hi) to
1132 * char using the simplest reasonable transformation and writes the
1133 * results to the destination array. For any char in the input that
1134 * cannot be converted, @a dfault is used instead. For an underived
1135 * ctype<char> facet, the argument will be copied unchanged.
1137 * do_narrow() is a hook for a derived facet to change the behavior of
1138 * narrowing. do_narrow() must always return the same result for the
1141 * Note: this is not what you want for codepage conversions. See
1144 * @param lo Pointer to start of range.
1145 * @param hi Pointer to end of range.
1146 * @param dfault Char to use if conversion fails.
1147 * @param to Pointer to the destination array.
1150 virtual const char_type
*
1151 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
1152 char, char* __dest
) const
1154 memcpy(__dest
, __lo
, __hi
- __lo
);
1160 void _M_widen_init() const
1162 char __tmp
[sizeof(_M_widen
)];
1163 for (size_t __i
= 0; __i
< sizeof(_M_widen
); ++__i
)
1165 do_widen(__tmp
, __tmp
+ sizeof(__tmp
), _M_widen
);
1168 // Set _M_widen_ok to 2 if memcpy can't be used.
1169 if (memcmp(__tmp
, _M_widen
, sizeof(_M_widen
)))
1173 // Fill in the narrowing cache and flag whether all values are
1174 // valid or not. _M_narrow_ok is set to 2 if memcpy can't
1176 void _M_narrow_init() const
1178 char __tmp
[sizeof(_M_narrow
)];
1179 for (size_t __i
= 0; __i
< sizeof(_M_narrow
); ++__i
)
1181 do_narrow(__tmp
, __tmp
+ sizeof(__tmp
), 0, _M_narrow
);
1184 if (memcmp(__tmp
, _M_narrow
, sizeof(_M_narrow
)))
1188 // Deal with the special case of zero: renarrow with a
1189 // different default and compare.
1191 do_narrow(__tmp
, __tmp
+ 1, 1, &__c
);
1200 use_facet
<ctype
<char> >(const locale
& __loc
);
1202 #ifdef _GLIBCXX_USE_WCHAR_T
1203 // 22.2.1.3 ctype<wchar_t> specialization
1205 * @brief The ctype<wchar_t> specialization.
1207 * This class defines classification and conversion functions for the
1208 * wchar_t type. It gets used by wchar_t streams for many I/O operations.
1209 * The wchar_t specialization provides a number of optimizations as well.
1211 * ctype<wchar_t> inherits its public methods from
1212 * __ctype_abstract_base<wchar_t>.
1215 class ctype
<wchar_t> : public __ctype_abstract_base
<wchar_t>
1219 /// Typedef for the template parameter wchar_t.
1220 typedef wchar_t char_type
;
1221 typedef wctype_t __wmask_type
;
1224 __c_locale _M_c_locale_ctype
;
1226 // Pre-computed narrowed and widened chars.
1228 char _M_narrow
[128];
1229 wint_t _M_widen
[1 + static_cast<unsigned char>(-1)];
1231 // Pre-computed elements for do_is.
1233 __wmask_type _M_wmask
[16];
1237 /// The facet id for ctype<wchar_t>
1238 static locale::id id
;
1241 * @brief Constructor performs initialization.
1243 * This is the constructor provided by the standard.
1245 * @param refs Passed to the base facet class.
1248 ctype(size_t __refs
= 0);
1251 * @brief Constructor performs static initialization.
1253 * This constructor is used to construct the initial C locale facet.
1255 * @param cloc Handle to C locale data.
1256 * @param refs Passed to the base facet class.
1259 ctype(__c_locale __cloc
, size_t __refs
= 0);
1263 _M_convert_to_wmask(const mask __m
) const;
1270 * @brief Test wchar_t classification.
1272 * This function finds a mask M for @a c and compares it to mask @a m.
1274 * do_is() is a hook for a derived facet to change the behavior of
1275 * classifying. do_is() must always return the same result for the
1278 * @param c The wchar_t to find the mask of.
1279 * @param m The mask to compare against.
1280 * @return (M & m) != 0.
1283 do_is(mask __m
, char_type __c
) const;
1286 * @brief Return a mask array.
1288 * This function finds the mask for each wchar_t in the range [lo,hi)
1289 * and successively writes it to vec. vec must have as many elements
1292 * do_is() is a hook for a derived facet to change the behavior of
1293 * classifying. do_is() must always return the same result for the
1296 * @param lo Pointer to start of range.
1297 * @param hi Pointer to end of range.
1298 * @param vec Pointer to an array of mask storage.
1301 virtual const char_type
*
1302 do_is(const char_type
* __lo
, const char_type
* __hi
, mask
* __vec
) const;
1305 * @brief Find wchar_t matching mask
1307 * This function searches for and returns the first wchar_t c in
1308 * [lo,hi) for which is(m,c) is true.
1310 * do_scan_is() is a hook for a derived facet to change the behavior of
1311 * match searching. do_is() must always return the same result for the
1314 * @param m The mask to compare against.
1315 * @param lo Pointer to start of range.
1316 * @param hi Pointer to end of range.
1317 * @return Pointer to a matching wchar_t if found, else @a hi.
1319 virtual const char_type
*
1320 do_scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const;
1323 * @brief Find wchar_t not matching mask
1325 * This function searches for and returns a pointer to the first
1326 * wchar_t c of [lo,hi) for which is(m,c) is false.
1328 * do_scan_is() is a hook for a derived facet to change the behavior of
1329 * match searching. do_is() must always return the same result for the
1332 * @param m The mask to compare against.
1333 * @param lo Pointer to start of range.
1334 * @param hi Pointer to end of range.
1335 * @return Pointer to a non-matching wchar_t if found, else @a hi.
1337 virtual const char_type
*
1338 do_scan_not(mask __m
, const char_type
* __lo
,
1339 const char_type
* __hi
) const;
1342 * @brief Convert to uppercase.
1344 * This virtual function converts the wchar_t argument to uppercase if
1345 * possible. If not possible (for example, '2'), returns the argument.
1347 * do_toupper() is a hook for a derived facet to change the behavior of
1348 * uppercasing. do_toupper() must always return the same result for
1351 * @param c The wchar_t to convert.
1352 * @return The uppercase wchar_t if convertible, else @a c.
1355 do_toupper(char_type
) const;
1358 * @brief Convert array to uppercase.
1360 * This virtual function converts each wchar_t in the range [lo,hi) to
1361 * uppercase if possible. Other elements remain untouched.
1363 * do_toupper() is a hook for a derived facet to change the behavior of
1364 * uppercasing. do_toupper() must always return the same result for
1367 * @param lo Pointer to start of range.
1368 * @param hi Pointer to end of range.
1371 virtual const char_type
*
1372 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
1375 * @brief Convert to lowercase.
1377 * This virtual function converts the argument to lowercase if
1378 * possible. If not possible (for example, '2'), returns the argument.
1380 * do_tolower() is a hook for a derived facet to change the behavior of
1381 * lowercasing. do_tolower() must always return the same result for
1384 * @param c The wchar_t to convert.
1385 * @return The lowercase wchar_t if convertible, else @a c.
1388 do_tolower(char_type
) const;
1391 * @brief Convert array to lowercase.
1393 * This virtual function converts each wchar_t in the range [lo,hi) to
1394 * lowercase if possible. Other elements remain untouched.
1396 * do_tolower() is a hook for a derived facet to change the behavior of
1397 * lowercasing. do_tolower() must always return the same result for
1400 * @param lo Pointer to start of range.
1401 * @param hi Pointer to end of range.
1404 virtual const char_type
*
1405 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
1408 * @brief Widen char to wchar_t
1410 * This virtual function converts the char to wchar_t using the
1411 * simplest reasonable transformation. For an underived ctype<wchar_t>
1412 * facet, the argument will be cast to wchar_t.
1414 * do_widen() is a hook for a derived facet to change the behavior of
1415 * widening. do_widen() must always return the same result for the
1418 * Note: this is not what you want for codepage conversions. See
1421 * @param c The char to convert.
1422 * @return The converted wchar_t.
1425 do_widen(char) const;
1428 * @brief Widen char array to wchar_t array
1430 * This function converts each char in the input to wchar_t using the
1431 * simplest reasonable transformation. For an underived ctype<wchar_t>
1432 * facet, the argument will be copied, casting each element to wchar_t.
1434 * do_widen() is a hook for a derived facet to change the behavior of
1435 * widening. do_widen() must always return the same result for the
1438 * Note: this is not what you want for codepage conversions. See
1441 * @param lo Pointer to start range.
1442 * @param hi Pointer to end of range.
1443 * @param to Pointer to the destination array.
1447 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const;
1450 * @brief Narrow wchar_t to char
1452 * This virtual function converts the argument to char using
1453 * the simplest reasonable transformation. If the conversion
1454 * fails, dfault is returned instead. For an underived
1455 * ctype<wchar_t> facet, @a c will be cast to char and
1458 * do_narrow() is a hook for a derived facet to change the
1459 * behavior of narrowing. do_narrow() must always return the
1460 * same result for the same input.
1462 * Note: this is not what you want for codepage conversions. See
1465 * @param c The wchar_t to convert.
1466 * @param dfault Char to return if conversion fails.
1467 * @return The converted char.
1470 do_narrow(char_type
, char __dfault
) const;
1473 * @brief Narrow wchar_t array to char array
1475 * This virtual function converts each wchar_t in the range [lo,hi) to
1476 * char using the simplest reasonable transformation and writes the
1477 * results to the destination array. For any wchar_t in the input that
1478 * cannot be converted, @a dfault is used instead. For an underived
1479 * ctype<wchar_t> facet, the argument will be copied, casting each
1482 * do_narrow() is a hook for a derived facet to change the behavior of
1483 * narrowing. do_narrow() must always return the same result for the
1486 * Note: this is not what you want for codepage conversions. See
1489 * @param lo Pointer to start of range.
1490 * @param hi Pointer to end of range.
1491 * @param dfault Char to use if conversion fails.
1492 * @param to Pointer to the destination array.
1495 virtual const char_type
*
1496 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
1497 char __dfault
, char* __dest
) const;
1499 // For use at construction time only.
1501 _M_initialize_ctype();
1505 const ctype
<wchar_t>&
1506 use_facet
<ctype
<wchar_t> >(const locale
& __loc
);
1507 #endif //_GLIBCXX_USE_WCHAR_T
1509 /// @brief class ctype_byname [22.2.1.2].
1510 template<typename _CharT
>
1511 class ctype_byname
: public ctype
<_CharT
>
1514 typedef typename ctype
<_CharT
>::mask mask
;
1517 ctype_byname(const char* __s
, size_t __refs
= 0);
1521 ~ctype_byname() { };
1524 /// 22.2.1.4 Class ctype_byname specializations.
1526 class ctype_byname
<char> : public ctype
<char>
1530 ctype_byname(const char* __s
, size_t __refs
= 0);
1537 #ifdef _GLIBCXX_USE_WCHAR_T
1539 class ctype_byname
<wchar_t> : public ctype
<wchar_t>
1543 ctype_byname(const char* __s
, size_t __refs
= 0);
1551 _GLIBCXX_END_NAMESPACE
1553 // Include host and configuration specific ctype inlines.
1554 #include <bits/ctype_inline.h>
1556 // 22.2.1.5 Template class codecvt
1557 #include <bits/codecvt.h>
1559 _GLIBCXX_BEGIN_NAMESPACE(std
)
1561 // 22.2.2 The numeric category.
1565 // NB: Code depends on the order of _S_atoms_out elements.
1566 // Below are the indices into _S_atoms_out.
1574 _S_odigits_end
= _S_odigits
+ 16,
1575 _S_oudigits
= _S_odigits_end
,
1576 _S_oudigits_end
= _S_oudigits
+ 16,
1577 _S_oe
= _S_odigits
+ 14, // For scientific notation, 'e'
1578 _S_oE
= _S_oudigits
+ 14, // For scientific notation, 'E'
1579 _S_oend
= _S_oudigits_end
1582 // A list of valid numeric literals for output. This array
1583 // contains chars that will be passed through the current locale's
1584 // ctype<_CharT>.widen() and then used to render numbers.
1585 // For the standard "C" locale, this is
1586 // "-+xX0123456789abcdef0123456789ABCDEF".
1587 static const char* _S_atoms_out
;
1589 // String literal of acceptable (narrow) input, for num_get.
1590 // "-+xX0123456789abcdefABCDEF"
1591 static const char* _S_atoms_in
;
1600 _S_ie
= _S_izero
+ 14,
1601 _S_iE
= _S_izero
+ 20,
1606 // Construct and return valid scanf format for floating point types.
1608 _S_format_float(const ios_base
& __io
, char* __fptr
, char __mod
);
1611 template<typename _CharT
>
1612 struct __numpunct_cache
: public locale::facet
1614 const char* _M_grouping
;
1615 size_t _M_grouping_size
;
1616 bool _M_use_grouping
;
1617 const _CharT
* _M_truename
;
1618 size_t _M_truename_size
;
1619 const _CharT
* _M_falsename
;
1620 size_t _M_falsename_size
;
1621 _CharT _M_decimal_point
;
1622 _CharT _M_thousands_sep
;
1624 // A list of valid numeric literals for output: in the standard
1625 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1626 // This array contains the chars after having been passed
1627 // through the current locale's ctype<_CharT>.widen().
1628 _CharT _M_atoms_out
[__num_base::_S_oend
];
1630 // A list of valid numeric literals for input: in the standard
1631 // "C" locale, this is "-+xX0123456789abcdefABCDEF"
1632 // This array contains the chars after having been passed
1633 // through the current locale's ctype<_CharT>.widen().
1634 _CharT _M_atoms_in
[__num_base::_S_iend
];
1638 __numpunct_cache(size_t __refs
= 0) : facet(__refs
),
1639 _M_grouping(NULL
), _M_grouping_size(0), _M_use_grouping(false),
1640 _M_truename(NULL
), _M_truename_size(0), _M_falsename(NULL
),
1641 _M_falsename_size(0), _M_decimal_point(_CharT()),
1642 _M_thousands_sep(_CharT()), _M_allocated(false)
1645 ~__numpunct_cache();
1648 _M_cache(const locale
& __loc
);
1652 operator=(const __numpunct_cache
&);
1655 __numpunct_cache(const __numpunct_cache
&);
1658 template<typename _CharT
>
1659 __numpunct_cache
<_CharT
>::~__numpunct_cache()
1663 delete [] _M_grouping
;
1664 delete [] _M_truename
;
1665 delete [] _M_falsename
;
1670 * @brief Numpunct facet.
1672 * This facet stores several pieces of information related to printing and
1673 * scanning numbers, such as the decimal point character. It takes a
1674 * template parameter specifying the char type. The numpunct facet is
1675 * used by streams for many I/O operations involving numbers.
1677 * The numpunct template uses protected virtual functions to provide the
1678 * actual results. The public accessors forward the call to the virtual
1679 * functions. These virtual functions are hooks for developers to
1680 * implement the behavior they require from a numpunct facet.
1682 template<typename _CharT
>
1683 class numpunct
: public locale::facet
1689 typedef _CharT char_type
;
1690 typedef basic_string
<_CharT
> string_type
;
1692 typedef __numpunct_cache
<_CharT
> __cache_type
;
1695 __cache_type
* _M_data
;
1698 /// Numpunct facet id.
1699 static locale::id id
;
1702 * @brief Numpunct constructor.
1704 * @param refs Refcount to pass to the base class.
1707 numpunct(size_t __refs
= 0) : facet(__refs
), _M_data(NULL
)
1708 { _M_initialize_numpunct(); }
1711 * @brief Internal constructor. Not for general use.
1713 * This is a constructor for use by the library itself to set up the
1714 * predefined locale facets.
1716 * @param cache __numpunct_cache object.
1717 * @param refs Refcount to pass to the base class.
1720 numpunct(__cache_type
* __cache
, size_t __refs
= 0)
1721 : facet(__refs
), _M_data(__cache
)
1722 { _M_initialize_numpunct(); }
1725 * @brief Internal constructor. Not for general use.
1727 * This is a constructor for use by the library itself to set up new
1730 * @param cloc The "C" locale.
1731 * @param refs Refcount to pass to the base class.
1734 numpunct(__c_locale __cloc
, size_t __refs
= 0)
1735 : facet(__refs
), _M_data(NULL
)
1736 { _M_initialize_numpunct(__cloc
); }
1739 * @brief Return decimal point character.
1741 * This function returns a char_type to use as a decimal point. It
1742 * does so by returning returning
1743 * numpunct<char_type>::do_decimal_point().
1745 * @return @a char_type representing a decimal point.
1748 decimal_point() const
1749 { return this->do_decimal_point(); }
1752 * @brief Return thousands separator character.
1754 * This function returns a char_type to use as a thousands
1755 * separator. It does so by returning returning
1756 * numpunct<char_type>::do_thousands_sep().
1758 * @return char_type representing a thousands separator.
1761 thousands_sep() const
1762 { return this->do_thousands_sep(); }
1765 * @brief Return grouping specification.
1767 * This function returns a string representing groupings for the
1768 * integer part of a number. Groupings indicate where thousands
1769 * separators should be inserted in the integer part of a number.
1771 * Each char in the return string is interpret as an integer
1772 * rather than a character. These numbers represent the number
1773 * of digits in a group. The first char in the string
1774 * represents the number of digits in the least significant
1775 * group. If a char is negative, it indicates an unlimited
1776 * number of digits for the group. If more chars from the
1777 * string are required to group a number, the last char is used
1780 * For example, if the grouping() returns "\003\002" and is
1781 * applied to the number 123456789, this corresponds to
1782 * 12,34,56,789. Note that if the string was "32", this would
1783 * put more than 50 digits into the least significant group if
1784 * the character set is ASCII.
1786 * The string is returned by calling
1787 * numpunct<char_type>::do_grouping().
1789 * @return string representing grouping specification.
1793 { return this->do_grouping(); }
1796 * @brief Return string representation of bool true.
1798 * This function returns a string_type containing the text
1799 * representation for true bool variables. It does so by calling
1800 * numpunct<char_type>::do_truename().
1802 * @return string_type representing printed form of true.
1806 { return this->do_truename(); }
1809 * @brief Return string representation of bool false.
1811 * This function returns a string_type containing the text
1812 * representation for false bool variables. It does so by calling
1813 * numpunct<char_type>::do_falsename().
1815 * @return string_type representing printed form of false.
1819 { return this->do_falsename(); }
1827 * @brief Return decimal point character.
1829 * Returns a char_type to use as a decimal point. This function is a
1830 * hook for derived classes to change the value returned.
1832 * @return @a char_type representing a decimal point.
1835 do_decimal_point() const
1836 { return _M_data
->_M_decimal_point
; }
1839 * @brief Return thousands separator character.
1841 * Returns a char_type to use as a thousands separator. This function
1842 * is a hook for derived classes to change the value returned.
1844 * @return @a char_type representing a thousands separator.
1847 do_thousands_sep() const
1848 { return _M_data
->_M_thousands_sep
; }
1851 * @brief Return grouping specification.
1853 * Returns a string representing groupings for the integer part of a
1854 * number. This function is a hook for derived classes to change the
1855 * value returned. @see grouping() for details.
1857 * @return String representing grouping specification.
1861 { return _M_data
->_M_grouping
; }
1864 * @brief Return string representation of bool true.
1866 * Returns a string_type containing the text representation for true
1867 * bool variables. This function is a hook for derived classes to
1868 * change the value returned.
1870 * @return string_type representing printed form of true.
1874 { return _M_data
->_M_truename
; }
1877 * @brief Return string representation of bool false.
1879 * Returns a string_type containing the text representation for false
1880 * bool variables. This function is a hook for derived classes to
1881 * change the value returned.
1883 * @return string_type representing printed form of false.
1886 do_falsename() const
1887 { return _M_data
->_M_falsename
; }
1889 // For use at construction time only.
1891 _M_initialize_numpunct(__c_locale __cloc
= NULL
);
1894 template<typename _CharT
>
1895 locale::id numpunct
<_CharT
>::id
;
1898 numpunct
<char>::~numpunct();
1902 numpunct
<char>::_M_initialize_numpunct(__c_locale __cloc
);
1904 #ifdef _GLIBCXX_USE_WCHAR_T
1906 numpunct
<wchar_t>::~numpunct();
1910 numpunct
<wchar_t>::_M_initialize_numpunct(__c_locale __cloc
);
1913 /// @brief class numpunct_byname [22.2.3.2].
1914 template<typename _CharT
>
1915 class numpunct_byname
: public numpunct
<_CharT
>
1918 typedef _CharT char_type
;
1919 typedef basic_string
<_CharT
> string_type
;
1922 numpunct_byname(const char* __s
, size_t __refs
= 0)
1923 : numpunct
<_CharT
>(__refs
)
1925 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
1928 this->_S_create_c_locale(__tmp
, __s
);
1929 this->_M_initialize_numpunct(__tmp
);
1930 this->_S_destroy_c_locale(__tmp
);
1936 ~numpunct_byname() { }
1939 _GLIBCXX_BEGIN_LDBL_NAMESPACE
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
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_get::do_get().
1982 * If ios_base::boolalpha is set, attempts to read
1983 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
1984 * @a v to true or false if successful. Sets err to
1985 * ios_base::failbit if reading the string fails. Sets err to
1986 * ios_base::eofbit if the stream is emptied.
1988 * If ios_base::boolalpha is not set, proceeds as with reading a long,
1989 * except if the value is 1, sets @a v to true, if the value is 0, sets
1990 * @a v to false, and otherwise set err to ios_base::failbit.
1992 * @param in Start of input stream.
1993 * @param end End of input stream.
1994 * @param io Source of locale and flags.
1995 * @param err Error flags to set.
1996 * @param v Value to format and insert.
1997 * @return Iterator after reading.
2000 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2001 ios_base::iostate
& __err
, bool& __v
) const
2002 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2006 * @brief Numeric parsing.
2008 * Parses the input stream into the integral variable @a v. It does so
2009 * by calling num_get::do_get().
2011 * Parsing is affected by the flag settings in @a io.
2013 * The basic parse is affected by the value of io.flags() &
2014 * ios_base::basefield. If equal to ios_base::oct, parses like the
2015 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X
2016 * specifier. Else if basefield equal to 0, parses like the %i
2017 * specifier. Otherwise, parses like %d for signed and %u for unsigned
2018 * types. The matching type length modifier is also used.
2020 * Digit grouping is intrepreted according to numpunct::grouping() and
2021 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2022 * consistent, sets err to ios_base::failbit.
2024 * If parsing the string yields a valid value for @a v, @a v is set.
2025 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2026 * Sets err to ios_base::eofbit if the stream is emptied.
2028 * @param in Start of input stream.
2029 * @param end End of input stream.
2030 * @param io Source of locale and flags.
2031 * @param err Error flags to set.
2032 * @param v Value to format and insert.
2033 * @return Iterator after reading.
2036 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2037 ios_base::iostate
& __err
, long& __v
) const
2038 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2041 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2042 ios_base::iostate
& __err
, unsigned short& __v
) const
2043 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2046 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2047 ios_base::iostate
& __err
, unsigned int& __v
) const
2048 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2051 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2052 ios_base::iostate
& __err
, unsigned long& __v
) const
2053 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2055 #ifdef _GLIBCXX_USE_LONG_LONG
2057 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2058 ios_base::iostate
& __err
, long long& __v
) const
2059 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2062 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2063 ios_base::iostate
& __err
, unsigned long long& __v
) const
2064 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2070 * @brief Numeric parsing.
2072 * Parses the input stream into the integral variable @a v. It does so
2073 * by calling num_get::do_get().
2075 * The input characters are parsed like the scanf %g specifier. The
2076 * matching type length modifier is also used.
2078 * The decimal point character used is numpunct::decimal_point().
2079 * Digit grouping is intrepreted according to numpunct::grouping() and
2080 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2081 * consistent, sets err to ios_base::failbit.
2083 * If parsing the string yields a valid value for @a v, @a v is set.
2084 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2085 * Sets err to ios_base::eofbit if the stream is emptied.
2087 * @param in Start of input stream.
2088 * @param end End of input stream.
2089 * @param io Source of locale and flags.
2090 * @param err Error flags to set.
2091 * @param v Value to format and insert.
2092 * @return Iterator after reading.
2095 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2096 ios_base::iostate
& __err
, float& __v
) const
2097 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2100 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2101 ios_base::iostate
& __err
, double& __v
) const
2102 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2105 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2106 ios_base::iostate
& __err
, long double& __v
) const
2107 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2111 * @brief Numeric parsing.
2113 * Parses the input stream into the pointer variable @a v. It does so
2114 * by calling num_get::do_get().
2116 * The input characters are parsed like the scanf %p specifier.
2118 * Digit grouping is intrepreted according to numpunct::grouping() and
2119 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2120 * consistent, sets err to ios_base::failbit.
2122 * Note that the digit grouping effect for pointers is a bit ambiguous
2123 * in the standard and shouldn't be relied on. See DR 344.
2125 * If parsing the string yields a valid value for @a v, @a v is set.
2126 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2127 * Sets err to ios_base::eofbit if the stream is emptied.
2129 * @param in Start of input stream.
2130 * @param end End of input stream.
2131 * @param io Source of locale and flags.
2132 * @param err Error flags to set.
2133 * @param v Value to format and insert.
2134 * @return Iterator after reading.
2137 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2138 ios_base::iostate
& __err
, void*& __v
) const
2139 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2143 virtual ~num_get() { }
2146 _M_extract_float(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2147 string
& __xtrc
) const;
2149 template<typename _ValueT
>
2151 _M_extract_int(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2152 _ValueT
& __v
) const;
2154 template<typename _CharT2
>
2155 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT2
>::__value
, int>::__type
2156 _M_find(const _CharT2
*, size_t __len
, _CharT2 __c
) const
2161 if (__c
>= _CharT2('0') && __c
< _CharT2(_CharT2('0') + __len
))
2162 __ret
= __c
- _CharT2('0');
2166 if (__c
>= _CharT2('0') && __c
<= _CharT2('9'))
2167 __ret
= __c
- _CharT2('0');
2168 else if (__c
>= _CharT2('a') && __c
<= _CharT2('f'))
2169 __ret
= 10 + (__c
- _CharT2('a'));
2170 else if (__c
>= _CharT2('A') && __c
<= _CharT2('F'))
2171 __ret
= 10 + (__c
- _CharT2('A'));
2176 template<typename _CharT2
>
2177 typename
__gnu_cxx::__enable_if
<!__is_char
<_CharT2
>::__value
,
2179 _M_find(const _CharT2
* __zero
, size_t __len
, _CharT2 __c
) const
2182 const char_type
* __q
= char_traits
<_CharT2
>::find(__zero
, __len
, __c
);
2185 __ret
= __q
- __zero
;
2194 * @brief Numeric parsing.
2196 * Parses the input stream into the variable @a v. This function is a
2197 * hook for derived classes to change the value returned. @see get()
2200 * @param in Start of input stream.
2201 * @param end End of input stream.
2202 * @param io Source of locale and flags.
2203 * @param err Error flags to set.
2204 * @param v Value to format and insert.
2205 * @return Iterator after reading.
2208 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, bool&) const;
2212 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, long&) const;
2215 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2216 unsigned short&) const;
2219 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2220 unsigned int&) const;
2223 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2224 unsigned long&) const;
2226 #ifdef _GLIBCXX_USE_LONG_LONG
2228 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2232 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2233 unsigned long long&) const;
2237 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2241 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2244 // XXX GLIBCXX_ABI Deprecated
2245 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2247 __do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2251 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2252 long double&) const;
2256 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2259 // XXX GLIBCXX_ABI Deprecated
2260 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2262 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2263 long double&) const;
2268 template<typename _CharT
, typename _InIter
>
2269 locale::id num_get
<_CharT
, _InIter
>::id
;
2273 * @brief Facet for converting numbers to strings.
2275 * This facet encapsulates the code to convert a number to a string. It is
2276 * used by the ostream numeric insertion operators.
2278 * The num_put template uses protected virtual functions to provide the
2279 * actual results. The public accessors forward the call to the virtual
2280 * functions. These virtual functions are hooks for developers to
2281 * implement the behavior they require from the num_put facet.
2283 template<typename _CharT
, typename _OutIter
>
2284 class num_put
: public locale::facet
2290 typedef _CharT char_type
;
2291 typedef _OutIter iter_type
;
2294 /// Numpunct facet id.
2295 static locale::id id
;
2298 * @brief Constructor performs initialization.
2300 * This is the constructor provided by the standard.
2302 * @param refs Passed to the base facet class.
2305 num_put(size_t __refs
= 0) : facet(__refs
) { }
2308 * @brief Numeric formatting.
2310 * Formats the boolean @a v and inserts it into a stream. It does so
2311 * by calling num_put::do_put().
2313 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2314 * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
2316 * @param s Stream to write to.
2317 * @param io Source of locale and flags.
2318 * @param fill Char_type to use for filling.
2319 * @param v Value to format and insert.
2320 * @return Iterator after writing.
2323 put(iter_type __s
, ios_base
& __f
, char_type __fill
, bool __v
) const
2324 { return this->do_put(__s
, __f
, __fill
, __v
); }
2328 * @brief Numeric formatting.
2330 * Formats the integral value @a v and inserts it into a
2331 * stream. It does so by calling num_put::do_put().
2333 * Formatting is affected by the flag settings in @a io.
2335 * The basic format is affected by the value of io.flags() &
2336 * ios_base::basefield. If equal to ios_base::oct, formats like the
2337 * printf %o specifier. Else if equal to ios_base::hex, formats like
2338 * %x or %X with ios_base::uppercase unset or set respectively.
2339 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2340 * for unsigned values. Note that if both oct and hex are set, neither
2343 * If ios_base::showpos is set, '+' is output before positive values.
2344 * If ios_base::showbase is set, '0' precedes octal values (except 0)
2345 * and '0[xX]' precedes hex values.
2347 * Thousands separators are inserted according to numpunct::grouping()
2348 * and numpunct::thousands_sep(). The decimal point character used is
2349 * numpunct::decimal_point().
2351 * If io.width() is non-zero, enough @a fill characters are inserted to
2352 * make the result at least that wide. If
2353 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2354 * padded at the end. If ios_base::internal, then padding occurs
2355 * immediately after either a '+' or '-' or after '0x' or '0X'.
2356 * Otherwise, padding occurs at the beginning.
2358 * @param s Stream to write to.
2359 * @param io Source of locale and flags.
2360 * @param fill Char_type to use for filling.
2361 * @param v Value to format and insert.
2362 * @return Iterator after writing.
2365 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long __v
) const
2366 { return this->do_put(__s
, __f
, __fill
, __v
); }
2369 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2370 unsigned long __v
) const
2371 { return this->do_put(__s
, __f
, __fill
, __v
); }
2373 #ifdef _GLIBCXX_USE_LONG_LONG
2375 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long long __v
) const
2376 { return this->do_put(__s
, __f
, __fill
, __v
); }
2379 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2380 unsigned long long __v
) const
2381 { return this->do_put(__s
, __f
, __fill
, __v
); }
2387 * @brief Numeric formatting.
2389 * Formats the floating point value @a v and inserts it into a stream.
2390 * It does so by calling num_put::do_put().
2392 * Formatting is affected by the flag settings in @a io.
2394 * The basic format is affected by the value of io.flags() &
2395 * ios_base::floatfield. If equal to ios_base::fixed, formats like the
2396 * printf %f specifier. Else if equal to ios_base::scientific, formats
2397 * like %e or %E with ios_base::uppercase unset or set respectively.
2398 * Otherwise, formats like %g or %G depending on uppercase. Note that
2399 * if both fixed and scientific are set, the effect will also be like
2402 * The output precision is given by io.precision(). This precision is
2403 * capped at numeric_limits::digits10 + 2 (different for double and
2404 * long double). The default precision is 6.
2406 * If ios_base::showpos is set, '+' is output before positive values.
2407 * If ios_base::showpoint is set, a decimal point will always be
2410 * Thousands separators are inserted according to numpunct::grouping()
2411 * and numpunct::thousands_sep(). The decimal point character used is
2412 * numpunct::decimal_point().
2414 * If io.width() is non-zero, enough @a fill characters are inserted to
2415 * make the result at least that wide. If
2416 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2417 * padded at the end. If ios_base::internal, then padding occurs
2418 * immediately after either a '+' or '-' or after '0x' or '0X'.
2419 * Otherwise, padding occurs at the beginning.
2421 * @param s Stream to write to.
2422 * @param io Source of locale and flags.
2423 * @param fill Char_type to use for filling.
2424 * @param v Value to format and insert.
2425 * @return Iterator after writing.
2428 put(iter_type __s
, ios_base
& __f
, char_type __fill
, double __v
) const
2429 { return this->do_put(__s
, __f
, __fill
, __v
); }
2432 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2433 long double __v
) const
2434 { return this->do_put(__s
, __f
, __fill
, __v
); }
2438 * @brief Numeric formatting.
2440 * Formats the pointer value @a v and inserts it into a stream. It
2441 * does so by calling num_put::do_put().
2443 * This function formats @a v as an unsigned long with ios_base::hex
2444 * and ios_base::showbase set.
2446 * @param s Stream to write to.
2447 * @param io Source of locale and flags.
2448 * @param fill Char_type to use for filling.
2449 * @param v Value to format and insert.
2450 * @return Iterator after writing.
2453 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2454 const void* __v
) const
2455 { return this->do_put(__s
, __f
, __fill
, __v
); }
2458 template<typename _ValueT
>
2460 _M_insert_float(iter_type
, ios_base
& __io
, char_type __fill
,
2461 char __mod
, _ValueT __v
) const;
2464 _M_group_float(const char* __grouping
, size_t __grouping_size
,
2465 char_type __sep
, const char_type
* __p
, char_type
* __new
,
2466 char_type
* __cs
, int& __len
) const;
2468 template<typename _ValueT
>
2470 _M_insert_int(iter_type
, ios_base
& __io
, char_type __fill
,
2474 _M_group_int(const char* __grouping
, size_t __grouping_size
,
2475 char_type __sep
, ios_base
& __io
, char_type
* __new
,
2476 char_type
* __cs
, int& __len
) const;
2479 _M_pad(char_type __fill
, streamsize __w
, ios_base
& __io
,
2480 char_type
* __new
, const char_type
* __cs
, int& __len
) const;
2488 * @brief Numeric formatting.
2490 * These functions do the work of formatting numeric values and
2491 * inserting them into a stream. This function is a hook for derived
2492 * classes to change the value returned.
2494 * @param s Stream to write to.
2495 * @param io Source of locale and flags.
2496 * @param fill Char_type to use for filling.
2497 * @param v Value to format and insert.
2498 * @return Iterator after writing.
2501 do_put(iter_type
, ios_base
&, char_type __fill
, bool __v
) const;
2504 do_put(iter_type
, ios_base
&, char_type __fill
, long __v
) const;
2507 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long) const;
2509 #ifdef _GLIBCXX_USE_LONG_LONG
2511 do_put(iter_type
, ios_base
&, char_type __fill
, long long __v
) const;
2514 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long long) const;
2518 do_put(iter_type
, ios_base
&, char_type __fill
, double __v
) const;
2520 // XXX GLIBCXX_ABI Deprecated
2521 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2523 __do_put(iter_type
, ios_base
&, char_type __fill
, double __v
) const;
2526 do_put(iter_type
, ios_base
&, char_type __fill
, long double __v
) const;
2530 do_put(iter_type
, ios_base
&, char_type __fill
, const void* __v
) const;
2532 // XXX GLIBCXX_ABI Deprecated
2533 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2535 do_put(iter_type
, ios_base
&, char_type __fill
, long double __v
) const;
2540 template <typename _CharT
, typename _OutIter
>
2541 locale::id num_put
<_CharT
, _OutIter
>::id
;
2543 _GLIBCXX_END_LDBL_NAMESPACE
2546 * @brief Facet for localized string comparison.
2548 * This facet encapsulates the code to compare strings in a localized
2551 * The collate template uses protected virtual functions to provide
2552 * the actual results. The public accessors forward the call to
2553 * the virtual functions. These virtual functions are hooks for
2554 * developers to implement the behavior they require from the
2557 template<typename _CharT
>
2558 class collate
: public locale::facet
2564 typedef _CharT char_type
;
2565 typedef basic_string
<_CharT
> string_type
;
2569 // Underlying "C" library locale information saved from
2570 // initialization, needed by collate_byname as well.
2571 __c_locale _M_c_locale_collate
;
2574 /// Numpunct facet id.
2575 static locale::id id
;
2578 * @brief Constructor performs initialization.
2580 * This is the constructor provided by the standard.
2582 * @param refs Passed to the base facet class.
2585 collate(size_t __refs
= 0)
2586 : facet(__refs
), _M_c_locale_collate(_S_get_c_locale())
2590 * @brief Internal constructor. Not for general use.
2592 * This is a constructor for use by the library itself to set up new
2595 * @param cloc The "C" locale.
2596 * @param refs Passed to the base facet class.
2599 collate(__c_locale __cloc
, size_t __refs
= 0)
2600 : facet(__refs
), _M_c_locale_collate(_S_clone_c_locale(__cloc
))
2604 * @brief Compare two strings.
2606 * This function compares two strings and returns the result by calling
2607 * collate::do_compare().
2609 * @param lo1 Start of string 1.
2610 * @param hi1 End of string 1.
2611 * @param lo2 Start of string 2.
2612 * @param hi2 End of string 2.
2613 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2616 compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
2617 const _CharT
* __lo2
, const _CharT
* __hi2
) const
2618 { return this->do_compare(__lo1
, __hi1
, __lo2
, __hi2
); }
2621 * @brief Transform string to comparable form.
2623 * This function is a wrapper for strxfrm functionality. It takes the
2624 * input string and returns a modified string that can be directly
2625 * compared to other transformed strings. In the "C" locale, this
2626 * function just returns a copy of the input string. In some other
2627 * locales, it may replace two chars with one, change a char for
2628 * another, etc. It does so by returning collate::do_transform().
2630 * @param lo Start of string.
2631 * @param hi End of string.
2632 * @return Transformed string_type.
2635 transform(const _CharT
* __lo
, const _CharT
* __hi
) const
2636 { return this->do_transform(__lo
, __hi
); }
2639 * @brief Return hash of a string.
2641 * This function computes and returns a hash on the input string. It
2642 * does so by returning collate::do_hash().
2644 * @param lo Start of string.
2645 * @param hi End of string.
2646 * @return Hash value.
2649 hash(const _CharT
* __lo
, const _CharT
* __hi
) const
2650 { return this->do_hash(__lo
, __hi
); }
2652 // Used to abstract out _CharT bits in virtual member functions, below.
2654 _M_compare(const _CharT
*, const _CharT
*) const;
2657 _M_transform(_CharT
*, const _CharT
*, size_t) const;
2663 { _S_destroy_c_locale(_M_c_locale_collate
); }
2666 * @brief Compare two strings.
2668 * This function is a hook for derived classes to change the value
2669 * returned. @see compare().
2671 * @param lo1 Start of string 1.
2672 * @param hi1 End of string 1.
2673 * @param lo2 Start of string 2.
2674 * @param hi2 End of string 2.
2675 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2678 do_compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
2679 const _CharT
* __lo2
, const _CharT
* __hi2
) const;
2682 * @brief Transform string to comparable form.
2684 * This function is a hook for derived classes to change the value
2687 * @param lo1 Start of string 1.
2688 * @param hi1 End of string 1.
2689 * @param lo2 Start of string 2.
2690 * @param hi2 End of string 2.
2691 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2694 do_transform(const _CharT
* __lo
, const _CharT
* __hi
) const;
2697 * @brief Return hash of a string.
2699 * This function computes and returns a hash on the input string. This
2700 * function is a hook for derived classes to change the value returned.
2702 * @param lo Start of string.
2703 * @param hi End of string.
2704 * @return Hash value.
2707 do_hash(const _CharT
* __lo
, const _CharT
* __hi
) const;
2710 template<typename _CharT
>
2711 locale::id collate
<_CharT
>::id
;
2716 collate
<char>::_M_compare(const char*, const char*) const;
2720 collate
<char>::_M_transform(char*, const char*, size_t) const;
2722 #ifdef _GLIBCXX_USE_WCHAR_T
2725 collate
<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
2729 collate
<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
2732 /// @brief class collate_byname [22.2.4.2].
2733 template<typename _CharT
>
2734 class collate_byname
: public collate
<_CharT
>
2739 typedef _CharT char_type
;
2740 typedef basic_string
<_CharT
> string_type
;
2744 collate_byname(const char* __s
, size_t __refs
= 0)
2745 : collate
<_CharT
>(__refs
)
2747 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
2749 this->_S_destroy_c_locale(this->_M_c_locale_collate
);
2750 this->_S_create_c_locale(this->_M_c_locale_collate
, __s
);
2756 ~collate_byname() { }
2761 * @brief Time format ordering data.
2763 * This class provides an enum representing different orderings of day,
2769 enum dateorder
{ no_order
, dmy
, mdy
, ymd
, ydm
};
2772 template<typename _CharT
>
2773 struct __timepunct_cache
: public locale::facet
2775 // List of all known timezones, with GMT first.
2776 static const _CharT
* _S_timezones
[14];
2778 const _CharT
* _M_date_format
;
2779 const _CharT
* _M_date_era_format
;
2780 const _CharT
* _M_time_format
;
2781 const _CharT
* _M_time_era_format
;
2782 const _CharT
* _M_date_time_format
;
2783 const _CharT
* _M_date_time_era_format
;
2784 const _CharT
* _M_am
;
2785 const _CharT
* _M_pm
;
2786 const _CharT
* _M_am_pm_format
;
2788 // Day names, starting with "C"'s Sunday.
2789 const _CharT
* _M_day1
;
2790 const _CharT
* _M_day2
;
2791 const _CharT
* _M_day3
;
2792 const _CharT
* _M_day4
;
2793 const _CharT
* _M_day5
;
2794 const _CharT
* _M_day6
;
2795 const _CharT
* _M_day7
;
2797 // Abbreviated day names, starting with "C"'s Sun.
2798 const _CharT
* _M_aday1
;
2799 const _CharT
* _M_aday2
;
2800 const _CharT
* _M_aday3
;
2801 const _CharT
* _M_aday4
;
2802 const _CharT
* _M_aday5
;
2803 const _CharT
* _M_aday6
;
2804 const _CharT
* _M_aday7
;
2806 // Month names, starting with "C"'s January.
2807 const _CharT
* _M_month01
;
2808 const _CharT
* _M_month02
;
2809 const _CharT
* _M_month03
;
2810 const _CharT
* _M_month04
;
2811 const _CharT
* _M_month05
;
2812 const _CharT
* _M_month06
;
2813 const _CharT
* _M_month07
;
2814 const _CharT
* _M_month08
;
2815 const _CharT
* _M_month09
;
2816 const _CharT
* _M_month10
;
2817 const _CharT
* _M_month11
;
2818 const _CharT
* _M_month12
;
2820 // Abbreviated month names, starting with "C"'s Jan.
2821 const _CharT
* _M_amonth01
;
2822 const _CharT
* _M_amonth02
;
2823 const _CharT
* _M_amonth03
;
2824 const _CharT
* _M_amonth04
;
2825 const _CharT
* _M_amonth05
;
2826 const _CharT
* _M_amonth06
;
2827 const _CharT
* _M_amonth07
;
2828 const _CharT
* _M_amonth08
;
2829 const _CharT
* _M_amonth09
;
2830 const _CharT
* _M_amonth10
;
2831 const _CharT
* _M_amonth11
;
2832 const _CharT
* _M_amonth12
;
2836 __timepunct_cache(size_t __refs
= 0) : facet(__refs
),
2837 _M_date_format(NULL
), _M_date_era_format(NULL
), _M_time_format(NULL
),
2838 _M_time_era_format(NULL
), _M_date_time_format(NULL
),
2839 _M_date_time_era_format(NULL
), _M_am(NULL
), _M_pm(NULL
),
2840 _M_am_pm_format(NULL
), _M_day1(NULL
), _M_day2(NULL
), _M_day3(NULL
),
2841 _M_day4(NULL
), _M_day5(NULL
), _M_day6(NULL
), _M_day7(NULL
),
2842 _M_aday1(NULL
), _M_aday2(NULL
), _M_aday3(NULL
), _M_aday4(NULL
),
2843 _M_aday5(NULL
), _M_aday6(NULL
), _M_aday7(NULL
), _M_month01(NULL
),
2844 _M_month02(NULL
), _M_month03(NULL
), _M_month04(NULL
), _M_month05(NULL
),
2845 _M_month06(NULL
), _M_month07(NULL
), _M_month08(NULL
), _M_month09(NULL
),
2846 _M_month10(NULL
), _M_month11(NULL
), _M_month12(NULL
), _M_amonth01(NULL
),
2847 _M_amonth02(NULL
), _M_amonth03(NULL
), _M_amonth04(NULL
),
2848 _M_amonth05(NULL
), _M_amonth06(NULL
), _M_amonth07(NULL
),
2849 _M_amonth08(NULL
), _M_amonth09(NULL
), _M_amonth10(NULL
),
2850 _M_amonth11(NULL
), _M_amonth12(NULL
), _M_allocated(false)
2853 ~__timepunct_cache();
2856 _M_cache(const locale
& __loc
);
2860 operator=(const __timepunct_cache
&);
2863 __timepunct_cache(const __timepunct_cache
&);
2866 template<typename _CharT
>
2867 __timepunct_cache
<_CharT
>::~__timepunct_cache()
2878 __timepunct_cache
<char>::_S_timezones
[14];
2880 #ifdef _GLIBCXX_USE_WCHAR_T
2883 __timepunct_cache
<wchar_t>::_S_timezones
[14];
2887 template<typename _CharT
>
2888 const _CharT
* __timepunct_cache
<_CharT
>::_S_timezones
[14];
2890 template<typename _CharT
>
2891 class __timepunct
: public locale::facet
2895 typedef _CharT __char_type
;
2896 typedef basic_string
<_CharT
> __string_type
;
2897 typedef __timepunct_cache
<_CharT
> __cache_type
;
2900 __cache_type
* _M_data
;
2901 __c_locale _M_c_locale_timepunct
;
2902 const char* _M_name_timepunct
;
2905 /// Numpunct facet id.
2906 static locale::id id
;
2909 __timepunct(size_t __refs
= 0);
2912 __timepunct(__cache_type
* __cache
, size_t __refs
= 0);
2915 * @brief Internal constructor. Not for general use.
2917 * This is a constructor for use by the library itself to set up new
2920 * @param cloc The "C" locale.
2921 * @param s The name of a locale.
2922 * @param refs Passed to the base facet class.
2925 __timepunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
2927 // FIXME: for error checking purposes _M_put should return the return
2928 // value of strftime/wcsftime.
2930 _M_put(_CharT
* __s
, size_t __maxlen
, const _CharT
* __format
,
2931 const tm
* __tm
) const;
2934 _M_date_formats(const _CharT
** __date
) const
2936 // Always have default first.
2937 __date
[0] = _M_data
->_M_date_format
;
2938 __date
[1] = _M_data
->_M_date_era_format
;
2942 _M_time_formats(const _CharT
** __time
) const
2944 // Always have default first.
2945 __time
[0] = _M_data
->_M_time_format
;
2946 __time
[1] = _M_data
->_M_time_era_format
;
2950 _M_date_time_formats(const _CharT
** __dt
) const
2952 // Always have default first.
2953 __dt
[0] = _M_data
->_M_date_time_format
;
2954 __dt
[1] = _M_data
->_M_date_time_era_format
;
2958 _M_am_pm_format(const _CharT
* __ampm
) const
2959 { __ampm
= _M_data
->_M_am_pm_format
; }
2962 _M_am_pm(const _CharT
** __ampm
) const
2964 __ampm
[0] = _M_data
->_M_am
;
2965 __ampm
[1] = _M_data
->_M_pm
;
2969 _M_days(const _CharT
** __days
) const
2971 __days
[0] = _M_data
->_M_day1
;
2972 __days
[1] = _M_data
->_M_day2
;
2973 __days
[2] = _M_data
->_M_day3
;
2974 __days
[3] = _M_data
->_M_day4
;
2975 __days
[4] = _M_data
->_M_day5
;
2976 __days
[5] = _M_data
->_M_day6
;
2977 __days
[6] = _M_data
->_M_day7
;
2981 _M_days_abbreviated(const _CharT
** __days
) const
2983 __days
[0] = _M_data
->_M_aday1
;
2984 __days
[1] = _M_data
->_M_aday2
;
2985 __days
[2] = _M_data
->_M_aday3
;
2986 __days
[3] = _M_data
->_M_aday4
;
2987 __days
[4] = _M_data
->_M_aday5
;
2988 __days
[5] = _M_data
->_M_aday6
;
2989 __days
[6] = _M_data
->_M_aday7
;
2993 _M_months(const _CharT
** __months
) const
2995 __months
[0] = _M_data
->_M_month01
;
2996 __months
[1] = _M_data
->_M_month02
;
2997 __months
[2] = _M_data
->_M_month03
;
2998 __months
[3] = _M_data
->_M_month04
;
2999 __months
[4] = _M_data
->_M_month05
;
3000 __months
[5] = _M_data
->_M_month06
;
3001 __months
[6] = _M_data
->_M_month07
;
3002 __months
[7] = _M_data
->_M_month08
;
3003 __months
[8] = _M_data
->_M_month09
;
3004 __months
[9] = _M_data
->_M_month10
;
3005 __months
[10] = _M_data
->_M_month11
;
3006 __months
[11] = _M_data
->_M_month12
;
3010 _M_months_abbreviated(const _CharT
** __months
) const
3012 __months
[0] = _M_data
->_M_amonth01
;
3013 __months
[1] = _M_data
->_M_amonth02
;
3014 __months
[2] = _M_data
->_M_amonth03
;
3015 __months
[3] = _M_data
->_M_amonth04
;
3016 __months
[4] = _M_data
->_M_amonth05
;
3017 __months
[5] = _M_data
->_M_amonth06
;
3018 __months
[6] = _M_data
->_M_amonth07
;
3019 __months
[7] = _M_data
->_M_amonth08
;
3020 __months
[8] = _M_data
->_M_amonth09
;
3021 __months
[9] = _M_data
->_M_amonth10
;
3022 __months
[10] = _M_data
->_M_amonth11
;
3023 __months
[11] = _M_data
->_M_amonth12
;
3030 // For use at construction time only.
3032 _M_initialize_timepunct(__c_locale __cloc
= NULL
);
3035 template<typename _CharT
>
3036 locale::id __timepunct
<_CharT
>::id
;
3041 __timepunct
<char>::_M_initialize_timepunct(__c_locale __cloc
);
3045 __timepunct
<char>::_M_put(char*, size_t, const char*, const tm
*) const;
3047 #ifdef _GLIBCXX_USE_WCHAR_T
3050 __timepunct
<wchar_t>::_M_initialize_timepunct(__c_locale __cloc
);
3054 __timepunct
<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
3058 _GLIBCXX_END_NAMESPACE
3060 // Include host and configuration specific timepunct functions.
3061 #include <bits/time_members.h>
3063 _GLIBCXX_BEGIN_NAMESPACE(std
)
3066 * @brief Facet for parsing dates and times.
3068 * This facet encapsulates the code to parse and return a date or
3069 * time from a string. It is used by the istream numeric
3070 * extraction operators.
3072 * The time_get template uses protected virtual functions to provide the
3073 * actual results. The public accessors forward the call to the virtual
3074 * functions. These virtual functions are hooks for developers to
3075 * implement the behavior they require from the time_get facet.
3077 template<typename _CharT
, typename _InIter
>
3078 class time_get
: public locale::facet
, public time_base
3084 typedef _CharT char_type
;
3085 typedef _InIter iter_type
;
3087 typedef basic_string
<_CharT
> __string_type
;
3089 /// Numpunct facet id.
3090 static locale::id id
;
3093 * @brief Constructor performs initialization.
3095 * This is the constructor provided by the standard.
3097 * @param refs Passed to the base facet class.
3100 time_get(size_t __refs
= 0)
3101 : facet (__refs
) { }
3104 * @brief Return preferred order of month, day, and year.
3106 * This function returns an enum from timebase::dateorder giving the
3107 * preferred ordering if the format "x" given to time_put::put() only
3108 * uses month, day, and year. If the format "x" for the associated
3109 * locale uses other fields, this function returns
3110 * timebase::dateorder::noorder.
3112 * NOTE: The library always returns noorder at the moment.
3114 * @return A member of timebase::dateorder.
3118 { return this->do_date_order(); }
3121 * @brief Parse input time string.
3123 * This function parses a time according to the format "x" and puts the
3124 * results into a user-supplied struct tm. The result is returned by
3125 * calling time_get::do_get_time().
3127 * If there is a valid time string according to format "x", @a tm will
3128 * be filled in accordingly and the returned iterator will point to the
3129 * first character beyond the time string. If an error occurs before
3130 * the end, err |= ios_base::failbit. If parsing reads all the
3131 * characters, err |= ios_base::eofbit.
3133 * @param beg Start of string to parse.
3134 * @param end End of string to parse.
3135 * @param io Source of the locale.
3136 * @param err Error flags to set.
3137 * @param tm Pointer to struct tm to fill in.
3138 * @return Iterator to first char beyond time string.
3141 get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3142 ios_base::iostate
& __err
, tm
* __tm
) const
3143 { return this->do_get_time(__beg
, __end
, __io
, __err
, __tm
); }
3146 * @brief Parse input date string.
3148 * This function parses a date according to the format "X" and puts the
3149 * results into a user-supplied struct tm. The result is returned by
3150 * calling time_get::do_get_date().
3152 * If there is a valid date string according to format "X", @a tm will
3153 * be filled in accordingly and the returned iterator will point to the
3154 * first character beyond the date string. If an error occurs before
3155 * the end, err |= ios_base::failbit. If parsing reads all the
3156 * characters, err |= ios_base::eofbit.
3158 * @param beg Start of string to parse.
3159 * @param end End of string to parse.
3160 * @param io Source of the locale.
3161 * @param err Error flags to set.
3162 * @param tm Pointer to struct tm to fill in.
3163 * @return Iterator to first char beyond date string.
3166 get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3167 ios_base::iostate
& __err
, tm
* __tm
) const
3168 { return this->do_get_date(__beg
, __end
, __io
, __err
, __tm
); }
3171 * @brief Parse input weekday string.
3173 * This function parses a weekday name and puts the results into a
3174 * user-supplied struct tm. The result is returned by calling
3175 * time_get::do_get_weekday().
3177 * Parsing starts by parsing an abbreviated weekday name. If a valid
3178 * abbreviation is followed by a character that would lead to the full
3179 * weekday name, parsing continues until the full name is found or an
3180 * error occurs. Otherwise parsing finishes at the end of the
3183 * If an error occurs before the end, err |= ios_base::failbit. If
3184 * parsing reads all the characters, err |= ios_base::eofbit.
3186 * @param beg Start of string to parse.
3187 * @param end End of string to parse.
3188 * @param io Source of the locale.
3189 * @param err Error flags to set.
3190 * @param tm Pointer to struct tm to fill in.
3191 * @return Iterator to first char beyond weekday name.
3194 get_weekday(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3195 ios_base::iostate
& __err
, tm
* __tm
) const
3196 { return this->do_get_weekday(__beg
, __end
, __io
, __err
, __tm
); }
3199 * @brief Parse input month string.
3201 * This function parses a month name and puts the results into a
3202 * user-supplied struct tm. The result is returned by calling
3203 * time_get::do_get_monthname().
3205 * Parsing starts by parsing an abbreviated month name. If a valid
3206 * abbreviation is followed by a character that would lead to the full
3207 * month name, parsing continues until the full name is found or an
3208 * error occurs. Otherwise parsing finishes at the end of the
3211 * If an error occurs before the end, err |= ios_base::failbit. If
3212 * parsing reads all the characters, err |=
3215 * @param beg Start of string to parse.
3216 * @param end End of string to parse.
3217 * @param io Source of the locale.
3218 * @param err Error flags to set.
3219 * @param tm Pointer to struct tm to fill in.
3220 * @return Iterator to first char beyond month name.
3223 get_monthname(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3224 ios_base::iostate
& __err
, tm
* __tm
) const
3225 { return this->do_get_monthname(__beg
, __end
, __io
, __err
, __tm
); }
3228 * @brief Parse input year string.
3230 * This function reads up to 4 characters to parse a year string and
3231 * puts the results into a user-supplied struct tm. The result is
3232 * returned by calling time_get::do_get_year().
3234 * 4 consecutive digits are interpreted as a full year. If there are
3235 * exactly 2 consecutive digits, the library interprets this as the
3236 * number of years since 1900.
3238 * If an error occurs before the end, err |= ios_base::failbit. If
3239 * parsing reads all the characters, err |= ios_base::eofbit.
3241 * @param beg Start of string to parse.
3242 * @param end End of string to parse.
3243 * @param io Source of the locale.
3244 * @param err Error flags to set.
3245 * @param tm Pointer to struct tm to fill in.
3246 * @return Iterator to first char beyond year.
3249 get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3250 ios_base::iostate
& __err
, tm
* __tm
) const
3251 { return this->do_get_year(__beg
, __end
, __io
, __err
, __tm
); }
3259 * @brief Return preferred order of month, day, and year.
3261 * This function returns an enum from timebase::dateorder giving the
3262 * preferred ordering if the format "x" given to time_put::put() only
3263 * uses month, day, and year. This function is a hook for derived
3264 * classes to change the value returned.
3266 * @return A member of timebase::dateorder.
3269 do_date_order() const;
3272 * @brief Parse input time string.
3274 * This function parses a time according to the format "x" and puts the
3275 * results into a user-supplied struct tm. This function is a hook for
3276 * derived classes to change the value returned. @see get_time() for
3279 * @param beg Start of string to parse.
3280 * @param end End of string to parse.
3281 * @param io Source of the locale.
3282 * @param err Error flags to set.
3283 * @param tm Pointer to struct tm to fill in.
3284 * @return Iterator to first char beyond time string.
3287 do_get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3288 ios_base::iostate
& __err
, tm
* __tm
) const;
3291 * @brief Parse input date string.
3293 * This function parses a date according to the format "X" and puts the
3294 * results into a user-supplied struct tm. This function is a hook for
3295 * derived classes to change the value returned. @see get_date() for
3298 * @param beg Start of string to parse.
3299 * @param end End of string to parse.
3300 * @param io Source of the locale.
3301 * @param err Error flags to set.
3302 * @param tm Pointer to struct tm to fill in.
3303 * @return Iterator to first char beyond date string.
3306 do_get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3307 ios_base::iostate
& __err
, tm
* __tm
) const;
3310 * @brief Parse input weekday string.
3312 * This function parses a weekday name and puts the results into a
3313 * user-supplied struct tm. This function is a hook for derived
3314 * classes to change the value returned. @see get_weekday() for
3317 * @param beg Start of string to parse.
3318 * @param end End of string to parse.
3319 * @param io Source of the locale.
3320 * @param err Error flags to set.
3321 * @param tm Pointer to struct tm to fill in.
3322 * @return Iterator to first char beyond weekday name.
3325 do_get_weekday(iter_type __beg
, iter_type __end
, ios_base
&,
3326 ios_base::iostate
& __err
, tm
* __tm
) const;
3329 * @brief Parse input month string.
3331 * This function parses a month name and puts the results into a
3332 * user-supplied struct tm. This function is a hook for derived
3333 * classes to change the value returned. @see get_monthname() for
3336 * @param beg Start of string to parse.
3337 * @param end End of string to parse.
3338 * @param io Source of the locale.
3339 * @param err Error flags to set.
3340 * @param tm Pointer to struct tm to fill in.
3341 * @return Iterator to first char beyond month name.
3344 do_get_monthname(iter_type __beg
, iter_type __end
, ios_base
&,
3345 ios_base::iostate
& __err
, tm
* __tm
) const;
3348 * @brief Parse input year string.
3350 * This function reads up to 4 characters to parse a year string and
3351 * puts the results into a user-supplied struct tm. This function is a
3352 * hook for derived classes to change the value returned. @see
3353 * get_year() for details.
3355 * @param beg Start of string to parse.
3356 * @param end End of string to parse.
3357 * @param io Source of the locale.
3358 * @param err Error flags to set.
3359 * @param tm Pointer to struct tm to fill in.
3360 * @return Iterator to first char beyond year.
3363 do_get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3364 ios_base::iostate
& __err
, tm
* __tm
) const;
3366 // Extract numeric component of length __len.
3368 _M_extract_num(iter_type __beg
, iter_type __end
, int& __member
,
3369 int __min
, int __max
, size_t __len
,
3370 ios_base
& __io
, ios_base::iostate
& __err
) const;
3372 // Extract day or month name, or any unique array of string
3373 // literals in a const _CharT* array.
3375 _M_extract_name(iter_type __beg
, iter_type __end
, int& __member
,
3376 const _CharT
** __names
, size_t __indexlen
,
3377 ios_base
& __io
, ios_base::iostate
& __err
) const;
3379 // Extract on a component-by-component basis, via __format argument.
3381 _M_extract_via_format(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3382 ios_base::iostate
& __err
, tm
* __tm
,
3383 const _CharT
* __format
) const;
3386 template<typename _CharT
, typename _InIter
>
3387 locale::id time_get
<_CharT
, _InIter
>::id
;
3389 /// @brief class time_get_byname [22.2.5.2].
3390 template<typename _CharT
, typename _InIter
>
3391 class time_get_byname
: public time_get
<_CharT
, _InIter
>
3395 typedef _CharT char_type
;
3396 typedef _InIter iter_type
;
3399 time_get_byname(const char*, size_t __refs
= 0)
3400 : time_get
<_CharT
, _InIter
>(__refs
) { }
3404 ~time_get_byname() { }
3408 * @brief Facet for outputting dates and times.
3410 * This facet encapsulates the code to format and output dates and times
3411 * according to formats used by strftime().
3413 * The time_put template uses protected virtual functions to provide the
3414 * actual results. The public accessors forward the call to the virtual
3415 * functions. These virtual functions are hooks for developers to
3416 * implement the behavior they require from the time_put facet.
3418 template<typename _CharT
, typename _OutIter
>
3419 class time_put
: public locale::facet
3425 typedef _CharT char_type
;
3426 typedef _OutIter iter_type
;
3429 /// Numpunct facet id.
3430 static locale::id id
;
3433 * @brief Constructor performs initialization.
3435 * This is the constructor provided by the standard.
3437 * @param refs Passed to the base facet class.
3440 time_put(size_t __refs
= 0)
3444 * @brief Format and output a time or date.
3446 * This function formats the data in struct tm according to the
3447 * provided format string. The format string is interpreted as by
3450 * @param s The stream to write to.
3451 * @param io Source of locale.
3452 * @param fill char_type to use for padding.
3453 * @param tm Struct tm with date and time info to format.
3454 * @param beg Start of format string.
3455 * @param end End of format string.
3456 * @return Iterator after writing.
3459 put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
3460 const _CharT
* __beg
, const _CharT
* __end
) const;
3463 * @brief Format and output a time or date.
3465 * This function formats the data in struct tm according to the
3466 * provided format char and optional modifier. The format and modifier
3467 * are interpreted as by strftime(). It does so by returning
3468 * time_put::do_put().
3470 * @param s The stream to write to.
3471 * @param io Source of locale.
3472 * @param fill char_type to use for padding.
3473 * @param tm Struct tm with date and time info to format.
3474 * @param format Format char.
3475 * @param mod Optional modifier char.
3476 * @return Iterator after writing.
3479 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
3480 const tm
* __tm
, char __format
, char __mod
= 0) const
3481 { return this->do_put(__s
, __io
, __fill
, __tm
, __format
, __mod
); }
3490 * @brief Format and output a time or date.
3492 * This function formats the data in struct tm according to the
3493 * provided format char and optional modifier. This function is a hook
3494 * for derived classes to change the value returned. @see put() for
3497 * @param s The stream to write to.
3498 * @param io Source of locale.
3499 * @param fill char_type to use for padding.
3500 * @param tm Struct tm with date and time info to format.
3501 * @param format Format char.
3502 * @param mod Optional modifier char.
3503 * @return Iterator after writing.
3506 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
3507 char __format
, char __mod
) const;
3510 template<typename _CharT
, typename _OutIter
>
3511 locale::id time_put
<_CharT
, _OutIter
>::id
;
3513 /// @brief class time_put_byname [22.2.5.4].
3514 template<typename _CharT
, typename _OutIter
>
3515 class time_put_byname
: public time_put
<_CharT
, _OutIter
>
3519 typedef _CharT char_type
;
3520 typedef _OutIter iter_type
;
3523 time_put_byname(const char*, size_t __refs
= 0)
3524 : time_put
<_CharT
, _OutIter
>(__refs
)
3529 ~time_put_byname() { }
3534 * @brief Money format ordering data.
3536 * This class contains an ordered array of 4 fields to represent the
3537 * pattern for formatting a money amount. Each field may contain one entry
3538 * from the part enum. symbol, sign, and value must be present and the
3539 * remaining field must contain either none or space. @see
3540 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
3541 * these fields are interpreted.
3546 enum part
{ none
, space
, symbol
, sign
, value
};
3547 struct pattern
{ char field
[4]; };
3549 static const pattern _S_default_pattern
;
3558 // String literal of acceptable (narrow) input/output, for
3559 // money_get/money_put. "-0123456789"
3560 static const char* _S_atoms
;
3562 // Construct and return valid pattern consisting of some combination of:
3563 // space none symbol sign value
3565 _S_construct_pattern(char __precedes
, char __space
, char __posn
);
3568 template<typename _CharT
, bool _Intl
>
3569 struct __moneypunct_cache
: public locale::facet
3571 const char* _M_grouping
;
3572 size_t _M_grouping_size
;
3573 bool _M_use_grouping
;
3574 _CharT _M_decimal_point
;
3575 _CharT _M_thousands_sep
;
3576 const _CharT
* _M_curr_symbol
;
3577 size_t _M_curr_symbol_size
;
3578 const _CharT
* _M_positive_sign
;
3579 size_t _M_positive_sign_size
;
3580 const _CharT
* _M_negative_sign
;
3581 size_t _M_negative_sign_size
;
3583 money_base::pattern _M_pos_format
;
3584 money_base::pattern _M_neg_format
;
3586 // A list of valid numeric literals for input and output: in the standard
3587 // "C" locale, this is "-0123456789". This array contains the chars after
3588 // having been passed through the current locale's ctype<_CharT>.widen().
3589 _CharT _M_atoms
[money_base::_S_end
];
3593 __moneypunct_cache(size_t __refs
= 0) : facet(__refs
),
3594 _M_grouping(NULL
), _M_grouping_size(0), _M_use_grouping(false),
3595 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
3596 _M_curr_symbol(NULL
), _M_curr_symbol_size(0),
3597 _M_positive_sign(NULL
), _M_positive_sign_size(0),
3598 _M_negative_sign(NULL
), _M_negative_sign_size(0),
3600 _M_pos_format(money_base::pattern()),
3601 _M_neg_format(money_base::pattern()), _M_allocated(false)
3604 ~__moneypunct_cache();
3607 _M_cache(const locale
& __loc
);
3611 operator=(const __moneypunct_cache
&);
3614 __moneypunct_cache(const __moneypunct_cache
&);
3617 template<typename _CharT
, bool _Intl
>
3618 __moneypunct_cache
<_CharT
, _Intl
>::~__moneypunct_cache()
3622 delete [] _M_grouping
;
3623 delete [] _M_curr_symbol
;
3624 delete [] _M_positive_sign
;
3625 delete [] _M_negative_sign
;
3630 * @brief Facet for formatting data for money amounts.
3632 * This facet encapsulates the punctuation, grouping and other formatting
3633 * features of money amount string representations.
3635 template<typename _CharT
, bool _Intl
>
3636 class moneypunct
: public locale::facet
, public money_base
3642 typedef _CharT char_type
;
3643 typedef basic_string
<_CharT
> string_type
;
3645 typedef __moneypunct_cache
<_CharT
, _Intl
> __cache_type
;
3648 __cache_type
* _M_data
;
3651 /// This value is provided by the standard, but no reason for its
3653 static const bool intl
= _Intl
;
3654 /// Numpunct facet id.
3655 static locale::id id
;
3658 * @brief Constructor performs initialization.
3660 * This is the constructor provided by the standard.
3662 * @param refs Passed to the base facet class.
3665 moneypunct(size_t __refs
= 0) : facet(__refs
), _M_data(NULL
)
3666 { _M_initialize_moneypunct(); }
3669 * @brief Constructor performs initialization.
3671 * This is an internal constructor.
3673 * @param cache Cache for optimization.
3674 * @param refs Passed to the base facet class.
3677 moneypunct(__cache_type
* __cache
, size_t __refs
= 0)
3678 : facet(__refs
), _M_data(__cache
)
3679 { _M_initialize_moneypunct(); }
3682 * @brief Internal constructor. Not for general use.
3684 * This is a constructor for use by the library itself to set up new
3687 * @param cloc The "C" locale.
3688 * @param s The name of a locale.
3689 * @param refs Passed to the base facet class.
3692 moneypunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0)
3693 : facet(__refs
), _M_data(NULL
)
3694 { _M_initialize_moneypunct(__cloc
, __s
); }
3697 * @brief Return decimal point character.
3699 * This function returns a char_type to use as a decimal point. It
3700 * does so by returning returning
3701 * moneypunct<char_type>::do_decimal_point().
3703 * @return @a char_type representing a decimal point.
3706 decimal_point() const
3707 { return this->do_decimal_point(); }
3710 * @brief Return thousands separator character.
3712 * This function returns a char_type to use as a thousands
3713 * separator. It does so by returning returning
3714 * moneypunct<char_type>::do_thousands_sep().
3716 * @return char_type representing a thousands separator.
3719 thousands_sep() const
3720 { return this->do_thousands_sep(); }
3723 * @brief Return grouping specification.
3725 * This function returns a string representing groupings for the
3726 * integer part of an amount. Groupings indicate where thousands
3727 * separators should be inserted.
3729 * Each char in the return string is interpret as an integer rather
3730 * than a character. These numbers represent the number of digits in a
3731 * group. The first char in the string represents the number of digits
3732 * in the least significant group. If a char is negative, it indicates
3733 * an unlimited number of digits for the group. If more chars from the
3734 * string are required to group a number, the last char is used
3737 * For example, if the grouping() returns "\003\002" and is applied to
3738 * the number 123456789, this corresponds to 12,34,56,789. Note that
3739 * if the string was "32", this would put more than 50 digits into the
3740 * least significant group if the character set is ASCII.
3742 * The string is returned by calling
3743 * moneypunct<char_type>::do_grouping().
3745 * @return string representing grouping specification.
3749 { return this->do_grouping(); }
3752 * @brief Return currency symbol string.
3754 * This function returns a string_type to use as a currency symbol. It
3755 * does so by returning returning
3756 * moneypunct<char_type>::do_curr_symbol().
3758 * @return @a string_type representing a currency symbol.
3762 { return this->do_curr_symbol(); }
3765 * @brief Return positive sign string.
3767 * This function returns a string_type to use as a sign for positive
3768 * amounts. It does so by returning returning
3769 * moneypunct<char_type>::do_positive_sign().
3771 * If the return value contains more than one character, the first
3772 * character appears in the position indicated by pos_format() and the
3773 * remainder appear at the end of the formatted string.
3775 * @return @a string_type representing a positive sign.
3778 positive_sign() const
3779 { return this->do_positive_sign(); }
3782 * @brief Return negative sign string.
3784 * This function returns a string_type to use as a sign for negative
3785 * amounts. It does so by returning returning
3786 * moneypunct<char_type>::do_negative_sign().
3788 * If the return value contains more than one character, the first
3789 * character appears in the position indicated by neg_format() and the
3790 * remainder appear at the end of the formatted string.
3792 * @return @a string_type representing a negative sign.
3795 negative_sign() const
3796 { return this->do_negative_sign(); }
3799 * @brief Return number of digits in fraction.
3801 * This function returns the exact number of digits that make up the
3802 * fractional part of a money amount. It does so by returning
3803 * returning moneypunct<char_type>::do_frac_digits().
3805 * The fractional part of a money amount is optional. But if it is
3806 * present, there must be frac_digits() digits.
3808 * @return Number of digits in amount fraction.
3812 { return this->do_frac_digits(); }
3816 * @brief Return pattern for money values.
3818 * This function returns a pattern describing the formatting of a
3819 * positive or negative valued money amount. It does so by returning
3820 * returning moneypunct<char_type>::do_pos_format() or
3821 * moneypunct<char_type>::do_neg_format().
3823 * The pattern has 4 fields describing the ordering of symbol, sign,
3824 * value, and none or space. There must be one of each in the pattern.
3825 * The none and space enums may not appear in the first field and space
3826 * may not appear in the final field.
3828 * The parts of a money string must appear in the order indicated by
3829 * the fields of the pattern. The symbol field indicates that the
3830 * value of curr_symbol() may be present. The sign field indicates
3831 * that the value of positive_sign() or negative_sign() must be
3832 * present. The value field indicates that the absolute value of the
3833 * money amount is present. none indicates 0 or more whitespace
3834 * characters, except at the end, where it permits no whitespace.
3835 * space indicates that 1 or more whitespace characters must be
3838 * For example, for the US locale and pos_format() pattern
3839 * {symbol,sign,value,none}, curr_symbol() == '$' positive_sign() ==
3840 * '+', and value 10.01, and options set to force the symbol, the
3841 * corresponding string is "$+10.01".
3843 * @return Pattern for money values.
3847 { return this->do_pos_format(); }
3851 { return this->do_neg_format(); }
3860 * @brief Return decimal point character.
3862 * Returns a char_type to use as a decimal point. This function is a
3863 * hook for derived classes to change the value returned.
3865 * @return @a char_type representing a decimal point.
3868 do_decimal_point() const
3869 { return _M_data
->_M_decimal_point
; }
3872 * @brief Return thousands separator character.
3874 * Returns a char_type to use as a thousands separator. This function
3875 * is a hook for derived classes to change the value returned.
3877 * @return @a char_type representing a thousands separator.
3880 do_thousands_sep() const
3881 { return _M_data
->_M_thousands_sep
; }
3884 * @brief Return grouping specification.
3886 * Returns a string representing groupings for the integer part of a
3887 * number. This function is a hook for derived classes to change the
3888 * value returned. @see grouping() for details.
3890 * @return String representing grouping specification.
3894 { return _M_data
->_M_grouping
; }
3897 * @brief Return currency symbol string.
3899 * This function returns a string_type to use as a currency symbol.
3900 * This function is a hook for derived classes to change the value
3901 * returned. @see curr_symbol() for details.
3903 * @return @a string_type representing a currency symbol.
3906 do_curr_symbol() const
3907 { return _M_data
->_M_curr_symbol
; }
3910 * @brief Return positive sign string.
3912 * This function returns a string_type to use as a sign for positive
3913 * amounts. This function is a hook for derived classes to change the
3914 * value returned. @see positive_sign() for details.
3916 * @return @a string_type representing a positive sign.
3919 do_positive_sign() const
3920 { return _M_data
->_M_positive_sign
; }
3923 * @brief Return negative sign string.
3925 * This function returns a string_type to use as a sign for negative
3926 * amounts. This function is a hook for derived classes to change the
3927 * value returned. @see negative_sign() for details.
3929 * @return @a string_type representing a negative sign.
3932 do_negative_sign() const
3933 { return _M_data
->_M_negative_sign
; }
3936 * @brief Return number of digits in fraction.
3938 * This function returns the exact number of digits that make up the
3939 * fractional part of a money amount. This function is a hook for
3940 * derived classes to change the value returned. @see frac_digits()
3943 * @return Number of digits in amount fraction.
3946 do_frac_digits() const
3947 { return _M_data
->_M_frac_digits
; }
3950 * @brief Return pattern for money values.
3952 * This function returns a pattern describing the formatting of a
3953 * positive valued money amount. This function is a hook for derived
3954 * classes to change the value returned. @see pos_format() for
3957 * @return Pattern for money values.
3960 do_pos_format() const
3961 { return _M_data
->_M_pos_format
; }
3964 * @brief Return pattern for money values.
3966 * This function returns a pattern describing the formatting of a
3967 * negative valued money amount. This function is a hook for derived
3968 * classes to change the value returned. @see neg_format() for
3971 * @return Pattern for money values.
3974 do_neg_format() const
3975 { return _M_data
->_M_neg_format
; }
3977 // For use at construction time only.
3979 _M_initialize_moneypunct(__c_locale __cloc
= NULL
,
3980 const char* __name
= NULL
);
3983 template<typename _CharT
, bool _Intl
>
3984 locale::id moneypunct
<_CharT
, _Intl
>::id
;
3986 template<typename _CharT
, bool _Intl
>
3987 const bool moneypunct
<_CharT
, _Intl
>::intl
;
3990 moneypunct
<char, true>::~moneypunct();
3993 moneypunct
<char, false>::~moneypunct();
3997 moneypunct
<char, true>::_M_initialize_moneypunct(__c_locale
, const char*);
4001 moneypunct
<char, false>::_M_initialize_moneypunct(__c_locale
, const char*);
4003 #ifdef _GLIBCXX_USE_WCHAR_T
4005 moneypunct
<wchar_t, true>::~moneypunct();
4008 moneypunct
<wchar_t, false>::~moneypunct();
4012 moneypunct
<wchar_t, true>::_M_initialize_moneypunct(__c_locale
,
4017 moneypunct
<wchar_t, false>::_M_initialize_moneypunct(__c_locale
,
4021 /// @brief class moneypunct_byname [22.2.6.4].
4022 template<typename _CharT
, bool _Intl
>
4023 class moneypunct_byname
: public moneypunct
<_CharT
, _Intl
>
4026 typedef _CharT char_type
;
4027 typedef basic_string
<_CharT
> string_type
;
4029 static const bool intl
= _Intl
;
4032 moneypunct_byname(const char* __s
, size_t __refs
= 0)
4033 : moneypunct
<_CharT
, _Intl
>(__refs
)
4035 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
4038 this->_S_create_c_locale(__tmp
, __s
);
4039 this->_M_initialize_moneypunct(__tmp
);
4040 this->_S_destroy_c_locale(__tmp
);
4046 ~moneypunct_byname() { }
4049 template<typename _CharT
, bool _Intl
>
4050 const bool moneypunct_byname
<_CharT
, _Intl
>::intl
;
4052 _GLIBCXX_BEGIN_LDBL_NAMESPACE
4054 * @brief Facet for parsing monetary amounts.
4056 * This facet encapsulates the code to parse and return a monetary
4057 * amount from a string.
4059 * The money_get template uses protected virtual functions to
4060 * provide the actual results. The public accessors forward the
4061 * call to the virtual functions. These virtual functions are
4062 * hooks for developers to implement the behavior they require from
4063 * the money_get facet.
4065 template<typename _CharT
, typename _InIter
>
4066 class money_get
: public locale::facet
4072 typedef _CharT char_type
;
4073 typedef _InIter iter_type
;
4074 typedef basic_string
<_CharT
> string_type
;
4077 /// Numpunct facet id.
4078 static locale::id id
;
4081 * @brief Constructor performs initialization.
4083 * This is the constructor provided by the standard.
4085 * @param refs Passed to the base facet class.
4088 money_get(size_t __refs
= 0) : facet(__refs
) { }
4091 * @brief Read and parse a monetary value.
4093 * This function reads characters from @a s, interprets them as a
4094 * monetary value according to moneypunct and ctype facets retrieved
4095 * from io.getloc(), and returns the result in @a units as an integral
4096 * value moneypunct::frac_digits() * the actual amount. For example,
4097 * the string $10.01 in a US locale would store 1001 in @a units.
4099 * Any characters not part of a valid money amount are not consumed.
4101 * If a money value cannot be parsed from the input stream, sets
4102 * err=(err|io.failbit). If the stream is consumed before finishing
4103 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
4104 * unchanged if parsing fails.
4106 * This function works by returning the result of do_get().
4108 * @param s Start of characters to parse.
4109 * @param end End of characters to parse.
4110 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4111 * @param io Source of facets and io state.
4112 * @param err Error field to set if parsing fails.
4113 * @param units Place to store result of parsing.
4114 * @return Iterator referencing first character beyond valid money
4118 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4119 ios_base::iostate
& __err
, long double& __units
) const
4120 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __units
); }
4123 * @brief Read and parse a monetary value.
4125 * This function reads characters from @a s, interprets them as a
4126 * monetary value according to moneypunct and ctype facets retrieved
4127 * from io.getloc(), and returns the result in @a digits. For example,
4128 * the string $10.01 in a US locale would store "1001" in @a digits.
4130 * Any characters not part of a valid money amount are not consumed.
4132 * If a money value cannot be parsed from the input stream, sets
4133 * err=(err|io.failbit). If the stream is consumed before finishing
4134 * parsing, sets err=(err|io.failbit|io.eofbit).
4136 * This function works by returning the result of do_get().
4138 * @param s Start of characters to parse.
4139 * @param end End of characters to parse.
4140 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4141 * @param io Source of facets and io state.
4142 * @param err Error field to set if parsing fails.
4143 * @param digits Place to store result of parsing.
4144 * @return Iterator referencing first character beyond valid money
4148 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4149 ios_base::iostate
& __err
, string_type
& __digits
) const
4150 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __digits
); }
4158 * @brief Read and parse a monetary value.
4160 * This function reads and parses characters representing a monetary
4161 * value. This function is a hook for derived classes to change the
4162 * value returned. @see get() for details.
4164 // XXX GLIBCXX_ABI Deprecated
4165 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4167 __do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4168 ios_base::iostate
& __err
, double& __units
) const;
4171 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4172 ios_base::iostate
& __err
, long double& __units
) const;
4176 * @brief Read and parse a monetary value.
4178 * This function reads and parses characters representing a monetary
4179 * value. This function is a hook for derived classes to change the
4180 * value returned. @see get() for details.
4183 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4184 ios_base::iostate
& __err
, string_type
& __digits
) const;
4186 // XXX GLIBCXX_ABI Deprecated
4187 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4189 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4190 ios_base::iostate
& __err
, long double& __units
) const;
4193 template<bool _Intl
>
4195 _M_extract(iter_type __s
, iter_type __end
, ios_base
& __io
,
4196 ios_base::iostate
& __err
, string
& __digits
) const;
4199 template<typename _CharT
, typename _InIter
>
4200 locale::id money_get
<_CharT
, _InIter
>::id
;
4203 * @brief Facet for outputting monetary amounts.
4205 * This facet encapsulates the code to format and output a monetary
4208 * The money_put template uses protected virtual functions to
4209 * provide the actual results. The public accessors forward the
4210 * call to the virtual functions. These virtual functions are
4211 * hooks for developers to implement the behavior they require from
4212 * the money_put facet.
4214 template<typename _CharT
, typename _OutIter
>
4215 class money_put
: public locale::facet
4220 typedef _CharT char_type
;
4221 typedef _OutIter iter_type
;
4222 typedef basic_string
<_CharT
> string_type
;
4225 /// Numpunct facet id.
4226 static locale::id id
;
4229 * @brief Constructor performs initialization.
4231 * This is the constructor provided by the standard.
4233 * @param refs Passed to the base facet class.
4236 money_put(size_t __refs
= 0) : facet(__refs
) { }
4239 * @brief Format and output a monetary value.
4241 * This function formats @a units as a monetary value according to
4242 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4243 * the resulting characters to @a s. For example, the value 1001 in a
4244 * US locale would write "$10.01" to @a s.
4246 * This function works by returning the result of do_put().
4248 * @param s The stream to write to.
4249 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4250 * @param io Source of facets and io state.
4251 * @param fill char_type to use for padding.
4252 * @param units Place to store result of parsing.
4253 * @return Iterator after writing.
4256 put(iter_type __s
, bool __intl
, ios_base
& __io
,
4257 char_type __fill
, long double __units
) const
4258 { return this->do_put(__s
, __intl
, __io
, __fill
, __units
); }
4261 * @brief Format and output a monetary value.
4263 * This function formats @a digits as a monetary value according to
4264 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4265 * the resulting characters to @a s. For example, the string "1001" in
4266 * a US locale would write "$10.01" to @a s.
4268 * This function works by returning the result of do_put().
4270 * @param s The stream to write to.
4271 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4272 * @param io Source of facets and io state.
4273 * @param fill char_type to use for padding.
4274 * @param units Place to store result of parsing.
4275 * @return Iterator after writing.
4278 put(iter_type __s
, bool __intl
, ios_base
& __io
,
4279 char_type __fill
, const string_type
& __digits
) const
4280 { return this->do_put(__s
, __intl
, __io
, __fill
, __digits
); }
4288 * @brief Format and output a monetary value.
4290 * This function formats @a units as a monetary value according to
4291 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4292 * the resulting characters to @a s. For example, the value 1001 in a
4293 * US locale would write "$10.01" to @a s.
4295 * This function is a hook for derived classes to change the value
4296 * returned. @see put().
4298 * @param s The stream to write to.
4299 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4300 * @param io Source of facets and io state.
4301 * @param fill char_type to use for padding.
4302 * @param units Place to store result of parsing.
4303 * @return Iterator after writing.
4305 // XXX GLIBCXX_ABI Deprecated
4306 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4308 __do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4309 double __units
) const;
4312 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4313 long double __units
) const;
4317 * @brief Format and output a monetary value.
4319 * This function formats @a digits as a monetary value according to
4320 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4321 * the resulting characters to @a s. For example, the string "1001" in
4322 * a US locale would write "$10.01" to @a s.
4324 * This function is a hook for derived classes to change the value
4325 * returned. @see put().
4327 * @param s The stream to write to.
4328 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4329 * @param io Source of facets and io state.
4330 * @param fill char_type to use for padding.
4331 * @param units Place to store result of parsing.
4332 * @return Iterator after writing.
4335 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4336 const string_type
& __digits
) const;
4338 // XXX GLIBCXX_ABI Deprecated
4339 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4341 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4342 long double __units
) const;
4345 template<bool _Intl
>
4347 _M_insert(iter_type __s
, ios_base
& __io
, char_type __fill
,
4348 const string_type
& __digits
) const;
4351 template<typename _CharT
, typename _OutIter
>
4352 locale::id money_put
<_CharT
, _OutIter
>::id
;
4354 _GLIBCXX_END_LDBL_NAMESPACE
4357 * @brief Messages facet base class providing catalog typedef.
4359 struct messages_base
4361 typedef int catalog
;
4365 * @brief Facet for handling message catalogs
4367 * This facet encapsulates the code to retrieve messages from
4368 * message catalogs. The only thing defined by the standard for this facet
4369 * is the interface. All underlying functionality is
4370 * implementation-defined.
4372 * This library currently implements 3 versions of the message facet. The
4373 * first version (gnu) is a wrapper around gettext, provided by libintl.
4374 * The second version (ieee) is a wrapper around catgets. The final
4375 * version (default) does no actual translation. These implementations are
4376 * only provided for char and wchar_t instantiations.
4378 * The messages template uses protected virtual functions to
4379 * provide the actual results. The public accessors forward the
4380 * call to the virtual functions. These virtual functions are
4381 * hooks for developers to implement the behavior they require from
4382 * the messages facet.
4384 template<typename _CharT
>
4385 class messages
: public locale::facet
, public messages_base
4391 typedef _CharT char_type
;
4392 typedef basic_string
<_CharT
> string_type
;
4396 // Underlying "C" library locale information saved from
4397 // initialization, needed by messages_byname as well.
4398 __c_locale _M_c_locale_messages
;
4399 const char* _M_name_messages
;
4402 /// Numpunct facet id.
4403 static locale::id id
;
4406 * @brief Constructor performs initialization.
4408 * This is the constructor provided by the standard.
4410 * @param refs Passed to the base facet class.
4413 messages(size_t __refs
= 0);
4417 * @brief Internal constructor. Not for general use.
4419 * This is a constructor for use by the library itself to set up new
4422 * @param cloc The "C" locale.
4423 * @param s The name of a locale.
4424 * @param refs Refcount to pass to the base class.
4427 messages(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
4430 * @brief Open a message catalog.
4432 * This function opens and returns a handle to a message catalog by
4433 * returning do_open(s, loc).
4435 * @param s The catalog to open.
4436 * @param loc Locale to use for character set conversions.
4437 * @return Handle to the catalog or value < 0 if open fails.
4440 open(const basic_string
<char>& __s
, const locale
& __loc
) const
4441 { return this->do_open(__s
, __loc
); }
4443 // Non-standard and unorthodox, yet effective.
4445 * @brief Open a message catalog.
4447 * This non-standard function opens and returns a handle to a message
4448 * catalog by returning do_open(s, loc). The third argument provides a
4449 * message catalog root directory for gnu gettext and is ignored
4452 * @param s The catalog to open.
4453 * @param loc Locale to use for character set conversions.
4454 * @param dir Message catalog root directory.
4455 * @return Handle to the catalog or value < 0 if open fails.
4458 open(const basic_string
<char>&, const locale
&, const char*) const;
4461 * @brief Look up a string in a message catalog.
4463 * This function retrieves and returns a message from a catalog by
4464 * returning do_get(c, set, msgid, s).
4466 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4467 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4469 * @param c The catalog to access.
4470 * @param set Implementation-defined.
4471 * @param msgid Implementation-defined.
4472 * @param s Default return value if retrieval fails.
4473 * @return Retrieved message or @a s if get fails.
4476 get(catalog __c
, int __set
, int __msgid
, const string_type
& __s
) const
4477 { return this->do_get(__c
, __set
, __msgid
, __s
); }
4480 * @brief Close a message catalog.
4482 * Closes catalog @a c by calling do_close(c).
4484 * @param c The catalog to close.
4487 close(catalog __c
) const
4488 { return this->do_close(__c
); }
4496 * @brief Open a message catalog.
4498 * This function opens and returns a handle to a message catalog in an
4499 * implementation-defined manner. This function is a hook for derived
4500 * classes to change the value returned.
4502 * @param s The catalog to open.
4503 * @param loc Locale to use for character set conversions.
4504 * @return Handle to the opened catalog, value < 0 if open failed.
4507 do_open(const basic_string
<char>&, const locale
&) const;
4510 * @brief Look up a string in a message catalog.
4512 * This function retrieves and returns a message from a catalog in an
4513 * implementation-defined manner. This function is a hook for derived
4514 * classes to change the value returned.
4516 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4517 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4519 * @param c The catalog to access.
4520 * @param set Implementation-defined.
4521 * @param msgid Implementation-defined.
4522 * @param s Default return value if retrieval fails.
4523 * @return Retrieved message or @a s if get fails.
4526 do_get(catalog
, int, int, const string_type
& __dfault
) const;
4529 * @brief Close a message catalog.
4531 * @param c The catalog to close.
4534 do_close(catalog
) const;
4536 // Returns a locale and codeset-converted string, given a char* message.
4538 _M_convert_to_char(const string_type
& __msg
) const
4541 return reinterpret_cast<char*>(const_cast<_CharT
*>(__msg
.c_str()));
4544 // Returns a locale and codeset-converted string, given a char* message.
4546 _M_convert_from_char(char*) const
4549 // Length of message string without terminating null.
4550 size_t __len
= char_traits
<char>::length(__msg
) - 1;
4552 // "everybody can easily convert the string using
4553 // mbsrtowcs/wcsrtombs or with iconv()"
4555 // Convert char* to _CharT in locale used to open catalog.
4556 // XXX need additional template parameter on messages class for this..
4557 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
4558 typedef typename codecvt
<char, _CharT
, mbstate_t> __codecvt_type
;
4560 __codecvt_type::state_type __state
;
4561 // XXX may need to initialize state.
4562 //initialize_state(__state._M_init());
4565 // XXX what size for this string?
4566 _CharT
* __to
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
4567 const __codecvt_type
& __cvt
= use_facet
<__codecvt_type
>(_M_locale_conv
);
4568 __cvt
.out(__state
, __msg
, __msg
+ __len
, __from_next
,
4569 __to
, __to
+ __len
+ 1, __to_next
);
4570 return string_type(__to
);
4573 typedef ctype
<_CharT
> __ctype_type
;
4574 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
4575 const __ctype_type
& __cvt
= use_facet
<__ctype_type
>(locale());
4576 // XXX Again, proper length of converted string an issue here.
4577 // For now, assume the converted length is not larger.
4578 _CharT
* __dest
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
4579 __cvt
.widen(__msg
, __msg
+ __len
, __dest
);
4580 return basic_string
<_CharT
>(__dest
);
4582 return string_type();
4586 template<typename _CharT
>
4587 locale::id messages
<_CharT
>::id
;
4589 // Specializations for required instantiations.
4592 messages
<char>::do_get(catalog
, int, int, const string
&) const;
4594 #ifdef _GLIBCXX_USE_WCHAR_T
4597 messages
<wchar_t>::do_get(catalog
, int, int, const wstring
&) const;
4600 /// @brief class messages_byname [22.2.7.2].
4601 template<typename _CharT
>
4602 class messages_byname
: public messages
<_CharT
>
4605 typedef _CharT char_type
;
4606 typedef basic_string
<_CharT
> string_type
;
4609 messages_byname(const char* __s
, size_t __refs
= 0);
4617 _GLIBCXX_END_NAMESPACE
4619 // Include host and configuration specific messages functions.
4620 #include <bits/messages_members.h>
4622 _GLIBCXX_BEGIN_NAMESPACE(std
)
4624 // Subclause convenience interfaces, inlines.
4625 // NB: These are inline because, when used in a loop, some compilers
4626 // can hoist the body out of the loop; then it's just as fast as the
4627 // C is*() function.
4629 /// Convenience interface to ctype.is(ctype_base::space, __c).
4630 template<typename _CharT
>
4632 isspace(_CharT __c
, const locale
& __loc
)
4633 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::space
, __c
); }
4635 /// Convenience interface to ctype.is(ctype_base::print, __c).
4636 template<typename _CharT
>
4638 isprint(_CharT __c
, const locale
& __loc
)
4639 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::print
, __c
); }
4641 /// Convenience interface to ctype.is(ctype_base::cntrl, __c).
4642 template<typename _CharT
>
4644 iscntrl(_CharT __c
, const locale
& __loc
)
4645 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::cntrl
, __c
); }
4647 /// Convenience interface to ctype.is(ctype_base::upper, __c).
4648 template<typename _CharT
>
4650 isupper(_CharT __c
, const locale
& __loc
)
4651 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::upper
, __c
); }
4653 /// Convenience interface to ctype.is(ctype_base::lower, __c).
4654 template<typename _CharT
>
4656 islower(_CharT __c
, const locale
& __loc
)
4657 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::lower
, __c
); }
4659 /// Convenience interface to ctype.is(ctype_base::alpha, __c).
4660 template<typename _CharT
>
4662 isalpha(_CharT __c
, const locale
& __loc
)
4663 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alpha
, __c
); }
4665 /// Convenience interface to ctype.is(ctype_base::digit, __c).
4666 template<typename _CharT
>
4668 isdigit(_CharT __c
, const locale
& __loc
)
4669 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::digit
, __c
); }
4671 /// Convenience interface to ctype.is(ctype_base::punct, __c).
4672 template<typename _CharT
>
4674 ispunct(_CharT __c
, const locale
& __loc
)
4675 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::punct
, __c
); }
4677 /// Convenience interface to ctype.is(ctype_base::xdigit, __c).
4678 template<typename _CharT
>
4680 isxdigit(_CharT __c
, const locale
& __loc
)
4681 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::xdigit
, __c
); }
4683 /// Convenience interface to ctype.is(ctype_base::alnum, __c).
4684 template<typename _CharT
>
4686 isalnum(_CharT __c
, const locale
& __loc
)
4687 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alnum
, __c
); }
4689 /// Convenience interface to ctype.is(ctype_base::graph, __c).
4690 template<typename _CharT
>
4692 isgraph(_CharT __c
, const locale
& __loc
)
4693 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::graph
, __c
); }
4695 /// Convenience interface to ctype.toupper(__c).
4696 template<typename _CharT
>
4698 toupper(_CharT __c
, const locale
& __loc
)
4699 { return use_facet
<ctype
<_CharT
> >(__loc
).toupper(__c
); }
4701 /// Convenience interface to ctype.tolower(__c).
4702 template<typename _CharT
>
4704 tolower(_CharT __c
, const locale
& __loc
)
4705 { return use_facet
<ctype
<_CharT
> >(__loc
).tolower(__c
); }
4707 _GLIBCXX_END_NAMESPACE