1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 22.1 Locales
35 /** @file locale_facets.h
36 * This is an internal header file, included by other library headers.
37 * You should not attempt to use it directly.
40 #ifndef _LOCALE_FACETS_H
41 #define _LOCALE_FACETS_H 1
43 #pragma GCC system_header
45 #include <ctime> // For struct tm
46 #include <cwctype> // For wctype_t
48 #include <bits/ios_base.h> // For ios_base, ios_base::iostate
53 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
54 #ifdef _GLIBCXX_USE_WCHAR_T
55 # define _GLIBCXX_NUM_FACETS 28
57 # define _GLIBCXX_NUM_FACETS 14
60 // Convert string to numeric value of type _Tv and store results.
61 // NB: This is specialized for all required types, there is no
62 // generic definition.
63 template<typename _Tv>
65 __convert_to_v(const char* __in, _Tv& __out, ios_base::iostate& __err,
66 const __c_locale& __cloc);
68 // Explicit specializations for required types.
71 __convert_to_v(const char*, float&, ios_base::iostate&,
76 __convert_to_v(const char*, double&, ios_base::iostate&,
81 __convert_to_v(const char*, long double&, ios_base::iostate&,
84 // NB: __pad is a struct, rather than a function, so it can be
85 // partially-specialized.
86 template<typename _CharT, typename _Traits>
90 _S_pad(ios_base& __io, _CharT __fill, _CharT* __news,
91 const _CharT* __olds, const streamsize __newlen,
92 const streamsize __oldlen, const bool __num);
95 // Used by both numeric and monetary facets.
96 // Inserts "group separator" characters into an array of characters.
97 // It's recursive, one iteration per group. It moves the characters
98 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
99 // only with __glen != 0.
100 template<typename _CharT>
102 __add_grouping(_CharT* __s, _CharT __sep,
103 const char* __gbeg, size_t __gsize,
104 const _CharT* __first, const _CharT* __last);
106 // This template permits specializing facet output code for
107 // ostreambuf_iterator. For ostreambuf_iterator, sputn is
108 // significantly more efficient than incrementing iterators.
109 template<typename _CharT>
111 ostreambuf_iterator<_CharT>
112 __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len)
114 __s._M_put(__ws, __len);
118 // This is the unspecialized form of the template.
119 template<typename _CharT, typename _OutIter>
122 __write(_OutIter __s, const _CharT* __ws, int __len)
124 for (int __j = 0; __j < __len; __j++, ++__s)
130 // 22.2.1.1 Template class ctype
131 // Include host and configuration specific ctype enums for ctype_base.
132 #include <bits/ctype_base.h>
134 // Common base for ctype<_CharT>.
136 * @brief Common base for ctype facet
138 * This template class provides implementations of the public functions
139 * that forward to the protected virtual functions.
141 * This template also provides abtract stubs for the protected virtual
144 template<typename _CharT>
145 class __ctype_abstract_base : public locale::facet, public ctype_base
149 /// Typedef for the template parameter
150 typedef _CharT char_type;
153 * @brief Test char_type classification.
155 * This function finds a mask M for @a c and compares it to mask @a m.
156 * It does so by returning the value of ctype<char_type>::do_is().
158 * @param c The char_type to compare the mask of.
159 * @param m The mask to compare against.
160 * @return (M & m) != 0.
163 is(mask __m, char_type __c) const
164 { return this->do_is(__m, __c); }
167 * @brief Return a mask array.
169 * This function finds the mask for each char_type in the range [lo,hi)
170 * and successively writes it to vec. vec must have as many elements
171 * as the char array. It does so by returning the value of
172 * ctype<char_type>::do_is().
174 * @param lo Pointer to start of range.
175 * @param hi Pointer to end of range.
176 * @param vec Pointer to an array of mask storage.
180 is(const char_type *__lo, const char_type *__hi, mask *__vec) const
181 { return this->do_is(__lo, __hi, __vec); }
184 * @brief Find char_type matching a mask
186 * This function searches for and returns the first char_type c in
187 * [lo,hi) for which is(m,c) is true. It does so by returning
188 * ctype<char_type>::do_scan_is().
190 * @param m The mask to compare against.
191 * @param lo Pointer to start of range.
192 * @param hi Pointer to end of range.
193 * @return Pointer to matching char_type if found, else @a hi.
196 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
197 { return this->do_scan_is(__m, __lo, __hi); }
200 * @brief Find char_type not matching a mask
202 * This function searches for and returns the first char_type c in
203 * [lo,hi) for which is(m,c) is false. It does so by returning
204 * ctype<char_type>::do_scan_not().
206 * @param m The mask to compare against.
207 * @param lo Pointer to first char in range.
208 * @param hi Pointer to end of range.
209 * @return Pointer to non-matching char if found, else @a hi.
212 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
213 { return this->do_scan_not(__m, __lo, __hi); }
216 * @brief Convert to uppercase.
218 * This function converts the argument to uppercase if possible.
219 * If not possible (for example, '2'), returns the argument. It does
220 * so by returning ctype<char_type>::do_toupper().
222 * @param c The char_type to convert.
223 * @return The uppercase char_type if convertible, else @a c.
226 toupper(char_type __c) const
227 { return this->do_toupper(__c); }
230 * @brief Convert array to uppercase.
232 * This function converts each char_type in the range [lo,hi) to
233 * uppercase if possible. Other elements remain untouched. It does so
234 * by returning ctype<char_type>:: do_toupper(lo, hi).
236 * @param lo Pointer to start of range.
237 * @param hi Pointer to end of range.
241 toupper(char_type *__lo, const char_type* __hi) const
242 { return this->do_toupper(__lo, __hi); }
245 * @brief Convert to lowercase.
247 * This function converts the argument to lowercase if possible. If
248 * not possible (for example, '2'), returns the argument. It does so
249 * by returning ctype<char_type>::do_tolower(c).
251 * @param c The char_type to convert.
252 * @return The lowercase char_type if convertible, else @a c.
255 tolower(char_type __c) const
256 { return this->do_tolower(__c); }
259 * @brief Convert array to lowercase.
261 * This function converts each char_type in the range [lo,hi) to
262 * lowercase if possible. Other elements remain untouched. It does so
263 * by returning ctype<char_type>:: do_tolower(lo, hi).
265 * @param lo Pointer to start of range.
266 * @param hi Pointer to end of range.
270 tolower(char_type* __lo, const char_type* __hi) const
271 { return this->do_tolower(__lo, __hi); }
274 * @brief Widen char to char_type
276 * This function converts the char argument to char_type using the
277 * simplest reasonable transformation. It does so by returning
278 * ctype<char_type>::do_widen(c).
280 * Note: this is not what you want for codepage conversions. See
283 * @param c The char to convert.
284 * @return The converted char_type.
287 widen(char __c) const
288 { return this->do_widen(__c); }
291 * @brief Widen array to char_type
293 * This function converts each char in the input to char_type using the
294 * simplest reasonable transformation. It does so by returning
295 * ctype<char_type>::do_widen(c).
297 * Note: this is not what you want for codepage conversions. See
300 * @param lo Pointer to start of range.
301 * @param hi Pointer to end of range.
302 * @param to Pointer to the destination array.
306 widen(const char* __lo, const char* __hi, char_type* __to) const
307 { return this->do_widen(__lo, __hi, __to); }
310 * @brief Narrow char_type to char
312 * This function converts the char_type to char using the simplest
313 * reasonable transformation. If the conversion fails, dfault is
314 * returned instead. It does so by returning
315 * ctype<char_type>::do_narrow(c).
317 * Note: this is not what you want for codepage conversions. See
320 * @param c The char_type to convert.
321 * @param dfault Char to return if conversion fails.
322 * @return The converted char.
325 narrow(char_type __c, char __dfault) const
326 { return this->do_narrow(__c, __dfault); }
329 * @brief Narrow array to char array
331 * This function converts each char_type in the input to char using the
332 * simplest reasonable transformation and writes the results to the
333 * destination array. For any char_type in the input that cannot be
334 * converted, @a dfault is used instead. It does so by returning
335 * ctype<char_type>::do_narrow(lo, hi, dfault, to).
337 * Note: this is not what you want for codepage conversions. See
340 * @param lo Pointer to start of range.
341 * @param hi Pointer to end of range.
342 * @param dfault Char to use if conversion fails.
343 * @param to Pointer to the destination array.
347 narrow(const char_type* __lo, const char_type* __hi,
348 char __dfault, char *__to) const
349 { return this->do_narrow(__lo, __hi, __dfault, __to); }
353 __ctype_abstract_base(size_t __refs = 0): facet(__refs) { }
356 ~__ctype_abstract_base() { }
359 * @brief Test char_type classification.
361 * This function finds a mask M for @a c and compares it to mask @a m.
363 * do_is() is a hook for a derived facet to change the behavior of
364 * classifying. do_is() must always return the same result for the
367 * @param c The char_type to find the mask of.
368 * @param m The mask to compare against.
369 * @return (M & m) != 0.
372 do_is(mask __m, char_type __c) const = 0;
375 * @brief Return a mask array.
377 * This function finds the mask for each char_type in the range [lo,hi)
378 * and successively writes it to vec. vec must have as many elements
381 * do_is() is a hook for a derived facet to change the behavior of
382 * classifying. do_is() must always return the same result for the
385 * @param lo Pointer to start of range.
386 * @param hi Pointer to end of range.
387 * @param vec Pointer to an array of mask storage.
390 virtual const char_type*
391 do_is(const char_type* __lo, const char_type* __hi,
392 mask* __vec) const = 0;
395 * @brief Find char_type matching mask
397 * This function searches for and returns the first char_type c in
398 * [lo,hi) for which is(m,c) is true.
400 * do_scan_is() is a hook for a derived facet to change the behavior of
401 * match searching. do_is() must always return the same result for the
404 * @param m The mask to compare against.
405 * @param lo Pointer to start of range.
406 * @param hi Pointer to end of range.
407 * @return Pointer to a matching char_type if found, else @a hi.
409 virtual const char_type*
410 do_scan_is(mask __m, const char_type* __lo,
411 const char_type* __hi) const = 0;
414 * @brief Find char_type not matching mask
416 * This function searches for and returns a pointer to the first
417 * char_type c of [lo,hi) for which is(m,c) is false.
419 * do_scan_is() is a hook for a derived facet to change the behavior of
420 * match searching. do_is() must always return the same result for the
423 * @param m The mask to compare against.
424 * @param lo Pointer to start of range.
425 * @param hi Pointer to end of range.
426 * @return Pointer to a non-matching char_type if found, else @a hi.
428 virtual const char_type*
429 do_scan_not(mask __m, const char_type* __lo,
430 const char_type* __hi) const = 0;
433 * @brief Convert to uppercase.
435 * This virtual function converts the char_type argument to uppercase
436 * if possible. If not possible (for example, '2'), returns the
439 * do_toupper() is a hook for a derived facet to change the behavior of
440 * uppercasing. do_toupper() must always return the same result for
443 * @param c The char_type to convert.
444 * @return The uppercase char_type if convertible, else @a c.
447 do_toupper(char_type) const = 0;
450 * @brief Convert array to uppercase.
452 * This virtual function converts each char_type in the range [lo,hi)
453 * to uppercase if possible. Other elements remain untouched.
455 * do_toupper() is a hook for a derived facet to change the behavior of
456 * uppercasing. do_toupper() must always return the same result for
459 * @param lo Pointer to start of range.
460 * @param hi Pointer to end of range.
463 virtual const char_type*
464 do_toupper(char_type* __lo, const char_type* __hi) const = 0;
467 * @brief Convert to lowercase.
469 * This virtual function converts the argument to lowercase if
470 * possible. If not possible (for example, '2'), returns the argument.
472 * do_tolower() is a hook for a derived facet to change the behavior of
473 * lowercasing. do_tolower() must always return the same result for
476 * @param c The char_type to convert.
477 * @return The lowercase char_type if convertible, else @a c.
480 do_tolower(char_type) const = 0;
483 * @brief Convert array to lowercase.
485 * This virtual function converts each char_type in the range [lo,hi)
486 * to lowercase if possible. Other elements remain untouched.
488 * do_tolower() is a hook for a derived facet to change the behavior of
489 * lowercasing. do_tolower() must always return the same result for
492 * @param lo Pointer to start of range.
493 * @param hi Pointer to end of range.
496 virtual const char_type*
497 do_tolower(char_type* __lo, const char_type* __hi) const = 0;
502 * This virtual function converts the char to char_type using the
503 * simplest reasonable transformation.
505 * do_widen() is a hook for a derived facet to change the behavior of
506 * widening. do_widen() must always return the same result for the
509 * Note: this is not what you want for codepage conversions. See
512 * @param c The char to convert.
513 * @return The converted char_type
516 do_widen(char) const = 0;
519 * @brief Widen char array
521 * This function converts each char in the input to char_type using the
522 * simplest reasonable transformation.
524 * do_widen() is a hook for a derived facet to change the behavior of
525 * widening. do_widen() must always return the same result for the
528 * Note: this is not what you want for codepage conversions. See
531 * @param lo Pointer to start range.
532 * @param hi Pointer to end of range.
533 * @param to Pointer to the destination array.
537 do_widen(const char* __lo, const char* __hi,
538 char_type* __dest) const = 0;
541 * @brief Narrow char_type to char
543 * This virtual function converts the argument to char using the
544 * simplest reasonable transformation. If the conversion fails, dfault
545 * is returned instead.
547 * do_narrow() is a hook for a derived facet to change the behavior of
548 * narrowing. do_narrow() must always return the same result for the
551 * Note: this is not what you want for codepage conversions. See
554 * @param c The char_type to convert.
555 * @param dfault Char to return if conversion fails.
556 * @return The converted char.
559 do_narrow(char_type, char __dfault) const = 0;
562 * @brief Narrow char_type array to char
564 * This virtual function converts each char_type in the range [lo,hi) to
565 * char using the simplest reasonable transformation and writes the
566 * results to the destination array. For any element in the input that
567 * cannot be converted, @a dfault is used instead.
569 * do_narrow() is a hook for a derived facet to change the behavior of
570 * narrowing. do_narrow() must always return the same result for the
573 * Note: this is not what you want for codepage conversions. See
576 * @param lo Pointer to start of range.
577 * @param hi Pointer to end of range.
578 * @param dfault Char to use if conversion fails.
579 * @param to Pointer to the destination array.
582 virtual const char_type*
583 do_narrow(const char_type* __lo, const char_type* __hi,
584 char __dfault, char* __dest) const = 0;
587 // NB: Generic, mostly useless implementation.
589 * @brief Template ctype facet
591 * This template class defines classification and conversion functions for
592 * character sets. It wraps <cctype> functionality. Ctype gets used by
593 * streams for many I/O operations.
595 * This template provides the protected virtual functions the developer
596 * will have to replace in a derived class or specialization to make a
597 * working facet. The public functions that access them are defined in
598 * __ctype_abstract_base, to allow for implementation flexibility. See
599 * ctype<wchar_t> for an example. The functions are documented in
600 * __ctype_abstract_base.
602 * Note: implementations are provided for all the protected virtual
603 * functions, but will likely not be useful.
605 template<typename _CharT>
606 class ctype : public __ctype_abstract_base<_CharT>
610 typedef _CharT char_type;
611 typedef typename __ctype_abstract_base<_CharT>::mask mask;
613 /// The facet id for ctype<char_type>
614 static locale::id id;
617 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
624 do_is(mask __m, char_type __c) const;
626 virtual const char_type*
627 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
629 virtual const char_type*
630 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
632 virtual const char_type*
633 do_scan_not(mask __m, const char_type* __lo,
634 const char_type* __hi) const;
637 do_toupper(char_type __c) const;
639 virtual const char_type*
640 do_toupper(char_type* __lo, const char_type* __hi) const;
643 do_tolower(char_type __c) const;
645 virtual const char_type*
646 do_tolower(char_type* __lo, const char_type* __hi) const;
649 do_widen(char __c) const;
652 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
655 do_narrow(char_type, char __dfault) const;
657 virtual const char_type*
658 do_narrow(const char_type* __lo, const char_type* __hi,
659 char __dfault, char* __dest) const;
662 template<typename _CharT>
663 locale::id ctype<_CharT>::id;
665 // 22.2.1.3 ctype<char> specialization.
667 * @brief The ctype<char> specialization.
669 * This class defines classification and conversion functions for
670 * the char type. It gets used by char streams for many I/O
671 * operations. The char specialization provides a number of
672 * optimizations as well.
675 class ctype<char> : public locale::facet, public ctype_base
679 /// Typedef for the template parameter char.
680 typedef char char_type;
684 __c_locale _M_c_locale_ctype;
686 __to_type _M_toupper;
687 __to_type _M_tolower;
688 const mask* _M_table;
689 mutable char _M_widen_ok;
690 mutable char _M_widen[1 + static_cast<unsigned char>(-1)];
691 mutable char _M_narrow[1 + static_cast<unsigned char>(-1)];
692 mutable char _M_narrow_ok; // 0 uninitialized, 1 init,
693 // 2 memcpy can't be used
696 /// The facet id for ctype<char>
697 static locale::id id;
698 /// The size of the mask table. It is SCHAR_MAX + 1.
699 static const size_t table_size = 1 + static_cast<unsigned char>(-1);
702 * @brief Constructor performs initialization.
704 * This is the constructor provided by the standard.
706 * @param table If non-zero, table is used as the per-char mask.
707 * Else classic_table() is used.
708 * @param del If true, passes ownership of table to this facet.
709 * @param refs Passed to the base facet class.
712 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
715 * @brief Constructor performs static initialization.
717 * This constructor is used to construct the initial C locale facet.
719 * @param cloc Handle to C locale data.
720 * @param table If non-zero, table is used as the per-char mask.
721 * @param del If true, passes ownership of table to this facet.
722 * @param refs Passed to the base facet class.
725 ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
729 * @brief Test char classification.
731 * This function compares the mask table[c] to @a m.
733 * @param c The char to compare the mask of.
734 * @param m The mask to compare against.
735 * @return True if m & table[c] is true, false otherwise.
738 is(mask __m, char __c) const;
741 * @brief Return a mask array.
743 * This function finds the mask for each char in the range [lo, hi) and
744 * successively writes it to vec. vec must have as many elements as
747 * @param lo Pointer to start of range.
748 * @param hi Pointer to end of range.
749 * @param vec Pointer to an array of mask storage.
753 is(const char* __lo, const char* __hi, mask* __vec) const;
756 * @brief Find char matching a mask
758 * This function searches for and returns the first char in [lo,hi) for
759 * which is(m,char) is true.
761 * @param m The mask to compare against.
762 * @param lo Pointer to start of range.
763 * @param hi Pointer to end of range.
764 * @return Pointer to a matching char if found, else @a hi.
767 scan_is(mask __m, const char* __lo, const char* __hi) const;
770 * @brief Find char not matching a mask
772 * This function searches for and returns a pointer to the first char
773 * in [lo,hi) for which is(m,char) is false.
775 * @param m The mask to compare against.
776 * @param lo Pointer to start of range.
777 * @param hi Pointer to end of range.
778 * @return Pointer to a non-matching char if found, else @a hi.
781 scan_not(mask __m, const char* __lo, const char* __hi) const;
784 * @brief Convert to uppercase.
786 * This function converts the char argument to uppercase if possible.
787 * If not possible (for example, '2'), returns the argument.
789 * toupper() acts as if it returns ctype<char>::do_toupper(c).
790 * do_toupper() must always return the same result for the same input.
792 * @param c The char to convert.
793 * @return The uppercase char if convertible, else @a c.
796 toupper(char_type __c) const
797 { return this->do_toupper(__c); }
800 * @brief Convert array to uppercase.
802 * This function converts each char in the range [lo,hi) to uppercase
803 * if possible. Other chars remain untouched.
805 * toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi).
806 * do_toupper() must always return the same result for the same input.
808 * @param lo Pointer to first char in range.
809 * @param hi Pointer to end of range.
813 toupper(char_type *__lo, const char_type* __hi) const
814 { return this->do_toupper(__lo, __hi); }
817 * @brief Convert to lowercase.
819 * This function converts the char argument to lowercase if possible.
820 * If not possible (for example, '2'), returns the argument.
822 * tolower() acts as if it returns ctype<char>::do_tolower(c).
823 * do_tolower() must always return the same result for the same input.
825 * @param c The char to convert.
826 * @return The lowercase char if convertible, else @a c.
829 tolower(char_type __c) const
830 { return this->do_tolower(__c); }
833 * @brief Convert array to lowercase.
835 * This function converts each char in the range [lo,hi) to lowercase
836 * if possible. Other chars remain untouched.
838 * tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi).
839 * do_tolower() must always return the same result for the same input.
841 * @param lo Pointer to first char in range.
842 * @param hi Pointer to end of range.
846 tolower(char_type* __lo, const char_type* __hi) const
847 { return this->do_tolower(__lo, __hi); }
852 * This function converts the char to char_type using the simplest
853 * reasonable transformation. For an underived ctype<char> facet, the
854 * argument will be returned unchanged.
856 * This function works as if it returns ctype<char>::do_widen(c).
857 * do_widen() must always return the same result for the same input.
859 * Note: this is not what you want for codepage conversions. See
862 * @param c The char to convert.
863 * @return The converted character.
866 widen(char __c) const
869 return _M_widen[static_cast<unsigned char>(__c)];
870 this->_M_widen_init();
871 return this->do_widen(__c);
875 * @brief Widen char array
877 * This function converts each char in the input to char using the
878 * simplest reasonable transformation. For an underived ctype<char>
879 * facet, the argument will be copied unchanged.
881 * This function works as if it returns ctype<char>::do_widen(c).
882 * do_widen() must always return the same result for the same input.
884 * Note: this is not what you want for codepage conversions. See
887 * @param lo Pointer to first char in range.
888 * @param hi Pointer to end of range.
889 * @param to Pointer to the destination array.
893 widen(const char* __lo, const char* __hi, char_type* __to) const
895 if (_M_widen_ok == 1)
897 memcpy(__to, __lo, __hi - __lo);
902 return this->do_widen(__lo, __hi, __to);
908 * This function converts the char to char using the simplest
909 * reasonable transformation. If the conversion fails, dfault is
910 * returned instead. For an underived ctype<char> facet, @a c
911 * will be returned unchanged.
913 * This function works as if it returns ctype<char>::do_narrow(c).
914 * do_narrow() must always return the same result for the same input.
916 * Note: this is not what you want for codepage conversions. See
919 * @param c The char to convert.
920 * @param dfault Char to return if conversion fails.
921 * @return The converted character.
924 narrow(char_type __c, char __dfault) const
926 if (_M_narrow[static_cast<unsigned char>(__c)])
927 return _M_narrow[static_cast<unsigned char>(__c)];
928 const char __t = do_narrow(__c, __dfault);
930 _M_narrow[static_cast<unsigned char>(__c)] = __t;
935 * @brief Narrow char array
937 * This function converts each char in the input to char using the
938 * simplest reasonable transformation and writes the results to the
939 * destination array. For any char in the input that cannot be
940 * converted, @a dfault is used instead. For an underived ctype<char>
941 * facet, the argument will be copied unchanged.
943 * This function works as if it returns ctype<char>::do_narrow(lo, hi,
944 * dfault, to). do_narrow() must always return the same result for the
947 * Note: this is not what you want for codepage conversions. See
950 * @param lo Pointer to start of range.
951 * @param hi Pointer to end of range.
952 * @param dfault Char to use if conversion fails.
953 * @param to Pointer to the destination array.
957 narrow(const char_type* __lo, const char_type* __hi,
958 char __dfault, char *__to) const
960 if (__builtin_expect(_M_narrow_ok == 1, true))
962 memcpy(__to, __lo, __hi - __lo);
967 return this->do_narrow(__lo, __hi, __dfault, __to);
971 /// Returns a pointer to the mask table provided to the constructor, or
972 /// the default from classic_table() if none was provided.
974 table() const throw()
977 /// Returns a pointer to the C locale mask table.
979 classic_table() throw();
984 * This function deletes table() if @a del was true in the
991 * @brief Convert to uppercase.
993 * This virtual function converts the char argument to uppercase if
994 * possible. If not possible (for example, '2'), returns the argument.
996 * do_toupper() is a hook for a derived facet to change the behavior of
997 * uppercasing. do_toupper() must always return the same result for
1000 * @param c The char to convert.
1001 * @return The uppercase char if convertible, else @a c.
1004 do_toupper(char_type) const;
1007 * @brief Convert array to uppercase.
1009 * This virtual function converts each char in the range [lo,hi) to
1010 * uppercase if possible. Other chars remain untouched.
1012 * do_toupper() is a hook for a derived facet to change the behavior of
1013 * uppercasing. do_toupper() must always return the same result for
1016 * @param lo Pointer to start of range.
1017 * @param hi Pointer to end of range.
1020 virtual const char_type*
1021 do_toupper(char_type* __lo, const char_type* __hi) const;
1024 * @brief Convert to lowercase.
1026 * This virtual function converts the char argument to lowercase if
1027 * possible. If not possible (for example, '2'), returns the argument.
1029 * do_tolower() is a hook for a derived facet to change the behavior of
1030 * lowercasing. do_tolower() must always return the same result for
1033 * @param c The char to convert.
1034 * @return The lowercase char if convertible, else @a c.
1037 do_tolower(char_type) const;
1040 * @brief Convert array to lowercase.
1042 * This virtual function converts each char in the range [lo,hi) to
1043 * lowercase if possible. Other chars remain untouched.
1045 * do_tolower() is a hook for a derived facet to change the behavior of
1046 * lowercasing. do_tolower() must always return the same result for
1049 * @param lo Pointer to first char in range.
1050 * @param hi Pointer to end of range.
1053 virtual const char_type*
1054 do_tolower(char_type* __lo, const char_type* __hi) const;
1059 * This virtual function converts the char to char using the simplest
1060 * reasonable transformation. For an underived ctype<char> facet, the
1061 * argument will be returned unchanged.
1063 * do_widen() is a hook for a derived facet to change the behavior of
1064 * widening. do_widen() must always return the same result for the
1067 * Note: this is not what you want for codepage conversions. See
1070 * @param c The char to convert.
1071 * @return The converted character.
1074 do_widen(char __c) const
1078 * @brief Widen char array
1080 * This function converts each char in the range [lo,hi) to char using
1081 * the simplest reasonable transformation. For an underived
1082 * ctype<char> facet, the argument will be copied unchanged.
1084 * do_widen() is a hook for a derived facet to change the behavior of
1085 * widening. do_widen() must always return the same result for the
1088 * Note: this is not what you want for codepage conversions. See
1091 * @param lo Pointer to start of range.
1092 * @param hi Pointer to end of range.
1093 * @param to Pointer to the destination array.
1097 do_widen(const char* __lo, const char* __hi, char_type* __dest) const
1099 memcpy(__dest, __lo, __hi - __lo);
1104 * @brief Narrow char
1106 * This virtual function converts the char to char using the simplest
1107 * reasonable transformation. If the conversion fails, dfault is
1108 * returned instead. For an underived ctype<char> facet, @a c will be
1109 * returned unchanged.
1111 * do_narrow() is a hook for a derived facet to change the behavior of
1112 * narrowing. do_narrow() must always return the same result for the
1115 * Note: this is not what you want for codepage conversions. See
1118 * @param c The char to convert.
1119 * @param dfault Char to return if conversion fails.
1120 * @return The converted char.
1123 do_narrow(char_type __c, char) const
1127 * @brief Narrow char array to char array
1129 * This virtual function converts each char in the range [lo,hi) to
1130 * char using the simplest reasonable transformation and writes the
1131 * results to the destination array. For any char in the input that
1132 * cannot be converted, @a dfault is used instead. For an underived
1133 * ctype<char> facet, the argument will be copied unchanged.
1135 * do_narrow() is a hook for a derived facet to change the behavior of
1136 * narrowing. do_narrow() must always return the same result for the
1139 * Note: this is not what you want for codepage conversions. See
1142 * @param lo Pointer to start of range.
1143 * @param hi Pointer to end of range.
1144 * @param dfault Char to use if conversion fails.
1145 * @param to Pointer to the destination array.
1148 virtual const char_type*
1149 do_narrow(const char_type* __lo, const char_type* __hi,
1150 char, char* __dest) const
1152 memcpy(__dest, __lo, __hi - __lo);
1158 void _M_widen_init() const
1160 char __tmp[sizeof(_M_widen)];
1161 for (size_t __i = 0; __i < sizeof(_M_widen); ++__i)
1163 do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen);
1166 // Set _M_widen_ok to 2 if memcpy can't be used.
1167 if (memcmp(__tmp, _M_widen, sizeof(_M_widen)))
1171 // Fill in the narrowing cache and flag whether all values are
1172 // valid or not. _M_narrow_ok is set to 2 if memcpy can't
1174 void _M_narrow_init() const
1176 char __tmp[sizeof(_M_narrow)];
1177 for (size_t __i = 0; __i < sizeof(_M_narrow); ++__i)
1179 do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow);
1182 if (memcmp(__tmp, _M_narrow, sizeof(_M_narrow)))
1186 // Deal with the special case of zero: renarrow with a
1187 // different default and compare.
1189 do_narrow(__tmp, __tmp + 1, 1, &__c);
1198 use_facet<ctype<char> >(const locale& __loc);
1200 #ifdef _GLIBCXX_USE_WCHAR_T
1201 // 22.2.1.3 ctype<wchar_t> specialization
1203 * @brief The ctype<wchar_t> specialization.
1205 * This class defines classification and conversion functions for the
1206 * wchar_t type. It gets used by wchar_t streams for many I/O operations.
1207 * The wchar_t specialization provides a number of optimizations as well.
1209 * ctype<wchar_t> inherits its public methods from
1210 * __ctype_abstract_base<wchar_t>.
1213 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
1217 /// Typedef for the template parameter wchar_t.
1218 typedef wchar_t char_type;
1219 typedef wctype_t __wmask_type;
1222 __c_locale _M_c_locale_ctype;
1224 // Pre-computed narrowed and widened chars.
1226 char _M_narrow[128];
1227 wint_t _M_widen[1 + static_cast<unsigned char>(-1)];
1229 // Pre-computed elements for do_is.
1231 __wmask_type _M_wmask[16];
1235 /// The facet id for ctype<wchar_t>
1236 static locale::id id;
1239 * @brief Constructor performs initialization.
1241 * This is the constructor provided by the standard.
1243 * @param refs Passed to the base facet class.
1246 ctype(size_t __refs = 0);
1249 * @brief Constructor performs static initialization.
1251 * This constructor is used to construct the initial C locale facet.
1253 * @param cloc Handle to C locale data.
1254 * @param refs Passed to the base facet class.
1257 ctype(__c_locale __cloc, size_t __refs = 0);
1261 _M_convert_to_wmask(const mask __m) const;
1268 * @brief Test wchar_t classification.
1270 * This function finds a mask M for @a c and compares it to mask @a m.
1272 * do_is() is a hook for a derived facet to change the behavior of
1273 * classifying. do_is() must always return the same result for the
1276 * @param c The wchar_t to find the mask of.
1277 * @param m The mask to compare against.
1278 * @return (M & m) != 0.
1281 do_is(mask __m, char_type __c) const;
1284 * @brief Return a mask array.
1286 * This function finds the mask for each wchar_t in the range [lo,hi)
1287 * and successively writes it to vec. vec must have as many elements
1290 * do_is() is a hook for a derived facet to change the behavior of
1291 * classifying. do_is() must always return the same result for the
1294 * @param lo Pointer to start of range.
1295 * @param hi Pointer to end of range.
1296 * @param vec Pointer to an array of mask storage.
1299 virtual const char_type*
1300 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
1303 * @brief Find wchar_t matching mask
1305 * This function searches for and returns the first wchar_t c in
1306 * [lo,hi) for which is(m,c) is true.
1308 * do_scan_is() is a hook for a derived facet to change the behavior of
1309 * match searching. do_is() must always return the same result for the
1312 * @param m The mask to compare against.
1313 * @param lo Pointer to start of range.
1314 * @param hi Pointer to end of range.
1315 * @return Pointer to a matching wchar_t if found, else @a hi.
1317 virtual const char_type*
1318 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
1321 * @brief Find wchar_t not matching mask
1323 * This function searches for and returns a pointer to the first
1324 * wchar_t c of [lo,hi) for which is(m,c) is false.
1326 * do_scan_is() is a hook for a derived facet to change the behavior of
1327 * match searching. do_is() must always return the same result for the
1330 * @param m The mask to compare against.
1331 * @param lo Pointer to start of range.
1332 * @param hi Pointer to end of range.
1333 * @return Pointer to a non-matching wchar_t if found, else @a hi.
1335 virtual const char_type*
1336 do_scan_not(mask __m, const char_type* __lo,
1337 const char_type* __hi) const;
1340 * @brief Convert to uppercase.
1342 * This virtual function converts the wchar_t argument to uppercase if
1343 * possible. If not possible (for example, '2'), returns the argument.
1345 * do_toupper() is a hook for a derived facet to change the behavior of
1346 * uppercasing. do_toupper() must always return the same result for
1349 * @param c The wchar_t to convert.
1350 * @return The uppercase wchar_t if convertible, else @a c.
1353 do_toupper(char_type) const;
1356 * @brief Convert array to uppercase.
1358 * This virtual function converts each wchar_t in the range [lo,hi) to
1359 * uppercase if possible. Other elements remain untouched.
1361 * do_toupper() is a hook for a derived facet to change the behavior of
1362 * uppercasing. do_toupper() must always return the same result for
1365 * @param lo Pointer to start of range.
1366 * @param hi Pointer to end of range.
1369 virtual const char_type*
1370 do_toupper(char_type* __lo, const char_type* __hi) const;
1373 * @brief Convert to lowercase.
1375 * This virtual function converts the argument to lowercase if
1376 * possible. If not possible (for example, '2'), returns the argument.
1378 * do_tolower() is a hook for a derived facet to change the behavior of
1379 * lowercasing. do_tolower() must always return the same result for
1382 * @param c The wchar_t to convert.
1383 * @return The lowercase wchar_t if convertible, else @a c.
1386 do_tolower(char_type) const;
1389 * @brief Convert array to lowercase.
1391 * This virtual function converts each wchar_t in the range [lo,hi) to
1392 * lowercase if possible. Other elements remain untouched.
1394 * do_tolower() is a hook for a derived facet to change the behavior of
1395 * lowercasing. do_tolower() must always return the same result for
1398 * @param lo Pointer to start of range.
1399 * @param hi Pointer to end of range.
1402 virtual const char_type*
1403 do_tolower(char_type* __lo, const char_type* __hi) const;
1406 * @brief Widen char to wchar_t
1408 * This virtual function converts the char to wchar_t using the
1409 * simplest reasonable transformation. For an underived ctype<wchar_t>
1410 * facet, the argument will be cast to wchar_t.
1412 * do_widen() is a hook for a derived facet to change the behavior of
1413 * widening. do_widen() must always return the same result for the
1416 * Note: this is not what you want for codepage conversions. See
1419 * @param c The char to convert.
1420 * @return The converted wchar_t.
1423 do_widen(char) const;
1426 * @brief Widen char array to wchar_t array
1428 * This function converts each char in the input to wchar_t using the
1429 * simplest reasonable transformation. For an underived ctype<wchar_t>
1430 * facet, the argument will be copied, casting each element to wchar_t.
1432 * do_widen() is a hook for a derived facet to change the behavior of
1433 * widening. do_widen() must always return the same result for the
1436 * Note: this is not what you want for codepage conversions. See
1439 * @param lo Pointer to start range.
1440 * @param hi Pointer to end of range.
1441 * @param to Pointer to the destination array.
1445 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
1448 * @brief Narrow wchar_t to char
1450 * This virtual function converts the argument to char using
1451 * the simplest reasonable transformation. If the conversion
1452 * fails, dfault is returned instead. For an underived
1453 * ctype<wchar_t> facet, @a c will be cast to char and
1456 * do_narrow() is a hook for a derived facet to change the
1457 * behavior of narrowing. do_narrow() must always return the
1458 * same result for the same input.
1460 * Note: this is not what you want for codepage conversions. See
1463 * @param c The wchar_t to convert.
1464 * @param dfault Char to return if conversion fails.
1465 * @return The converted char.
1468 do_narrow(char_type, char __dfault) const;
1471 * @brief Narrow wchar_t array to char array
1473 * This virtual function converts each wchar_t in the range [lo,hi) to
1474 * char using the simplest reasonable transformation and writes the
1475 * results to the destination array. For any wchar_t in the input that
1476 * cannot be converted, @a dfault is used instead. For an underived
1477 * ctype<wchar_t> facet, the argument will be copied, casting each
1480 * do_narrow() is a hook for a derived facet to change the behavior of
1481 * narrowing. do_narrow() must always return the same result for the
1484 * Note: this is not what you want for codepage conversions. See
1487 * @param lo Pointer to start of range.
1488 * @param hi Pointer to end of range.
1489 * @param dfault Char to use if conversion fails.
1490 * @param to Pointer to the destination array.
1493 virtual const char_type*
1494 do_narrow(const char_type* __lo, const char_type* __hi,
1495 char __dfault, char* __dest) const;
1497 // For use at construction time only.
1499 _M_initialize_ctype();
1503 const ctype<wchar_t>&
1504 use_facet<ctype<wchar_t> >(const locale& __loc);
1505 #endif //_GLIBCXX_USE_WCHAR_T
1507 // Include host and configuration specific ctype inlines.
1508 #include <bits/ctype_inline.h>
1510 // 22.2.1.2 Template class ctype_byname
1511 template<typename _CharT>
1512 class ctype_byname : public ctype<_CharT>
1515 typedef _CharT char_type;
1518 ctype_byname(const char* __s, size_t __refs = 0);
1522 ~ctype_byname() { };
1525 // 22.2.1.4 Class ctype_byname specializations.
1527 ctype_byname<char>::ctype_byname(const char*, size_t refs);
1530 ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs);
1532 // 22.2.1.5 Template class codecvt
1533 #include <bits/codecvt.h>
1535 // 22.2.2 The numeric category.
1539 // NB: Code depends on the order of _S_atoms_out elements.
1540 // Below are the indices into _S_atoms_out.
1548 _S_odigits_end = _S_odigits + 16,
1549 _S_oudigits = _S_odigits_end,
1550 _S_oudigits_end = _S_oudigits + 16,
1551 _S_oe = _S_odigits + 14, // For scientific notation, 'e'
1552 _S_oE = _S_oudigits + 14, // For scientific notation, 'E'
1553 _S_oend = _S_oudigits_end
1556 // A list of valid numeric literals for output. This array
1557 // contains chars that will be passed through the current locale's
1558 // ctype<_CharT>.widen() and then used to render numbers.
1559 // For the standard "C" locale, this is
1560 // "-+xX0123456789abcdef0123456789ABCDEF".
1561 static const char* _S_atoms_out;
1563 // String literal of acceptable (narrow) input, for num_get.
1564 // "-+xX0123456789abcdefABCDEF"
1565 static const char* _S_atoms_in;
1574 _S_ie = _S_izero + 14,
1575 _S_iE = _S_izero + 20,
1580 // Construct and return valid scanf format for floating point types.
1582 _S_format_float(const ios_base& __io, char* __fptr, char __mod);
1585 template<typename _CharT>
1586 struct __numpunct_cache : public locale::facet
1588 const char* _M_grouping;
1589 size_t _M_grouping_size;
1590 bool _M_use_grouping;
1591 const _CharT* _M_truename;
1592 size_t _M_truename_size;
1593 const _CharT* _M_falsename;
1594 size_t _M_falsename_size;
1595 _CharT _M_decimal_point;
1596 _CharT _M_thousands_sep;
1598 // A list of valid numeric literals for output: in the standard
1599 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1600 // This array contains the chars after having been passed
1601 // through the current locale's ctype<_CharT>.widen().
1602 _CharT _M_atoms_out[__num_base::_S_oend];
1604 // A list of valid numeric literals for input: in the standard
1605 // "C" locale, this is "-+xX0123456789abcdefABCDEF"
1606 // This array contains the chars after having been passed
1607 // through the current locale's ctype<_CharT>.widen().
1608 _CharT _M_atoms_in[__num_base::_S_iend];
1612 __numpunct_cache(size_t __refs = 0) : facet(__refs),
1613 _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
1614 _M_truename(NULL), _M_truename_size(0), _M_falsename(NULL),
1615 _M_falsename_size(0), _M_decimal_point(_CharT()),
1616 _M_thousands_sep(_CharT()), _M_allocated(false)
1619 ~__numpunct_cache();
1622 _M_cache(const locale& __loc);
1626 operator=(const __numpunct_cache&);
1629 __numpunct_cache(const __numpunct_cache&);
1632 template<typename _CharT>
1633 __numpunct_cache<_CharT>::~__numpunct_cache()
1637 delete [] _M_grouping;
1638 delete [] _M_truename;
1639 delete [] _M_falsename;
1644 * @brief Numpunct facet.
1646 * This facet stores several pieces of information related to printing and
1647 * scanning numbers, such as the decimal point character. It takes a
1648 * template parameter specifying the char type. The numpunct facet is
1649 * used by streams for many I/O operations involving numbers.
1651 * The numpunct template uses protected virtual functions to provide the
1652 * actual results. The public accessors forward the call to the virtual
1653 * functions. These virtual functions are hooks for developers to
1654 * implement the behavior they require from a numpunct facet.
1656 template<typename _CharT>
1657 class numpunct : public locale::facet
1663 typedef _CharT char_type;
1664 typedef basic_string<_CharT> string_type;
1666 typedef __numpunct_cache<_CharT> __cache_type;
1669 __cache_type* _M_data;
1672 /// Numpunct facet id.
1673 static locale::id id;
1676 * @brief Numpunct constructor.
1678 * @param refs Refcount to pass to the base class.
1681 numpunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
1682 { _M_initialize_numpunct(); }
1685 * @brief Internal constructor. Not for general use.
1687 * This is a constructor for use by the library itself to set up the
1688 * predefined locale facets.
1690 * @param cache __numpunct_cache object.
1691 * @param refs Refcount to pass to the base class.
1694 numpunct(__cache_type* __cache, size_t __refs = 0)
1695 : facet(__refs), _M_data(__cache)
1696 { _M_initialize_numpunct(); }
1699 * @brief Internal constructor. Not for general use.
1701 * This is a constructor for use by the library itself to set up new
1704 * @param cloc The "C" locale.
1705 * @param refs Refcount to pass to the base class.
1708 numpunct(__c_locale __cloc, size_t __refs = 0)
1709 : facet(__refs), _M_data(NULL)
1710 { _M_initialize_numpunct(__cloc); }
1713 * @brief Return decimal point character.
1715 * This function returns a char_type to use as a decimal point. It
1716 * does so by returning returning
1717 * numpunct<char_type>::do_decimal_point().
1719 * @return @a char_type representing a decimal point.
1722 decimal_point() const
1723 { return this->do_decimal_point(); }
1726 * @brief Return thousands separator character.
1728 * This function returns a char_type to use as a thousands
1729 * separator. It does so by returning returning
1730 * numpunct<char_type>::do_thousands_sep().
1732 * @return char_type representing a thousands separator.
1735 thousands_sep() const
1736 { return this->do_thousands_sep(); }
1739 * @brief Return grouping specification.
1741 * This function returns a string representing groupings for the
1742 * integer part of a number. Groupings indicate where thousands
1743 * separators should be inserted in the integer part of a number.
1745 * Each char in the return string is interpret as an integer
1746 * rather than a character. These numbers represent the number
1747 * of digits in a group. The first char in the string
1748 * represents the number of digits in the least significant
1749 * group. If a char is negative, it indicates an unlimited
1750 * number of digits for the group. If more chars from the
1751 * string are required to group a number, the last char is used
1754 * For example, if the grouping() returns "\003\002" and is
1755 * applied to the number 123456789, this corresponds to
1756 * 12,34,56,789. Note that if the string was "32", this would
1757 * put more than 50 digits into the least significant group if
1758 * the character set is ASCII.
1760 * The string is returned by calling
1761 * numpunct<char_type>::do_grouping().
1763 * @return string representing grouping specification.
1767 { return this->do_grouping(); }
1770 * @brief Return string representation of bool true.
1772 * This function returns a string_type containing the text
1773 * representation for true bool variables. It does so by calling
1774 * numpunct<char_type>::do_truename().
1776 * @return string_type representing printed form of true.
1780 { return this->do_truename(); }
1783 * @brief Return string representation of bool false.
1785 * This function returns a string_type containing the text
1786 * representation for false bool variables. It does so by calling
1787 * numpunct<char_type>::do_falsename().
1789 * @return string_type representing printed form of false.
1793 { return this->do_falsename(); }
1801 * @brief Return decimal point character.
1803 * Returns a char_type to use as a decimal point. This function is a
1804 * hook for derived classes to change the value returned.
1806 * @return @a char_type representing a decimal point.
1809 do_decimal_point() const
1810 { return _M_data->_M_decimal_point; }
1813 * @brief Return thousands separator character.
1815 * Returns a char_type to use as a thousands separator. This function
1816 * is a hook for derived classes to change the value returned.
1818 * @return @a char_type representing a thousands separator.
1821 do_thousands_sep() const
1822 { return _M_data->_M_thousands_sep; }
1825 * @brief Return grouping specification.
1827 * Returns a string representing groupings for the integer part of a
1828 * number. This function is a hook for derived classes to change the
1829 * value returned. @see grouping() for details.
1831 * @return String representing grouping specification.
1835 { return _M_data->_M_grouping; }
1838 * @brief Return string representation of bool true.
1840 * Returns a string_type containing the text representation for true
1841 * bool variables. This function is a hook for derived classes to
1842 * change the value returned.
1844 * @return string_type representing printed form of true.
1848 { return _M_data->_M_truename; }
1851 * @brief Return string representation of bool false.
1853 * Returns a string_type containing the text representation for false
1854 * bool variables. This function is a hook for derived classes to
1855 * change the value returned.
1857 * @return string_type representing printed form of false.
1860 do_falsename() const
1861 { return _M_data->_M_falsename; }
1863 // For use at construction time only.
1865 _M_initialize_numpunct(__c_locale __cloc = NULL);
1868 template<typename _CharT>
1869 locale::id numpunct<_CharT>::id;
1872 numpunct<char>::~numpunct();
1876 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
1878 #ifdef _GLIBCXX_USE_WCHAR_T
1880 numpunct<wchar_t>::~numpunct();
1884 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
1887 template<typename _CharT>
1888 class numpunct_byname : public numpunct<_CharT>
1891 typedef _CharT char_type;
1892 typedef basic_string<_CharT> string_type;
1895 numpunct_byname(const char* __s, size_t __refs = 0)
1896 : numpunct<_CharT>(__refs)
1898 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
1901 this->_S_create_c_locale(__tmp, __s);
1902 this->_M_initialize_numpunct(__tmp);
1903 this->_S_destroy_c_locale(__tmp);
1909 ~numpunct_byname() { }
1913 * @brief Facet for parsing number strings.
1915 * This facet encapsulates the code to parse and return a number
1916 * from a string. It is used by the istream numeric extraction
1919 * The num_get template uses protected virtual functions to provide the
1920 * actual results. The public accessors forward the call to the virtual
1921 * functions. These virtual functions are hooks for developers to
1922 * implement the behavior they require from the num_get facet.
1924 template<typename _CharT, typename _InIter>
1925 class num_get : public locale::facet
1931 typedef _CharT char_type;
1932 typedef _InIter iter_type;
1935 /// Numpunct facet id.
1936 static locale::id id;
1939 * @brief Constructor performs initialization.
1941 * This is the constructor provided by the standard.
1943 * @param refs Passed to the base facet class.
1946 num_get(size_t __refs = 0) : facet(__refs) { }
1949 * @brief Numeric parsing.
1951 * Parses the input stream into the bool @a v. It does so by calling
1952 * num_put::do_put().
1954 * If ios_base::boolalpha is set, attempts to read
1955 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
1956 * @a v to true or false if successful. Sets err to
1957 * ios_base::failbit if reading the string fails. Sets err to
1958 * ios_base::eofbit if the stream is emptied.
1960 * If ios_base::boolalpha is not set, proceeds as with reading a long,
1961 * except if the value is 1, sets @a v to true, if the value is 0, sets
1962 * @a v to false, and otherwise set err to ios_base::failbit.
1964 * @param in Start of input stream.
1965 * @param end End of input stream.
1966 * @param io Source of locale and flags.
1967 * @param err Error flags to set.
1968 * @param v Value to format and insert.
1969 * @return Iterator after reading.
1972 get(iter_type __in, iter_type __end, ios_base& __io,
1973 ios_base::iostate& __err, bool& __v) const
1974 { return this->do_get(__in, __end, __io, __err, __v); }
1978 * @brief Numeric parsing.
1980 * Parses the input stream into the integral variable @a v. It does so
1981 * by calling num_put::do_put().
1983 * Parsing is affected by the flag settings in @a io.
1985 * The basic parse is affected by the value of io.flags() &
1986 * ios_base::basefield. If equal to ios_base::oct, parses like the
1987 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X
1988 * specifier. Else if basefield equal to 0, parses like the %i
1989 * specifier. Otherwise, parses like %d for signed and %u for unsigned
1990 * types. The matching type length modifier is also used.
1992 * Digit grouping is intrepreted according to numpunct::grouping() and
1993 * numpunct::thousands_sep(). If the pattern of digit groups isn't
1994 * consistent, sets err to ios_base::failbit.
1996 * If parsing the string yields a valid value for @a v, @a v is set.
1997 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
1998 * Sets err to ios_base::eofbit if the stream is emptied.
2000 * @param in Start of input stream.
2001 * @param end End of input stream.
2002 * @param io Source of locale and flags.
2003 * @param err Error flags to set.
2004 * @param v Value to format and insert.
2005 * @return Iterator after reading.
2008 get(iter_type __in, iter_type __end, ios_base& __io,
2009 ios_base::iostate& __err, long& __v) const
2010 { return this->do_get(__in, __end, __io, __err, __v); }
2013 get(iter_type __in, iter_type __end, ios_base& __io,
2014 ios_base::iostate& __err, unsigned short& __v) const
2015 { return this->do_get(__in, __end, __io, __err, __v); }
2018 get(iter_type __in, iter_type __end, ios_base& __io,
2019 ios_base::iostate& __err, unsigned int& __v) const
2020 { return this->do_get(__in, __end, __io, __err, __v); }
2023 get(iter_type __in, iter_type __end, ios_base& __io,
2024 ios_base::iostate& __err, unsigned long& __v) const
2025 { return this->do_get(__in, __end, __io, __err, __v); }
2027 #ifdef _GLIBCXX_USE_LONG_LONG
2029 get(iter_type __in, iter_type __end, ios_base& __io,
2030 ios_base::iostate& __err, long long& __v) const
2031 { return this->do_get(__in, __end, __io, __err, __v); }
2034 get(iter_type __in, iter_type __end, ios_base& __io,
2035 ios_base::iostate& __err, unsigned long long& __v) const
2036 { return this->do_get(__in, __end, __io, __err, __v); }
2042 * @brief Numeric parsing.
2044 * Parses the input stream into the integral variable @a v. It does so
2045 * by calling num_put::do_put().
2047 * The input characters are parsed like the scanf %g specifier. The
2048 * matching type length modifier is also used.
2050 * The decimal point character used is numpunct::decimal_point().
2051 * Digit grouping is intrepreted according to numpunct::grouping() and
2052 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2053 * consistent, sets err to ios_base::failbit.
2055 * If parsing the string yields a valid value for @a v, @a v is set.
2056 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2057 * Sets err to ios_base::eofbit if the stream is emptied.
2059 * @param in Start of input stream.
2060 * @param end End of input stream.
2061 * @param io Source of locale and flags.
2062 * @param err Error flags to set.
2063 * @param v Value to format and insert.
2064 * @return Iterator after reading.
2067 get(iter_type __in, iter_type __end, ios_base& __io,
2068 ios_base::iostate& __err, float& __v) const
2069 { return this->do_get(__in, __end, __io, __err, __v); }
2072 get(iter_type __in, iter_type __end, ios_base& __io,
2073 ios_base::iostate& __err, double& __v) const
2074 { return this->do_get(__in, __end, __io, __err, __v); }
2077 get(iter_type __in, iter_type __end, ios_base& __io,
2078 ios_base::iostate& __err, long double& __v) const
2079 { return this->do_get(__in, __end, __io, __err, __v); }
2083 * @brief Numeric parsing.
2085 * Parses the input stream into the pointer variable @a v. It does so
2086 * by calling num_put::do_put().
2088 * The input characters are parsed like the scanf %p specifier.
2090 * Digit grouping is intrepreted according to numpunct::grouping() and
2091 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2092 * consistent, sets err to ios_base::failbit.
2094 * Note that the digit grouping effect for pointers is a bit ambiguous
2095 * in the standard and shouldn't be relied on. See DR 344.
2097 * If parsing the string yields a valid value for @a v, @a v is set.
2098 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2099 * Sets err to ios_base::eofbit if the stream is emptied.
2101 * @param in Start of input stream.
2102 * @param end End of input stream.
2103 * @param io Source of locale and flags.
2104 * @param err Error flags to set.
2105 * @param v Value to format and insert.
2106 * @return Iterator after reading.
2109 get(iter_type __in, iter_type __end, ios_base& __io,
2110 ios_base::iostate& __err, void*& __v) const
2111 { return this->do_get(__in, __end, __io, __err, __v); }
2115 virtual ~num_get() { }
2118 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
2119 string& __xtrc) const;
2121 template<typename _ValueT>
2123 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
2124 _ValueT& __v) const;
2128 * @brief Numeric parsing.
2130 * Parses the input stream into the variable @a v. This function is a
2131 * hook for derived classes to change the value returned. @see get()
2134 * @param in Start of input stream.
2135 * @param end End of input stream.
2136 * @param io Source of locale and flags.
2137 * @param err Error flags to set.
2138 * @param v Value to format and insert.
2139 * @return Iterator after reading.
2142 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
2146 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
2149 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2150 unsigned short&) const;
2153 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2154 unsigned int&) const;
2157 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2158 unsigned long&) const;
2160 #ifdef _GLIBCXX_USE_LONG_LONG
2162 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2166 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2167 unsigned long long&) const;
2171 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2175 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2179 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2180 long double&) const;
2183 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2188 template<typename _CharT, typename _InIter>
2189 locale::id num_get<_CharT, _InIter>::id;
2193 * @brief Facet for converting numbers to strings.
2195 * This facet encapsulates the code to convert a number to a string. It is
2196 * used by the ostream numeric insertion operators.
2198 * The num_put template uses protected virtual functions to provide the
2199 * actual results. The public accessors forward the call to the virtual
2200 * functions. These virtual functions are hooks for developers to
2201 * implement the behavior they require from the num_put facet.
2203 template<typename _CharT, typename _OutIter>
2204 class num_put : public locale::facet
2210 typedef _CharT char_type;
2211 typedef _OutIter iter_type;
2214 /// Numpunct facet id.
2215 static locale::id id;
2218 * @brief Constructor performs initialization.
2220 * This is the constructor provided by the standard.
2222 * @param refs Passed to the base facet class.
2225 num_put(size_t __refs = 0) : facet(__refs) { }
2228 * @brief Numeric formatting.
2230 * Formats the boolean @a v and inserts it into a stream. It does so
2231 * by calling num_put::do_put().
2233 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2234 * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
2236 * @param s Stream to write to.
2237 * @param io Source of locale and flags.
2238 * @param fill Char_type to use for filling.
2239 * @param v Value to format and insert.
2240 * @return Iterator after writing.
2243 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
2244 { return this->do_put(__s, __f, __fill, __v); }
2248 * @brief Numeric formatting.
2250 * Formats the integral value @a v and inserts it into a
2251 * stream. It does so by calling num_put::do_put().
2253 * Formatting is affected by the flag settings in @a io.
2255 * The basic format is affected by the value of io.flags() &
2256 * ios_base::basefield. If equal to ios_base::oct, formats like the
2257 * printf %o specifier. Else if equal to ios_base::hex, formats like
2258 * %x or %X with ios_base::uppercase unset or set respectively.
2259 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2260 * for unsigned values. Note that if both oct and hex are set, neither
2263 * If ios_base::showpos is set, '+' is output before positive values.
2264 * If ios_base::showbase is set, '0' precedes octal values (except 0)
2265 * and '0[xX]' precedes hex values.
2267 * Thousands separators are inserted according to numpunct::grouping()
2268 * and numpunct::thousands_sep(). The decimal point character used is
2269 * numpunct::decimal_point().
2271 * If io.width() is non-zero, enough @a fill characters are inserted to
2272 * make the result at least that wide. If
2273 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2274 * padded at the end. If ios_base::internal, then padding occurs
2275 * immediately after either a '+' or '-' or after '0x' or '0X'.
2276 * Otherwise, padding occurs at the beginning.
2278 * @param s Stream to write to.
2279 * @param io Source of locale and flags.
2280 * @param fill Char_type to use for filling.
2281 * @param v Value to format and insert.
2282 * @return Iterator after writing.
2285 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
2286 { return this->do_put(__s, __f, __fill, __v); }
2289 put(iter_type __s, ios_base& __f, char_type __fill,
2290 unsigned long __v) const
2291 { return this->do_put(__s, __f, __fill, __v); }
2293 #ifdef _GLIBCXX_USE_LONG_LONG
2295 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
2296 { return this->do_put(__s, __f, __fill, __v); }
2299 put(iter_type __s, ios_base& __f, char_type __fill,
2300 unsigned long long __v) const
2301 { return this->do_put(__s, __f, __fill, __v); }
2307 * @brief Numeric formatting.
2309 * Formats the floating point value @a v and inserts it into a stream.
2310 * It does so by calling num_put::do_put().
2312 * Formatting is affected by the flag settings in @a io.
2314 * The basic format is affected by the value of io.flags() &
2315 * ios_base::floatfield. If equal to ios_base::fixed, formats like the
2316 * printf %f specifier. Else if equal to ios_base::scientific, formats
2317 * like %e or %E with ios_base::uppercase unset or set respectively.
2318 * Otherwise, formats like %g or %G depending on uppercase. Note that
2319 * if both fixed and scientific are set, the effect will also be like
2322 * The output precision is given by io.precision(). This precision is
2323 * capped at numeric_limits::digits10 + 2 (different for double and
2324 * long double). The default precision is 6.
2326 * If ios_base::showpos is set, '+' is output before positive values.
2327 * If ios_base::showpoint is set, a decimal point will always be
2330 * Thousands separators are inserted according to numpunct::grouping()
2331 * and numpunct::thousands_sep(). The decimal point character used is
2332 * numpunct::decimal_point().
2334 * If io.width() is non-zero, enough @a fill characters are inserted to
2335 * make the result at least that wide. If
2336 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2337 * padded at the end. If ios_base::internal, then padding occurs
2338 * immediately after either a '+' or '-' or after '0x' or '0X'.
2339 * Otherwise, padding occurs at the beginning.
2341 * @param s Stream to write to.
2342 * @param io Source of locale and flags.
2343 * @param fill Char_type to use for filling.
2344 * @param v Value to format and insert.
2345 * @return Iterator after writing.
2348 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
2349 { return this->do_put(__s, __f, __fill, __v); }
2352 put(iter_type __s, ios_base& __f, char_type __fill,
2353 long double __v) const
2354 { return this->do_put(__s, __f, __fill, __v); }
2358 * @brief Numeric formatting.
2360 * Formats the pointer value @a v and inserts it into a stream. It
2361 * does so by calling num_put::do_put().
2363 * This function formats @a v as an unsigned long with ios_base::hex
2364 * and ios_base::showbase set.
2366 * @param s Stream to write to.
2367 * @param io Source of locale and flags.
2368 * @param fill Char_type to use for filling.
2369 * @param v Value to format and insert.
2370 * @return Iterator after writing.
2373 put(iter_type __s, ios_base& __f, char_type __fill,
2374 const void* __v) const
2375 { return this->do_put(__s, __f, __fill, __v); }
2378 template<typename _ValueT>
2380 _M_insert_float(iter_type, ios_base& __io, char_type __fill,
2381 char __mod, _ValueT __v) const;
2384 _M_group_float(const char* __grouping, size_t __grouping_size,
2385 char_type __sep, const char_type* __p, char_type* __new,
2386 char_type* __cs, int& __len) const;
2388 template<typename _ValueT>
2390 _M_insert_int(iter_type, ios_base& __io, char_type __fill,
2394 _M_group_int(const char* __grouping, size_t __grouping_size,
2395 char_type __sep, ios_base& __io, char_type* __new,
2396 char_type* __cs, int& __len) const;
2399 _M_pad(char_type __fill, streamsize __w, ios_base& __io,
2400 char_type* __new, const char_type* __cs, int& __len) const;
2408 * @brief Numeric formatting.
2410 * These functions do the work of formatting numeric values and
2411 * inserting them into a stream. This function is a hook for derived
2412 * classes to change the value returned.
2414 * @param s Stream to write to.
2415 * @param io Source of locale and flags.
2416 * @param fill Char_type to use for filling.
2417 * @param v Value to format and insert.
2418 * @return Iterator after writing.
2421 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
2424 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
2427 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
2429 #ifdef _GLIBCXX_USE_LONG_LONG
2431 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
2434 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
2438 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2441 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2444 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
2448 template <typename _CharT, typename _OutIter>
2449 locale::id num_put<_CharT, _OutIter>::id;
2453 * @brief Facet for localized string comparison.
2455 * This facet encapsulates the code to compare strings in a localized
2458 * The collate template uses protected virtual functions to provide
2459 * the actual results. The public accessors forward the call to
2460 * the virtual functions. These virtual functions are hooks for
2461 * developers to implement the behavior they require from the
2464 template<typename _CharT>
2465 class collate : public locale::facet
2471 typedef _CharT char_type;
2472 typedef basic_string<_CharT> string_type;
2476 // Underlying "C" library locale information saved from
2477 // initialization, needed by collate_byname as well.
2478 __c_locale _M_c_locale_collate;
2481 /// Numpunct facet id.
2482 static locale::id id;
2485 * @brief Constructor performs initialization.
2487 * This is the constructor provided by the standard.
2489 * @param refs Passed to the base facet class.
2492 collate(size_t __refs = 0)
2493 : facet(__refs), _M_c_locale_collate(_S_get_c_locale())
2497 * @brief Internal constructor. Not for general use.
2499 * This is a constructor for use by the library itself to set up new
2502 * @param cloc The "C" locale.
2503 * @param refs Passed to the base facet class.
2506 collate(__c_locale __cloc, size_t __refs = 0)
2507 : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc))
2511 * @brief Compare two strings.
2513 * This function compares two strings and returns the result by calling
2514 * collate::do_compare().
2516 * @param lo1 Start of string 1.
2517 * @param hi1 End of string 1.
2518 * @param lo2 Start of string 2.
2519 * @param hi2 End of string 2.
2520 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2523 compare(const _CharT* __lo1, const _CharT* __hi1,
2524 const _CharT* __lo2, const _CharT* __hi2) const
2525 { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
2528 * @brief Transform string to comparable form.
2530 * This function is a wrapper for strxfrm functionality. It takes the
2531 * input string and returns a modified string that can be directly
2532 * compared to other transformed strings. In the "C" locale, this
2533 * function just returns a copy of the input string. In some other
2534 * locales, it may replace two chars with one, change a char for
2535 * another, etc. It does so by returning collate::do_transform().
2537 * @param lo Start of string.
2538 * @param hi End of string.
2539 * @return Transformed string_type.
2542 transform(const _CharT* __lo, const _CharT* __hi) const
2543 { return this->do_transform(__lo, __hi); }
2546 * @brief Return hash of a string.
2548 * This function computes and returns a hash on the input string. It
2549 * does so by returning collate::do_hash().
2551 * @param lo Start of string.
2552 * @param hi End of string.
2553 * @return Hash value.
2556 hash(const _CharT* __lo, const _CharT* __hi) const
2557 { return this->do_hash(__lo, __hi); }
2559 // Used to abstract out _CharT bits in virtual member functions, below.
2561 _M_compare(const _CharT*, const _CharT*) const;
2564 _M_transform(_CharT*, const _CharT*, size_t) const;
2570 { _S_destroy_c_locale(_M_c_locale_collate); }
2573 * @brief Compare two strings.
2575 * This function is a hook for derived classes to change the value
2576 * returned. @see compare().
2578 * @param lo1 Start of string 1.
2579 * @param hi1 End of string 1.
2580 * @param lo2 Start of string 2.
2581 * @param hi2 End of string 2.
2582 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2585 do_compare(const _CharT* __lo1, const _CharT* __hi1,
2586 const _CharT* __lo2, const _CharT* __hi2) const;
2589 * @brief Transform string to comparable form.
2591 * This function is a hook for derived classes to change the value
2594 * @param lo1 Start of string 1.
2595 * @param hi1 End of string 1.
2596 * @param lo2 Start of string 2.
2597 * @param hi2 End of string 2.
2598 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2601 do_transform(const _CharT* __lo, const _CharT* __hi) const;
2604 * @brief Return hash of a string.
2606 * This function computes and returns a hash on the input string. This
2607 * function is a hook for derived classes to change the value returned.
2609 * @param lo Start of string.
2610 * @param hi End of string.
2611 * @return Hash value.
2614 do_hash(const _CharT* __lo, const _CharT* __hi) const;
2617 template<typename _CharT>
2618 locale::id collate<_CharT>::id;
2623 collate<char>::_M_compare(const char*, const char*) const;
2627 collate<char>::_M_transform(char*, const char*, size_t) const;
2629 #ifdef _GLIBCXX_USE_WCHAR_T
2632 collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
2636 collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
2639 template<typename _CharT>
2640 class collate_byname : public collate<_CharT>
2645 typedef _CharT char_type;
2646 typedef basic_string<_CharT> string_type;
2650 collate_byname(const char* __s, size_t __refs = 0)
2651 : collate<_CharT>(__refs)
2653 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
2655 this->_S_destroy_c_locale(this->_M_c_locale_collate);
2656 this->_S_create_c_locale(this->_M_c_locale_collate, __s);
2662 ~collate_byname() { }
2667 * @brief Time format ordering data.
2669 * This class provides an enum representing different orderings of day,
2675 enum dateorder { no_order, dmy, mdy, ymd, ydm };
2678 template<typename _CharT>
2679 struct __timepunct_cache : public locale::facet
2681 // List of all known timezones, with GMT first.
2682 static const _CharT* _S_timezones[14];
2684 const _CharT* _M_date_format;
2685 const _CharT* _M_date_era_format;
2686 const _CharT* _M_time_format;
2687 const _CharT* _M_time_era_format;
2688 const _CharT* _M_date_time_format;
2689 const _CharT* _M_date_time_era_format;
2690 const _CharT* _M_am;
2691 const _CharT* _M_pm;
2692 const _CharT* _M_am_pm_format;
2694 // Day names, starting with "C"'s Sunday.
2695 const _CharT* _M_day1;
2696 const _CharT* _M_day2;
2697 const _CharT* _M_day3;
2698 const _CharT* _M_day4;
2699 const _CharT* _M_day5;
2700 const _CharT* _M_day6;
2701 const _CharT* _M_day7;
2703 // Abbreviated day names, starting with "C"'s Sun.
2704 const _CharT* _M_aday1;
2705 const _CharT* _M_aday2;
2706 const _CharT* _M_aday3;
2707 const _CharT* _M_aday4;
2708 const _CharT* _M_aday5;
2709 const _CharT* _M_aday6;
2710 const _CharT* _M_aday7;
2712 // Month names, starting with "C"'s January.
2713 const _CharT* _M_month01;
2714 const _CharT* _M_month02;
2715 const _CharT* _M_month03;
2716 const _CharT* _M_month04;
2717 const _CharT* _M_month05;
2718 const _CharT* _M_month06;
2719 const _CharT* _M_month07;
2720 const _CharT* _M_month08;
2721 const _CharT* _M_month09;
2722 const _CharT* _M_month10;
2723 const _CharT* _M_month11;
2724 const _CharT* _M_month12;
2726 // Abbreviated month names, starting with "C"'s Jan.
2727 const _CharT* _M_amonth01;
2728 const _CharT* _M_amonth02;
2729 const _CharT* _M_amonth03;
2730 const _CharT* _M_amonth04;
2731 const _CharT* _M_amonth05;
2732 const _CharT* _M_amonth06;
2733 const _CharT* _M_amonth07;
2734 const _CharT* _M_amonth08;
2735 const _CharT* _M_amonth09;
2736 const _CharT* _M_amonth10;
2737 const _CharT* _M_amonth11;
2738 const _CharT* _M_amonth12;
2742 __timepunct_cache(size_t __refs = 0) : facet(__refs),
2743 _M_date_format(NULL), _M_date_era_format(NULL), _M_time_format(NULL),
2744 _M_time_era_format(NULL), _M_date_time_format(NULL),
2745 _M_date_time_era_format(NULL), _M_am(NULL), _M_pm(NULL),
2746 _M_am_pm_format(NULL), _M_day1(NULL), _M_day2(NULL), _M_day3(NULL),
2747 _M_day4(NULL), _M_day5(NULL), _M_day6(NULL), _M_day7(NULL),
2748 _M_aday1(NULL), _M_aday2(NULL), _M_aday3(NULL), _M_aday4(NULL),
2749 _M_aday5(NULL), _M_aday6(NULL), _M_aday7(NULL), _M_month01(NULL),
2750 _M_month02(NULL), _M_month03(NULL), _M_month04(NULL), _M_month05(NULL),
2751 _M_month06(NULL), _M_month07(NULL), _M_month08(NULL), _M_month09(NULL),
2752 _M_month10(NULL), _M_month11(NULL), _M_month12(NULL), _M_amonth01(NULL),
2753 _M_amonth02(NULL), _M_amonth03(NULL), _M_amonth04(NULL),
2754 _M_amonth05(NULL), _M_amonth06(NULL), _M_amonth07(NULL),
2755 _M_amonth08(NULL), _M_amonth09(NULL), _M_amonth10(NULL),
2756 _M_amonth11(NULL), _M_amonth12(NULL), _M_allocated(false)
2759 ~__timepunct_cache();
2762 _M_cache(const locale& __loc);
2766 operator=(const __timepunct_cache&);
2769 __timepunct_cache(const __timepunct_cache&);
2772 template<typename _CharT>
2773 __timepunct_cache<_CharT>::~__timepunct_cache()
2784 __timepunct_cache<char>::_S_timezones[14];
2786 #ifdef _GLIBCXX_USE_WCHAR_T
2789 __timepunct_cache<wchar_t>::_S_timezones[14];
2793 template<typename _CharT>
2794 const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
2796 template<typename _CharT>
2797 class __timepunct : public locale::facet
2801 typedef _CharT __char_type;
2802 typedef basic_string<_CharT> __string_type;
2803 typedef __timepunct_cache<_CharT> __cache_type;
2806 __cache_type* _M_data;
2807 __c_locale _M_c_locale_timepunct;
2808 const char* _M_name_timepunct;
2811 /// Numpunct facet id.
2812 static locale::id id;
2815 __timepunct(size_t __refs = 0);
2818 __timepunct(__cache_type* __cache, size_t __refs = 0);
2821 * @brief Internal constructor. Not for general use.
2823 * This is a constructor for use by the library itself to set up new
2826 * @param cloc The "C" locale.
2827 * @param s The name of a locale.
2828 * @param refs Passed to the base facet class.
2831 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
2834 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
2835 const tm* __tm) const;
2838 _M_date_formats(const _CharT** __date) const
2840 // Always have default first.
2841 __date[0] = _M_data->_M_date_format;
2842 __date[1] = _M_data->_M_date_era_format;
2846 _M_time_formats(const _CharT** __time) const
2848 // Always have default first.
2849 __time[0] = _M_data->_M_time_format;
2850 __time[1] = _M_data->_M_time_era_format;
2854 _M_date_time_formats(const _CharT** __dt) const
2856 // Always have default first.
2857 __dt[0] = _M_data->_M_date_time_format;
2858 __dt[1] = _M_data->_M_date_time_era_format;
2862 _M_am_pm_format(const _CharT* __ampm) const
2863 { __ampm = _M_data->_M_am_pm_format; }
2866 _M_am_pm(const _CharT** __ampm) const
2868 __ampm[0] = _M_data->_M_am;
2869 __ampm[1] = _M_data->_M_pm;
2873 _M_days(const _CharT** __days) const
2875 __days[0] = _M_data->_M_day1;
2876 __days[1] = _M_data->_M_day2;
2877 __days[2] = _M_data->_M_day3;
2878 __days[3] = _M_data->_M_day4;
2879 __days[4] = _M_data->_M_day5;
2880 __days[5] = _M_data->_M_day6;
2881 __days[6] = _M_data->_M_day7;
2885 _M_days_abbreviated(const _CharT** __days) const
2887 __days[0] = _M_data->_M_aday1;
2888 __days[1] = _M_data->_M_aday2;
2889 __days[2] = _M_data->_M_aday3;
2890 __days[3] = _M_data->_M_aday4;
2891 __days[4] = _M_data->_M_aday5;
2892 __days[5] = _M_data->_M_aday6;
2893 __days[6] = _M_data->_M_aday7;
2897 _M_months(const _CharT** __months) const
2899 __months[0] = _M_data->_M_month01;
2900 __months[1] = _M_data->_M_month02;
2901 __months[2] = _M_data->_M_month03;
2902 __months[3] = _M_data->_M_month04;
2903 __months[4] = _M_data->_M_month05;
2904 __months[5] = _M_data->_M_month06;
2905 __months[6] = _M_data->_M_month07;
2906 __months[7] = _M_data->_M_month08;
2907 __months[8] = _M_data->_M_month09;
2908 __months[9] = _M_data->_M_month10;
2909 __months[10] = _M_data->_M_month11;
2910 __months[11] = _M_data->_M_month12;
2914 _M_months_abbreviated(const _CharT** __months) const
2916 __months[0] = _M_data->_M_amonth01;
2917 __months[1] = _M_data->_M_amonth02;
2918 __months[2] = _M_data->_M_amonth03;
2919 __months[3] = _M_data->_M_amonth04;
2920 __months[4] = _M_data->_M_amonth05;
2921 __months[5] = _M_data->_M_amonth06;
2922 __months[6] = _M_data->_M_amonth07;
2923 __months[7] = _M_data->_M_amonth08;
2924 __months[8] = _M_data->_M_amonth09;
2925 __months[9] = _M_data->_M_amonth10;
2926 __months[10] = _M_data->_M_amonth11;
2927 __months[11] = _M_data->_M_amonth12;
2934 // For use at construction time only.
2936 _M_initialize_timepunct(__c_locale __cloc = NULL);
2939 template<typename _CharT>
2940 locale::id __timepunct<_CharT>::id;
2945 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
2949 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const;
2951 #ifdef _GLIBCXX_USE_WCHAR_T
2954 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
2958 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
2962 // Include host and configuration specific timepunct functions.
2963 #include <bits/time_members.h>
2966 * @brief Facet for parsing dates and times.
2968 * This facet encapsulates the code to parse and return a date or
2969 * time from a string. It is used by the istream numeric
2970 * extraction operators.
2972 * The time_get template uses protected virtual functions to provide the
2973 * actual results. The public accessors forward the call to the virtual
2974 * functions. These virtual functions are hooks for developers to
2975 * implement the behavior they require from the time_get facet.
2977 template<typename _CharT, typename _InIter>
2978 class time_get : public locale::facet, public time_base
2984 typedef _CharT char_type;
2985 typedef _InIter iter_type;
2987 typedef basic_string<_CharT> __string_type;
2989 /// Numpunct facet id.
2990 static locale::id id;
2993 * @brief Constructor performs initialization.
2995 * This is the constructor provided by the standard.
2997 * @param refs Passed to the base facet class.
3000 time_get(size_t __refs = 0)
3001 : facet (__refs) { }
3004 * @brief Return preferred order of month, day, and year.
3006 * This function returns an enum from timebase::dateorder giving the
3007 * preferred ordering if the format "x" given to time_put::put() only
3008 * uses month, day, and year. If the format "x" for the associated
3009 * locale uses other fields, this function returns
3010 * timebase::dateorder::noorder.
3012 * NOTE: The library always returns noorder at the moment.
3014 * @return A member of timebase::dateorder.
3018 { return this->do_date_order(); }
3021 * @brief Parse input time string.
3023 * This function parses a time according to the format "x" and puts the
3024 * results into a user-supplied struct tm. The result is returned by
3025 * calling time_get::do_get_time().
3027 * If there is a valid time string according to format "x", @a tm will
3028 * be filled in accordingly and the returned iterator will point to the
3029 * first character beyond the time string. If an error occurs before
3030 * the end, err |= ios_base::failbit. If parsing reads all the
3031 * characters, err |= ios_base::eofbit.
3033 * @param beg Start of string to parse.
3034 * @param end End of string to parse.
3035 * @param io Source of the locale.
3036 * @param err Error flags to set.
3037 * @param tm Pointer to struct tm to fill in.
3038 * @return Iterator to first char beyond time string.
3041 get_time(iter_type __beg, iter_type __end, ios_base& __io,
3042 ios_base::iostate& __err, tm* __tm) const
3043 { return this->do_get_time(__beg, __end, __io, __err, __tm); }
3046 * @brief Parse input date string.
3048 * This function parses a date according to the format "X" and puts the
3049 * results into a user-supplied struct tm. The result is returned by
3050 * calling time_get::do_get_date().
3052 * If there is a valid date string according to format "X", @a tm will
3053 * be filled in accordingly and the returned iterator will point to the
3054 * first character beyond the date string. If an error occurs before
3055 * the end, err |= ios_base::failbit. If parsing reads all the
3056 * characters, err |= ios_base::eofbit.
3058 * @param beg Start of string to parse.
3059 * @param end End of string to parse.
3060 * @param io Source of the locale.
3061 * @param err Error flags to set.
3062 * @param tm Pointer to struct tm to fill in.
3063 * @return Iterator to first char beyond date string.
3066 get_date(iter_type __beg, iter_type __end, ios_base& __io,
3067 ios_base::iostate& __err, tm* __tm) const
3068 { return this->do_get_date(__beg, __end, __io, __err, __tm); }
3071 * @brief Parse input weekday string.
3073 * This function parses a weekday name and puts the results into a
3074 * user-supplied struct tm. The result is returned by calling
3075 * time_get::do_get_weekday().
3077 * Parsing starts by parsing an abbreviated weekday name. If a valid
3078 * abbreviation is followed by a character that would lead to the full
3079 * weekday name, parsing continues until the full name is found or an
3080 * error occurs. Otherwise parsing finishes at the end of the
3083 * If an error occurs before the end, err |= ios_base::failbit. If
3084 * parsing reads all the characters, err |= ios_base::eofbit.
3086 * @param beg Start of string to parse.
3087 * @param end End of string to parse.
3088 * @param io Source of the locale.
3089 * @param err Error flags to set.
3090 * @param tm Pointer to struct tm to fill in.
3091 * @return Iterator to first char beyond weekday name.
3094 get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
3095 ios_base::iostate& __err, tm* __tm) const
3096 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
3099 * @brief Parse input month string.
3101 * This function parses a month name and puts the results into a
3102 * user-supplied struct tm. The result is returned by calling
3103 * time_get::do_get_monthname().
3105 * Parsing starts by parsing an abbreviated month name. If a valid
3106 * abbreviation is followed by a character that would lead to the full
3107 * month name, parsing continues until the full name is found or an
3108 * error occurs. Otherwise parsing finishes at the end of the
3111 * If an error occurs before the end, err |= ios_base::failbit. If
3112 * parsing reads all the characters, err |=
3115 * @param beg Start of string to parse.
3116 * @param end End of string to parse.
3117 * @param io Source of the locale.
3118 * @param err Error flags to set.
3119 * @param tm Pointer to struct tm to fill in.
3120 * @return Iterator to first char beyond month name.
3123 get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
3124 ios_base::iostate& __err, tm* __tm) const
3125 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
3128 * @brief Parse input year string.
3130 * This function reads up to 4 characters to parse a year string and
3131 * puts the results into a user-supplied struct tm. The result is
3132 * returned by calling time_get::do_get_year().
3134 * 4 consecutive digits are interpreted as a full year. If there are
3135 * exactly 2 consecutive digits, the library interprets this as the
3136 * number of years since 1900.
3138 * If an error occurs before the end, err |= ios_base::failbit. If
3139 * parsing reads all the characters, err |= ios_base::eofbit.
3141 * @param beg Start of string to parse.
3142 * @param end End of string to parse.
3143 * @param io Source of the locale.
3144 * @param err Error flags to set.
3145 * @param tm Pointer to struct tm to fill in.
3146 * @return Iterator to first char beyond year.
3149 get_year(iter_type __beg, iter_type __end, ios_base& __io,
3150 ios_base::iostate& __err, tm* __tm) const
3151 { return this->do_get_year(__beg, __end, __io, __err, __tm); }
3159 * @brief Return preferred order of month, day, and year.
3161 * This function returns an enum from timebase::dateorder giving the
3162 * preferred ordering if the format "x" given to time_put::put() only
3163 * uses month, day, and year. This function is a hook for derived
3164 * classes to change the value returned.
3166 * @return A member of timebase::dateorder.
3169 do_date_order() const;
3172 * @brief Parse input time string.
3174 * This function parses a time according to the format "x" and puts the
3175 * results into a user-supplied struct tm. This function is a hook for
3176 * derived classes to change the value returned. @see get_time() for
3179 * @param beg Start of string to parse.
3180 * @param end End of string to parse.
3181 * @param io Source of the locale.
3182 * @param err Error flags to set.
3183 * @param tm Pointer to struct tm to fill in.
3184 * @return Iterator to first char beyond time string.
3187 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
3188 ios_base::iostate& __err, tm* __tm) const;
3191 * @brief Parse input date string.
3193 * This function parses a date according to the format "X" and puts the
3194 * results into a user-supplied struct tm. This function is a hook for
3195 * derived classes to change the value returned. @see get_date() for
3198 * @param beg Start of string to parse.
3199 * @param end End of string to parse.
3200 * @param io Source of the locale.
3201 * @param err Error flags to set.
3202 * @param tm Pointer to struct tm to fill in.
3203 * @return Iterator to first char beyond date string.
3206 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
3207 ios_base::iostate& __err, tm* __tm) const;
3210 * @brief Parse input weekday string.
3212 * This function parses a weekday name and puts the results into a
3213 * user-supplied struct tm. This function is a hook for derived
3214 * classes to change the value returned. @see get_weekday() for
3217 * @param beg Start of string to parse.
3218 * @param end End of string to parse.
3219 * @param io Source of the locale.
3220 * @param err Error flags to set.
3221 * @param tm Pointer to struct tm to fill in.
3222 * @return Iterator to first char beyond weekday name.
3225 do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
3226 ios_base::iostate& __err, tm* __tm) const;
3229 * @brief Parse input month string.
3231 * This function parses a month name and puts the results into a
3232 * user-supplied struct tm. This function is a hook for derived
3233 * classes to change the value returned. @see get_monthname() for
3236 * @param beg Start of string to parse.
3237 * @param end End of string to parse.
3238 * @param io Source of the locale.
3239 * @param err Error flags to set.
3240 * @param tm Pointer to struct tm to fill in.
3241 * @return Iterator to first char beyond month name.
3244 do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
3245 ios_base::iostate& __err, tm* __tm) const;
3248 * @brief Parse input year string.
3250 * This function reads up to 4 characters to parse a year string and
3251 * puts the results into a user-supplied struct tm. This function is a
3252 * hook for derived classes to change the value returned. @see
3253 * get_year() for details.
3255 * @param beg Start of string to parse.
3256 * @param end End of string to parse.
3257 * @param io Source of the locale.
3258 * @param err Error flags to set.
3259 * @param tm Pointer to struct tm to fill in.
3260 * @return Iterator to first char beyond year.
3263 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
3264 ios_base::iostate& __err, tm* __tm) const;
3266 // Extract numeric component of length __len.
3268 _M_extract_num(iter_type __beg, iter_type __end, int& __member,
3269 int __min, int __max, size_t __len,
3270 ios_base& __io, ios_base::iostate& __err) const;
3272 // Extract day or month name, or any unique array of string
3273 // literals in a const _CharT* array.
3275 _M_extract_name(iter_type __beg, iter_type __end, int& __member,
3276 const _CharT** __names, size_t __indexlen,
3277 ios_base& __io, ios_base::iostate& __err) const;
3279 // Extract on a component-by-component basis, via __format argument.
3281 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
3282 ios_base::iostate& __err, tm* __tm,
3283 const _CharT* __format) const;
3286 template<typename _CharT, typename _InIter>
3287 locale::id time_get<_CharT, _InIter>::id;
3289 template<typename _CharT, typename _InIter>
3290 class time_get_byname : public time_get<_CharT, _InIter>
3294 typedef _CharT char_type;
3295 typedef _InIter iter_type;
3298 time_get_byname(const char*, size_t __refs = 0)
3299 : time_get<_CharT, _InIter>(__refs) { }
3303 ~time_get_byname() { }
3307 * @brief Facet for outputting dates and times.
3309 * This facet encapsulates the code to format and output dates and times
3310 * according to formats used by strftime().
3312 * The time_put template uses protected virtual functions to provide the
3313 * actual results. The public accessors forward the call to the virtual
3314 * functions. These virtual functions are hooks for developers to
3315 * implement the behavior they require from the time_put facet.
3317 template<typename _CharT, typename _OutIter>
3318 class time_put : public locale::facet
3324 typedef _CharT char_type;
3325 typedef _OutIter iter_type;
3328 /// Numpunct facet id.
3329 static locale::id id;
3332 * @brief Constructor performs initialization.
3334 * This is the constructor provided by the standard.
3336 * @param refs Passed to the base facet class.
3339 time_put(size_t __refs = 0)
3343 * @brief Format and output a time or date.
3345 * This function formats the data in struct tm according to the
3346 * provided format string. The format string is interpreted as by
3349 * @param s The stream to write to.
3350 * @param io Source of locale.
3351 * @param fill char_type to use for padding.
3352 * @param tm Struct tm with date and time info to format.
3353 * @param beg Start of format string.
3354 * @param end End of format string.
3355 * @return Iterator after writing.
3358 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
3359 const _CharT* __beg, const _CharT* __end) const;
3362 * @brief Format and output a time or date.
3364 * This function formats the data in struct tm according to the
3365 * provided format char and optional modifier. The format and modifier
3366 * are interpreted as by strftime(). It does so by returning
3367 * time_put::do_put().
3369 * @param s The stream to write to.
3370 * @param io Source of locale.
3371 * @param fill char_type to use for padding.
3372 * @param tm Struct tm with date and time info to format.
3373 * @param format Format char.
3374 * @param mod Optional modifier char.
3375 * @return Iterator after writing.
3378 put(iter_type __s, ios_base& __io, char_type __fill,
3379 const tm* __tm, char __format, char __mod = 0) const
3380 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
3389 * @brief Format and output a time or date.
3391 * This function formats the data in struct tm according to the
3392 * provided format char and optional modifier. This function is a hook
3393 * for derived classes to change the value returned. @see put() for
3396 * @param s The stream to write to.
3397 * @param io Source of locale.
3398 * @param fill char_type to use for padding.
3399 * @param tm Struct tm with date and time info to format.
3400 * @param format Format char.
3401 * @param mod Optional modifier char.
3402 * @return Iterator after writing.
3405 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
3406 char __format, char __mod) const;
3409 template<typename _CharT, typename _OutIter>
3410 locale::id time_put<_CharT, _OutIter>::id;
3412 template<typename _CharT, typename _OutIter>
3413 class time_put_byname : public time_put<_CharT, _OutIter>
3417 typedef _CharT char_type;
3418 typedef _OutIter iter_type;
3421 time_put_byname(const char*, size_t __refs = 0)
3422 : time_put<_CharT, _OutIter>(__refs)
3427 ~time_put_byname() { }
3432 * @brief Money format ordering data.
3434 * This class contains an ordered array of 4 fields to represent the
3435 * pattern for formatting a money amount. Each field may contain one entry
3436 * from the part enum. symbol, sign, and value must be present and the
3437 * remaining field must contain either none or space. @see
3438 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
3439 * these fields are interpreted.
3444 enum part { none, space, symbol, sign, value };
3445 struct pattern { char field[4]; };
3447 static const pattern _S_default_pattern;
3456 // String literal of acceptable (narrow) input/output, for
3457 // money_get/money_put. "-0123456789"
3458 static const char* _S_atoms;
3460 // Construct and return valid pattern consisting of some combination of:
3461 // space none symbol sign value
3463 _S_construct_pattern(char __precedes, char __space, char __posn);
3466 template<typename _CharT, bool _Intl>
3467 struct __moneypunct_cache : public locale::facet
3469 const char* _M_grouping;
3470 size_t _M_grouping_size;
3471 bool _M_use_grouping;
3472 _CharT _M_decimal_point;
3473 _CharT _M_thousands_sep;
3474 const _CharT* _M_curr_symbol;
3475 size_t _M_curr_symbol_size;
3476 const _CharT* _M_positive_sign;
3477 size_t _M_positive_sign_size;
3478 const _CharT* _M_negative_sign;
3479 size_t _M_negative_sign_size;
3481 money_base::pattern _M_pos_format;
3482 money_base::pattern _M_neg_format;
3484 // A list of valid numeric literals for input and output: in the standard
3485 // "C" locale, this is "-0123456789". This array contains the chars after
3486 // having been passed through the current locale's ctype<_CharT>.widen().
3487 _CharT _M_atoms[money_base::_S_end];
3491 __moneypunct_cache(size_t __refs = 0) : facet(__refs),
3492 _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
3493 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
3494 _M_curr_symbol(NULL), _M_curr_symbol_size(0),
3495 _M_positive_sign(NULL), _M_positive_sign_size(0),
3496 _M_negative_sign(NULL), _M_negative_sign_size(0),
3498 _M_pos_format(money_base::pattern()),
3499 _M_neg_format(money_base::pattern()), _M_allocated(false)
3502 ~__moneypunct_cache();
3505 _M_cache(const locale& __loc);
3509 operator=(const __moneypunct_cache&);
3512 __moneypunct_cache(const __moneypunct_cache&);
3515 template<typename _CharT, bool _Intl>
3516 __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
3520 delete [] _M_grouping;
3521 delete [] _M_curr_symbol;
3522 delete [] _M_positive_sign;
3523 delete [] _M_negative_sign;
3528 * @brief Facet for formatting data for money amounts.
3530 * This facet encapsulates the punctuation, grouping and other formatting
3531 * features of money amount string representations.
3533 template<typename _CharT, bool _Intl>
3534 class moneypunct : public locale::facet, public money_base
3540 typedef _CharT char_type;
3541 typedef basic_string<_CharT> string_type;
3543 typedef __moneypunct_cache<_CharT, _Intl> __cache_type;
3546 __cache_type* _M_data;
3549 /// This value is provided by the standard, but no reason for its
3551 static const bool intl = _Intl;
3552 /// Numpunct facet id.
3553 static locale::id id;
3556 * @brief Constructor performs initialization.
3558 * This is the constructor provided by the standard.
3560 * @param refs Passed to the base facet class.
3563 moneypunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
3564 { _M_initialize_moneypunct(); }
3567 * @brief Constructor performs initialization.
3569 * This is an internal constructor.
3571 * @param cache Cache for optimization.
3572 * @param refs Passed to the base facet class.
3575 moneypunct(__cache_type* __cache, size_t __refs = 0)
3576 : facet(__refs), _M_data(__cache)
3577 { _M_initialize_moneypunct(); }
3580 * @brief Internal constructor. Not for general use.
3582 * This is a constructor for use by the library itself to set up new
3585 * @param cloc The "C" locale.
3586 * @param s The name of a locale.
3587 * @param refs Passed to the base facet class.
3590 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
3591 : facet(__refs), _M_data(NULL)
3592 { _M_initialize_moneypunct(__cloc, __s); }
3595 * @brief Return decimal point character.
3597 * This function returns a char_type to use as a decimal point. It
3598 * does so by returning returning
3599 * moneypunct<char_type>::do_decimal_point().
3601 * @return @a char_type representing a decimal point.
3604 decimal_point() const
3605 { return this->do_decimal_point(); }
3608 * @brief Return thousands separator character.
3610 * This function returns a char_type to use as a thousands
3611 * separator. It does so by returning returning
3612 * moneypunct<char_type>::do_thousands_sep().
3614 * @return char_type representing a thousands separator.
3617 thousands_sep() const
3618 { return this->do_thousands_sep(); }
3621 * @brief Return grouping specification.
3623 * This function returns a string representing groupings for the
3624 * integer part of an amount. Groupings indicate where thousands
3625 * separators should be inserted.
3627 * Each char in the return string is interpret as an integer rather
3628 * than a character. These numbers represent the number of digits in a
3629 * group. The first char in the string represents the number of digits
3630 * in the least significant group. If a char is negative, it indicates
3631 * an unlimited number of digits for the group. If more chars from the
3632 * string are required to group a number, the last char is used
3635 * For example, if the grouping() returns "\003\002" and is applied to
3636 * the number 123456789, this corresponds to 12,34,56,789. Note that
3637 * if the string was "32", this would put more than 50 digits into the
3638 * least significant group if the character set is ASCII.
3640 * The string is returned by calling
3641 * moneypunct<char_type>::do_grouping().
3643 * @return string representing grouping specification.
3647 { return this->do_grouping(); }
3650 * @brief Return currency symbol string.
3652 * This function returns a string_type to use as a currency symbol. It
3653 * does so by returning returning
3654 * moneypunct<char_type>::do_curr_symbol().
3656 * @return @a string_type representing a currency symbol.
3660 { return this->do_curr_symbol(); }
3663 * @brief Return positive sign string.
3665 * This function returns a string_type to use as a sign for positive
3666 * amounts. It does so by returning returning
3667 * moneypunct<char_type>::do_positive_sign().
3669 * If the return value contains more than one character, the first
3670 * character appears in the position indicated by pos_format() and the
3671 * remainder appear at the end of the formatted string.
3673 * @return @a string_type representing a positive sign.
3676 positive_sign() const
3677 { return this->do_positive_sign(); }
3680 * @brief Return negative sign string.
3682 * This function returns a string_type to use as a sign for negative
3683 * amounts. It does so by returning returning
3684 * moneypunct<char_type>::do_negative_sign().
3686 * If the return value contains more than one character, the first
3687 * character appears in the position indicated by neg_format() and the
3688 * remainder appear at the end of the formatted string.
3690 * @return @a string_type representing a negative sign.
3693 negative_sign() const
3694 { return this->do_negative_sign(); }
3697 * @brief Return number of digits in fraction.
3699 * This function returns the exact number of digits that make up the
3700 * fractional part of a money amount. It does so by returning
3701 * returning moneypunct<char_type>::do_frac_digits().
3703 * The fractional part of a money amount is optional. But if it is
3704 * present, there must be frac_digits() digits.
3706 * @return Number of digits in amount fraction.
3710 { return this->do_frac_digits(); }
3714 * @brief Return pattern for money values.
3716 * This function returns a pattern describing the formatting of a
3717 * positive or negative valued money amount. It does so by returning
3718 * returning moneypunct<char_type>::do_pos_format() or
3719 * moneypunct<char_type>::do_neg_format().
3721 * The pattern has 4 fields describing the ordering of symbol, sign,
3722 * value, and none or space. There must be one of each in the pattern.
3723 * The none and space enums may not appear in the first field and space
3724 * may not appear in the final field.
3726 * The parts of a money string must appear in the order indicated by
3727 * the fields of the pattern. The symbol field indicates that the
3728 * value of curr_symbol() may be present. The sign field indicates
3729 * that the value of positive_sign() or negative_sign() must be
3730 * present. The value field indicates that the absolute value of the
3731 * money amount is present. none indicates 0 or more whitespace
3732 * characters, except at the end, where it permits no whitespace.
3733 * space indicates that 1 or more whitespace characters must be
3736 * For example, for the US locale and pos_format() pattern
3737 * {symbol,sign,value,none}, curr_symbol() == '$' positive_sign() ==
3738 * '+', and value 10.01, and options set to force the symbol, the
3739 * corresponding string is "$+10.01".
3741 * @return Pattern for money values.
3745 { return this->do_pos_format(); }
3749 { return this->do_neg_format(); }
3758 * @brief Return decimal point character.
3760 * Returns a char_type to use as a decimal point. This function is a
3761 * hook for derived classes to change the value returned.
3763 * @return @a char_type representing a decimal point.
3766 do_decimal_point() const
3767 { return _M_data->_M_decimal_point; }
3770 * @brief Return thousands separator character.
3772 * Returns a char_type to use as a thousands separator. This function
3773 * is a hook for derived classes to change the value returned.
3775 * @return @a char_type representing a thousands separator.
3778 do_thousands_sep() const
3779 { return _M_data->_M_thousands_sep; }
3782 * @brief Return grouping specification.
3784 * Returns a string representing groupings for the integer part of a
3785 * number. This function is a hook for derived classes to change the
3786 * value returned. @see grouping() for details.
3788 * @return String representing grouping specification.
3792 { return _M_data->_M_grouping; }
3795 * @brief Return currency symbol string.
3797 * This function returns a string_type to use as a currency symbol.
3798 * This function is a hook for derived classes to change the value
3799 * returned. @see curr_symbol() for details.
3801 * @return @a string_type representing a currency symbol.
3804 do_curr_symbol() const
3805 { return _M_data->_M_curr_symbol; }
3808 * @brief Return positive sign string.
3810 * This function returns a string_type to use as a sign for positive
3811 * amounts. This function is a hook for derived classes to change the
3812 * value returned. @see positive_sign() for details.
3814 * @return @a string_type representing a positive sign.
3817 do_positive_sign() const
3818 { return _M_data->_M_positive_sign; }
3821 * @brief Return negative sign string.
3823 * This function returns a string_type to use as a sign for negative
3824 * amounts. This function is a hook for derived classes to change the
3825 * value returned. @see negative_sign() for details.
3827 * @return @a string_type representing a negative sign.
3830 do_negative_sign() const
3831 { return _M_data->_M_negative_sign; }
3834 * @brief Return number of digits in fraction.
3836 * This function returns the exact number of digits that make up the
3837 * fractional part of a money amount. This function is a hook for
3838 * derived classes to change the value returned. @see frac_digits()
3841 * @return Number of digits in amount fraction.
3844 do_frac_digits() const
3845 { return _M_data->_M_frac_digits; }
3848 * @brief Return pattern for money values.
3850 * This function returns a pattern describing the formatting of a
3851 * positive valued money amount. This function is a hook for derived
3852 * classes to change the value returned. @see pos_format() for
3855 * @return Pattern for money values.
3858 do_pos_format() const
3859 { return _M_data->_M_pos_format; }
3862 * @brief Return pattern for money values.
3864 * This function returns a pattern describing the formatting of a
3865 * negative valued money amount. This function is a hook for derived
3866 * classes to change the value returned. @see neg_format() for
3869 * @return Pattern for money values.
3872 do_neg_format() const
3873 { return _M_data->_M_neg_format; }
3875 // For use at construction time only.
3877 _M_initialize_moneypunct(__c_locale __cloc = NULL,
3878 const char* __name = NULL);
3881 template<typename _CharT, bool _Intl>
3882 locale::id moneypunct<_CharT, _Intl>::id;
3884 template<typename _CharT, bool _Intl>
3885 const bool moneypunct<_CharT, _Intl>::intl;
3888 moneypunct<char, true>::~moneypunct();
3891 moneypunct<char, false>::~moneypunct();
3895 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
3899 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
3901 #ifdef _GLIBCXX_USE_WCHAR_T
3903 moneypunct<wchar_t, true>::~moneypunct();
3906 moneypunct<wchar_t, false>::~moneypunct();
3910 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
3915 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
3919 template<typename _CharT, bool _Intl>
3920 class moneypunct_byname : public moneypunct<_CharT, _Intl>
3923 typedef _CharT char_type;
3924 typedef basic_string<_CharT> string_type;
3926 static const bool intl = _Intl;
3929 moneypunct_byname(const char* __s, size_t __refs = 0)
3930 : moneypunct<_CharT, _Intl>(__refs)
3932 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
3935 this->_S_create_c_locale(__tmp, __s);
3936 this->_M_initialize_moneypunct(__tmp);
3937 this->_S_destroy_c_locale(__tmp);
3943 ~moneypunct_byname() { }
3946 template<typename _CharT, bool _Intl>
3947 const bool moneypunct_byname<_CharT, _Intl>::intl;
3950 * @brief Facet for parsing monetary amounts.
3952 * This facet encapsulates the code to parse and return a monetary
3953 * amount from a string.
3955 * The money_get template uses protected virtual functions to
3956 * provide the actual results. The public accessors forward the
3957 * call to the virtual functions. These virtual functions are
3958 * hooks for developers to implement the behavior they require from
3959 * the money_get facet.
3961 template<typename _CharT, typename _InIter>
3962 class money_get : public locale::facet
3968 typedef _CharT char_type;
3969 typedef _InIter iter_type;
3970 typedef basic_string<_CharT> string_type;
3973 /// Numpunct facet id.
3974 static locale::id id;
3977 * @brief Constructor performs initialization.
3979 * This is the constructor provided by the standard.
3981 * @param refs Passed to the base facet class.
3984 money_get(size_t __refs = 0) : facet(__refs) { }
3987 * @brief Read and parse a monetary value.
3989 * This function reads characters from @a s, interprets them as a
3990 * monetary value according to moneypunct and ctype facets retrieved
3991 * from io.getloc(), and returns the result in @a units as an integral
3992 * value moneypunct::frac_digits() * the actual amount. For example,
3993 * the string $10.01 in a US locale would store 1001 in @a units.
3995 * Any characters not part of a valid money amount are not consumed.
3997 * If a money value cannot be parsed from the input stream, sets
3998 * err=(err|io.failbit). If the stream is consumed before finishing
3999 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
4000 * unchanged if parsing fails.
4002 * This function works by returning the result of do_get().
4004 * @param s Start of characters to parse.
4005 * @param end End of characters to parse.
4006 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4007 * @param io Source of facets and io state.
4008 * @param err Error field to set if parsing fails.
4009 * @param units Place to store result of parsing.
4010 * @return Iterator referencing first character beyond valid money
4014 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4015 ios_base::iostate& __err, long double& __units) const
4016 { return this->do_get(__s, __end, __intl, __io, __err, __units); }
4019 * @brief Read and parse a monetary value.
4021 * This function reads characters from @a s, interprets them as a
4022 * monetary value according to moneypunct and ctype facets retrieved
4023 * from io.getloc(), and returns the result in @a digits. For example,
4024 * the string $10.01 in a US locale would store "1001" in @a digits.
4026 * Any characters not part of a valid money amount are not consumed.
4028 * If a money value cannot be parsed from the input stream, sets
4029 * err=(err|io.failbit). If the stream is consumed before finishing
4030 * parsing, sets err=(err|io.failbit|io.eofbit).
4032 * This function works by returning the result of do_get().
4034 * @param s Start of characters to parse.
4035 * @param end End of characters to parse.
4036 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4037 * @param io Source of facets and io state.
4038 * @param err Error field to set if parsing fails.
4039 * @param digits Place to store result of parsing.
4040 * @return Iterator referencing first character beyond valid money
4044 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4045 ios_base::iostate& __err, string_type& __digits) const
4046 { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
4054 * @brief Read and parse a monetary value.
4056 * This function reads and parses characters representing a monetary
4057 * value. This function is a hook for derived classes to change the
4058 * value returned. @see get() for details.
4061 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4062 ios_base::iostate& __err, long double& __units) const;
4065 * @brief Read and parse a monetary value.
4067 * This function reads and parses characters representing a monetary
4068 * value. This function is a hook for derived classes to change the
4069 * value returned. @see get() for details.
4072 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4073 ios_base::iostate& __err, string_type& __digits) const;
4075 template<bool _Intl>
4077 _M_extract(iter_type __s, iter_type __end, ios_base& __io,
4078 ios_base::iostate& __err, string& __digits) const;
4081 template<typename _CharT, typename _InIter>
4082 locale::id money_get<_CharT, _InIter>::id;
4085 * @brief Facet for outputting monetary amounts.
4087 * This facet encapsulates the code to format and output a monetary
4090 * The money_put template uses protected virtual functions to
4091 * provide the actual results. The public accessors forward the
4092 * call to the virtual functions. These virtual functions are
4093 * hooks for developers to implement the behavior they require from
4094 * the money_put facet.
4096 template<typename _CharT, typename _OutIter>
4097 class money_put : public locale::facet
4102 typedef _CharT char_type;
4103 typedef _OutIter iter_type;
4104 typedef basic_string<_CharT> string_type;
4107 /// Numpunct facet id.
4108 static locale::id id;
4111 * @brief Constructor performs initialization.
4113 * This is the constructor provided by the standard.
4115 * @param refs Passed to the base facet class.
4118 money_put(size_t __refs = 0) : facet(__refs) { }
4121 * @brief Format and output a monetary value.
4123 * This function formats @a units as a monetary value according to
4124 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4125 * the resulting characters to @a s. For example, the value 1001 in a
4126 * US locale would write "$10.01" to @a s.
4128 * This function works by returning the result of do_put().
4130 * @param s The stream to write to.
4131 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4132 * @param io Source of facets and io state.
4133 * @param fill char_type to use for padding.
4134 * @param units Place to store result of parsing.
4135 * @return Iterator after writing.
4138 put(iter_type __s, bool __intl, ios_base& __io,
4139 char_type __fill, long double __units) const
4140 { return this->do_put(__s, __intl, __io, __fill, __units); }
4143 * @brief Format and output a monetary value.
4145 * This function formats @a digits as a monetary value according to
4146 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4147 * the resulting characters to @a s. For example, the string "1001" in
4148 * a US locale would write "$10.01" to @a s.
4150 * This function works by returning the result of do_put().
4152 * @param s The stream to write to.
4153 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4154 * @param io Source of facets and io state.
4155 * @param fill char_type to use for padding.
4156 * @param units Place to store result of parsing.
4157 * @return Iterator after writing.
4160 put(iter_type __s, bool __intl, ios_base& __io,
4161 char_type __fill, const string_type& __digits) const
4162 { return this->do_put(__s, __intl, __io, __fill, __digits); }
4170 * @brief Format and output a monetary value.
4172 * This function formats @a units as a monetary value according to
4173 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4174 * the resulting characters to @a s. For example, the value 1001 in a
4175 * US locale would write "$10.01" to @a s.
4177 * This function is a hook for derived classes to change the value
4178 * returned. @see put().
4180 * @param s The stream to write to.
4181 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4182 * @param io Source of facets and io state.
4183 * @param fill char_type to use for padding.
4184 * @param units Place to store result of parsing.
4185 * @return Iterator after writing.
4188 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4189 long double __units) const;
4192 * @brief Format and output a monetary value.
4194 * This function formats @a digits as a monetary value according to
4195 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4196 * the resulting characters to @a s. For example, the string "1001" in
4197 * a US locale would write "$10.01" to @a s.
4199 * This function is a hook for derived classes to change the value
4200 * returned. @see put().
4202 * @param s The stream to write to.
4203 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4204 * @param io Source of facets and io state.
4205 * @param fill char_type to use for padding.
4206 * @param units Place to store result of parsing.
4207 * @return Iterator after writing.
4210 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4211 const string_type& __digits) const;
4213 template<bool _Intl>
4215 _M_insert(iter_type __s, ios_base& __io, char_type __fill,
4216 const string_type& __digits) const;
4219 template<typename _CharT, typename _OutIter>
4220 locale::id money_put<_CharT, _OutIter>::id;
4223 * @brief Messages facet base class providing catalog typedef.
4225 struct messages_base
4227 typedef int catalog;
4231 * @brief Facet for handling message catalogs
4233 * This facet encapsulates the code to retrieve messages from
4234 * message catalogs. The only thing defined by the standard for this facet
4235 * is the interface. All underlying functionality is
4236 * implementation-defined.
4238 * This library currently implements 3 versions of the message facet. The
4239 * first version (gnu) is a wrapper around gettext, provided by libintl.
4240 * The second version (ieee) is a wrapper around catgets. The final
4241 * version (default) does no actual translation. These implementations are
4242 * only provided for char and wchar_t instantiations.
4244 * The messages template uses protected virtual functions to
4245 * provide the actual results. The public accessors forward the
4246 * call to the virtual functions. These virtual functions are
4247 * hooks for developers to implement the behavior they require from
4248 * the messages facet.
4250 template<typename _CharT>
4251 class messages : public locale::facet, public messages_base
4257 typedef _CharT char_type;
4258 typedef basic_string<_CharT> string_type;
4262 // Underlying "C" library locale information saved from
4263 // initialization, needed by messages_byname as well.
4264 __c_locale _M_c_locale_messages;
4265 const char* _M_name_messages;
4268 /// Numpunct facet id.
4269 static locale::id id;
4272 * @brief Constructor performs initialization.
4274 * This is the constructor provided by the standard.
4276 * @param refs Passed to the base facet class.
4279 messages(size_t __refs = 0);
4283 * @brief Internal constructor. Not for general use.
4285 * This is a constructor for use by the library itself to set up new
4288 * @param cloc The "C" locale.
4289 * @param s The name of a locale.
4290 * @param refs Refcount to pass to the base class.
4293 messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
4296 * @brief Open a message catalog.
4298 * This function opens and returns a handle to a message catalog by
4299 * returning do_open(s, loc).
4301 * @param s The catalog to open.
4302 * @param loc Locale to use for character set conversions.
4303 * @return Handle to the catalog or value < 0 if open fails.
4306 open(const basic_string<char>& __s, const locale& __loc) const
4307 { return this->do_open(__s, __loc); }
4309 // Non-standard and unorthodox, yet effective.
4311 * @brief Open a message catalog.
4313 * This non-standard function opens and returns a handle to a message
4314 * catalog by returning do_open(s, loc). The third argument provides a
4315 * message catalog root directory for gnu gettext and is ignored
4318 * @param s The catalog to open.
4319 * @param loc Locale to use for character set conversions.
4320 * @param dir Message catalog root directory.
4321 * @return Handle to the catalog or value < 0 if open fails.
4324 open(const basic_string<char>&, const locale&, const char*) const;
4327 * @brief Look up a string in a message catalog.
4329 * This function retrieves and returns a message from a catalog by
4330 * returning do_get(c, set, msgid, s).
4332 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4333 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4335 * @param c The catalog to access.
4336 * @param set Implementation-defined.
4337 * @param msgid Implementation-defined.
4338 * @param s Default return value if retrieval fails.
4339 * @return Retrieved message or @a s if get fails.
4342 get(catalog __c, int __set, int __msgid, const string_type& __s) const
4343 { return this->do_get(__c, __set, __msgid, __s); }
4346 * @brief Close a message catalog.
4348 * Closes catalog @a c by calling do_close(c).
4350 * @param c The catalog to close.
4353 close(catalog __c) const
4354 { return this->do_close(__c); }
4362 * @brief Open a message catalog.
4364 * This function opens and returns a handle to a message catalog in an
4365 * implementation-defined manner. This function is a hook for derived
4366 * classes to change the value returned.
4368 * @param s The catalog to open.
4369 * @param loc Locale to use for character set conversions.
4370 * @return Handle to the opened catalog, value < 0 if open failed.
4373 do_open(const basic_string<char>&, const locale&) const;
4376 * @brief Look up a string in a message catalog.
4378 * This function retrieves and returns a message from a catalog in an
4379 * implementation-defined manner. This function is a hook for derived
4380 * classes to change the value returned.
4382 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4383 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4385 * @param c The catalog to access.
4386 * @param set Implementation-defined.
4387 * @param msgid Implementation-defined.
4388 * @param s Default return value if retrieval fails.
4389 * @return Retrieved message or @a s if get fails.
4392 do_get(catalog, int, int, const string_type& __dfault) const;
4395 * @brief Close a message catalog.
4397 * @param c The catalog to close.
4400 do_close(catalog) const;
4402 // Returns a locale and codeset-converted string, given a char* message.
4404 _M_convert_to_char(const string_type& __msg) const
4407 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
4410 // Returns a locale and codeset-converted string, given a char* message.
4412 _M_convert_from_char(char*) const
4415 // Length of message string without terminating null.
4416 size_t __len = char_traits<char>::length(__msg) - 1;
4418 // "everybody can easily convert the string using
4419 // mbsrtowcs/wcsrtombs or with iconv()"
4421 // Convert char* to _CharT in locale used to open catalog.
4422 // XXX need additional template parameter on messages class for this..
4423 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
4424 typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;
4426 __codecvt_type::state_type __state;
4427 // XXX may need to initialize state.
4428 //initialize_state(__state._M_init());
4431 // XXX what size for this string?
4432 _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
4433 const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
4434 __cvt.out(__state, __msg, __msg + __len, __from_next,
4435 __to, __to + __len + 1, __to_next);
4436 return string_type(__to);
4439 typedef ctype<_CharT> __ctype_type;
4440 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
4441 const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
4442 // XXX Again, proper length of converted string an issue here.
4443 // For now, assume the converted length is not larger.
4444 _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
4445 __cvt.widen(__msg, __msg + __len, __dest);
4446 return basic_string<_CharT>(__dest);
4448 return string_type();
4452 template<typename _CharT>
4453 locale::id messages<_CharT>::id;
4455 // Specializations for required instantiations.
4458 messages<char>::do_get(catalog, int, int, const string&) const;
4460 #ifdef _GLIBCXX_USE_WCHAR_T
4463 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
4466 template<typename _CharT>
4467 class messages_byname : public messages<_CharT>
4470 typedef _CharT char_type;
4471 typedef basic_string<_CharT> string_type;
4474 messages_byname(const char* __s, size_t __refs = 0);
4482 // Include host and configuration specific messages functions.
4483 #include <bits/messages_members.h>
4486 // Subclause convenience interfaces, inlines.
4487 // NB: These are inline because, when used in a loop, some compilers
4488 // can hoist the body out of the loop; then it's just as fast as the
4489 // C is*() function.
4491 /// Convenience interface to ctype.is().
4492 template<typename _CharT>
4494 isspace(_CharT __c, const locale& __loc)
4495 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
4497 template<typename _CharT>
4499 isprint(_CharT __c, const locale& __loc)
4500 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
4502 template<typename _CharT>
4504 iscntrl(_CharT __c, const locale& __loc)
4505 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
4507 template<typename _CharT>
4509 isupper(_CharT __c, const locale& __loc)
4510 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
4512 template<typename _CharT>
4513 inline bool islower(_CharT __c, const locale& __loc)
4514 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
4516 template<typename _CharT>
4518 isalpha(_CharT __c, const locale& __loc)
4519 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
4521 template<typename _CharT>
4523 isdigit(_CharT __c, const locale& __loc)
4524 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
4526 template<typename _CharT>
4528 ispunct(_CharT __c, const locale& __loc)
4529 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
4531 template<typename _CharT>
4533 isxdigit(_CharT __c, const locale& __loc)
4534 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
4536 template<typename _CharT>
4538 isalnum(_CharT __c, const locale& __loc)
4539 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
4541 template<typename _CharT>
4543 isgraph(_CharT __c, const locale& __loc)
4544 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
4546 template<typename _CharT>
4548 toupper(_CharT __c, const locale& __loc)
4549 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
4551 template<typename _CharT>
4553 tolower(_CharT __c, const locale& __loc)
4554 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }