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
49 #include <bits/ctype_base.h>
51 #include <bits/ios_base.h> // For ios_base, ios_base::iostate
53 #include <bits/cpp_type_traits.h>
55 _GLIBCXX_BEGIN_NAMESPACE(std
)
57 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
58 #ifdef _GLIBCXX_USE_WCHAR_T
59 # define _GLIBCXX_NUM_FACETS 28
61 # define _GLIBCXX_NUM_FACETS 14
64 // Convert string to numeric value of type _Tv and store results.
65 // NB: This is specialized for all required types, there is no
66 // generic definition.
67 template<typename _Tv
>
69 __convert_to_v(const char* __in
, _Tv
& __out
, ios_base::iostate
& __err
,
70 const __c_locale
& __cloc
);
72 // Explicit specializations for required types.
75 __convert_to_v(const char*, float&, ios_base::iostate
&,
80 __convert_to_v(const char*, double&, ios_base::iostate
&,
85 __convert_to_v(const char*, long double&, ios_base::iostate
&,
88 // NB: __pad is a struct, rather than a function, so it can be
89 // partially-specialized.
90 template<typename _CharT
, typename _Traits
>
94 _S_pad(ios_base
& __io
, _CharT __fill
, _CharT
* __news
,
95 const _CharT
* __olds
, const streamsize __newlen
,
96 const streamsize __oldlen
, const bool __num
);
99 // Used by both numeric and monetary facets.
100 // Inserts "group separator" characters into an array of characters.
101 // It's recursive, one iteration per group. It moves the characters
102 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
103 // only with __glen != 0.
104 template<typename _CharT
>
106 __add_grouping(_CharT
* __s
, _CharT __sep
,
107 const char* __gbeg
, size_t __gsize
,
108 const _CharT
* __first
, const _CharT
* __last
);
110 // This template permits specializing facet output code for
111 // ostreambuf_iterator. For ostreambuf_iterator, sputn is
112 // significantly more efficient than incrementing iterators.
113 template<typename _CharT
>
115 ostreambuf_iterator
<_CharT
>
116 __write(ostreambuf_iterator
<_CharT
> __s
, const _CharT
* __ws
, int __len
)
118 __s
._M_put(__ws
, __len
);
122 // This is the unspecialized form of the template.
123 template<typename _CharT
, typename _OutIter
>
126 __write(_OutIter __s
, const _CharT
* __ws
, int __len
)
128 for (int __j
= 0; __j
< __len
; __j
++, ++__s
)
134 // 22.2.1.1 Template class ctype
135 // Include host and configuration specific ctype enums for ctype_base.
137 // Common base for ctype<_CharT>.
139 * @brief Common base for ctype facet
141 * This template class provides implementations of the public functions
142 * that forward to the protected virtual functions.
144 * This template also provides abtract stubs for the protected virtual
147 template<typename _CharT
>
148 class __ctype_abstract_base
: public locale::facet
, public ctype_base
152 /// Typedef for the template parameter
153 typedef _CharT char_type
;
156 * @brief Test char_type classification.
158 * This function finds a mask M for @a c and compares it to mask @a m.
159 * It does so by returning the value of ctype<char_type>::do_is().
161 * @param c The char_type to compare the mask of.
162 * @param m The mask to compare against.
163 * @return (M & m) != 0.
166 is(mask __m
, char_type __c
) const
167 { return this->do_is(__m
, __c
); }
170 * @brief Return a mask array.
172 * This function finds the mask for each char_type in the range [lo,hi)
173 * and successively writes it to vec. vec must have as many elements
174 * as the char array. It does so by returning the value of
175 * ctype<char_type>::do_is().
177 * @param lo Pointer to start of range.
178 * @param hi Pointer to end of range.
179 * @param vec Pointer to an array of mask storage.
183 is(const char_type
*__lo
, const char_type
*__hi
, mask
*__vec
) const
184 { return this->do_is(__lo
, __hi
, __vec
); }
187 * @brief Find char_type matching a mask
189 * This function searches for and returns the first char_type c in
190 * [lo,hi) for which is(m,c) is true. It does so by returning
191 * ctype<char_type>::do_scan_is().
193 * @param m The mask to compare against.
194 * @param lo Pointer to start of range.
195 * @param hi Pointer to end of range.
196 * @return Pointer to matching char_type if found, else @a hi.
199 scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
200 { return this->do_scan_is(__m
, __lo
, __hi
); }
203 * @brief Find char_type not matching a mask
205 * This function searches for and returns the first char_type c in
206 * [lo,hi) for which is(m,c) is false. It does so by returning
207 * ctype<char_type>::do_scan_not().
209 * @param m The mask to compare against.
210 * @param lo Pointer to first char in range.
211 * @param hi Pointer to end of range.
212 * @return Pointer to non-matching char if found, else @a hi.
215 scan_not(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
216 { return this->do_scan_not(__m
, __lo
, __hi
); }
219 * @brief Convert to uppercase.
221 * This function converts the argument to uppercase if possible.
222 * If not possible (for example, '2'), returns the argument. It does
223 * so by returning ctype<char_type>::do_toupper().
225 * @param c The char_type to convert.
226 * @return The uppercase char_type if convertible, else @a c.
229 toupper(char_type __c
) const
230 { return this->do_toupper(__c
); }
233 * @brief Convert array to uppercase.
235 * This function converts each char_type in the range [lo,hi) to
236 * uppercase if possible. Other elements remain untouched. It does so
237 * by returning ctype<char_type>:: do_toupper(lo, hi).
239 * @param lo Pointer to start of range.
240 * @param hi Pointer to end of range.
244 toupper(char_type
*__lo
, const char_type
* __hi
) const
245 { return this->do_toupper(__lo
, __hi
); }
248 * @brief Convert to lowercase.
250 * This function converts the argument to lowercase if possible. If
251 * not possible (for example, '2'), returns the argument. It does so
252 * by returning ctype<char_type>::do_tolower(c).
254 * @param c The char_type to convert.
255 * @return The lowercase char_type if convertible, else @a c.
258 tolower(char_type __c
) const
259 { return this->do_tolower(__c
); }
262 * @brief Convert array to lowercase.
264 * This function converts each char_type in the range [lo,hi) to
265 * lowercase if possible. Other elements remain untouched. It does so
266 * by returning ctype<char_type>:: do_tolower(lo, hi).
268 * @param lo Pointer to start of range.
269 * @param hi Pointer to end of range.
273 tolower(char_type
* __lo
, const char_type
* __hi
) const
274 { return this->do_tolower(__lo
, __hi
); }
277 * @brief Widen char to char_type
279 * This function converts the char argument to char_type using the
280 * simplest reasonable transformation. It does so by returning
281 * ctype<char_type>::do_widen(c).
283 * Note: this is not what you want for codepage conversions. See
286 * @param c The char to convert.
287 * @return The converted char_type.
290 widen(char __c
) const
291 { return this->do_widen(__c
); }
294 * @brief Widen array to char_type
296 * This function converts each char in the input to char_type using the
297 * simplest reasonable transformation. It does so by returning
298 * ctype<char_type>::do_widen(c).
300 * Note: this is not what you want for codepage conversions. See
303 * @param lo Pointer to start of range.
304 * @param hi Pointer to end of range.
305 * @param to Pointer to the destination array.
309 widen(const char* __lo
, const char* __hi
, char_type
* __to
) const
310 { return this->do_widen(__lo
, __hi
, __to
); }
313 * @brief Narrow char_type to char
315 * This function converts the char_type to char using the simplest
316 * reasonable transformation. If the conversion fails, dfault is
317 * returned instead. It does so by returning
318 * ctype<char_type>::do_narrow(c).
320 * Note: this is not what you want for codepage conversions. See
323 * @param c The char_type to convert.
324 * @param dfault Char to return if conversion fails.
325 * @return The converted char.
328 narrow(char_type __c
, char __dfault
) const
329 { return this->do_narrow(__c
, __dfault
); }
332 * @brief Narrow array to char array
334 * This function converts each char_type in the input to char using the
335 * simplest reasonable transformation and writes the results to the
336 * destination array. For any char_type in the input that cannot be
337 * converted, @a dfault is used instead. It does so by returning
338 * ctype<char_type>::do_narrow(lo, hi, dfault, to).
340 * Note: this is not what you want for codepage conversions. See
343 * @param lo Pointer to start of range.
344 * @param hi Pointer to end of range.
345 * @param dfault Char to use if conversion fails.
346 * @param to Pointer to the destination array.
350 narrow(const char_type
* __lo
, const char_type
* __hi
,
351 char __dfault
, char *__to
) const
352 { return this->do_narrow(__lo
, __hi
, __dfault
, __to
); }
356 __ctype_abstract_base(size_t __refs
= 0): facet(__refs
) { }
359 ~__ctype_abstract_base() { }
362 * @brief Test char_type classification.
364 * This function finds a mask M for @a c and compares it to mask @a m.
366 * do_is() is a hook for a derived facet to change the behavior of
367 * classifying. do_is() must always return the same result for the
370 * @param c The char_type to find the mask of.
371 * @param m The mask to compare against.
372 * @return (M & m) != 0.
375 do_is(mask __m
, char_type __c
) const = 0;
378 * @brief Return a mask array.
380 * This function finds the mask for each char_type in the range [lo,hi)
381 * and successively writes it to vec. vec must have as many elements
384 * do_is() is a hook for a derived facet to change the behavior of
385 * classifying. do_is() must always return the same result for the
388 * @param lo Pointer to start of range.
389 * @param hi Pointer to end of range.
390 * @param vec Pointer to an array of mask storage.
393 virtual const char_type
*
394 do_is(const char_type
* __lo
, const char_type
* __hi
,
395 mask
* __vec
) const = 0;
398 * @brief Find char_type matching mask
400 * This function searches for and returns the first char_type c in
401 * [lo,hi) for which is(m,c) is true.
403 * do_scan_is() is a hook for a derived facet to change the behavior of
404 * match searching. do_is() must always return the same result for the
407 * @param m The mask to compare against.
408 * @param lo Pointer to start of range.
409 * @param hi Pointer to end of range.
410 * @return Pointer to a matching char_type if found, else @a hi.
412 virtual const char_type
*
413 do_scan_is(mask __m
, const char_type
* __lo
,
414 const char_type
* __hi
) const = 0;
417 * @brief Find char_type not matching mask
419 * This function searches for and returns a pointer to the first
420 * char_type c of [lo,hi) for which is(m,c) is false.
422 * do_scan_is() is a hook for a derived facet to change the behavior of
423 * match searching. do_is() must always return the same result for the
426 * @param m The mask to compare against.
427 * @param lo Pointer to start of range.
428 * @param hi Pointer to end of range.
429 * @return Pointer to a non-matching char_type if found, else @a hi.
431 virtual const char_type
*
432 do_scan_not(mask __m
, const char_type
* __lo
,
433 const char_type
* __hi
) const = 0;
436 * @brief Convert to uppercase.
438 * This virtual function converts the char_type argument to uppercase
439 * if possible. If not possible (for example, '2'), returns the
442 * do_toupper() is a hook for a derived facet to change the behavior of
443 * uppercasing. do_toupper() must always return the same result for
446 * @param c The char_type to convert.
447 * @return The uppercase char_type if convertible, else @a c.
450 do_toupper(char_type
) const = 0;
453 * @brief Convert array to uppercase.
455 * This virtual function converts each char_type in the range [lo,hi)
456 * to uppercase if possible. Other elements remain untouched.
458 * do_toupper() is a hook for a derived facet to change the behavior of
459 * uppercasing. do_toupper() must always return the same result for
462 * @param lo Pointer to start of range.
463 * @param hi Pointer to end of range.
466 virtual const char_type
*
467 do_toupper(char_type
* __lo
, const char_type
* __hi
) const = 0;
470 * @brief Convert to lowercase.
472 * This virtual function converts the argument to lowercase if
473 * possible. If not possible (for example, '2'), returns the argument.
475 * do_tolower() is a hook for a derived facet to change the behavior of
476 * lowercasing. do_tolower() must always return the same result for
479 * @param c The char_type to convert.
480 * @return The lowercase char_type if convertible, else @a c.
483 do_tolower(char_type
) const = 0;
486 * @brief Convert array to lowercase.
488 * This virtual function converts each char_type in the range [lo,hi)
489 * to lowercase if possible. Other elements remain untouched.
491 * do_tolower() is a hook for a derived facet to change the behavior of
492 * lowercasing. do_tolower() must always return the same result for
495 * @param lo Pointer to start of range.
496 * @param hi Pointer to end of range.
499 virtual const char_type
*
500 do_tolower(char_type
* __lo
, const char_type
* __hi
) const = 0;
505 * This virtual function converts the char to char_type using the
506 * simplest reasonable transformation.
508 * do_widen() is a hook for a derived facet to change the behavior of
509 * widening. do_widen() must always return the same result for the
512 * Note: this is not what you want for codepage conversions. See
515 * @param c The char to convert.
516 * @return The converted char_type
519 do_widen(char) const = 0;
522 * @brief Widen char array
524 * This function converts each char in the input to char_type using the
525 * simplest reasonable transformation.
527 * do_widen() is a hook for a derived facet to change the behavior of
528 * widening. do_widen() must always return the same result for the
531 * Note: this is not what you want for codepage conversions. See
534 * @param lo Pointer to start range.
535 * @param hi Pointer to end of range.
536 * @param to Pointer to the destination array.
540 do_widen(const char* __lo
, const char* __hi
,
541 char_type
* __dest
) const = 0;
544 * @brief Narrow char_type to char
546 * This virtual function converts the argument to char using the
547 * simplest reasonable transformation. If the conversion fails, dfault
548 * is returned instead.
550 * do_narrow() is a hook for a derived facet to change the behavior of
551 * narrowing. do_narrow() must always return the same result for the
554 * Note: this is not what you want for codepage conversions. See
557 * @param c The char_type to convert.
558 * @param dfault Char to return if conversion fails.
559 * @return The converted char.
562 do_narrow(char_type
, char __dfault
) const = 0;
565 * @brief Narrow char_type array to char
567 * This virtual function converts each char_type in the range [lo,hi) to
568 * char using the simplest reasonable transformation and writes the
569 * results to the destination array. For any element in the input that
570 * cannot be converted, @a dfault is used instead.
572 * do_narrow() is a hook for a derived facet to change the behavior of
573 * narrowing. do_narrow() must always return the same result for the
576 * Note: this is not what you want for codepage conversions. See
579 * @param lo Pointer to start of range.
580 * @param hi Pointer to end of range.
581 * @param dfault Char to use if conversion fails.
582 * @param to Pointer to the destination array.
585 virtual const char_type
*
586 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
587 char __dfault
, char* __dest
) const = 0;
590 // NB: Generic, mostly useless implementation.
592 * @brief Template ctype facet
594 * This template class defines classification and conversion functions for
595 * character sets. It wraps <cctype> functionality. Ctype gets used by
596 * streams for many I/O operations.
598 * This template provides the protected virtual functions the developer
599 * will have to replace in a derived class or specialization to make a
600 * working facet. The public functions that access them are defined in
601 * __ctype_abstract_base, to allow for implementation flexibility. See
602 * ctype<wchar_t> for an example. The functions are documented in
603 * __ctype_abstract_base.
605 * Note: implementations are provided for all the protected virtual
606 * functions, but will likely not be useful.
608 template<typename _CharT
>
609 class ctype
: public __ctype_abstract_base
<_CharT
>
613 typedef _CharT char_type
;
614 typedef typename __ctype_abstract_base
<_CharT
>::mask mask
;
616 /// The facet id for ctype<char_type>
617 static locale::id id
;
620 ctype(size_t __refs
= 0) : __ctype_abstract_base
<_CharT
>(__refs
) { }
627 do_is(mask __m
, char_type __c
) const;
629 virtual const char_type
*
630 do_is(const char_type
* __lo
, const char_type
* __hi
, mask
* __vec
) const;
632 virtual const char_type
*
633 do_scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const;
635 virtual const char_type
*
636 do_scan_not(mask __m
, const char_type
* __lo
,
637 const char_type
* __hi
) const;
640 do_toupper(char_type __c
) const;
642 virtual const char_type
*
643 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
646 do_tolower(char_type __c
) const;
648 virtual const char_type
*
649 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
652 do_widen(char __c
) const;
655 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const;
658 do_narrow(char_type
, char __dfault
) const;
660 virtual const char_type
*
661 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
662 char __dfault
, char* __dest
) const;
665 template<typename _CharT
>
666 locale::id ctype
<_CharT
>::id
;
668 // 22.2.1.3 ctype<char> specialization.
670 * @brief The ctype<char> specialization.
672 * This class defines classification and conversion functions for
673 * the char type. It gets used by char streams for many I/O
674 * operations. The char specialization provides a number of
675 * optimizations as well.
678 class ctype
<char> : public locale::facet
, public ctype_base
682 /// Typedef for the template parameter char.
683 typedef char char_type
;
687 __c_locale _M_c_locale_ctype
;
689 __to_type _M_toupper
;
690 __to_type _M_tolower
;
691 const mask
* _M_table
;
692 mutable char _M_widen_ok
;
693 mutable char _M_widen
[1 + static_cast<unsigned char>(-1)];
694 mutable char _M_narrow
[1 + static_cast<unsigned char>(-1)];
695 mutable char _M_narrow_ok
; // 0 uninitialized, 1 init,
696 // 2 memcpy can't be used
699 /// The facet id for ctype<char>
700 static locale::id id
;
701 /// The size of the mask table. It is SCHAR_MAX + 1.
702 static const size_t table_size
= 1 + static_cast<unsigned char>(-1);
705 * @brief Constructor performs initialization.
707 * This is the constructor provided by the standard.
709 * @param table If non-zero, table is used as the per-char mask.
710 * Else classic_table() is used.
711 * @param del If true, passes ownership of table to this facet.
712 * @param refs Passed to the base facet class.
715 ctype(const mask
* __table
= 0, bool __del
= false, size_t __refs
= 0);
718 * @brief Constructor performs static initialization.
720 * This constructor is used to construct the initial C locale facet.
722 * @param cloc Handle to C locale data.
723 * @param table If non-zero, table is used as the per-char mask.
724 * @param del If true, passes ownership of table to this facet.
725 * @param refs Passed to the base facet class.
728 ctype(__c_locale __cloc
, const mask
* __table
= 0, bool __del
= false,
732 * @brief Test char classification.
734 * This function compares the mask table[c] to @a m.
736 * @param c The char to compare the mask of.
737 * @param m The mask to compare against.
738 * @return True if m & table[c] is true, false otherwise.
741 is(mask __m
, char __c
) const;
744 * @brief Return a mask array.
746 * This function finds the mask for each char in the range [lo, hi) and
747 * successively writes it to vec. vec must have as many elements as
750 * @param lo Pointer to start of range.
751 * @param hi Pointer to end of range.
752 * @param vec Pointer to an array of mask storage.
756 is(const char* __lo
, const char* __hi
, mask
* __vec
) const;
759 * @brief Find char matching a mask
761 * This function searches for and returns the first char in [lo,hi) for
762 * which is(m,char) is true.
764 * @param m The mask to compare against.
765 * @param lo Pointer to start of range.
766 * @param hi Pointer to end of range.
767 * @return Pointer to a matching char if found, else @a hi.
770 scan_is(mask __m
, const char* __lo
, const char* __hi
) const;
773 * @brief Find char not matching a mask
775 * This function searches for and returns a pointer to the first char
776 * in [lo,hi) for which is(m,char) is false.
778 * @param m The mask to compare against.
779 * @param lo Pointer to start of range.
780 * @param hi Pointer to end of range.
781 * @return Pointer to a non-matching char if found, else @a hi.
784 scan_not(mask __m
, const char* __lo
, const char* __hi
) const;
787 * @brief Convert to uppercase.
789 * This function converts the char argument to uppercase if possible.
790 * If not possible (for example, '2'), returns the argument.
792 * toupper() acts as if it returns ctype<char>::do_toupper(c).
793 * do_toupper() must always return the same result for the same input.
795 * @param c The char to convert.
796 * @return The uppercase char if convertible, else @a c.
799 toupper(char_type __c
) const
800 { return this->do_toupper(__c
); }
803 * @brief Convert array to uppercase.
805 * This function converts each char in the range [lo,hi) to uppercase
806 * if possible. Other chars remain untouched.
808 * toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi).
809 * do_toupper() must always return the same result for the same input.
811 * @param lo Pointer to first char in range.
812 * @param hi Pointer to end of range.
816 toupper(char_type
*__lo
, const char_type
* __hi
) const
817 { return this->do_toupper(__lo
, __hi
); }
820 * @brief Convert to lowercase.
822 * This function converts the char argument to lowercase if possible.
823 * If not possible (for example, '2'), returns the argument.
825 * tolower() acts as if it returns ctype<char>::do_tolower(c).
826 * do_tolower() must always return the same result for the same input.
828 * @param c The char to convert.
829 * @return The lowercase char if convertible, else @a c.
832 tolower(char_type __c
) const
833 { return this->do_tolower(__c
); }
836 * @brief Convert array to lowercase.
838 * This function converts each char in the range [lo,hi) to lowercase
839 * if possible. Other chars remain untouched.
841 * tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi).
842 * do_tolower() must always return the same result for the same input.
844 * @param lo Pointer to first char in range.
845 * @param hi Pointer to end of range.
849 tolower(char_type
* __lo
, const char_type
* __hi
) const
850 { return this->do_tolower(__lo
, __hi
); }
855 * This function converts the char to char_type using the simplest
856 * reasonable transformation. For an underived ctype<char> facet, the
857 * argument will be returned unchanged.
859 * This function works as if it returns ctype<char>::do_widen(c).
860 * do_widen() must always return the same result for the same input.
862 * Note: this is not what you want for codepage conversions. See
865 * @param c The char to convert.
866 * @return The converted character.
869 widen(char __c
) const
872 return _M_widen
[static_cast<unsigned char>(__c
)];
873 this->_M_widen_init();
874 return this->do_widen(__c
);
878 * @brief Widen char array
880 * This function converts each char in the input to char using the
881 * simplest reasonable transformation. For an underived ctype<char>
882 * facet, the argument will be copied unchanged.
884 * This function works as if it returns ctype<char>::do_widen(c).
885 * do_widen() must always return the same result for the same input.
887 * Note: this is not what you want for codepage conversions. See
890 * @param lo Pointer to first char in range.
891 * @param hi Pointer to end of range.
892 * @param to Pointer to the destination array.
896 widen(const char* __lo
, const char* __hi
, char_type
* __to
) const
898 if (_M_widen_ok
== 1)
900 memcpy(__to
, __lo
, __hi
- __lo
);
905 return this->do_widen(__lo
, __hi
, __to
);
911 * This function converts the char to char using the simplest
912 * reasonable transformation. If the conversion fails, dfault is
913 * returned instead. For an underived ctype<char> facet, @a c
914 * will be returned unchanged.
916 * This function works as if it returns ctype<char>::do_narrow(c).
917 * do_narrow() must always return the same result for the same input.
919 * Note: this is not what you want for codepage conversions. See
922 * @param c The char to convert.
923 * @param dfault Char to return if conversion fails.
924 * @return The converted character.
927 narrow(char_type __c
, char __dfault
) const
929 if (_M_narrow
[static_cast<unsigned char>(__c
)])
930 return _M_narrow
[static_cast<unsigned char>(__c
)];
931 const char __t
= do_narrow(__c
, __dfault
);
933 _M_narrow
[static_cast<unsigned char>(__c
)] = __t
;
938 * @brief Narrow char array
940 * This function converts each char in the input to char using the
941 * simplest reasonable transformation and writes the results to the
942 * destination array. For any char in the input that cannot be
943 * converted, @a dfault is used instead. For an underived ctype<char>
944 * facet, the argument will be copied unchanged.
946 * This function works as if it returns ctype<char>::do_narrow(lo, hi,
947 * dfault, to). do_narrow() must always return the same result for the
950 * Note: this is not what you want for codepage conversions. See
953 * @param lo Pointer to start of range.
954 * @param hi Pointer to end of range.
955 * @param dfault Char to use if conversion fails.
956 * @param to Pointer to the destination array.
960 narrow(const char_type
* __lo
, const char_type
* __hi
,
961 char __dfault
, char *__to
) const
963 if (__builtin_expect(_M_narrow_ok
== 1, true))
965 memcpy(__to
, __lo
, __hi
- __lo
);
970 return this->do_narrow(__lo
, __hi
, __dfault
, __to
);
974 /// Returns a pointer to the mask table provided to the constructor, or
975 /// the default from classic_table() if none was provided.
977 table() const throw()
980 /// Returns a pointer to the C locale mask table.
982 classic_table() throw();
987 * This function deletes table() if @a del was true in the
994 * @brief Convert to uppercase.
996 * This virtual function converts the char argument to uppercase if
997 * possible. If not possible (for example, '2'), returns the argument.
999 * do_toupper() is a hook for a derived facet to change the behavior of
1000 * uppercasing. do_toupper() must always return the same result for
1003 * @param c The char to convert.
1004 * @return The uppercase char if convertible, else @a c.
1007 do_toupper(char_type
) const;
1010 * @brief Convert array to uppercase.
1012 * This virtual function converts each char in the range [lo,hi) to
1013 * uppercase if possible. Other chars remain untouched.
1015 * do_toupper() is a hook for a derived facet to change the behavior of
1016 * uppercasing. do_toupper() must always return the same result for
1019 * @param lo Pointer to start of range.
1020 * @param hi Pointer to end of range.
1023 virtual const char_type
*
1024 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
1027 * @brief Convert to lowercase.
1029 * This virtual function converts the char argument to lowercase if
1030 * possible. If not possible (for example, '2'), returns the argument.
1032 * do_tolower() is a hook for a derived facet to change the behavior of
1033 * lowercasing. do_tolower() must always return the same result for
1036 * @param c The char to convert.
1037 * @return The lowercase char if convertible, else @a c.
1040 do_tolower(char_type
) const;
1043 * @brief Convert array to lowercase.
1045 * This virtual function converts each char in the range [lo,hi) to
1046 * lowercase if possible. Other chars remain untouched.
1048 * do_tolower() is a hook for a derived facet to change the behavior of
1049 * lowercasing. do_tolower() must always return the same result for
1052 * @param lo Pointer to first char in range.
1053 * @param hi Pointer to end of range.
1056 virtual const char_type
*
1057 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
1062 * This virtual function converts the char to char using the simplest
1063 * reasonable transformation. For an underived ctype<char> facet, the
1064 * argument will be returned unchanged.
1066 * do_widen() is a hook for a derived facet to change the behavior of
1067 * widening. do_widen() must always return the same result for the
1070 * Note: this is not what you want for codepage conversions. See
1073 * @param c The char to convert.
1074 * @return The converted character.
1077 do_widen(char __c
) const
1081 * @brief Widen char array
1083 * This function converts each char in the range [lo,hi) to char using
1084 * the simplest reasonable transformation. For an underived
1085 * ctype<char> facet, the argument will be copied unchanged.
1087 * do_widen() is a hook for a derived facet to change the behavior of
1088 * widening. do_widen() must always return the same result for the
1091 * Note: this is not what you want for codepage conversions. See
1094 * @param lo Pointer to start of range.
1095 * @param hi Pointer to end of range.
1096 * @param to Pointer to the destination array.
1100 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const
1102 memcpy(__dest
, __lo
, __hi
- __lo
);
1107 * @brief Narrow char
1109 * This virtual function converts the char to char using the simplest
1110 * reasonable transformation. If the conversion fails, dfault is
1111 * returned instead. For an underived ctype<char> facet, @a c will be
1112 * returned unchanged.
1114 * do_narrow() is a hook for a derived facet to change the behavior of
1115 * narrowing. do_narrow() must always return the same result for the
1118 * Note: this is not what you want for codepage conversions. See
1121 * @param c The char to convert.
1122 * @param dfault Char to return if conversion fails.
1123 * @return The converted char.
1126 do_narrow(char_type __c
, char) const
1130 * @brief Narrow char array to char array
1132 * This virtual function converts each char in the range [lo,hi) to
1133 * char using the simplest reasonable transformation and writes the
1134 * results to the destination array. For any char in the input that
1135 * cannot be converted, @a dfault is used instead. For an underived
1136 * ctype<char> facet, the argument will be copied unchanged.
1138 * do_narrow() is a hook for a derived facet to change the behavior of
1139 * narrowing. do_narrow() must always return the same result for the
1142 * Note: this is not what you want for codepage conversions. See
1145 * @param lo Pointer to start of range.
1146 * @param hi Pointer to end of range.
1147 * @param dfault Char to use if conversion fails.
1148 * @param to Pointer to the destination array.
1151 virtual const char_type
*
1152 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
1153 char, char* __dest
) const
1155 memcpy(__dest
, __lo
, __hi
- __lo
);
1161 void _M_widen_init() const
1163 char __tmp
[sizeof(_M_widen
)];
1164 for (size_t __i
= 0; __i
< sizeof(_M_widen
); ++__i
)
1166 do_widen(__tmp
, __tmp
+ sizeof(__tmp
), _M_widen
);
1169 // Set _M_widen_ok to 2 if memcpy can't be used.
1170 if (memcmp(__tmp
, _M_widen
, sizeof(_M_widen
)))
1174 // Fill in the narrowing cache and flag whether all values are
1175 // valid or not. _M_narrow_ok is set to 2 if memcpy can't
1177 void _M_narrow_init() const
1179 char __tmp
[sizeof(_M_narrow
)];
1180 for (size_t __i
= 0; __i
< sizeof(_M_narrow
); ++__i
)
1182 do_narrow(__tmp
, __tmp
+ sizeof(__tmp
), 0, _M_narrow
);
1185 if (memcmp(__tmp
, _M_narrow
, sizeof(_M_narrow
)))
1189 // Deal with the special case of zero: renarrow with a
1190 // different default and compare.
1192 do_narrow(__tmp
, __tmp
+ 1, 1, &__c
);
1201 use_facet
<ctype
<char> >(const locale
& __loc
);
1203 #ifdef _GLIBCXX_USE_WCHAR_T
1204 // 22.2.1.3 ctype<wchar_t> specialization
1206 * @brief The ctype<wchar_t> specialization.
1208 * This class defines classification and conversion functions for the
1209 * wchar_t type. It gets used by wchar_t streams for many I/O operations.
1210 * The wchar_t specialization provides a number of optimizations as well.
1212 * ctype<wchar_t> inherits its public methods from
1213 * __ctype_abstract_base<wchar_t>.
1216 class ctype
<wchar_t> : public __ctype_abstract_base
<wchar_t>
1220 /// Typedef for the template parameter wchar_t.
1221 typedef wchar_t char_type
;
1222 typedef wctype_t __wmask_type
;
1225 __c_locale _M_c_locale_ctype
;
1227 // Pre-computed narrowed and widened chars.
1229 char _M_narrow
[128];
1230 wint_t _M_widen
[1 + static_cast<unsigned char>(-1)];
1232 // Pre-computed elements for do_is.
1234 __wmask_type _M_wmask
[16];
1238 /// The facet id for ctype<wchar_t>
1239 static locale::id id
;
1242 * @brief Constructor performs initialization.
1244 * This is the constructor provided by the standard.
1246 * @param refs Passed to the base facet class.
1249 ctype(size_t __refs
= 0);
1252 * @brief Constructor performs static initialization.
1254 * This constructor is used to construct the initial C locale facet.
1256 * @param cloc Handle to C locale data.
1257 * @param refs Passed to the base facet class.
1260 ctype(__c_locale __cloc
, size_t __refs
= 0);
1264 _M_convert_to_wmask(const mask __m
) const;
1271 * @brief Test wchar_t classification.
1273 * This function finds a mask M for @a c and compares it to mask @a m.
1275 * do_is() is a hook for a derived facet to change the behavior of
1276 * classifying. do_is() must always return the same result for the
1279 * @param c The wchar_t to find the mask of.
1280 * @param m The mask to compare against.
1281 * @return (M & m) != 0.
1284 do_is(mask __m
, char_type __c
) const;
1287 * @brief Return a mask array.
1289 * This function finds the mask for each wchar_t in the range [lo,hi)
1290 * and successively writes it to vec. vec must have as many elements
1293 * do_is() is a hook for a derived facet to change the behavior of
1294 * classifying. do_is() must always return the same result for the
1297 * @param lo Pointer to start of range.
1298 * @param hi Pointer to end of range.
1299 * @param vec Pointer to an array of mask storage.
1302 virtual const char_type
*
1303 do_is(const char_type
* __lo
, const char_type
* __hi
, mask
* __vec
) const;
1306 * @brief Find wchar_t matching mask
1308 * This function searches for and returns the first wchar_t c in
1309 * [lo,hi) for which is(m,c) is true.
1311 * do_scan_is() is a hook for a derived facet to change the behavior of
1312 * match searching. do_is() must always return the same result for the
1315 * @param m The mask to compare against.
1316 * @param lo Pointer to start of range.
1317 * @param hi Pointer to end of range.
1318 * @return Pointer to a matching wchar_t if found, else @a hi.
1320 virtual const char_type
*
1321 do_scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const;
1324 * @brief Find wchar_t not matching mask
1326 * This function searches for and returns a pointer to the first
1327 * wchar_t c of [lo,hi) for which is(m,c) is false.
1329 * do_scan_is() is a hook for a derived facet to change the behavior of
1330 * match searching. do_is() must always return the same result for the
1333 * @param m The mask to compare against.
1334 * @param lo Pointer to start of range.
1335 * @param hi Pointer to end of range.
1336 * @return Pointer to a non-matching wchar_t if found, else @a hi.
1338 virtual const char_type
*
1339 do_scan_not(mask __m
, const char_type
* __lo
,
1340 const char_type
* __hi
) const;
1343 * @brief Convert to uppercase.
1345 * This virtual function converts the wchar_t argument to uppercase if
1346 * possible. If not possible (for example, '2'), returns the argument.
1348 * do_toupper() is a hook for a derived facet to change the behavior of
1349 * uppercasing. do_toupper() must always return the same result for
1352 * @param c The wchar_t to convert.
1353 * @return The uppercase wchar_t if convertible, else @a c.
1356 do_toupper(char_type
) const;
1359 * @brief Convert array to uppercase.
1361 * This virtual function converts each wchar_t in the range [lo,hi) to
1362 * uppercase if possible. Other elements remain untouched.
1364 * do_toupper() is a hook for a derived facet to change the behavior of
1365 * uppercasing. do_toupper() must always return the same result for
1368 * @param lo Pointer to start of range.
1369 * @param hi Pointer to end of range.
1372 virtual const char_type
*
1373 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
1376 * @brief Convert to lowercase.
1378 * This virtual function converts the argument to lowercase if
1379 * possible. If not possible (for example, '2'), returns the argument.
1381 * do_tolower() is a hook for a derived facet to change the behavior of
1382 * lowercasing. do_tolower() must always return the same result for
1385 * @param c The wchar_t to convert.
1386 * @return The lowercase wchar_t if convertible, else @a c.
1389 do_tolower(char_type
) const;
1392 * @brief Convert array to lowercase.
1394 * This virtual function converts each wchar_t in the range [lo,hi) to
1395 * lowercase if possible. Other elements remain untouched.
1397 * do_tolower() is a hook for a derived facet to change the behavior of
1398 * lowercasing. do_tolower() must always return the same result for
1401 * @param lo Pointer to start of range.
1402 * @param hi Pointer to end of range.
1405 virtual const char_type
*
1406 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
1409 * @brief Widen char to wchar_t
1411 * This virtual function converts the char to wchar_t using the
1412 * simplest reasonable transformation. For an underived ctype<wchar_t>
1413 * facet, the argument will be cast to wchar_t.
1415 * do_widen() is a hook for a derived facet to change the behavior of
1416 * widening. do_widen() must always return the same result for the
1419 * Note: this is not what you want for codepage conversions. See
1422 * @param c The char to convert.
1423 * @return The converted wchar_t.
1426 do_widen(char) const;
1429 * @brief Widen char array to wchar_t array
1431 * This function converts each char in the input to wchar_t using the
1432 * simplest reasonable transformation. For an underived ctype<wchar_t>
1433 * facet, the argument will be copied, casting each element to wchar_t.
1435 * do_widen() is a hook for a derived facet to change the behavior of
1436 * widening. do_widen() must always return the same result for the
1439 * Note: this is not what you want for codepage conversions. See
1442 * @param lo Pointer to start range.
1443 * @param hi Pointer to end of range.
1444 * @param to Pointer to the destination array.
1448 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const;
1451 * @brief Narrow wchar_t to char
1453 * This virtual function converts the argument to char using
1454 * the simplest reasonable transformation. If the conversion
1455 * fails, dfault is returned instead. For an underived
1456 * ctype<wchar_t> facet, @a c will be cast to char and
1459 * do_narrow() is a hook for a derived facet to change the
1460 * behavior of narrowing. do_narrow() must always return the
1461 * same result for the same input.
1463 * Note: this is not what you want for codepage conversions. See
1466 * @param c The wchar_t to convert.
1467 * @param dfault Char to return if conversion fails.
1468 * @return The converted char.
1471 do_narrow(char_type
, char __dfault
) const;
1474 * @brief Narrow wchar_t array to char array
1476 * This virtual function converts each wchar_t in the range [lo,hi) to
1477 * char using the simplest reasonable transformation and writes the
1478 * results to the destination array. For any wchar_t in the input that
1479 * cannot be converted, @a dfault is used instead. For an underived
1480 * ctype<wchar_t> facet, the argument will be copied, casting each
1483 * do_narrow() is a hook for a derived facet to change the behavior of
1484 * narrowing. do_narrow() must always return the same result for the
1487 * Note: this is not what you want for codepage conversions. See
1490 * @param lo Pointer to start of range.
1491 * @param hi Pointer to end of range.
1492 * @param dfault Char to use if conversion fails.
1493 * @param to Pointer to the destination array.
1496 virtual const char_type
*
1497 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
1498 char __dfault
, char* __dest
) const;
1500 // For use at construction time only.
1502 _M_initialize_ctype();
1506 const ctype
<wchar_t>&
1507 use_facet
<ctype
<wchar_t> >(const locale
& __loc
);
1508 #endif //_GLIBCXX_USE_WCHAR_T
1510 /// @brief class ctype_byname [22.2.1.2].
1511 template<typename _CharT
>
1512 class ctype_byname
: public ctype
<_CharT
>
1515 typedef typename ctype
<_CharT
>::mask mask
;
1518 ctype_byname(const char* __s
, size_t __refs
= 0);
1522 ~ctype_byname() { };
1525 /// 22.2.1.4 Class ctype_byname specializations.
1527 class ctype_byname
<char> : public ctype
<char>
1531 ctype_byname(const char* __s
, size_t __refs
= 0);
1538 #ifdef _GLIBCXX_USE_WCHAR_T
1540 class ctype_byname
<wchar_t> : public ctype
<wchar_t>
1544 ctype_byname(const char* __s
, size_t __refs
= 0);
1552 _GLIBCXX_END_NAMESPACE
1554 // Include host and configuration specific ctype inlines.
1555 #include <bits/ctype_inline.h>
1557 // 22.2.1.5 Template class codecvt
1558 #include <bits/codecvt.h>
1560 _GLIBCXX_BEGIN_NAMESPACE(std
)
1562 // 22.2.2 The numeric category.
1566 // NB: Code depends on the order of _S_atoms_out elements.
1567 // Below are the indices into _S_atoms_out.
1575 _S_odigits_end
= _S_odigits
+ 16,
1576 _S_oudigits
= _S_odigits_end
,
1577 _S_oudigits_end
= _S_oudigits
+ 16,
1578 _S_oe
= _S_odigits
+ 14, // For scientific notation, 'e'
1579 _S_oE
= _S_oudigits
+ 14, // For scientific notation, 'E'
1580 _S_oend
= _S_oudigits_end
1583 // A list of valid numeric literals for output. This array
1584 // contains chars that will be passed through the current locale's
1585 // ctype<_CharT>.widen() and then used to render numbers.
1586 // For the standard "C" locale, this is
1587 // "-+xX0123456789abcdef0123456789ABCDEF".
1588 static const char* _S_atoms_out
;
1590 // String literal of acceptable (narrow) input, for num_get.
1591 // "-+xX0123456789abcdefABCDEF"
1592 static const char* _S_atoms_in
;
1601 _S_ie
= _S_izero
+ 14,
1602 _S_iE
= _S_izero
+ 20,
1607 // Construct and return valid scanf format for floating point types.
1609 _S_format_float(const ios_base
& __io
, char* __fptr
, char __mod
);
1612 template<typename _CharT
>
1613 struct __numpunct_cache
: public locale::facet
1615 const char* _M_grouping
;
1616 size_t _M_grouping_size
;
1617 bool _M_use_grouping
;
1618 const _CharT
* _M_truename
;
1619 size_t _M_truename_size
;
1620 const _CharT
* _M_falsename
;
1621 size_t _M_falsename_size
;
1622 _CharT _M_decimal_point
;
1623 _CharT _M_thousands_sep
;
1625 // A list of valid numeric literals for output: in the standard
1626 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1627 // This array contains the chars after having been passed
1628 // through the current locale's ctype<_CharT>.widen().
1629 _CharT _M_atoms_out
[__num_base::_S_oend
];
1631 // A list of valid numeric literals for input: in the standard
1632 // "C" locale, this is "-+xX0123456789abcdefABCDEF"
1633 // This array contains the chars after having been passed
1634 // through the current locale's ctype<_CharT>.widen().
1635 _CharT _M_atoms_in
[__num_base::_S_iend
];
1639 __numpunct_cache(size_t __refs
= 0) : facet(__refs
),
1640 _M_grouping(NULL
), _M_grouping_size(0), _M_use_grouping(false),
1641 _M_truename(NULL
), _M_truename_size(0), _M_falsename(NULL
),
1642 _M_falsename_size(0), _M_decimal_point(_CharT()),
1643 _M_thousands_sep(_CharT()), _M_allocated(false)
1646 ~__numpunct_cache();
1649 _M_cache(const locale
& __loc
);
1653 operator=(const __numpunct_cache
&);
1656 __numpunct_cache(const __numpunct_cache
&);
1659 template<typename _CharT
>
1660 __numpunct_cache
<_CharT
>::~__numpunct_cache()
1664 delete [] _M_grouping
;
1665 delete [] _M_truename
;
1666 delete [] _M_falsename
;
1671 * @brief Numpunct facet.
1673 * This facet stores several pieces of information related to printing and
1674 * scanning numbers, such as the decimal point character. It takes a
1675 * template parameter specifying the char type. The numpunct facet is
1676 * used by streams for many I/O operations involving numbers.
1678 * The numpunct template uses protected virtual functions to provide the
1679 * actual results. The public accessors forward the call to the virtual
1680 * functions. These virtual functions are hooks for developers to
1681 * implement the behavior they require from a numpunct facet.
1683 template<typename _CharT
>
1684 class numpunct
: public locale::facet
1690 typedef _CharT char_type
;
1691 typedef basic_string
<_CharT
> string_type
;
1693 typedef __numpunct_cache
<_CharT
> __cache_type
;
1696 __cache_type
* _M_data
;
1699 /// Numpunct facet id.
1700 static locale::id id
;
1703 * @brief Numpunct constructor.
1705 * @param refs Refcount to pass to the base class.
1708 numpunct(size_t __refs
= 0) : facet(__refs
), _M_data(NULL
)
1709 { _M_initialize_numpunct(); }
1712 * @brief Internal constructor. Not for general use.
1714 * This is a constructor for use by the library itself to set up the
1715 * predefined locale facets.
1717 * @param cache __numpunct_cache object.
1718 * @param refs Refcount to pass to the base class.
1721 numpunct(__cache_type
* __cache
, size_t __refs
= 0)
1722 : facet(__refs
), _M_data(__cache
)
1723 { _M_initialize_numpunct(); }
1726 * @brief Internal constructor. Not for general use.
1728 * This is a constructor for use by the library itself to set up new
1731 * @param cloc The "C" locale.
1732 * @param refs Refcount to pass to the base class.
1735 numpunct(__c_locale __cloc
, size_t __refs
= 0)
1736 : facet(__refs
), _M_data(NULL
)
1737 { _M_initialize_numpunct(__cloc
); }
1740 * @brief Return decimal point character.
1742 * This function returns a char_type to use as a decimal point. It
1743 * does so by returning returning
1744 * numpunct<char_type>::do_decimal_point().
1746 * @return @a char_type representing a decimal point.
1749 decimal_point() const
1750 { return this->do_decimal_point(); }
1753 * @brief Return thousands separator character.
1755 * This function returns a char_type to use as a thousands
1756 * separator. It does so by returning returning
1757 * numpunct<char_type>::do_thousands_sep().
1759 * @return char_type representing a thousands separator.
1762 thousands_sep() const
1763 { return this->do_thousands_sep(); }
1766 * @brief Return grouping specification.
1768 * This function returns a string representing groupings for the
1769 * integer part of a number. Groupings indicate where thousands
1770 * separators should be inserted in the integer part of a number.
1772 * Each char in the return string is interpret as an integer
1773 * rather than a character. These numbers represent the number
1774 * of digits in a group. The first char in the string
1775 * represents the number of digits in the least significant
1776 * group. If a char is negative, it indicates an unlimited
1777 * number of digits for the group. If more chars from the
1778 * string are required to group a number, the last char is used
1781 * For example, if the grouping() returns "\003\002" and is
1782 * applied to the number 123456789, this corresponds to
1783 * 12,34,56,789. Note that if the string was "32", this would
1784 * put more than 50 digits into the least significant group if
1785 * the character set is ASCII.
1787 * The string is returned by calling
1788 * numpunct<char_type>::do_grouping().
1790 * @return string representing grouping specification.
1794 { return this->do_grouping(); }
1797 * @brief Return string representation of bool true.
1799 * This function returns a string_type containing the text
1800 * representation for true bool variables. It does so by calling
1801 * numpunct<char_type>::do_truename().
1803 * @return string_type representing printed form of true.
1807 { return this->do_truename(); }
1810 * @brief Return string representation of bool false.
1812 * This function returns a string_type containing the text
1813 * representation for false bool variables. It does so by calling
1814 * numpunct<char_type>::do_falsename().
1816 * @return string_type representing printed form of false.
1820 { return this->do_falsename(); }
1828 * @brief Return decimal point character.
1830 * Returns a char_type to use as a decimal point. This function is a
1831 * hook for derived classes to change the value returned.
1833 * @return @a char_type representing a decimal point.
1836 do_decimal_point() const
1837 { return _M_data
->_M_decimal_point
; }
1840 * @brief Return thousands separator character.
1842 * Returns a char_type to use as a thousands separator. This function
1843 * is a hook for derived classes to change the value returned.
1845 * @return @a char_type representing a thousands separator.
1848 do_thousands_sep() const
1849 { return _M_data
->_M_thousands_sep
; }
1852 * @brief Return grouping specification.
1854 * Returns a string representing groupings for the integer part of a
1855 * number. This function is a hook for derived classes to change the
1856 * value returned. @see grouping() for details.
1858 * @return String representing grouping specification.
1862 { return _M_data
->_M_grouping
; }
1865 * @brief Return string representation of bool true.
1867 * Returns a string_type containing the text representation for true
1868 * bool variables. This function is a hook for derived classes to
1869 * change the value returned.
1871 * @return string_type representing printed form of true.
1875 { return _M_data
->_M_truename
; }
1878 * @brief Return string representation of bool false.
1880 * Returns a string_type containing the text representation for false
1881 * bool variables. This function is a hook for derived classes to
1882 * change the value returned.
1884 * @return string_type representing printed form of false.
1887 do_falsename() const
1888 { return _M_data
->_M_falsename
; }
1890 // For use at construction time only.
1892 _M_initialize_numpunct(__c_locale __cloc
= NULL
);
1895 template<typename _CharT
>
1896 locale::id numpunct
<_CharT
>::id
;
1899 numpunct
<char>::~numpunct();
1903 numpunct
<char>::_M_initialize_numpunct(__c_locale __cloc
);
1905 #ifdef _GLIBCXX_USE_WCHAR_T
1907 numpunct
<wchar_t>::~numpunct();
1911 numpunct
<wchar_t>::_M_initialize_numpunct(__c_locale __cloc
);
1914 /// @brief class numpunct_byname [22.2.3.2].
1915 template<typename _CharT
>
1916 class numpunct_byname
: public numpunct
<_CharT
>
1919 typedef _CharT char_type
;
1920 typedef basic_string
<_CharT
> string_type
;
1923 numpunct_byname(const char* __s
, size_t __refs
= 0)
1924 : numpunct
<_CharT
>(__refs
)
1926 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
1929 this->_S_create_c_locale(__tmp
, __s
);
1930 this->_M_initialize_numpunct(__tmp
);
1931 this->_S_destroy_c_locale(__tmp
);
1937 ~numpunct_byname() { }
1940 _GLIBCXX_BEGIN_LDBL_NAMESPACE
1942 * @brief Facet for parsing number strings.
1944 * This facet encapsulates the code to parse and return a number
1945 * from a string. It is used by the istream numeric extraction
1948 * The num_get template uses protected virtual functions to provide the
1949 * actual results. The public accessors forward the call to the virtual
1950 * functions. These virtual functions are hooks for developers to
1951 * implement the behavior they require from the num_get facet.
1953 template<typename _CharT
, typename _InIter
>
1954 class num_get
: public locale::facet
1960 typedef _CharT char_type
;
1961 typedef _InIter iter_type
;
1964 /// Numpunct facet id.
1965 static locale::id id
;
1968 * @brief Constructor performs initialization.
1970 * This is the constructor provided by the standard.
1972 * @param refs Passed to the base facet class.
1975 num_get(size_t __refs
= 0) : facet(__refs
) { }
1978 * @brief Numeric parsing.
1980 * Parses the input stream into the bool @a v. It does so by calling
1981 * num_get::do_get().
1983 * If ios_base::boolalpha is set, attempts to read
1984 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
1985 * @a v to true or false if successful. Sets err to
1986 * ios_base::failbit if reading the string fails. Sets err to
1987 * ios_base::eofbit if the stream is emptied.
1989 * If ios_base::boolalpha is not set, proceeds as with reading a long,
1990 * except if the value is 1, sets @a v to true, if the value is 0, sets
1991 * @a v to false, and otherwise set err to ios_base::failbit.
1993 * @param in Start of input stream.
1994 * @param end End of input stream.
1995 * @param io Source of locale and flags.
1996 * @param err Error flags to set.
1997 * @param v Value to format and insert.
1998 * @return Iterator after reading.
2001 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2002 ios_base::iostate
& __err
, bool& __v
) const
2003 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2007 * @brief Numeric parsing.
2009 * Parses the input stream into the integral variable @a v. It does so
2010 * by calling num_get::do_get().
2012 * Parsing is affected by the flag settings in @a io.
2014 * The basic parse is affected by the value of io.flags() &
2015 * ios_base::basefield. If equal to ios_base::oct, parses like the
2016 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X
2017 * specifier. Else if basefield equal to 0, parses like the %i
2018 * specifier. Otherwise, parses like %d for signed and %u for unsigned
2019 * types. The matching type length modifier is also used.
2021 * Digit grouping is intrepreted according to numpunct::grouping() and
2022 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2023 * consistent, sets err to ios_base::failbit.
2025 * If parsing the string yields a valid value for @a v, @a v is set.
2026 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2027 * Sets err to ios_base::eofbit if the stream is emptied.
2029 * @param in Start of input stream.
2030 * @param end End of input stream.
2031 * @param io Source of locale and flags.
2032 * @param err Error flags to set.
2033 * @param v Value to format and insert.
2034 * @return Iterator after reading.
2037 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2038 ios_base::iostate
& __err
, long& __v
) const
2039 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2042 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2043 ios_base::iostate
& __err
, unsigned short& __v
) const
2044 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2047 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2048 ios_base::iostate
& __err
, unsigned int& __v
) const
2049 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2052 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2053 ios_base::iostate
& __err
, unsigned long& __v
) const
2054 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2056 #ifdef _GLIBCXX_USE_LONG_LONG
2058 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2059 ios_base::iostate
& __err
, long long& __v
) const
2060 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2063 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2064 ios_base::iostate
& __err
, unsigned long long& __v
) const
2065 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2071 * @brief Numeric parsing.
2073 * Parses the input stream into the integral variable @a v. It does so
2074 * by calling num_get::do_get().
2076 * The input characters are parsed like the scanf %g specifier. The
2077 * matching type length modifier is also used.
2079 * The decimal point character used is numpunct::decimal_point().
2080 * Digit grouping is intrepreted according to numpunct::grouping() and
2081 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2082 * consistent, sets err to ios_base::failbit.
2084 * If parsing the string yields a valid value for @a v, @a v is set.
2085 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2086 * Sets err to ios_base::eofbit if the stream is emptied.
2088 * @param in Start of input stream.
2089 * @param end End of input stream.
2090 * @param io Source of locale and flags.
2091 * @param err Error flags to set.
2092 * @param v Value to format and insert.
2093 * @return Iterator after reading.
2096 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2097 ios_base::iostate
& __err
, float& __v
) const
2098 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2101 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2102 ios_base::iostate
& __err
, double& __v
) const
2103 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2106 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2107 ios_base::iostate
& __err
, long double& __v
) const
2108 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2112 * @brief Numeric parsing.
2114 * Parses the input stream into the pointer variable @a v. It does so
2115 * by calling num_get::do_get().
2117 * The input characters are parsed like the scanf %p specifier.
2119 * Digit grouping is intrepreted according to numpunct::grouping() and
2120 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2121 * consistent, sets err to ios_base::failbit.
2123 * Note that the digit grouping effect for pointers is a bit ambiguous
2124 * in the standard and shouldn't be relied on. See DR 344.
2126 * If parsing the string yields a valid value for @a v, @a v is set.
2127 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2128 * Sets err to ios_base::eofbit if the stream is emptied.
2130 * @param in Start of input stream.
2131 * @param end End of input stream.
2132 * @param io Source of locale and flags.
2133 * @param err Error flags to set.
2134 * @param v Value to format and insert.
2135 * @return Iterator after reading.
2138 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2139 ios_base::iostate
& __err
, void*& __v
) const
2140 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2144 virtual ~num_get() { }
2147 _M_extract_float(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2148 string
& __xtrc
) const;
2150 template<typename _ValueT
>
2152 _M_extract_int(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2153 _ValueT
& __v
) const;
2155 template<typename _CharT2
>
2156 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT2
>::__value
, int>::__type
2157 _M_find(const _CharT2
*, size_t __len
, _CharT2 __c
) const
2162 if (__c
>= _CharT2('0') && __c
< _CharT2(_CharT2('0') + __len
))
2163 __ret
= __c
- _CharT2('0');
2167 if (__c
>= _CharT2('0') && __c
<= _CharT2('9'))
2168 __ret
= __c
- _CharT2('0');
2169 else if (__c
>= _CharT2('a') && __c
<= _CharT2('f'))
2170 __ret
= 10 + (__c
- _CharT2('a'));
2171 else if (__c
>= _CharT2('A') && __c
<= _CharT2('F'))
2172 __ret
= 10 + (__c
- _CharT2('A'));
2177 template<typename _CharT2
>
2178 typename
__gnu_cxx::__enable_if
<!__is_char
<_CharT2
>::__value
,
2180 _M_find(const _CharT2
* __zero
, size_t __len
, _CharT2 __c
) const
2183 const char_type
* __q
= char_traits
<_CharT2
>::find(__zero
, __len
, __c
);
2186 __ret
= __q
- __zero
;
2195 * @brief Numeric parsing.
2197 * Parses the input stream into the variable @a v. This function is a
2198 * hook for derived classes to change the value returned. @see get()
2201 * @param in Start of input stream.
2202 * @param end End of input stream.
2203 * @param io Source of locale and flags.
2204 * @param err Error flags to set.
2205 * @param v Value to format and insert.
2206 * @return Iterator after reading.
2209 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, bool&) const;
2213 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, long&) const;
2216 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2217 unsigned short&) const;
2220 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2221 unsigned int&) const;
2224 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2225 unsigned long&) const;
2227 #ifdef _GLIBCXX_USE_LONG_LONG
2229 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2233 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2234 unsigned long long&) const;
2238 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2242 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2245 // XXX GLIBCXX_ABI Deprecated
2246 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2248 __do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2252 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2253 long double&) const;
2257 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2260 // XXX GLIBCXX_ABI Deprecated
2261 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2263 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
& __err
,
2264 long double&) const;
2269 template<typename _CharT
, typename _InIter
>
2270 locale::id num_get
<_CharT
, _InIter
>::id
;
2274 * @brief Facet for converting numbers to strings.
2276 * This facet encapsulates the code to convert a number to a string. It is
2277 * used by the ostream numeric insertion operators.
2279 * The num_put template uses protected virtual functions to provide the
2280 * actual results. The public accessors forward the call to the virtual
2281 * functions. These virtual functions are hooks for developers to
2282 * implement the behavior they require from the num_put facet.
2284 template<typename _CharT
, typename _OutIter
>
2285 class num_put
: public locale::facet
2291 typedef _CharT char_type
;
2292 typedef _OutIter iter_type
;
2295 /// Numpunct facet id.
2296 static locale::id id
;
2299 * @brief Constructor performs initialization.
2301 * This is the constructor provided by the standard.
2303 * @param refs Passed to the base facet class.
2306 num_put(size_t __refs
= 0) : facet(__refs
) { }
2309 * @brief Numeric formatting.
2311 * Formats the boolean @a v and inserts it into a stream. It does so
2312 * by calling num_put::do_put().
2314 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2315 * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
2317 * @param s Stream to write to.
2318 * @param io Source of locale and flags.
2319 * @param fill Char_type to use for filling.
2320 * @param v Value to format and insert.
2321 * @return Iterator after writing.
2324 put(iter_type __s
, ios_base
& __f
, char_type __fill
, bool __v
) const
2325 { return this->do_put(__s
, __f
, __fill
, __v
); }
2329 * @brief Numeric formatting.
2331 * Formats the integral value @a v and inserts it into a
2332 * stream. It does so by calling num_put::do_put().
2334 * Formatting is affected by the flag settings in @a io.
2336 * The basic format is affected by the value of io.flags() &
2337 * ios_base::basefield. If equal to ios_base::oct, formats like the
2338 * printf %o specifier. Else if equal to ios_base::hex, formats like
2339 * %x or %X with ios_base::uppercase unset or set respectively.
2340 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2341 * for unsigned values. Note that if both oct and hex are set, neither
2344 * If ios_base::showpos is set, '+' is output before positive values.
2345 * If ios_base::showbase is set, '0' precedes octal values (except 0)
2346 * and '0[xX]' precedes hex values.
2348 * Thousands separators are inserted according to numpunct::grouping()
2349 * and numpunct::thousands_sep(). The decimal point character used is
2350 * numpunct::decimal_point().
2352 * If io.width() is non-zero, enough @a fill characters are inserted to
2353 * make the result at least that wide. If
2354 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2355 * padded at the end. If ios_base::internal, then padding occurs
2356 * immediately after either a '+' or '-' or after '0x' or '0X'.
2357 * Otherwise, padding occurs at the beginning.
2359 * @param s Stream to write to.
2360 * @param io Source of locale and flags.
2361 * @param fill Char_type to use for filling.
2362 * @param v Value to format and insert.
2363 * @return Iterator after writing.
2366 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long __v
) const
2367 { return this->do_put(__s
, __f
, __fill
, __v
); }
2370 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2371 unsigned long __v
) const
2372 { return this->do_put(__s
, __f
, __fill
, __v
); }
2374 #ifdef _GLIBCXX_USE_LONG_LONG
2376 put(iter_type __s
, ios_base
& __f
, char_type __fill
, long long __v
) const
2377 { return this->do_put(__s
, __f
, __fill
, __v
); }
2380 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2381 unsigned long long __v
) const
2382 { return this->do_put(__s
, __f
, __fill
, __v
); }
2388 * @brief Numeric formatting.
2390 * Formats the floating point value @a v and inserts it into a stream.
2391 * It does so by calling num_put::do_put().
2393 * Formatting is affected by the flag settings in @a io.
2395 * The basic format is affected by the value of io.flags() &
2396 * ios_base::floatfield. If equal to ios_base::fixed, formats like the
2397 * printf %f specifier. Else if equal to ios_base::scientific, formats
2398 * like %e or %E with ios_base::uppercase unset or set respectively.
2399 * Otherwise, formats like %g or %G depending on uppercase. Note that
2400 * if both fixed and scientific are set, the effect will also be like
2403 * The output precision is given by io.precision(). This precision is
2404 * capped at numeric_limits::digits10 + 2 (different for double and
2405 * long double). The default precision is 6.
2407 * If ios_base::showpos is set, '+' is output before positive values.
2408 * If ios_base::showpoint is set, a decimal point will always be
2411 * Thousands separators are inserted according to numpunct::grouping()
2412 * and numpunct::thousands_sep(). The decimal point character used is
2413 * numpunct::decimal_point().
2415 * If io.width() is non-zero, enough @a fill characters are inserted to
2416 * make the result at least that wide. If
2417 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2418 * padded at the end. If ios_base::internal, then padding occurs
2419 * immediately after either a '+' or '-' or after '0x' or '0X'.
2420 * Otherwise, padding occurs at the beginning.
2422 * @param s Stream to write to.
2423 * @param io Source of locale and flags.
2424 * @param fill Char_type to use for filling.
2425 * @param v Value to format and insert.
2426 * @return Iterator after writing.
2429 put(iter_type __s
, ios_base
& __f
, char_type __fill
, double __v
) const
2430 { return this->do_put(__s
, __f
, __fill
, __v
); }
2433 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2434 long double __v
) const
2435 { return this->do_put(__s
, __f
, __fill
, __v
); }
2439 * @brief Numeric formatting.
2441 * Formats the pointer value @a v and inserts it into a stream. It
2442 * does so by calling num_put::do_put().
2444 * This function formats @a v as an unsigned long with ios_base::hex
2445 * and ios_base::showbase set.
2447 * @param s Stream to write to.
2448 * @param io Source of locale and flags.
2449 * @param fill Char_type to use for filling.
2450 * @param v Value to format and insert.
2451 * @return Iterator after writing.
2454 put(iter_type __s
, ios_base
& __f
, char_type __fill
,
2455 const void* __v
) const
2456 { return this->do_put(__s
, __f
, __fill
, __v
); }
2459 template<typename _ValueT
>
2461 _M_insert_float(iter_type
, ios_base
& __io
, char_type __fill
,
2462 char __mod
, _ValueT __v
) const;
2465 _M_group_float(const char* __grouping
, size_t __grouping_size
,
2466 char_type __sep
, const char_type
* __p
, char_type
* __new
,
2467 char_type
* __cs
, int& __len
) const;
2469 template<typename _ValueT
>
2471 _M_insert_int(iter_type
, ios_base
& __io
, char_type __fill
,
2475 _M_group_int(const char* __grouping
, size_t __grouping_size
,
2476 char_type __sep
, ios_base
& __io
, char_type
* __new
,
2477 char_type
* __cs
, int& __len
) const;
2480 _M_pad(char_type __fill
, streamsize __w
, ios_base
& __io
,
2481 char_type
* __new
, const char_type
* __cs
, int& __len
) const;
2489 * @brief Numeric formatting.
2491 * These functions do the work of formatting numeric values and
2492 * inserting them into a stream. This function is a hook for derived
2493 * classes to change the value returned.
2495 * @param s Stream to write to.
2496 * @param io Source of locale and flags.
2497 * @param fill Char_type to use for filling.
2498 * @param v Value to format and insert.
2499 * @return Iterator after writing.
2502 do_put(iter_type
, ios_base
&, char_type __fill
, bool __v
) const;
2505 do_put(iter_type
, ios_base
&, char_type __fill
, long __v
) const;
2508 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long) const;
2510 #ifdef _GLIBCXX_USE_LONG_LONG
2512 do_put(iter_type
, ios_base
&, char_type __fill
, long long __v
) const;
2515 do_put(iter_type
, ios_base
&, char_type __fill
, unsigned long long) const;
2519 do_put(iter_type
, ios_base
&, char_type __fill
, double __v
) const;
2521 // XXX GLIBCXX_ABI Deprecated
2522 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2524 __do_put(iter_type
, ios_base
&, char_type __fill
, double __v
) const;
2527 do_put(iter_type
, ios_base
&, char_type __fill
, long double __v
) const;
2531 do_put(iter_type
, ios_base
&, char_type __fill
, const void* __v
) const;
2533 // XXX GLIBCXX_ABI Deprecated
2534 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2536 do_put(iter_type
, ios_base
&, char_type __fill
, long double __v
) const;
2541 template <typename _CharT
, typename _OutIter
>
2542 locale::id num_put
<_CharT
, _OutIter
>::id
;
2544 _GLIBCXX_END_LDBL_NAMESPACE
2547 * @brief Facet for localized string comparison.
2549 * This facet encapsulates the code to compare strings in a localized
2552 * The collate template uses protected virtual functions to provide
2553 * the actual results. The public accessors forward the call to
2554 * the virtual functions. These virtual functions are hooks for
2555 * developers to implement the behavior they require from the
2558 template<typename _CharT
>
2559 class collate
: public locale::facet
2565 typedef _CharT char_type
;
2566 typedef basic_string
<_CharT
> string_type
;
2570 // Underlying "C" library locale information saved from
2571 // initialization, needed by collate_byname as well.
2572 __c_locale _M_c_locale_collate
;
2575 /// Numpunct facet id.
2576 static locale::id id
;
2579 * @brief Constructor performs initialization.
2581 * This is the constructor provided by the standard.
2583 * @param refs Passed to the base facet class.
2586 collate(size_t __refs
= 0)
2587 : facet(__refs
), _M_c_locale_collate(_S_get_c_locale())
2591 * @brief Internal constructor. Not for general use.
2593 * This is a constructor for use by the library itself to set up new
2596 * @param cloc The "C" locale.
2597 * @param refs Passed to the base facet class.
2600 collate(__c_locale __cloc
, size_t __refs
= 0)
2601 : facet(__refs
), _M_c_locale_collate(_S_clone_c_locale(__cloc
))
2605 * @brief Compare two strings.
2607 * This function compares two strings and returns the result by calling
2608 * collate::do_compare().
2610 * @param lo1 Start of string 1.
2611 * @param hi1 End of string 1.
2612 * @param lo2 Start of string 2.
2613 * @param hi2 End of string 2.
2614 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2617 compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
2618 const _CharT
* __lo2
, const _CharT
* __hi2
) const
2619 { return this->do_compare(__lo1
, __hi1
, __lo2
, __hi2
); }
2622 * @brief Transform string to comparable form.
2624 * This function is a wrapper for strxfrm functionality. It takes the
2625 * input string and returns a modified string that can be directly
2626 * compared to other transformed strings. In the "C" locale, this
2627 * function just returns a copy of the input string. In some other
2628 * locales, it may replace two chars with one, change a char for
2629 * another, etc. It does so by returning collate::do_transform().
2631 * @param lo Start of string.
2632 * @param hi End of string.
2633 * @return Transformed string_type.
2636 transform(const _CharT
* __lo
, const _CharT
* __hi
) const
2637 { return this->do_transform(__lo
, __hi
); }
2640 * @brief Return hash of a string.
2642 * This function computes and returns a hash on the input string. It
2643 * does so by returning collate::do_hash().
2645 * @param lo Start of string.
2646 * @param hi End of string.
2647 * @return Hash value.
2650 hash(const _CharT
* __lo
, const _CharT
* __hi
) const
2651 { return this->do_hash(__lo
, __hi
); }
2653 // Used to abstract out _CharT bits in virtual member functions, below.
2655 _M_compare(const _CharT
*, const _CharT
*) const;
2658 _M_transform(_CharT
*, const _CharT
*, size_t) const;
2664 { _S_destroy_c_locale(_M_c_locale_collate
); }
2667 * @brief Compare two strings.
2669 * This function is a hook for derived classes to change the value
2670 * returned. @see compare().
2672 * @param lo1 Start of string 1.
2673 * @param hi1 End of string 1.
2674 * @param lo2 Start of string 2.
2675 * @param hi2 End of string 2.
2676 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2679 do_compare(const _CharT
* __lo1
, const _CharT
* __hi1
,
2680 const _CharT
* __lo2
, const _CharT
* __hi2
) const;
2683 * @brief Transform string to comparable form.
2685 * This function is a hook for derived classes to change the value
2688 * @param lo1 Start of string 1.
2689 * @param hi1 End of string 1.
2690 * @param lo2 Start of string 2.
2691 * @param hi2 End of string 2.
2692 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2695 do_transform(const _CharT
* __lo
, const _CharT
* __hi
) const;
2698 * @brief Return hash of a string.
2700 * This function computes and returns a hash on the input string. This
2701 * function is a hook for derived classes to change the value returned.
2703 * @param lo Start of string.
2704 * @param hi End of string.
2705 * @return Hash value.
2708 do_hash(const _CharT
* __lo
, const _CharT
* __hi
) const;
2711 template<typename _CharT
>
2712 locale::id collate
<_CharT
>::id
;
2717 collate
<char>::_M_compare(const char*, const char*) const;
2721 collate
<char>::_M_transform(char*, const char*, size_t) const;
2723 #ifdef _GLIBCXX_USE_WCHAR_T
2726 collate
<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
2730 collate
<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
2733 /// @brief class collate_byname [22.2.4.2].
2734 template<typename _CharT
>
2735 class collate_byname
: public collate
<_CharT
>
2740 typedef _CharT char_type
;
2741 typedef basic_string
<_CharT
> string_type
;
2745 collate_byname(const char* __s
, size_t __refs
= 0)
2746 : collate
<_CharT
>(__refs
)
2748 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
2750 this->_S_destroy_c_locale(this->_M_c_locale_collate
);
2751 this->_S_create_c_locale(this->_M_c_locale_collate
, __s
);
2757 ~collate_byname() { }
2762 * @brief Time format ordering data.
2764 * This class provides an enum representing different orderings of day,
2770 enum dateorder
{ no_order
, dmy
, mdy
, ymd
, ydm
};
2773 template<typename _CharT
>
2774 struct __timepunct_cache
: public locale::facet
2776 // List of all known timezones, with GMT first.
2777 static const _CharT
* _S_timezones
[14];
2779 const _CharT
* _M_date_format
;
2780 const _CharT
* _M_date_era_format
;
2781 const _CharT
* _M_time_format
;
2782 const _CharT
* _M_time_era_format
;
2783 const _CharT
* _M_date_time_format
;
2784 const _CharT
* _M_date_time_era_format
;
2785 const _CharT
* _M_am
;
2786 const _CharT
* _M_pm
;
2787 const _CharT
* _M_am_pm_format
;
2789 // Day names, starting with "C"'s Sunday.
2790 const _CharT
* _M_day1
;
2791 const _CharT
* _M_day2
;
2792 const _CharT
* _M_day3
;
2793 const _CharT
* _M_day4
;
2794 const _CharT
* _M_day5
;
2795 const _CharT
* _M_day6
;
2796 const _CharT
* _M_day7
;
2798 // Abbreviated day names, starting with "C"'s Sun.
2799 const _CharT
* _M_aday1
;
2800 const _CharT
* _M_aday2
;
2801 const _CharT
* _M_aday3
;
2802 const _CharT
* _M_aday4
;
2803 const _CharT
* _M_aday5
;
2804 const _CharT
* _M_aday6
;
2805 const _CharT
* _M_aday7
;
2807 // Month names, starting with "C"'s January.
2808 const _CharT
* _M_month01
;
2809 const _CharT
* _M_month02
;
2810 const _CharT
* _M_month03
;
2811 const _CharT
* _M_month04
;
2812 const _CharT
* _M_month05
;
2813 const _CharT
* _M_month06
;
2814 const _CharT
* _M_month07
;
2815 const _CharT
* _M_month08
;
2816 const _CharT
* _M_month09
;
2817 const _CharT
* _M_month10
;
2818 const _CharT
* _M_month11
;
2819 const _CharT
* _M_month12
;
2821 // Abbreviated month names, starting with "C"'s Jan.
2822 const _CharT
* _M_amonth01
;
2823 const _CharT
* _M_amonth02
;
2824 const _CharT
* _M_amonth03
;
2825 const _CharT
* _M_amonth04
;
2826 const _CharT
* _M_amonth05
;
2827 const _CharT
* _M_amonth06
;
2828 const _CharT
* _M_amonth07
;
2829 const _CharT
* _M_amonth08
;
2830 const _CharT
* _M_amonth09
;
2831 const _CharT
* _M_amonth10
;
2832 const _CharT
* _M_amonth11
;
2833 const _CharT
* _M_amonth12
;
2837 __timepunct_cache(size_t __refs
= 0) : facet(__refs
),
2838 _M_date_format(NULL
), _M_date_era_format(NULL
), _M_time_format(NULL
),
2839 _M_time_era_format(NULL
), _M_date_time_format(NULL
),
2840 _M_date_time_era_format(NULL
), _M_am(NULL
), _M_pm(NULL
),
2841 _M_am_pm_format(NULL
), _M_day1(NULL
), _M_day2(NULL
), _M_day3(NULL
),
2842 _M_day4(NULL
), _M_day5(NULL
), _M_day6(NULL
), _M_day7(NULL
),
2843 _M_aday1(NULL
), _M_aday2(NULL
), _M_aday3(NULL
), _M_aday4(NULL
),
2844 _M_aday5(NULL
), _M_aday6(NULL
), _M_aday7(NULL
), _M_month01(NULL
),
2845 _M_month02(NULL
), _M_month03(NULL
), _M_month04(NULL
), _M_month05(NULL
),
2846 _M_month06(NULL
), _M_month07(NULL
), _M_month08(NULL
), _M_month09(NULL
),
2847 _M_month10(NULL
), _M_month11(NULL
), _M_month12(NULL
), _M_amonth01(NULL
),
2848 _M_amonth02(NULL
), _M_amonth03(NULL
), _M_amonth04(NULL
),
2849 _M_amonth05(NULL
), _M_amonth06(NULL
), _M_amonth07(NULL
),
2850 _M_amonth08(NULL
), _M_amonth09(NULL
), _M_amonth10(NULL
),
2851 _M_amonth11(NULL
), _M_amonth12(NULL
), _M_allocated(false)
2854 ~__timepunct_cache();
2857 _M_cache(const locale
& __loc
);
2861 operator=(const __timepunct_cache
&);
2864 __timepunct_cache(const __timepunct_cache
&);
2867 template<typename _CharT
>
2868 __timepunct_cache
<_CharT
>::~__timepunct_cache()
2879 __timepunct_cache
<char>::_S_timezones
[14];
2881 #ifdef _GLIBCXX_USE_WCHAR_T
2884 __timepunct_cache
<wchar_t>::_S_timezones
[14];
2888 template<typename _CharT
>
2889 const _CharT
* __timepunct_cache
<_CharT
>::_S_timezones
[14];
2891 template<typename _CharT
>
2892 class __timepunct
: public locale::facet
2896 typedef _CharT __char_type
;
2897 typedef basic_string
<_CharT
> __string_type
;
2898 typedef __timepunct_cache
<_CharT
> __cache_type
;
2901 __cache_type
* _M_data
;
2902 __c_locale _M_c_locale_timepunct
;
2903 const char* _M_name_timepunct
;
2906 /// Numpunct facet id.
2907 static locale::id id
;
2910 __timepunct(size_t __refs
= 0);
2913 __timepunct(__cache_type
* __cache
, size_t __refs
= 0);
2916 * @brief Internal constructor. Not for general use.
2918 * This is a constructor for use by the library itself to set up new
2921 * @param cloc The "C" locale.
2922 * @param s The name of a locale.
2923 * @param refs Passed to the base facet class.
2926 __timepunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
2928 // FIXME: for error checking purposes _M_put should return the return
2929 // value of strftime/wcsftime.
2931 _M_put(_CharT
* __s
, size_t __maxlen
, const _CharT
* __format
,
2932 const tm
* __tm
) const;
2935 _M_date_formats(const _CharT
** __date
) const
2937 // Always have default first.
2938 __date
[0] = _M_data
->_M_date_format
;
2939 __date
[1] = _M_data
->_M_date_era_format
;
2943 _M_time_formats(const _CharT
** __time
) const
2945 // Always have default first.
2946 __time
[0] = _M_data
->_M_time_format
;
2947 __time
[1] = _M_data
->_M_time_era_format
;
2951 _M_date_time_formats(const _CharT
** __dt
) const
2953 // Always have default first.
2954 __dt
[0] = _M_data
->_M_date_time_format
;
2955 __dt
[1] = _M_data
->_M_date_time_era_format
;
2959 _M_am_pm_format(const _CharT
* __ampm
) const
2960 { __ampm
= _M_data
->_M_am_pm_format
; }
2963 _M_am_pm(const _CharT
** __ampm
) const
2965 __ampm
[0] = _M_data
->_M_am
;
2966 __ampm
[1] = _M_data
->_M_pm
;
2970 _M_days(const _CharT
** __days
) const
2972 __days
[0] = _M_data
->_M_day1
;
2973 __days
[1] = _M_data
->_M_day2
;
2974 __days
[2] = _M_data
->_M_day3
;
2975 __days
[3] = _M_data
->_M_day4
;
2976 __days
[4] = _M_data
->_M_day5
;
2977 __days
[5] = _M_data
->_M_day6
;
2978 __days
[6] = _M_data
->_M_day7
;
2982 _M_days_abbreviated(const _CharT
** __days
) const
2984 __days
[0] = _M_data
->_M_aday1
;
2985 __days
[1] = _M_data
->_M_aday2
;
2986 __days
[2] = _M_data
->_M_aday3
;
2987 __days
[3] = _M_data
->_M_aday4
;
2988 __days
[4] = _M_data
->_M_aday5
;
2989 __days
[5] = _M_data
->_M_aday6
;
2990 __days
[6] = _M_data
->_M_aday7
;
2994 _M_months(const _CharT
** __months
) const
2996 __months
[0] = _M_data
->_M_month01
;
2997 __months
[1] = _M_data
->_M_month02
;
2998 __months
[2] = _M_data
->_M_month03
;
2999 __months
[3] = _M_data
->_M_month04
;
3000 __months
[4] = _M_data
->_M_month05
;
3001 __months
[5] = _M_data
->_M_month06
;
3002 __months
[6] = _M_data
->_M_month07
;
3003 __months
[7] = _M_data
->_M_month08
;
3004 __months
[8] = _M_data
->_M_month09
;
3005 __months
[9] = _M_data
->_M_month10
;
3006 __months
[10] = _M_data
->_M_month11
;
3007 __months
[11] = _M_data
->_M_month12
;
3011 _M_months_abbreviated(const _CharT
** __months
) const
3013 __months
[0] = _M_data
->_M_amonth01
;
3014 __months
[1] = _M_data
->_M_amonth02
;
3015 __months
[2] = _M_data
->_M_amonth03
;
3016 __months
[3] = _M_data
->_M_amonth04
;
3017 __months
[4] = _M_data
->_M_amonth05
;
3018 __months
[5] = _M_data
->_M_amonth06
;
3019 __months
[6] = _M_data
->_M_amonth07
;
3020 __months
[7] = _M_data
->_M_amonth08
;
3021 __months
[8] = _M_data
->_M_amonth09
;
3022 __months
[9] = _M_data
->_M_amonth10
;
3023 __months
[10] = _M_data
->_M_amonth11
;
3024 __months
[11] = _M_data
->_M_amonth12
;
3031 // For use at construction time only.
3033 _M_initialize_timepunct(__c_locale __cloc
= NULL
);
3036 template<typename _CharT
>
3037 locale::id __timepunct
<_CharT
>::id
;
3042 __timepunct
<char>::_M_initialize_timepunct(__c_locale __cloc
);
3046 __timepunct
<char>::_M_put(char*, size_t, const char*, const tm
*) const;
3048 #ifdef _GLIBCXX_USE_WCHAR_T
3051 __timepunct
<wchar_t>::_M_initialize_timepunct(__c_locale __cloc
);
3055 __timepunct
<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
3059 _GLIBCXX_END_NAMESPACE
3061 // Include host and configuration specific timepunct functions.
3062 #include <bits/time_members.h>
3064 _GLIBCXX_BEGIN_NAMESPACE(std
)
3067 * @brief Facet for parsing dates and times.
3069 * This facet encapsulates the code to parse and return a date or
3070 * time from a string. It is used by the istream numeric
3071 * extraction operators.
3073 * The time_get template uses protected virtual functions to provide the
3074 * actual results. The public accessors forward the call to the virtual
3075 * functions. These virtual functions are hooks for developers to
3076 * implement the behavior they require from the time_get facet.
3078 template<typename _CharT
, typename _InIter
>
3079 class time_get
: public locale::facet
, public time_base
3085 typedef _CharT char_type
;
3086 typedef _InIter iter_type
;
3088 typedef basic_string
<_CharT
> __string_type
;
3090 /// Numpunct facet id.
3091 static locale::id id
;
3094 * @brief Constructor performs initialization.
3096 * This is the constructor provided by the standard.
3098 * @param refs Passed to the base facet class.
3101 time_get(size_t __refs
= 0)
3102 : facet (__refs
) { }
3105 * @brief Return preferred order of month, day, and year.
3107 * This function returns an enum from timebase::dateorder giving the
3108 * preferred ordering if the format "x" given to time_put::put() only
3109 * uses month, day, and year. If the format "x" for the associated
3110 * locale uses other fields, this function returns
3111 * timebase::dateorder::noorder.
3113 * NOTE: The library always returns noorder at the moment.
3115 * @return A member of timebase::dateorder.
3119 { return this->do_date_order(); }
3122 * @brief Parse input time string.
3124 * This function parses a time according to the format "x" and puts the
3125 * results into a user-supplied struct tm. The result is returned by
3126 * calling time_get::do_get_time().
3128 * If there is a valid time string according to format "x", @a tm will
3129 * be filled in accordingly and the returned iterator will point to the
3130 * first character beyond the time string. If an error occurs before
3131 * the end, err |= ios_base::failbit. If parsing reads all the
3132 * characters, err |= ios_base::eofbit.
3134 * @param beg Start of string to parse.
3135 * @param end End of string to parse.
3136 * @param io Source of the locale.
3137 * @param err Error flags to set.
3138 * @param tm Pointer to struct tm to fill in.
3139 * @return Iterator to first char beyond time string.
3142 get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3143 ios_base::iostate
& __err
, tm
* __tm
) const
3144 { return this->do_get_time(__beg
, __end
, __io
, __err
, __tm
); }
3147 * @brief Parse input date string.
3149 * This function parses a date according to the format "X" and puts the
3150 * results into a user-supplied struct tm. The result is returned by
3151 * calling time_get::do_get_date().
3153 * If there is a valid date string according to format "X", @a tm will
3154 * be filled in accordingly and the returned iterator will point to the
3155 * first character beyond the date string. If an error occurs before
3156 * the end, err |= ios_base::failbit. If parsing reads all the
3157 * characters, err |= ios_base::eofbit.
3159 * @param beg Start of string to parse.
3160 * @param end End of string to parse.
3161 * @param io Source of the locale.
3162 * @param err Error flags to set.
3163 * @param tm Pointer to struct tm to fill in.
3164 * @return Iterator to first char beyond date string.
3167 get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3168 ios_base::iostate
& __err
, tm
* __tm
) const
3169 { return this->do_get_date(__beg
, __end
, __io
, __err
, __tm
); }
3172 * @brief Parse input weekday string.
3174 * This function parses a weekday name and puts the results into a
3175 * user-supplied struct tm. The result is returned by calling
3176 * time_get::do_get_weekday().
3178 * Parsing starts by parsing an abbreviated weekday name. If a valid
3179 * abbreviation is followed by a character that would lead to the full
3180 * weekday name, parsing continues until the full name is found or an
3181 * error occurs. Otherwise parsing finishes at the end of the
3184 * If an error occurs before the end, err |= ios_base::failbit. If
3185 * parsing reads all the characters, err |= ios_base::eofbit.
3187 * @param beg Start of string to parse.
3188 * @param end End of string to parse.
3189 * @param io Source of the locale.
3190 * @param err Error flags to set.
3191 * @param tm Pointer to struct tm to fill in.
3192 * @return Iterator to first char beyond weekday name.
3195 get_weekday(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3196 ios_base::iostate
& __err
, tm
* __tm
) const
3197 { return this->do_get_weekday(__beg
, __end
, __io
, __err
, __tm
); }
3200 * @brief Parse input month string.
3202 * This function parses a month name and puts the results into a
3203 * user-supplied struct tm. The result is returned by calling
3204 * time_get::do_get_monthname().
3206 * Parsing starts by parsing an abbreviated month name. If a valid
3207 * abbreviation is followed by a character that would lead to the full
3208 * month name, parsing continues until the full name is found or an
3209 * error occurs. Otherwise parsing finishes at the end of the
3212 * If an error occurs before the end, err |= ios_base::failbit. If
3213 * parsing reads all the characters, err |=
3216 * @param beg Start of string to parse.
3217 * @param end End of string to parse.
3218 * @param io Source of the locale.
3219 * @param err Error flags to set.
3220 * @param tm Pointer to struct tm to fill in.
3221 * @return Iterator to first char beyond month name.
3224 get_monthname(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3225 ios_base::iostate
& __err
, tm
* __tm
) const
3226 { return this->do_get_monthname(__beg
, __end
, __io
, __err
, __tm
); }
3229 * @brief Parse input year string.
3231 * This function reads up to 4 characters to parse a year string and
3232 * puts the results into a user-supplied struct tm. The result is
3233 * returned by calling time_get::do_get_year().
3235 * 4 consecutive digits are interpreted as a full year. If there are
3236 * exactly 2 consecutive digits, the library interprets this as the
3237 * number of years since 1900.
3239 * If an error occurs before the end, err |= ios_base::failbit. If
3240 * parsing reads all the characters, err |= ios_base::eofbit.
3242 * @param beg Start of string to parse.
3243 * @param end End of string to parse.
3244 * @param io Source of the locale.
3245 * @param err Error flags to set.
3246 * @param tm Pointer to struct tm to fill in.
3247 * @return Iterator to first char beyond year.
3250 get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3251 ios_base::iostate
& __err
, tm
* __tm
) const
3252 { return this->do_get_year(__beg
, __end
, __io
, __err
, __tm
); }
3260 * @brief Return preferred order of month, day, and year.
3262 * This function returns an enum from timebase::dateorder giving the
3263 * preferred ordering if the format "x" given to time_put::put() only
3264 * uses month, day, and year. This function is a hook for derived
3265 * classes to change the value returned.
3267 * @return A member of timebase::dateorder.
3270 do_date_order() const;
3273 * @brief Parse input time string.
3275 * This function parses a time according to the format "x" and puts the
3276 * results into a user-supplied struct tm. This function is a hook for
3277 * derived classes to change the value returned. @see get_time() for
3280 * @param beg Start of string to parse.
3281 * @param end End of string to parse.
3282 * @param io Source of the locale.
3283 * @param err Error flags to set.
3284 * @param tm Pointer to struct tm to fill in.
3285 * @return Iterator to first char beyond time string.
3288 do_get_time(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3289 ios_base::iostate
& __err
, tm
* __tm
) const;
3292 * @brief Parse input date string.
3294 * This function parses a date according to the format "X" and puts the
3295 * results into a user-supplied struct tm. This function is a hook for
3296 * derived classes to change the value returned. @see get_date() for
3299 * @param beg Start of string to parse.
3300 * @param end End of string to parse.
3301 * @param io Source of the locale.
3302 * @param err Error flags to set.
3303 * @param tm Pointer to struct tm to fill in.
3304 * @return Iterator to first char beyond date string.
3307 do_get_date(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3308 ios_base::iostate
& __err
, tm
* __tm
) const;
3311 * @brief Parse input weekday string.
3313 * This function parses a weekday name and puts the results into a
3314 * user-supplied struct tm. This function is a hook for derived
3315 * classes to change the value returned. @see get_weekday() for
3318 * @param beg Start of string to parse.
3319 * @param end End of string to parse.
3320 * @param io Source of the locale.
3321 * @param err Error flags to set.
3322 * @param tm Pointer to struct tm to fill in.
3323 * @return Iterator to first char beyond weekday name.
3326 do_get_weekday(iter_type __beg
, iter_type __end
, ios_base
&,
3327 ios_base::iostate
& __err
, tm
* __tm
) const;
3330 * @brief Parse input month string.
3332 * This function parses a month name and puts the results into a
3333 * user-supplied struct tm. This function is a hook for derived
3334 * classes to change the value returned. @see get_monthname() for
3337 * @param beg Start of string to parse.
3338 * @param end End of string to parse.
3339 * @param io Source of the locale.
3340 * @param err Error flags to set.
3341 * @param tm Pointer to struct tm to fill in.
3342 * @return Iterator to first char beyond month name.
3345 do_get_monthname(iter_type __beg
, iter_type __end
, ios_base
&,
3346 ios_base::iostate
& __err
, tm
* __tm
) const;
3349 * @brief Parse input year string.
3351 * This function reads up to 4 characters to parse a year string and
3352 * puts the results into a user-supplied struct tm. This function is a
3353 * hook for derived classes to change the value returned. @see
3354 * get_year() for details.
3356 * @param beg Start of string to parse.
3357 * @param end End of string to parse.
3358 * @param io Source of the locale.
3359 * @param err Error flags to set.
3360 * @param tm Pointer to struct tm to fill in.
3361 * @return Iterator to first char beyond year.
3364 do_get_year(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3365 ios_base::iostate
& __err
, tm
* __tm
) const;
3367 // Extract numeric component of length __len.
3369 _M_extract_num(iter_type __beg
, iter_type __end
, int& __member
,
3370 int __min
, int __max
, size_t __len
,
3371 ios_base
& __io
, ios_base::iostate
& __err
) const;
3373 // Extract day or month name, or any unique array of string
3374 // literals in a const _CharT* array.
3376 _M_extract_name(iter_type __beg
, iter_type __end
, int& __member
,
3377 const _CharT
** __names
, size_t __indexlen
,
3378 ios_base
& __io
, ios_base::iostate
& __err
) const;
3380 // Extract on a component-by-component basis, via __format argument.
3382 _M_extract_via_format(iter_type __beg
, iter_type __end
, ios_base
& __io
,
3383 ios_base::iostate
& __err
, tm
* __tm
,
3384 const _CharT
* __format
) const;
3387 template<typename _CharT
, typename _InIter
>
3388 locale::id time_get
<_CharT
, _InIter
>::id
;
3390 /// @brief class time_get_byname [22.2.5.2].
3391 template<typename _CharT
, typename _InIter
>
3392 class time_get_byname
: public time_get
<_CharT
, _InIter
>
3396 typedef _CharT char_type
;
3397 typedef _InIter iter_type
;
3400 time_get_byname(const char*, size_t __refs
= 0)
3401 : time_get
<_CharT
, _InIter
>(__refs
) { }
3405 ~time_get_byname() { }
3409 * @brief Facet for outputting dates and times.
3411 * This facet encapsulates the code to format and output dates and times
3412 * according to formats used by strftime().
3414 * The time_put template uses protected virtual functions to provide the
3415 * actual results. The public accessors forward the call to the virtual
3416 * functions. These virtual functions are hooks for developers to
3417 * implement the behavior they require from the time_put facet.
3419 template<typename _CharT
, typename _OutIter
>
3420 class time_put
: public locale::facet
3426 typedef _CharT char_type
;
3427 typedef _OutIter iter_type
;
3430 /// Numpunct facet id.
3431 static locale::id id
;
3434 * @brief Constructor performs initialization.
3436 * This is the constructor provided by the standard.
3438 * @param refs Passed to the base facet class.
3441 time_put(size_t __refs
= 0)
3445 * @brief Format and output a time or date.
3447 * This function formats the data in struct tm according to the
3448 * provided format string. The format string is interpreted as by
3451 * @param s The stream to write to.
3452 * @param io Source of locale.
3453 * @param fill char_type to use for padding.
3454 * @param tm Struct tm with date and time info to format.
3455 * @param beg Start of format string.
3456 * @param end End of format string.
3457 * @return Iterator after writing.
3460 put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
3461 const _CharT
* __beg
, const _CharT
* __end
) const;
3464 * @brief Format and output a time or date.
3466 * This function formats the data in struct tm according to the
3467 * provided format char and optional modifier. The format and modifier
3468 * are interpreted as by strftime(). It does so by returning
3469 * time_put::do_put().
3471 * @param s The stream to write to.
3472 * @param io Source of locale.
3473 * @param fill char_type to use for padding.
3474 * @param tm Struct tm with date and time info to format.
3475 * @param format Format char.
3476 * @param mod Optional modifier char.
3477 * @return Iterator after writing.
3480 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
3481 const tm
* __tm
, char __format
, char __mod
= 0) const
3482 { return this->do_put(__s
, __io
, __fill
, __tm
, __format
, __mod
); }
3491 * @brief Format and output a time or date.
3493 * This function formats the data in struct tm according to the
3494 * provided format char and optional modifier. This function is a hook
3495 * for derived classes to change the value returned. @see put() for
3498 * @param s The stream to write to.
3499 * @param io Source of locale.
3500 * @param fill char_type to use for padding.
3501 * @param tm Struct tm with date and time info to format.
3502 * @param format Format char.
3503 * @param mod Optional modifier char.
3504 * @return Iterator after writing.
3507 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
, const tm
* __tm
,
3508 char __format
, char __mod
) const;
3511 template<typename _CharT
, typename _OutIter
>
3512 locale::id time_put
<_CharT
, _OutIter
>::id
;
3514 /// @brief class time_put_byname [22.2.5.4].
3515 template<typename _CharT
, typename _OutIter
>
3516 class time_put_byname
: public time_put
<_CharT
, _OutIter
>
3520 typedef _CharT char_type
;
3521 typedef _OutIter iter_type
;
3524 time_put_byname(const char*, size_t __refs
= 0)
3525 : time_put
<_CharT
, _OutIter
>(__refs
)
3530 ~time_put_byname() { }
3535 * @brief Money format ordering data.
3537 * This class contains an ordered array of 4 fields to represent the
3538 * pattern for formatting a money amount. Each field may contain one entry
3539 * from the part enum. symbol, sign, and value must be present and the
3540 * remaining field must contain either none or space. @see
3541 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
3542 * these fields are interpreted.
3547 enum part
{ none
, space
, symbol
, sign
, value
};
3548 struct pattern
{ char field
[4]; };
3550 static const pattern _S_default_pattern
;
3559 // String literal of acceptable (narrow) input/output, for
3560 // money_get/money_put. "-0123456789"
3561 static const char* _S_atoms
;
3563 // Construct and return valid pattern consisting of some combination of:
3564 // space none symbol sign value
3566 _S_construct_pattern(char __precedes
, char __space
, char __posn
);
3569 template<typename _CharT
, bool _Intl
>
3570 struct __moneypunct_cache
: public locale::facet
3572 const char* _M_grouping
;
3573 size_t _M_grouping_size
;
3574 bool _M_use_grouping
;
3575 _CharT _M_decimal_point
;
3576 _CharT _M_thousands_sep
;
3577 const _CharT
* _M_curr_symbol
;
3578 size_t _M_curr_symbol_size
;
3579 const _CharT
* _M_positive_sign
;
3580 size_t _M_positive_sign_size
;
3581 const _CharT
* _M_negative_sign
;
3582 size_t _M_negative_sign_size
;
3584 money_base::pattern _M_pos_format
;
3585 money_base::pattern _M_neg_format
;
3587 // A list of valid numeric literals for input and output: in the standard
3588 // "C" locale, this is "-0123456789". This array contains the chars after
3589 // having been passed through the current locale's ctype<_CharT>.widen().
3590 _CharT _M_atoms
[money_base::_S_end
];
3594 __moneypunct_cache(size_t __refs
= 0) : facet(__refs
),
3595 _M_grouping(NULL
), _M_grouping_size(0), _M_use_grouping(false),
3596 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
3597 _M_curr_symbol(NULL
), _M_curr_symbol_size(0),
3598 _M_positive_sign(NULL
), _M_positive_sign_size(0),
3599 _M_negative_sign(NULL
), _M_negative_sign_size(0),
3601 _M_pos_format(money_base::pattern()),
3602 _M_neg_format(money_base::pattern()), _M_allocated(false)
3605 ~__moneypunct_cache();
3608 _M_cache(const locale
& __loc
);
3612 operator=(const __moneypunct_cache
&);
3615 __moneypunct_cache(const __moneypunct_cache
&);
3618 template<typename _CharT
, bool _Intl
>
3619 __moneypunct_cache
<_CharT
, _Intl
>::~__moneypunct_cache()
3623 delete [] _M_grouping
;
3624 delete [] _M_curr_symbol
;
3625 delete [] _M_positive_sign
;
3626 delete [] _M_negative_sign
;
3631 * @brief Facet for formatting data for money amounts.
3633 * This facet encapsulates the punctuation, grouping and other formatting
3634 * features of money amount string representations.
3636 template<typename _CharT
, bool _Intl
>
3637 class moneypunct
: public locale::facet
, public money_base
3643 typedef _CharT char_type
;
3644 typedef basic_string
<_CharT
> string_type
;
3646 typedef __moneypunct_cache
<_CharT
, _Intl
> __cache_type
;
3649 __cache_type
* _M_data
;
3652 /// This value is provided by the standard, but no reason for its
3654 static const bool intl
= _Intl
;
3655 /// Numpunct facet id.
3656 static locale::id id
;
3659 * @brief Constructor performs initialization.
3661 * This is the constructor provided by the standard.
3663 * @param refs Passed to the base facet class.
3666 moneypunct(size_t __refs
= 0) : facet(__refs
), _M_data(NULL
)
3667 { _M_initialize_moneypunct(); }
3670 * @brief Constructor performs initialization.
3672 * This is an internal constructor.
3674 * @param cache Cache for optimization.
3675 * @param refs Passed to the base facet class.
3678 moneypunct(__cache_type
* __cache
, size_t __refs
= 0)
3679 : facet(__refs
), _M_data(__cache
)
3680 { _M_initialize_moneypunct(); }
3683 * @brief Internal constructor. Not for general use.
3685 * This is a constructor for use by the library itself to set up new
3688 * @param cloc The "C" locale.
3689 * @param s The name of a locale.
3690 * @param refs Passed to the base facet class.
3693 moneypunct(__c_locale __cloc
, const char* __s
, size_t __refs
= 0)
3694 : facet(__refs
), _M_data(NULL
)
3695 { _M_initialize_moneypunct(__cloc
, __s
); }
3698 * @brief Return decimal point character.
3700 * This function returns a char_type to use as a decimal point. It
3701 * does so by returning returning
3702 * moneypunct<char_type>::do_decimal_point().
3704 * @return @a char_type representing a decimal point.
3707 decimal_point() const
3708 { return this->do_decimal_point(); }
3711 * @brief Return thousands separator character.
3713 * This function returns a char_type to use as a thousands
3714 * separator. It does so by returning returning
3715 * moneypunct<char_type>::do_thousands_sep().
3717 * @return char_type representing a thousands separator.
3720 thousands_sep() const
3721 { return this->do_thousands_sep(); }
3724 * @brief Return grouping specification.
3726 * This function returns a string representing groupings for the
3727 * integer part of an amount. Groupings indicate where thousands
3728 * separators should be inserted.
3730 * Each char in the return string is interpret as an integer rather
3731 * than a character. These numbers represent the number of digits in a
3732 * group. The first char in the string represents the number of digits
3733 * in the least significant group. If a char is negative, it indicates
3734 * an unlimited number of digits for the group. If more chars from the
3735 * string are required to group a number, the last char is used
3738 * For example, if the grouping() returns "\003\002" and is applied to
3739 * the number 123456789, this corresponds to 12,34,56,789. Note that
3740 * if the string was "32", this would put more than 50 digits into the
3741 * least significant group if the character set is ASCII.
3743 * The string is returned by calling
3744 * moneypunct<char_type>::do_grouping().
3746 * @return string representing grouping specification.
3750 { return this->do_grouping(); }
3753 * @brief Return currency symbol string.
3755 * This function returns a string_type to use as a currency symbol. It
3756 * does so by returning returning
3757 * moneypunct<char_type>::do_curr_symbol().
3759 * @return @a string_type representing a currency symbol.
3763 { return this->do_curr_symbol(); }
3766 * @brief Return positive sign string.
3768 * This function returns a string_type to use as a sign for positive
3769 * amounts. It does so by returning returning
3770 * moneypunct<char_type>::do_positive_sign().
3772 * If the return value contains more than one character, the first
3773 * character appears in the position indicated by pos_format() and the
3774 * remainder appear at the end of the formatted string.
3776 * @return @a string_type representing a positive sign.
3779 positive_sign() const
3780 { return this->do_positive_sign(); }
3783 * @brief Return negative sign string.
3785 * This function returns a string_type to use as a sign for negative
3786 * amounts. It does so by returning returning
3787 * moneypunct<char_type>::do_negative_sign().
3789 * If the return value contains more than one character, the first
3790 * character appears in the position indicated by neg_format() and the
3791 * remainder appear at the end of the formatted string.
3793 * @return @a string_type representing a negative sign.
3796 negative_sign() const
3797 { return this->do_negative_sign(); }
3800 * @brief Return number of digits in fraction.
3802 * This function returns the exact number of digits that make up the
3803 * fractional part of a money amount. It does so by returning
3804 * returning moneypunct<char_type>::do_frac_digits().
3806 * The fractional part of a money amount is optional. But if it is
3807 * present, there must be frac_digits() digits.
3809 * @return Number of digits in amount fraction.
3813 { return this->do_frac_digits(); }
3817 * @brief Return pattern for money values.
3819 * This function returns a pattern describing the formatting of a
3820 * positive or negative valued money amount. It does so by returning
3821 * returning moneypunct<char_type>::do_pos_format() or
3822 * moneypunct<char_type>::do_neg_format().
3824 * The pattern has 4 fields describing the ordering of symbol, sign,
3825 * value, and none or space. There must be one of each in the pattern.
3826 * The none and space enums may not appear in the first field and space
3827 * may not appear in the final field.
3829 * The parts of a money string must appear in the order indicated by
3830 * the fields of the pattern. The symbol field indicates that the
3831 * value of curr_symbol() may be present. The sign field indicates
3832 * that the value of positive_sign() or negative_sign() must be
3833 * present. The value field indicates that the absolute value of the
3834 * money amount is present. none indicates 0 or more whitespace
3835 * characters, except at the end, where it permits no whitespace.
3836 * space indicates that 1 or more whitespace characters must be
3839 * For example, for the US locale and pos_format() pattern
3840 * {symbol,sign,value,none}, curr_symbol() == '$' positive_sign() ==
3841 * '+', and value 10.01, and options set to force the symbol, the
3842 * corresponding string is "$+10.01".
3844 * @return Pattern for money values.
3848 { return this->do_pos_format(); }
3852 { return this->do_neg_format(); }
3861 * @brief Return decimal point character.
3863 * Returns a char_type to use as a decimal point. This function is a
3864 * hook for derived classes to change the value returned.
3866 * @return @a char_type representing a decimal point.
3869 do_decimal_point() const
3870 { return _M_data
->_M_decimal_point
; }
3873 * @brief Return thousands separator character.
3875 * Returns a char_type to use as a thousands separator. This function
3876 * is a hook for derived classes to change the value returned.
3878 * @return @a char_type representing a thousands separator.
3881 do_thousands_sep() const
3882 { return _M_data
->_M_thousands_sep
; }
3885 * @brief Return grouping specification.
3887 * Returns a string representing groupings for the integer part of a
3888 * number. This function is a hook for derived classes to change the
3889 * value returned. @see grouping() for details.
3891 * @return String representing grouping specification.
3895 { return _M_data
->_M_grouping
; }
3898 * @brief Return currency symbol string.
3900 * This function returns a string_type to use as a currency symbol.
3901 * This function is a hook for derived classes to change the value
3902 * returned. @see curr_symbol() for details.
3904 * @return @a string_type representing a currency symbol.
3907 do_curr_symbol() const
3908 { return _M_data
->_M_curr_symbol
; }
3911 * @brief Return positive sign string.
3913 * This function returns a string_type to use as a sign for positive
3914 * amounts. This function is a hook for derived classes to change the
3915 * value returned. @see positive_sign() for details.
3917 * @return @a string_type representing a positive sign.
3920 do_positive_sign() const
3921 { return _M_data
->_M_positive_sign
; }
3924 * @brief Return negative sign string.
3926 * This function returns a string_type to use as a sign for negative
3927 * amounts. This function is a hook for derived classes to change the
3928 * value returned. @see negative_sign() for details.
3930 * @return @a string_type representing a negative sign.
3933 do_negative_sign() const
3934 { return _M_data
->_M_negative_sign
; }
3937 * @brief Return number of digits in fraction.
3939 * This function returns the exact number of digits that make up the
3940 * fractional part of a money amount. This function is a hook for
3941 * derived classes to change the value returned. @see frac_digits()
3944 * @return Number of digits in amount fraction.
3947 do_frac_digits() const
3948 { return _M_data
->_M_frac_digits
; }
3951 * @brief Return pattern for money values.
3953 * This function returns a pattern describing the formatting of a
3954 * positive valued money amount. This function is a hook for derived
3955 * classes to change the value returned. @see pos_format() for
3958 * @return Pattern for money values.
3961 do_pos_format() const
3962 { return _M_data
->_M_pos_format
; }
3965 * @brief Return pattern for money values.
3967 * This function returns a pattern describing the formatting of a
3968 * negative valued money amount. This function is a hook for derived
3969 * classes to change the value returned. @see neg_format() for
3972 * @return Pattern for money values.
3975 do_neg_format() const
3976 { return _M_data
->_M_neg_format
; }
3978 // For use at construction time only.
3980 _M_initialize_moneypunct(__c_locale __cloc
= NULL
,
3981 const char* __name
= NULL
);
3984 template<typename _CharT
, bool _Intl
>
3985 locale::id moneypunct
<_CharT
, _Intl
>::id
;
3987 template<typename _CharT
, bool _Intl
>
3988 const bool moneypunct
<_CharT
, _Intl
>::intl
;
3991 moneypunct
<char, true>::~moneypunct();
3994 moneypunct
<char, false>::~moneypunct();
3998 moneypunct
<char, true>::_M_initialize_moneypunct(__c_locale
, const char*);
4002 moneypunct
<char, false>::_M_initialize_moneypunct(__c_locale
, const char*);
4004 #ifdef _GLIBCXX_USE_WCHAR_T
4006 moneypunct
<wchar_t, true>::~moneypunct();
4009 moneypunct
<wchar_t, false>::~moneypunct();
4013 moneypunct
<wchar_t, true>::_M_initialize_moneypunct(__c_locale
,
4018 moneypunct
<wchar_t, false>::_M_initialize_moneypunct(__c_locale
,
4022 /// @brief class moneypunct_byname [22.2.6.4].
4023 template<typename _CharT
, bool _Intl
>
4024 class moneypunct_byname
: public moneypunct
<_CharT
, _Intl
>
4027 typedef _CharT char_type
;
4028 typedef basic_string
<_CharT
> string_type
;
4030 static const bool intl
= _Intl
;
4033 moneypunct_byname(const char* __s
, size_t __refs
= 0)
4034 : moneypunct
<_CharT
, _Intl
>(__refs
)
4036 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
4039 this->_S_create_c_locale(__tmp
, __s
);
4040 this->_M_initialize_moneypunct(__tmp
);
4041 this->_S_destroy_c_locale(__tmp
);
4047 ~moneypunct_byname() { }
4050 template<typename _CharT
, bool _Intl
>
4051 const bool moneypunct_byname
<_CharT
, _Intl
>::intl
;
4053 _GLIBCXX_BEGIN_LDBL_NAMESPACE
4055 * @brief Facet for parsing monetary amounts.
4057 * This facet encapsulates the code to parse and return a monetary
4058 * amount from a string.
4060 * The money_get template uses protected virtual functions to
4061 * provide the actual results. The public accessors forward the
4062 * call to the virtual functions. These virtual functions are
4063 * hooks for developers to implement the behavior they require from
4064 * the money_get facet.
4066 template<typename _CharT
, typename _InIter
>
4067 class money_get
: public locale::facet
4073 typedef _CharT char_type
;
4074 typedef _InIter iter_type
;
4075 typedef basic_string
<_CharT
> string_type
;
4078 /// Numpunct facet id.
4079 static locale::id id
;
4082 * @brief Constructor performs initialization.
4084 * This is the constructor provided by the standard.
4086 * @param refs Passed to the base facet class.
4089 money_get(size_t __refs
= 0) : facet(__refs
) { }
4092 * @brief Read and parse a monetary value.
4094 * This function reads characters from @a s, interprets them as a
4095 * monetary value according to moneypunct and ctype facets retrieved
4096 * from io.getloc(), and returns the result in @a units as an integral
4097 * value moneypunct::frac_digits() * the actual amount. For example,
4098 * the string $10.01 in a US locale would store 1001 in @a units.
4100 * Any characters not part of a valid money amount are not consumed.
4102 * If a money value cannot be parsed from the input stream, sets
4103 * err=(err|io.failbit). If the stream is consumed before finishing
4104 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
4105 * unchanged if parsing fails.
4107 * This function works by returning the result of do_get().
4109 * @param s Start of characters to parse.
4110 * @param end End of characters to parse.
4111 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4112 * @param io Source of facets and io state.
4113 * @param err Error field to set if parsing fails.
4114 * @param units Place to store result of parsing.
4115 * @return Iterator referencing first character beyond valid money
4119 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4120 ios_base::iostate
& __err
, long double& __units
) const
4121 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __units
); }
4124 * @brief Read and parse a monetary value.
4126 * This function reads characters from @a s, interprets them as a
4127 * monetary value according to moneypunct and ctype facets retrieved
4128 * from io.getloc(), and returns the result in @a digits. For example,
4129 * the string $10.01 in a US locale would store "1001" in @a digits.
4131 * Any characters not part of a valid money amount are not consumed.
4133 * If a money value cannot be parsed from the input stream, sets
4134 * err=(err|io.failbit). If the stream is consumed before finishing
4135 * parsing, sets err=(err|io.failbit|io.eofbit).
4137 * This function works by returning the result of do_get().
4139 * @param s Start of characters to parse.
4140 * @param end End of characters to parse.
4141 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4142 * @param io Source of facets and io state.
4143 * @param err Error field to set if parsing fails.
4144 * @param digits Place to store result of parsing.
4145 * @return Iterator referencing first character beyond valid money
4149 get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4150 ios_base::iostate
& __err
, string_type
& __digits
) const
4151 { return this->do_get(__s
, __end
, __intl
, __io
, __err
, __digits
); }
4159 * @brief Read and parse a monetary value.
4161 * This function reads and parses characters representing a monetary
4162 * value. This function is a hook for derived classes to change the
4163 * value returned. @see get() for details.
4165 // XXX GLIBCXX_ABI Deprecated
4166 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4168 __do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4169 ios_base::iostate
& __err
, double& __units
) const;
4172 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4173 ios_base::iostate
& __err
, long double& __units
) const;
4177 * @brief Read and parse a monetary value.
4179 * This function reads and parses characters representing a monetary
4180 * value. This function is a hook for derived classes to change the
4181 * value returned. @see get() for details.
4184 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4185 ios_base::iostate
& __err
, string_type
& __digits
) const;
4187 // XXX GLIBCXX_ABI Deprecated
4188 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4190 do_get(iter_type __s
, iter_type __end
, bool __intl
, ios_base
& __io
,
4191 ios_base::iostate
& __err
, long double& __units
) const;
4194 template<bool _Intl
>
4196 _M_extract(iter_type __s
, iter_type __end
, ios_base
& __io
,
4197 ios_base::iostate
& __err
, string
& __digits
) const;
4200 template<typename _CharT
, typename _InIter
>
4201 locale::id money_get
<_CharT
, _InIter
>::id
;
4204 * @brief Facet for outputting monetary amounts.
4206 * This facet encapsulates the code to format and output a monetary
4209 * The money_put template uses protected virtual functions to
4210 * provide the actual results. The public accessors forward the
4211 * call to the virtual functions. These virtual functions are
4212 * hooks for developers to implement the behavior they require from
4213 * the money_put facet.
4215 template<typename _CharT
, typename _OutIter
>
4216 class money_put
: public locale::facet
4221 typedef _CharT char_type
;
4222 typedef _OutIter iter_type
;
4223 typedef basic_string
<_CharT
> string_type
;
4226 /// Numpunct facet id.
4227 static locale::id id
;
4230 * @brief Constructor performs initialization.
4232 * This is the constructor provided by the standard.
4234 * @param refs Passed to the base facet class.
4237 money_put(size_t __refs
= 0) : facet(__refs
) { }
4240 * @brief Format and output a monetary value.
4242 * This function formats @a units as a monetary value according to
4243 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4244 * the resulting characters to @a s. For example, the value 1001 in a
4245 * US locale would write "$10.01" to @a s.
4247 * This function works by returning the result of do_put().
4249 * @param s The stream to write to.
4250 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4251 * @param io Source of facets and io state.
4252 * @param fill char_type to use for padding.
4253 * @param units Place to store result of parsing.
4254 * @return Iterator after writing.
4257 put(iter_type __s
, bool __intl
, ios_base
& __io
,
4258 char_type __fill
, long double __units
) const
4259 { return this->do_put(__s
, __intl
, __io
, __fill
, __units
); }
4262 * @brief Format and output a monetary value.
4264 * This function formats @a digits as a monetary value according to
4265 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4266 * the resulting characters to @a s. For example, the string "1001" in
4267 * a US locale would write "$10.01" to @a s.
4269 * This function works by returning the result of do_put().
4271 * @param s The stream to write to.
4272 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4273 * @param io Source of facets and io state.
4274 * @param fill char_type to use for padding.
4275 * @param units Place to store result of parsing.
4276 * @return Iterator after writing.
4279 put(iter_type __s
, bool __intl
, ios_base
& __io
,
4280 char_type __fill
, const string_type
& __digits
) const
4281 { return this->do_put(__s
, __intl
, __io
, __fill
, __digits
); }
4289 * @brief Format and output a monetary value.
4291 * This function formats @a units as a monetary value according to
4292 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4293 * the resulting characters to @a s. For example, the value 1001 in a
4294 * US locale would write "$10.01" to @a s.
4296 * This function is a hook for derived classes to change the value
4297 * returned. @see put().
4299 * @param s The stream to write to.
4300 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4301 * @param io Source of facets and io state.
4302 * @param fill char_type to use for padding.
4303 * @param units Place to store result of parsing.
4304 * @return Iterator after writing.
4306 // XXX GLIBCXX_ABI Deprecated
4307 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4309 __do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4310 double __units
) const;
4313 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4314 long double __units
) const;
4318 * @brief Format and output a monetary value.
4320 * This function formats @a digits as a monetary value according to
4321 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4322 * the resulting characters to @a s. For example, the string "1001" in
4323 * a US locale would write "$10.01" to @a s.
4325 * This function is a hook for derived classes to change the value
4326 * returned. @see put().
4328 * @param s The stream to write to.
4329 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4330 * @param io Source of facets and io state.
4331 * @param fill char_type to use for padding.
4332 * @param units Place to store result of parsing.
4333 * @return Iterator after writing.
4336 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4337 const string_type
& __digits
) const;
4339 // XXX GLIBCXX_ABI Deprecated
4340 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4342 do_put(iter_type __s
, bool __intl
, ios_base
& __io
, char_type __fill
,
4343 long double __units
) const;
4346 template<bool _Intl
>
4348 _M_insert(iter_type __s
, ios_base
& __io
, char_type __fill
,
4349 const string_type
& __digits
) const;
4352 template<typename _CharT
, typename _OutIter
>
4353 locale::id money_put
<_CharT
, _OutIter
>::id
;
4355 _GLIBCXX_END_LDBL_NAMESPACE
4358 * @brief Messages facet base class providing catalog typedef.
4360 struct messages_base
4362 typedef int catalog
;
4366 * @brief Facet for handling message catalogs
4368 * This facet encapsulates the code to retrieve messages from
4369 * message catalogs. The only thing defined by the standard for this facet
4370 * is the interface. All underlying functionality is
4371 * implementation-defined.
4373 * This library currently implements 3 versions of the message facet. The
4374 * first version (gnu) is a wrapper around gettext, provided by libintl.
4375 * The second version (ieee) is a wrapper around catgets. The final
4376 * version (default) does no actual translation. These implementations are
4377 * only provided for char and wchar_t instantiations.
4379 * The messages template uses protected virtual functions to
4380 * provide the actual results. The public accessors forward the
4381 * call to the virtual functions. These virtual functions are
4382 * hooks for developers to implement the behavior they require from
4383 * the messages facet.
4385 template<typename _CharT
>
4386 class messages
: public locale::facet
, public messages_base
4392 typedef _CharT char_type
;
4393 typedef basic_string
<_CharT
> string_type
;
4397 // Underlying "C" library locale information saved from
4398 // initialization, needed by messages_byname as well.
4399 __c_locale _M_c_locale_messages
;
4400 const char* _M_name_messages
;
4403 /// Numpunct facet id.
4404 static locale::id id
;
4407 * @brief Constructor performs initialization.
4409 * This is the constructor provided by the standard.
4411 * @param refs Passed to the base facet class.
4414 messages(size_t __refs
= 0);
4418 * @brief Internal constructor. Not for general use.
4420 * This is a constructor for use by the library itself to set up new
4423 * @param cloc The "C" locale.
4424 * @param s The name of a locale.
4425 * @param refs Refcount to pass to the base class.
4428 messages(__c_locale __cloc
, const char* __s
, size_t __refs
= 0);
4431 * @brief Open a message catalog.
4433 * This function opens and returns a handle to a message catalog by
4434 * returning do_open(s, loc).
4436 * @param s The catalog to open.
4437 * @param loc Locale to use for character set conversions.
4438 * @return Handle to the catalog or value < 0 if open fails.
4441 open(const basic_string
<char>& __s
, const locale
& __loc
) const
4442 { return this->do_open(__s
, __loc
); }
4444 // Non-standard and unorthodox, yet effective.
4446 * @brief Open a message catalog.
4448 * This non-standard function opens and returns a handle to a message
4449 * catalog by returning do_open(s, loc). The third argument provides a
4450 * message catalog root directory for gnu gettext and is ignored
4453 * @param s The catalog to open.
4454 * @param loc Locale to use for character set conversions.
4455 * @param dir Message catalog root directory.
4456 * @return Handle to the catalog or value < 0 if open fails.
4459 open(const basic_string
<char>&, const locale
&, const char*) const;
4462 * @brief Look up a string in a message catalog.
4464 * This function retrieves and returns a message from a catalog by
4465 * returning do_get(c, set, msgid, s).
4467 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4468 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4470 * @param c The catalog to access.
4471 * @param set Implementation-defined.
4472 * @param msgid Implementation-defined.
4473 * @param s Default return value if retrieval fails.
4474 * @return Retrieved message or @a s if get fails.
4477 get(catalog __c
, int __set
, int __msgid
, const string_type
& __s
) const
4478 { return this->do_get(__c
, __set
, __msgid
, __s
); }
4481 * @brief Close a message catalog.
4483 * Closes catalog @a c by calling do_close(c).
4485 * @param c The catalog to close.
4488 close(catalog __c
) const
4489 { return this->do_close(__c
); }
4497 * @brief Open a message catalog.
4499 * This function opens and returns a handle to a message catalog in an
4500 * implementation-defined manner. This function is a hook for derived
4501 * classes to change the value returned.
4503 * @param s The catalog to open.
4504 * @param loc Locale to use for character set conversions.
4505 * @return Handle to the opened catalog, value < 0 if open failed.
4508 do_open(const basic_string
<char>&, const locale
&) const;
4511 * @brief Look up a string in a message catalog.
4513 * This function retrieves and returns a message from a catalog in an
4514 * implementation-defined manner. This function is a hook for derived
4515 * classes to change the value returned.
4517 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4518 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4520 * @param c The catalog to access.
4521 * @param set Implementation-defined.
4522 * @param msgid Implementation-defined.
4523 * @param s Default return value if retrieval fails.
4524 * @return Retrieved message or @a s if get fails.
4527 do_get(catalog
, int, int, const string_type
& __dfault
) const;
4530 * @brief Close a message catalog.
4532 * @param c The catalog to close.
4535 do_close(catalog
) const;
4537 // Returns a locale and codeset-converted string, given a char* message.
4539 _M_convert_to_char(const string_type
& __msg
) const
4542 return reinterpret_cast<char*>(const_cast<_CharT
*>(__msg
.c_str()));
4545 // Returns a locale and codeset-converted string, given a char* message.
4547 _M_convert_from_char(char*) const
4550 // Length of message string without terminating null.
4551 size_t __len
= char_traits
<char>::length(__msg
) - 1;
4553 // "everybody can easily convert the string using
4554 // mbsrtowcs/wcsrtombs or with iconv()"
4556 // Convert char* to _CharT in locale used to open catalog.
4557 // XXX need additional template parameter on messages class for this..
4558 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
4559 typedef typename codecvt
<char, _CharT
, mbstate_t> __codecvt_type
;
4561 __codecvt_type::state_type __state
;
4562 // XXX may need to initialize state.
4563 //initialize_state(__state._M_init());
4566 // XXX what size for this string?
4567 _CharT
* __to
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
4568 const __codecvt_type
& __cvt
= use_facet
<__codecvt_type
>(_M_locale_conv
);
4569 __cvt
.out(__state
, __msg
, __msg
+ __len
, __from_next
,
4570 __to
, __to
+ __len
+ 1, __to_next
);
4571 return string_type(__to
);
4574 typedef ctype
<_CharT
> __ctype_type
;
4575 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
4576 const __ctype_type
& __cvt
= use_facet
<__ctype_type
>(locale());
4577 // XXX Again, proper length of converted string an issue here.
4578 // For now, assume the converted length is not larger.
4579 _CharT
* __dest
= static_cast<_CharT
*>(__builtin_alloca(__len
+ 1));
4580 __cvt
.widen(__msg
, __msg
+ __len
, __dest
);
4581 return basic_string
<_CharT
>(__dest
);
4583 return string_type();
4587 template<typename _CharT
>
4588 locale::id messages
<_CharT
>::id
;
4590 // Specializations for required instantiations.
4593 messages
<char>::do_get(catalog
, int, int, const string
&) const;
4595 #ifdef _GLIBCXX_USE_WCHAR_T
4598 messages
<wchar_t>::do_get(catalog
, int, int, const wstring
&) const;
4601 /// @brief class messages_byname [22.2.7.2].
4602 template<typename _CharT
>
4603 class messages_byname
: public messages
<_CharT
>
4606 typedef _CharT char_type
;
4607 typedef basic_string
<_CharT
> string_type
;
4610 messages_byname(const char* __s
, size_t __refs
= 0);
4618 _GLIBCXX_END_NAMESPACE
4620 // Include host and configuration specific messages functions.
4621 #include <bits/messages_members.h>
4623 _GLIBCXX_BEGIN_NAMESPACE(std
)
4625 // Subclause convenience interfaces, inlines.
4626 // NB: These are inline because, when used in a loop, some compilers
4627 // can hoist the body out of the loop; then it's just as fast as the
4628 // C is*() function.
4630 /// Convenience interface to ctype.is(ctype_base::space, __c).
4631 template<typename _CharT
>
4633 isspace(_CharT __c
, const locale
& __loc
)
4634 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::space
, __c
); }
4636 /// Convenience interface to ctype.is(ctype_base::print, __c).
4637 template<typename _CharT
>
4639 isprint(_CharT __c
, const locale
& __loc
)
4640 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::print
, __c
); }
4642 /// Convenience interface to ctype.is(ctype_base::cntrl, __c).
4643 template<typename _CharT
>
4645 iscntrl(_CharT __c
, const locale
& __loc
)
4646 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::cntrl
, __c
); }
4648 /// Convenience interface to ctype.is(ctype_base::upper, __c).
4649 template<typename _CharT
>
4651 isupper(_CharT __c
, const locale
& __loc
)
4652 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::upper
, __c
); }
4654 /// Convenience interface to ctype.is(ctype_base::lower, __c).
4655 template<typename _CharT
>
4657 islower(_CharT __c
, const locale
& __loc
)
4658 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::lower
, __c
); }
4660 /// Convenience interface to ctype.is(ctype_base::alpha, __c).
4661 template<typename _CharT
>
4663 isalpha(_CharT __c
, const locale
& __loc
)
4664 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alpha
, __c
); }
4666 /// Convenience interface to ctype.is(ctype_base::digit, __c).
4667 template<typename _CharT
>
4669 isdigit(_CharT __c
, const locale
& __loc
)
4670 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::digit
, __c
); }
4672 /// Convenience interface to ctype.is(ctype_base::punct, __c).
4673 template<typename _CharT
>
4675 ispunct(_CharT __c
, const locale
& __loc
)
4676 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::punct
, __c
); }
4678 /// Convenience interface to ctype.is(ctype_base::xdigit, __c).
4679 template<typename _CharT
>
4681 isxdigit(_CharT __c
, const locale
& __loc
)
4682 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::xdigit
, __c
); }
4684 /// Convenience interface to ctype.is(ctype_base::alnum, __c).
4685 template<typename _CharT
>
4687 isalnum(_CharT __c
, const locale
& __loc
)
4688 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alnum
, __c
); }
4690 /// Convenience interface to ctype.is(ctype_base::graph, __c).
4691 template<typename _CharT
>
4693 isgraph(_CharT __c
, const locale
& __loc
)
4694 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::graph
, __c
); }
4696 /// Convenience interface to ctype.toupper(__c).
4697 template<typename _CharT
>
4699 toupper(_CharT __c
, const locale
& __loc
)
4700 { return use_facet
<ctype
<_CharT
> >(__loc
).toupper(__c
); }
4702 /// Convenience interface to ctype.tolower(__c).
4703 template<typename _CharT
>
4705 tolower(_CharT __c
, const locale
& __loc
)
4706 { return use_facet
<ctype
<_CharT
> >(__loc
).tolower(__c
); }
4708 _GLIBCXX_END_NAMESPACE