* Mainline merge as of 2006-02-16 (@111136).
[official-gcc.git] / libstdc++-v3 / include / bits / locale_facets.h
blob538fa5183504e2a4c8bc66a413cbc571853e25af
1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
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
47 #include <iosfwd>
48 #include <bits/ios_base.h> // For ios_base, ios_base::iostate
49 #include <streambuf>
51 _GLIBCXX_BEGIN_NAMESPACE(std)
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
56 #else
57 # define _GLIBCXX_NUM_FACETS 14
58 #endif
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>
64 void
65 __convert_to_v(const char* __in, _Tv& __out, ios_base::iostate& __err,
66 const __c_locale& __cloc);
68 // Explicit specializations for required types.
69 template<>
70 void
71 __convert_to_v(const char*, float&, ios_base::iostate&,
72 const __c_locale&);
74 template<>
75 void
76 __convert_to_v(const char*, double&, ios_base::iostate&,
77 const __c_locale&);
79 template<>
80 void
81 __convert_to_v(const char*, long double&, ios_base::iostate&,
82 const __c_locale&);
84 // NB: __pad is a struct, rather than a function, so it can be
85 // partially-specialized.
86 template<typename _CharT, typename _Traits>
87 struct __pad
89 static void
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>
101 _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>
110 inline
111 ostreambuf_iterator<_CharT>
112 __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len)
114 __s._M_put(__ws, __len);
115 return __s;
118 // This is the unspecialized form of the template.
119 template<typename _CharT, typename _OutIter>
120 inline
121 _OutIter
122 __write(_OutIter __s, const _CharT* __ws, int __len)
124 for (int __j = 0; __j < __len; __j++, ++__s)
125 *__s = __ws[__j];
126 return __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
142 * functions.
144 template<typename _CharT>
145 class __ctype_abstract_base : public locale::facet, public ctype_base
147 public:
148 // Types:
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.
162 bool
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.
177 * @return @a hi.
179 const char_type*
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.
195 const char_type*
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.
211 const char_type*
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.
225 char_type
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.
238 * @return @a hi.
240 const char_type*
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.
254 char_type
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.
267 * @return @a hi.
269 const char_type*
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
281 * codecvt for that.
283 * @param c The char to convert.
284 * @return The converted char_type.
286 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
298 * codecvt for that.
300 * @param lo Pointer to start of range.
301 * @param hi Pointer to end of range.
302 * @param to Pointer to the destination array.
303 * @return @a hi.
305 const char*
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
318 * codecvt for that.
320 * @param c The char_type to convert.
321 * @param dfault Char to return if conversion fails.
322 * @return The converted char.
324 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
338 * codecvt for that.
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.
344 * @return @a hi.
346 const char_type*
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); }
351 protected:
352 explicit
353 __ctype_abstract_base(size_t __refs = 0): facet(__refs) { }
355 virtual
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
365 * same input.
367 * @param c The char_type to find the mask of.
368 * @param m The mask to compare against.
369 * @return (M & m) != 0.
371 virtual bool
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
379 * as the input.
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
383 * same input.
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.
388 * @return @a hi.
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
402 * same input.
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
421 * same input.
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
437 * argument.
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
441 * the same input.
443 * @param c The char_type to convert.
444 * @return The uppercase char_type if convertible, else @a c.
446 virtual char_type
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
457 * the same input.
459 * @param lo Pointer to start of range.
460 * @param hi Pointer to end of range.
461 * @return @a hi.
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
474 * the same input.
476 * @param c The char_type to convert.
477 * @return The lowercase char_type if convertible, else @a c.
479 virtual char_type
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
490 * the same input.
492 * @param lo Pointer to start of range.
493 * @param hi Pointer to end of range.
494 * @return @a hi.
496 virtual const char_type*
497 do_tolower(char_type* __lo, const char_type* __hi) const = 0;
500 * @brief Widen char
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
507 * same input.
509 * Note: this is not what you want for codepage conversions. See
510 * codecvt for that.
512 * @param c The char to convert.
513 * @return The converted char_type
515 virtual 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
526 * same input.
528 * Note: this is not what you want for codepage conversions. See
529 * codecvt for that.
531 * @param lo Pointer to start range.
532 * @param hi Pointer to end of range.
533 * @param to Pointer to the destination array.
534 * @return @a hi.
536 virtual const char*
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
549 * same input.
551 * Note: this is not what you want for codepage conversions. See
552 * codecvt for that.
554 * @param c The char_type to convert.
555 * @param dfault Char to return if conversion fails.
556 * @return The converted char.
558 virtual 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
571 * same input.
573 * Note: this is not what you want for codepage conversions. See
574 * codecvt for that.
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.
580 * @return @a hi.
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>
608 public:
609 // Types:
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;
616 explicit
617 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
619 protected:
620 virtual
621 ~ctype();
623 virtual bool
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;
636 virtual char_type
637 do_toupper(char_type __c) const;
639 virtual const char_type*
640 do_toupper(char_type* __lo, const char_type* __hi) const;
642 virtual char_type
643 do_tolower(char_type __c) const;
645 virtual const char_type*
646 do_tolower(char_type* __lo, const char_type* __hi) const;
648 virtual char_type
649 do_widen(char __c) const;
651 virtual const char*
652 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
654 virtual char
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.
674 template<>
675 class ctype<char> : public locale::facet, public ctype_base
677 public:
678 // Types:
679 /// Typedef for the template parameter char.
680 typedef char char_type;
682 protected:
683 // Data Members:
684 __c_locale _M_c_locale_ctype;
685 bool _M_del;
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
695 public:
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.
711 explicit
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.
724 explicit
725 ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
726 size_t __refs = 0);
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.
737 inline bool
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
745 * the char array.
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.
750 * @return @a hi.
752 inline const char*
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.
766 inline const char*
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.
780 inline const char*
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.
795 char_type
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.
810 * @return @a hi.
812 const char_type*
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.
828 char_type
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.
843 * @return @a hi.
845 const char_type*
846 tolower(char_type* __lo, const char_type* __hi) const
847 { return this->do_tolower(__lo, __hi); }
850 * @brief Widen char
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
860 * codecvt for that.
862 * @param c The char to convert.
863 * @return The converted character.
865 char_type
866 widen(char __c) const
868 if (_M_widen_ok)
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
885 * codecvt for that.
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.
890 * @return @a hi.
892 const char*
893 widen(const char* __lo, const char* __hi, char_type* __to) const
895 if (_M_widen_ok == 1)
897 memcpy(__to, __lo, __hi - __lo);
898 return __hi;
900 if (!_M_widen_ok)
901 _M_widen_init();
902 return this->do_widen(__lo, __hi, __to);
906 * @brief Narrow char
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
917 * codecvt for that.
919 * @param c The char to convert.
920 * @param dfault Char to return if conversion fails.
921 * @return The converted character.
923 char
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);
929 if (__t != __dfault)
930 _M_narrow[static_cast<unsigned char>(__c)] = __t;
931 return __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
945 * same input.
947 * Note: this is not what you want for codepage conversions. See
948 * codecvt for that.
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.
954 * @return @a hi.
956 const char_type*
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);
963 return __hi;
965 if (!_M_narrow_ok)
966 _M_narrow_init();
967 return this->do_narrow(__lo, __hi, __dfault, __to);
970 protected:
971 /// Returns a pointer to the mask table provided to the constructor, or
972 /// the default from classic_table() if none was provided.
973 const mask*
974 table() const throw()
975 { return _M_table; }
977 /// Returns a pointer to the C locale mask table.
978 static const mask*
979 classic_table() throw();
982 * @brief Destructor.
984 * This function deletes table() if @a del was true in the
985 * constructor.
987 virtual
988 ~ctype();
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
998 * the same input.
1000 * @param c The char to convert.
1001 * @return The uppercase char if convertible, else @a c.
1003 virtual char_type
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
1014 * the same input.
1016 * @param lo Pointer to start of range.
1017 * @param hi Pointer to end of range.
1018 * @return @a hi.
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
1031 * the same input.
1033 * @param c The char to convert.
1034 * @return The lowercase char if convertible, else @a c.
1036 virtual char_type
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
1047 * the same input.
1049 * @param lo Pointer to first char in range.
1050 * @param hi Pointer to end of range.
1051 * @return @a hi.
1053 virtual const char_type*
1054 do_tolower(char_type* __lo, const char_type* __hi) const;
1057 * @brief Widen char
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
1065 * same input.
1067 * Note: this is not what you want for codepage conversions. See
1068 * codecvt for that.
1070 * @param c The char to convert.
1071 * @return The converted character.
1073 virtual char_type
1074 do_widen(char __c) const
1075 { return __c; }
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
1086 * same input.
1088 * Note: this is not what you want for codepage conversions. See
1089 * codecvt for that.
1091 * @param lo Pointer to start of range.
1092 * @param hi Pointer to end of range.
1093 * @param to Pointer to the destination array.
1094 * @return @a hi.
1096 virtual const char*
1097 do_widen(const char* __lo, const char* __hi, char_type* __dest) const
1099 memcpy(__dest, __lo, __hi - __lo);
1100 return __hi;
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
1113 * same input.
1115 * Note: this is not what you want for codepage conversions. See
1116 * codecvt for that.
1118 * @param c The char to convert.
1119 * @param dfault Char to return if conversion fails.
1120 * @return The converted char.
1122 virtual char
1123 do_narrow(char_type __c, char) const
1124 { return __c; }
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
1137 * same input.
1139 * Note: this is not what you want for codepage conversions. See
1140 * codecvt for that.
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.
1146 * @return @a hi.
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);
1153 return __hi;
1156 private:
1158 void _M_widen_init() const
1160 char __tmp[sizeof(_M_widen)];
1161 for (size_t __i = 0; __i < sizeof(_M_widen); ++__i)
1162 __tmp[__i] = __i;
1163 do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen);
1165 _M_widen_ok = 1;
1166 // Set _M_widen_ok to 2 if memcpy can't be used.
1167 if (memcmp(__tmp, _M_widen, sizeof(_M_widen)))
1168 _M_widen_ok = 2;
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
1173 // be used.
1174 void _M_narrow_init() const
1176 char __tmp[sizeof(_M_narrow)];
1177 for (size_t __i = 0; __i < sizeof(_M_narrow); ++__i)
1178 __tmp[__i] = __i;
1179 do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow);
1181 _M_narrow_ok = 1;
1182 if (memcmp(__tmp, _M_narrow, sizeof(_M_narrow)))
1183 _M_narrow_ok = 2;
1184 else
1186 // Deal with the special case of zero: renarrow with a
1187 // different default and compare.
1188 char __c;
1189 do_narrow(__tmp, __tmp + 1, 1, &__c);
1190 if (__c == 1)
1191 _M_narrow_ok = 2;
1196 template<>
1197 const ctype<char>&
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>.
1212 template<>
1213 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
1215 public:
1216 // Types:
1217 /// Typedef for the template parameter wchar_t.
1218 typedef wchar_t char_type;
1219 typedef wctype_t __wmask_type;
1221 protected:
1222 __c_locale _M_c_locale_ctype;
1224 // Pre-computed narrowed and widened chars.
1225 bool _M_narrow_ok;
1226 char _M_narrow[128];
1227 wint_t _M_widen[1 + static_cast<unsigned char>(-1)];
1229 // Pre-computed elements for do_is.
1230 mask _M_bit[16];
1231 __wmask_type _M_wmask[16];
1233 public:
1234 // Data Members:
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.
1245 explicit
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.
1256 explicit
1257 ctype(__c_locale __cloc, size_t __refs = 0);
1259 protected:
1260 __wmask_type
1261 _M_convert_to_wmask(const mask __m) const;
1263 /// Destructor
1264 virtual
1265 ~ctype();
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
1274 * same input.
1276 * @param c The wchar_t to find the mask of.
1277 * @param m The mask to compare against.
1278 * @return (M & m) != 0.
1280 virtual bool
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
1288 * as the input.
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
1292 * same input.
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.
1297 * @return @a hi.
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
1310 * same input.
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
1328 * same input.
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
1347 * the same input.
1349 * @param c The wchar_t to convert.
1350 * @return The uppercase wchar_t if convertible, else @a c.
1352 virtual char_type
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
1363 * the same input.
1365 * @param lo Pointer to start of range.
1366 * @param hi Pointer to end of range.
1367 * @return @a hi.
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
1380 * the same input.
1382 * @param c The wchar_t to convert.
1383 * @return The lowercase wchar_t if convertible, else @a c.
1385 virtual char_type
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
1396 * the same input.
1398 * @param lo Pointer to start of range.
1399 * @param hi Pointer to end of range.
1400 * @return @a hi.
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
1414 * same input.
1416 * Note: this is not what you want for codepage conversions. See
1417 * codecvt for that.
1419 * @param c The char to convert.
1420 * @return The converted wchar_t.
1422 virtual char_type
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
1434 * same input.
1436 * Note: this is not what you want for codepage conversions. See
1437 * codecvt for that.
1439 * @param lo Pointer to start range.
1440 * @param hi Pointer to end of range.
1441 * @param to Pointer to the destination array.
1442 * @return @a hi.
1444 virtual const char*
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
1454 * returned.
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
1461 * codecvt for that.
1463 * @param c The wchar_t to convert.
1464 * @param dfault Char to return if conversion fails.
1465 * @return The converted char.
1467 virtual 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
1478 * element to char.
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
1482 * same input.
1484 * Note: this is not what you want for codepage conversions. See
1485 * codecvt for that.
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.
1491 * @return @a hi.
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.
1498 void
1499 _M_initialize_ctype();
1502 template<>
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 /// @brief class ctype_byname [22.2.1.2].
1511 template<typename _CharT>
1512 class ctype_byname : public ctype<_CharT>
1514 public:
1515 typedef _CharT char_type;
1517 explicit
1518 ctype_byname(const char* __s, size_t __refs = 0);
1520 protected:
1521 virtual
1522 ~ctype_byname() { };
1525 /// 22.2.1.4 Class ctype_byname specializations.
1526 template<>
1527 ctype_byname<char>::ctype_byname(const char*, size_t refs);
1529 template<>
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.
1536 class __num_base
1538 public:
1539 // NB: Code depends on the order of _S_atoms_out elements.
1540 // Below are the indices into _S_atoms_out.
1541 enum
1543 _S_ominus,
1544 _S_oplus,
1545 _S_ox,
1546 _S_oX,
1547 _S_odigits,
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;
1567 enum
1569 _S_iminus,
1570 _S_iplus,
1571 _S_ix,
1572 _S_iX,
1573 _S_izero,
1574 _S_ie = _S_izero + 14,
1575 _S_iE = _S_izero + 20,
1576 _S_iend = 26
1579 // num_put
1580 // Construct and return valid scanf format for floating point types.
1581 static void
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];
1610 bool _M_allocated;
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();
1621 void
1622 _M_cache(const locale& __loc);
1624 private:
1625 __numpunct_cache&
1626 operator=(const __numpunct_cache&);
1628 explicit
1629 __numpunct_cache(const __numpunct_cache&);
1632 template<typename _CharT>
1633 __numpunct_cache<_CharT>::~__numpunct_cache()
1635 if (_M_allocated)
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
1659 public:
1660 // Types:
1661 //@{
1662 /// Public typedefs
1663 typedef _CharT char_type;
1664 typedef basic_string<_CharT> string_type;
1665 //@}
1666 typedef __numpunct_cache<_CharT> __cache_type;
1668 protected:
1669 __cache_type* _M_data;
1671 public:
1672 /// Numpunct facet id.
1673 static locale::id id;
1676 * @brief Numpunct constructor.
1678 * @param refs Refcount to pass to the base class.
1680 explicit
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.
1693 explicit
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
1702 * locales.
1704 * @param cloc The "C" locale.
1705 * @param refs Refcount to pass to the base class.
1707 explicit
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.
1721 char_type
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.
1734 char_type
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
1752 * repeatedly.
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.
1765 string
1766 grouping() const
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.
1778 string_type
1779 truename() const
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.
1791 string_type
1792 falsename() const
1793 { return this->do_falsename(); }
1795 protected:
1796 /// Destructor.
1797 virtual
1798 ~numpunct();
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.
1808 virtual char_type
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.
1820 virtual char_type
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.
1833 virtual string
1834 do_grouping() const
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.
1846 virtual string_type
1847 do_truename() const
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.
1859 virtual string_type
1860 do_falsename() const
1861 { return _M_data->_M_falsename; }
1863 // For use at construction time only.
1864 void
1865 _M_initialize_numpunct(__c_locale __cloc = NULL);
1868 template<typename _CharT>
1869 locale::id numpunct<_CharT>::id;
1871 template<>
1872 numpunct<char>::~numpunct();
1874 template<>
1875 void
1876 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
1878 #ifdef _GLIBCXX_USE_WCHAR_T
1879 template<>
1880 numpunct<wchar_t>::~numpunct();
1882 template<>
1883 void
1884 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
1885 #endif
1887 /// @brief class numpunct_byname [22.2.3.2].
1888 template<typename _CharT>
1889 class numpunct_byname : public numpunct<_CharT>
1891 public:
1892 typedef _CharT char_type;
1893 typedef basic_string<_CharT> string_type;
1895 explicit
1896 numpunct_byname(const char* __s, size_t __refs = 0)
1897 : numpunct<_CharT>(__refs)
1899 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
1901 __c_locale __tmp;
1902 this->_S_create_c_locale(__tmp, __s);
1903 this->_M_initialize_numpunct(__tmp);
1904 this->_S_destroy_c_locale(__tmp);
1908 protected:
1909 virtual
1910 ~numpunct_byname() { }
1913 _GLIBCXX_BEGIN_LDBL_NAMESPACE
1915 * @brief Facet for parsing number strings.
1917 * This facet encapsulates the code to parse and return a number
1918 * from a string. It is used by the istream numeric extraction
1919 * operators.
1921 * The num_get template uses protected virtual functions to provide the
1922 * actual results. The public accessors forward the call to the virtual
1923 * functions. These virtual functions are hooks for developers to
1924 * implement the behavior they require from the num_get facet.
1926 template<typename _CharT, typename _InIter>
1927 class num_get : public locale::facet
1929 public:
1930 // Types:
1931 //@{
1932 /// Public typedefs
1933 typedef _CharT char_type;
1934 typedef _InIter iter_type;
1935 //@}
1937 /// Numpunct facet id.
1938 static locale::id id;
1941 * @brief Constructor performs initialization.
1943 * This is the constructor provided by the standard.
1945 * @param refs Passed to the base facet class.
1947 explicit
1948 num_get(size_t __refs = 0) : facet(__refs) { }
1951 * @brief Numeric parsing.
1953 * Parses the input stream into the bool @a v. It does so by calling
1954 * num_get::do_get().
1956 * If ios_base::boolalpha is set, attempts to read
1957 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
1958 * @a v to true or false if successful. Sets err to
1959 * ios_base::failbit if reading the string fails. Sets err to
1960 * ios_base::eofbit if the stream is emptied.
1962 * If ios_base::boolalpha is not set, proceeds as with reading a long,
1963 * except if the value is 1, sets @a v to true, if the value is 0, sets
1964 * @a v to false, and otherwise set err to ios_base::failbit.
1966 * @param in Start of input stream.
1967 * @param end End of input stream.
1968 * @param io Source of locale and flags.
1969 * @param err Error flags to set.
1970 * @param v Value to format and insert.
1971 * @return Iterator after reading.
1973 iter_type
1974 get(iter_type __in, iter_type __end, ios_base& __io,
1975 ios_base::iostate& __err, bool& __v) const
1976 { return this->do_get(__in, __end, __io, __err, __v); }
1978 //@{
1980 * @brief Numeric parsing.
1982 * Parses the input stream into the integral variable @a v. It does so
1983 * by calling num_get::do_get().
1985 * Parsing is affected by the flag settings in @a io.
1987 * The basic parse is affected by the value of io.flags() &
1988 * ios_base::basefield. If equal to ios_base::oct, parses like the
1989 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X
1990 * specifier. Else if basefield equal to 0, parses like the %i
1991 * specifier. Otherwise, parses like %d for signed and %u for unsigned
1992 * types. The matching type length modifier is also used.
1994 * Digit grouping is intrepreted according to numpunct::grouping() and
1995 * numpunct::thousands_sep(). If the pattern of digit groups isn't
1996 * consistent, sets err to ios_base::failbit.
1998 * If parsing the string yields a valid value for @a v, @a v is set.
1999 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2000 * Sets err to ios_base::eofbit if the stream is emptied.
2002 * @param in Start of input stream.
2003 * @param end End of input stream.
2004 * @param io Source of locale and flags.
2005 * @param err Error flags to set.
2006 * @param v Value to format and insert.
2007 * @return Iterator after reading.
2009 iter_type
2010 get(iter_type __in, iter_type __end, ios_base& __io,
2011 ios_base::iostate& __err, long& __v) const
2012 { return this->do_get(__in, __end, __io, __err, __v); }
2014 iter_type
2015 get(iter_type __in, iter_type __end, ios_base& __io,
2016 ios_base::iostate& __err, unsigned short& __v) const
2017 { return this->do_get(__in, __end, __io, __err, __v); }
2019 iter_type
2020 get(iter_type __in, iter_type __end, ios_base& __io,
2021 ios_base::iostate& __err, unsigned int& __v) const
2022 { return this->do_get(__in, __end, __io, __err, __v); }
2024 iter_type
2025 get(iter_type __in, iter_type __end, ios_base& __io,
2026 ios_base::iostate& __err, unsigned long& __v) const
2027 { return this->do_get(__in, __end, __io, __err, __v); }
2029 #ifdef _GLIBCXX_USE_LONG_LONG
2030 iter_type
2031 get(iter_type __in, iter_type __end, ios_base& __io,
2032 ios_base::iostate& __err, long long& __v) const
2033 { return this->do_get(__in, __end, __io, __err, __v); }
2035 iter_type
2036 get(iter_type __in, iter_type __end, ios_base& __io,
2037 ios_base::iostate& __err, unsigned long long& __v) const
2038 { return this->do_get(__in, __end, __io, __err, __v); }
2039 #endif
2040 //@}
2042 //@{
2044 * @brief Numeric parsing.
2046 * Parses the input stream into the integral variable @a v. It does so
2047 * by calling num_get::do_get().
2049 * The input characters are parsed like the scanf %g specifier. The
2050 * matching type length modifier is also used.
2052 * The decimal point character used is numpunct::decimal_point().
2053 * Digit grouping is intrepreted according to numpunct::grouping() and
2054 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2055 * consistent, sets err to ios_base::failbit.
2057 * If parsing the string yields a valid value for @a v, @a v is set.
2058 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2059 * Sets err to ios_base::eofbit if the stream is emptied.
2061 * @param in Start of input stream.
2062 * @param end End of input stream.
2063 * @param io Source of locale and flags.
2064 * @param err Error flags to set.
2065 * @param v Value to format and insert.
2066 * @return Iterator after reading.
2068 iter_type
2069 get(iter_type __in, iter_type __end, ios_base& __io,
2070 ios_base::iostate& __err, float& __v) const
2071 { return this->do_get(__in, __end, __io, __err, __v); }
2073 iter_type
2074 get(iter_type __in, iter_type __end, ios_base& __io,
2075 ios_base::iostate& __err, double& __v) const
2076 { return this->do_get(__in, __end, __io, __err, __v); }
2078 iter_type
2079 get(iter_type __in, iter_type __end, ios_base& __io,
2080 ios_base::iostate& __err, long double& __v) const
2081 { return this->do_get(__in, __end, __io, __err, __v); }
2082 //@}
2085 * @brief Numeric parsing.
2087 * Parses the input stream into the pointer variable @a v. It does so
2088 * by calling num_get::do_get().
2090 * The input characters are parsed like the scanf %p specifier.
2092 * Digit grouping is intrepreted according to numpunct::grouping() and
2093 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2094 * consistent, sets err to ios_base::failbit.
2096 * Note that the digit grouping effect for pointers is a bit ambiguous
2097 * in the standard and shouldn't be relied on. See DR 344.
2099 * If parsing the string yields a valid value for @a v, @a v is set.
2100 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2101 * Sets err to ios_base::eofbit if the stream is emptied.
2103 * @param in Start of input stream.
2104 * @param end End of input stream.
2105 * @param io Source of locale and flags.
2106 * @param err Error flags to set.
2107 * @param v Value to format and insert.
2108 * @return Iterator after reading.
2110 iter_type
2111 get(iter_type __in, iter_type __end, ios_base& __io,
2112 ios_base::iostate& __err, void*& __v) const
2113 { return this->do_get(__in, __end, __io, __err, __v); }
2115 protected:
2116 /// Destructor.
2117 virtual ~num_get() { }
2119 iter_type
2120 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
2121 string& __xtrc) const;
2123 template<typename _ValueT>
2124 iter_type
2125 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
2126 _ValueT& __v) const;
2128 //@{
2130 * @brief Numeric parsing.
2132 * Parses the input stream into the variable @a v. This function is a
2133 * hook for derived classes to change the value returned. @see get()
2134 * for more details.
2136 * @param in Start of input stream.
2137 * @param end End of input stream.
2138 * @param io Source of locale and flags.
2139 * @param err Error flags to set.
2140 * @param v Value to format and insert.
2141 * @return Iterator after reading.
2143 virtual iter_type
2144 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
2147 virtual iter_type
2148 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
2150 virtual iter_type
2151 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2152 unsigned short&) const;
2154 virtual iter_type
2155 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2156 unsigned int&) const;
2158 virtual iter_type
2159 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2160 unsigned long&) const;
2162 #ifdef _GLIBCXX_USE_LONG_LONG
2163 virtual iter_type
2164 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2165 long long&) const;
2167 virtual iter_type
2168 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2169 unsigned long long&) const;
2170 #endif
2172 virtual iter_type
2173 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2174 float&) const;
2176 virtual iter_type
2177 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2178 double&) const;
2180 // XXX GLIBCXX_ABI Deprecated
2181 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2182 virtual iter_type
2183 __do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2184 double&) const;
2185 #else
2186 virtual iter_type
2187 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2188 long double&) const;
2189 #endif
2191 virtual iter_type
2192 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2193 void*&) const;
2195 // XXX GLIBCXX_ABI Deprecated
2196 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2197 virtual iter_type
2198 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2199 long double&) const;
2200 #endif
2201 //@}
2204 template<typename _CharT, typename _InIter>
2205 locale::id num_get<_CharT, _InIter>::id;
2209 * @brief Facet for converting numbers to strings.
2211 * This facet encapsulates the code to convert a number to a string. It is
2212 * used by the ostream numeric insertion operators.
2214 * The num_put template uses protected virtual functions to provide the
2215 * actual results. The public accessors forward the call to the virtual
2216 * functions. These virtual functions are hooks for developers to
2217 * implement the behavior they require from the num_put facet.
2219 template<typename _CharT, typename _OutIter>
2220 class num_put : public locale::facet
2222 public:
2223 // Types:
2224 //@{
2225 /// Public typedefs
2226 typedef _CharT char_type;
2227 typedef _OutIter iter_type;
2228 //@}
2230 /// Numpunct facet id.
2231 static locale::id id;
2234 * @brief Constructor performs initialization.
2236 * This is the constructor provided by the standard.
2238 * @param refs Passed to the base facet class.
2240 explicit
2241 num_put(size_t __refs = 0) : facet(__refs) { }
2244 * @brief Numeric formatting.
2246 * Formats the boolean @a v and inserts it into a stream. It does so
2247 * by calling num_put::do_put().
2249 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2250 * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
2252 * @param s Stream to write to.
2253 * @param io Source of locale and flags.
2254 * @param fill Char_type to use for filling.
2255 * @param v Value to format and insert.
2256 * @return Iterator after writing.
2258 iter_type
2259 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
2260 { return this->do_put(__s, __f, __fill, __v); }
2262 //@{
2264 * @brief Numeric formatting.
2266 * Formats the integral value @a v and inserts it into a
2267 * stream. It does so by calling num_put::do_put().
2269 * Formatting is affected by the flag settings in @a io.
2271 * The basic format is affected by the value of io.flags() &
2272 * ios_base::basefield. If equal to ios_base::oct, formats like the
2273 * printf %o specifier. Else if equal to ios_base::hex, formats like
2274 * %x or %X with ios_base::uppercase unset or set respectively.
2275 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2276 * for unsigned values. Note that if both oct and hex are set, neither
2277 * will take effect.
2279 * If ios_base::showpos is set, '+' is output before positive values.
2280 * If ios_base::showbase is set, '0' precedes octal values (except 0)
2281 * and '0[xX]' precedes hex values.
2283 * Thousands separators are inserted according to numpunct::grouping()
2284 * and numpunct::thousands_sep(). The decimal point character used is
2285 * numpunct::decimal_point().
2287 * If io.width() is non-zero, enough @a fill characters are inserted to
2288 * make the result at least that wide. If
2289 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2290 * padded at the end. If ios_base::internal, then padding occurs
2291 * immediately after either a '+' or '-' or after '0x' or '0X'.
2292 * Otherwise, padding occurs at the beginning.
2294 * @param s Stream to write to.
2295 * @param io Source of locale and flags.
2296 * @param fill Char_type to use for filling.
2297 * @param v Value to format and insert.
2298 * @return Iterator after writing.
2300 iter_type
2301 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
2302 { return this->do_put(__s, __f, __fill, __v); }
2304 iter_type
2305 put(iter_type __s, ios_base& __f, char_type __fill,
2306 unsigned long __v) const
2307 { return this->do_put(__s, __f, __fill, __v); }
2309 #ifdef _GLIBCXX_USE_LONG_LONG
2310 iter_type
2311 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
2312 { return this->do_put(__s, __f, __fill, __v); }
2314 iter_type
2315 put(iter_type __s, ios_base& __f, char_type __fill,
2316 unsigned long long __v) const
2317 { return this->do_put(__s, __f, __fill, __v); }
2318 #endif
2319 //@}
2321 //@{
2323 * @brief Numeric formatting.
2325 * Formats the floating point value @a v and inserts it into a stream.
2326 * It does so by calling num_put::do_put().
2328 * Formatting is affected by the flag settings in @a io.
2330 * The basic format is affected by the value of io.flags() &
2331 * ios_base::floatfield. If equal to ios_base::fixed, formats like the
2332 * printf %f specifier. Else if equal to ios_base::scientific, formats
2333 * like %e or %E with ios_base::uppercase unset or set respectively.
2334 * Otherwise, formats like %g or %G depending on uppercase. Note that
2335 * if both fixed and scientific are set, the effect will also be like
2336 * %g or %G.
2338 * The output precision is given by io.precision(). This precision is
2339 * capped at numeric_limits::digits10 + 2 (different for double and
2340 * long double). The default precision is 6.
2342 * If ios_base::showpos is set, '+' is output before positive values.
2343 * If ios_base::showpoint is set, a decimal point will always be
2344 * output.
2346 * Thousands separators are inserted according to numpunct::grouping()
2347 * and numpunct::thousands_sep(). The decimal point character used is
2348 * numpunct::decimal_point().
2350 * If io.width() is non-zero, enough @a fill characters are inserted to
2351 * make the result at least that wide. If
2352 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2353 * padded at the end. If ios_base::internal, then padding occurs
2354 * immediately after either a '+' or '-' or after '0x' or '0X'.
2355 * Otherwise, padding occurs at the beginning.
2357 * @param s Stream to write to.
2358 * @param io Source of locale and flags.
2359 * @param fill Char_type to use for filling.
2360 * @param v Value to format and insert.
2361 * @return Iterator after writing.
2363 iter_type
2364 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
2365 { return this->do_put(__s, __f, __fill, __v); }
2367 iter_type
2368 put(iter_type __s, ios_base& __f, char_type __fill,
2369 long double __v) const
2370 { return this->do_put(__s, __f, __fill, __v); }
2371 //@}
2374 * @brief Numeric formatting.
2376 * Formats the pointer value @a v and inserts it into a stream. It
2377 * does so by calling num_put::do_put().
2379 * This function formats @a v as an unsigned long with ios_base::hex
2380 * and ios_base::showbase set.
2382 * @param s Stream to write to.
2383 * @param io Source of locale and flags.
2384 * @param fill Char_type to use for filling.
2385 * @param v Value to format and insert.
2386 * @return Iterator after writing.
2388 iter_type
2389 put(iter_type __s, ios_base& __f, char_type __fill,
2390 const void* __v) const
2391 { return this->do_put(__s, __f, __fill, __v); }
2393 protected:
2394 template<typename _ValueT>
2395 iter_type
2396 _M_insert_float(iter_type, ios_base& __io, char_type __fill,
2397 char __mod, _ValueT __v) const;
2399 void
2400 _M_group_float(const char* __grouping, size_t __grouping_size,
2401 char_type __sep, const char_type* __p, char_type* __new,
2402 char_type* __cs, int& __len) const;
2404 template<typename _ValueT>
2405 iter_type
2406 _M_insert_int(iter_type, ios_base& __io, char_type __fill,
2407 _ValueT __v) const;
2409 void
2410 _M_group_int(const char* __grouping, size_t __grouping_size,
2411 char_type __sep, ios_base& __io, char_type* __new,
2412 char_type* __cs, int& __len) const;
2414 void
2415 _M_pad(char_type __fill, streamsize __w, ios_base& __io,
2416 char_type* __new, const char_type* __cs, int& __len) const;
2418 /// Destructor.
2419 virtual
2420 ~num_put() { };
2422 //@{
2424 * @brief Numeric formatting.
2426 * These functions do the work of formatting numeric values and
2427 * inserting them into a stream. This function is a hook for derived
2428 * classes to change the value returned.
2430 * @param s Stream to write to.
2431 * @param io Source of locale and flags.
2432 * @param fill Char_type to use for filling.
2433 * @param v Value to format and insert.
2434 * @return Iterator after writing.
2436 virtual iter_type
2437 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
2439 virtual iter_type
2440 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
2442 virtual iter_type
2443 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
2445 #ifdef _GLIBCXX_USE_LONG_LONG
2446 virtual iter_type
2447 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
2449 virtual iter_type
2450 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
2451 #endif
2453 virtual iter_type
2454 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2456 // XXX GLIBCXX_ABI Deprecated
2457 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2458 virtual iter_type
2459 __do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2460 #else
2461 virtual iter_type
2462 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2463 #endif
2465 virtual iter_type
2466 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
2468 // XXX GLIBCXX_ABI Deprecated
2469 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2470 virtual iter_type
2471 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2472 #endif
2473 //@}
2476 template <typename _CharT, typename _OutIter>
2477 locale::id num_put<_CharT, _OutIter>::id;
2479 _GLIBCXX_END_LDBL_NAMESPACE
2482 * @brief Facet for localized string comparison.
2484 * This facet encapsulates the code to compare strings in a localized
2485 * manner.
2487 * The collate template uses protected virtual functions to provide
2488 * the actual results. The public accessors forward the call to
2489 * the virtual functions. These virtual functions are hooks for
2490 * developers to implement the behavior they require from the
2491 * collate facet.
2493 template<typename _CharT>
2494 class collate : public locale::facet
2496 public:
2497 // Types:
2498 //@{
2499 /// Public typedefs
2500 typedef _CharT char_type;
2501 typedef basic_string<_CharT> string_type;
2502 //@}
2504 protected:
2505 // Underlying "C" library locale information saved from
2506 // initialization, needed by collate_byname as well.
2507 __c_locale _M_c_locale_collate;
2509 public:
2510 /// Numpunct facet id.
2511 static locale::id id;
2514 * @brief Constructor performs initialization.
2516 * This is the constructor provided by the standard.
2518 * @param refs Passed to the base facet class.
2520 explicit
2521 collate(size_t __refs = 0)
2522 : facet(__refs), _M_c_locale_collate(_S_get_c_locale())
2526 * @brief Internal constructor. Not for general use.
2528 * This is a constructor for use by the library itself to set up new
2529 * locales.
2531 * @param cloc The "C" locale.
2532 * @param refs Passed to the base facet class.
2534 explicit
2535 collate(__c_locale __cloc, size_t __refs = 0)
2536 : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc))
2540 * @brief Compare two strings.
2542 * This function compares two strings and returns the result by calling
2543 * collate::do_compare().
2545 * @param lo1 Start of string 1.
2546 * @param hi1 End of string 1.
2547 * @param lo2 Start of string 2.
2548 * @param hi2 End of string 2.
2549 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2552 compare(const _CharT* __lo1, const _CharT* __hi1,
2553 const _CharT* __lo2, const _CharT* __hi2) const
2554 { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
2557 * @brief Transform string to comparable form.
2559 * This function is a wrapper for strxfrm functionality. It takes the
2560 * input string and returns a modified string that can be directly
2561 * compared to other transformed strings. In the "C" locale, this
2562 * function just returns a copy of the input string. In some other
2563 * locales, it may replace two chars with one, change a char for
2564 * another, etc. It does so by returning collate::do_transform().
2566 * @param lo Start of string.
2567 * @param hi End of string.
2568 * @return Transformed string_type.
2570 string_type
2571 transform(const _CharT* __lo, const _CharT* __hi) const
2572 { return this->do_transform(__lo, __hi); }
2575 * @brief Return hash of a string.
2577 * This function computes and returns a hash on the input string. It
2578 * does so by returning collate::do_hash().
2580 * @param lo Start of string.
2581 * @param hi End of string.
2582 * @return Hash value.
2584 long
2585 hash(const _CharT* __lo, const _CharT* __hi) const
2586 { return this->do_hash(__lo, __hi); }
2588 // Used to abstract out _CharT bits in virtual member functions, below.
2590 _M_compare(const _CharT*, const _CharT*) const;
2592 size_t
2593 _M_transform(_CharT*, const _CharT*, size_t) const;
2595 protected:
2596 /// Destructor.
2597 virtual
2598 ~collate()
2599 { _S_destroy_c_locale(_M_c_locale_collate); }
2602 * @brief Compare two strings.
2604 * This function is a hook for derived classes to change the value
2605 * returned. @see compare().
2607 * @param lo1 Start of string 1.
2608 * @param hi1 End of string 1.
2609 * @param lo2 Start of string 2.
2610 * @param hi2 End of string 2.
2611 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2613 virtual int
2614 do_compare(const _CharT* __lo1, const _CharT* __hi1,
2615 const _CharT* __lo2, const _CharT* __hi2) const;
2618 * @brief Transform string to comparable form.
2620 * This function is a hook for derived classes to change the value
2621 * returned.
2623 * @param lo1 Start of string 1.
2624 * @param hi1 End of string 1.
2625 * @param lo2 Start of string 2.
2626 * @param hi2 End of string 2.
2627 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2629 virtual string_type
2630 do_transform(const _CharT* __lo, const _CharT* __hi) const;
2633 * @brief Return hash of a string.
2635 * This function computes and returns a hash on the input string. This
2636 * function is a hook for derived classes to change the value returned.
2638 * @param lo Start of string.
2639 * @param hi End of string.
2640 * @return Hash value.
2642 virtual long
2643 do_hash(const _CharT* __lo, const _CharT* __hi) const;
2646 template<typename _CharT>
2647 locale::id collate<_CharT>::id;
2649 // Specializations.
2650 template<>
2652 collate<char>::_M_compare(const char*, const char*) const;
2654 template<>
2655 size_t
2656 collate<char>::_M_transform(char*, const char*, size_t) const;
2658 #ifdef _GLIBCXX_USE_WCHAR_T
2659 template<>
2661 collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
2663 template<>
2664 size_t
2665 collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
2666 #endif
2668 /// @brief class collate_byname [22.2.4.2].
2669 template<typename _CharT>
2670 class collate_byname : public collate<_CharT>
2672 public:
2673 //@{
2674 /// Public typedefs
2675 typedef _CharT char_type;
2676 typedef basic_string<_CharT> string_type;
2677 //@}
2679 explicit
2680 collate_byname(const char* __s, size_t __refs = 0)
2681 : collate<_CharT>(__refs)
2683 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
2685 this->_S_destroy_c_locale(this->_M_c_locale_collate);
2686 this->_S_create_c_locale(this->_M_c_locale_collate, __s);
2690 protected:
2691 virtual
2692 ~collate_byname() { }
2697 * @brief Time format ordering data.
2699 * This class provides an enum representing different orderings of day,
2700 * month, and year.
2702 class time_base
2704 public:
2705 enum dateorder { no_order, dmy, mdy, ymd, ydm };
2708 template<typename _CharT>
2709 struct __timepunct_cache : public locale::facet
2711 // List of all known timezones, with GMT first.
2712 static const _CharT* _S_timezones[14];
2714 const _CharT* _M_date_format;
2715 const _CharT* _M_date_era_format;
2716 const _CharT* _M_time_format;
2717 const _CharT* _M_time_era_format;
2718 const _CharT* _M_date_time_format;
2719 const _CharT* _M_date_time_era_format;
2720 const _CharT* _M_am;
2721 const _CharT* _M_pm;
2722 const _CharT* _M_am_pm_format;
2724 // Day names, starting with "C"'s Sunday.
2725 const _CharT* _M_day1;
2726 const _CharT* _M_day2;
2727 const _CharT* _M_day3;
2728 const _CharT* _M_day4;
2729 const _CharT* _M_day5;
2730 const _CharT* _M_day6;
2731 const _CharT* _M_day7;
2733 // Abbreviated day names, starting with "C"'s Sun.
2734 const _CharT* _M_aday1;
2735 const _CharT* _M_aday2;
2736 const _CharT* _M_aday3;
2737 const _CharT* _M_aday4;
2738 const _CharT* _M_aday5;
2739 const _CharT* _M_aday6;
2740 const _CharT* _M_aday7;
2742 // Month names, starting with "C"'s January.
2743 const _CharT* _M_month01;
2744 const _CharT* _M_month02;
2745 const _CharT* _M_month03;
2746 const _CharT* _M_month04;
2747 const _CharT* _M_month05;
2748 const _CharT* _M_month06;
2749 const _CharT* _M_month07;
2750 const _CharT* _M_month08;
2751 const _CharT* _M_month09;
2752 const _CharT* _M_month10;
2753 const _CharT* _M_month11;
2754 const _CharT* _M_month12;
2756 // Abbreviated month names, starting with "C"'s Jan.
2757 const _CharT* _M_amonth01;
2758 const _CharT* _M_amonth02;
2759 const _CharT* _M_amonth03;
2760 const _CharT* _M_amonth04;
2761 const _CharT* _M_amonth05;
2762 const _CharT* _M_amonth06;
2763 const _CharT* _M_amonth07;
2764 const _CharT* _M_amonth08;
2765 const _CharT* _M_amonth09;
2766 const _CharT* _M_amonth10;
2767 const _CharT* _M_amonth11;
2768 const _CharT* _M_amonth12;
2770 bool _M_allocated;
2772 __timepunct_cache(size_t __refs = 0) : facet(__refs),
2773 _M_date_format(NULL), _M_date_era_format(NULL), _M_time_format(NULL),
2774 _M_time_era_format(NULL), _M_date_time_format(NULL),
2775 _M_date_time_era_format(NULL), _M_am(NULL), _M_pm(NULL),
2776 _M_am_pm_format(NULL), _M_day1(NULL), _M_day2(NULL), _M_day3(NULL),
2777 _M_day4(NULL), _M_day5(NULL), _M_day6(NULL), _M_day7(NULL),
2778 _M_aday1(NULL), _M_aday2(NULL), _M_aday3(NULL), _M_aday4(NULL),
2779 _M_aday5(NULL), _M_aday6(NULL), _M_aday7(NULL), _M_month01(NULL),
2780 _M_month02(NULL), _M_month03(NULL), _M_month04(NULL), _M_month05(NULL),
2781 _M_month06(NULL), _M_month07(NULL), _M_month08(NULL), _M_month09(NULL),
2782 _M_month10(NULL), _M_month11(NULL), _M_month12(NULL), _M_amonth01(NULL),
2783 _M_amonth02(NULL), _M_amonth03(NULL), _M_amonth04(NULL),
2784 _M_amonth05(NULL), _M_amonth06(NULL), _M_amonth07(NULL),
2785 _M_amonth08(NULL), _M_amonth09(NULL), _M_amonth10(NULL),
2786 _M_amonth11(NULL), _M_amonth12(NULL), _M_allocated(false)
2789 ~__timepunct_cache();
2791 void
2792 _M_cache(const locale& __loc);
2794 private:
2795 __timepunct_cache&
2796 operator=(const __timepunct_cache&);
2798 explicit
2799 __timepunct_cache(const __timepunct_cache&);
2802 template<typename _CharT>
2803 __timepunct_cache<_CharT>::~__timepunct_cache()
2805 if (_M_allocated)
2807 // Unused.
2811 // Specializations.
2812 template<>
2813 const char*
2814 __timepunct_cache<char>::_S_timezones[14];
2816 #ifdef _GLIBCXX_USE_WCHAR_T
2817 template<>
2818 const wchar_t*
2819 __timepunct_cache<wchar_t>::_S_timezones[14];
2820 #endif
2822 // Generic.
2823 template<typename _CharT>
2824 const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
2826 template<typename _CharT>
2827 class __timepunct : public locale::facet
2829 public:
2830 // Types:
2831 typedef _CharT __char_type;
2832 typedef basic_string<_CharT> __string_type;
2833 typedef __timepunct_cache<_CharT> __cache_type;
2835 protected:
2836 __cache_type* _M_data;
2837 __c_locale _M_c_locale_timepunct;
2838 const char* _M_name_timepunct;
2840 public:
2841 /// Numpunct facet id.
2842 static locale::id id;
2844 explicit
2845 __timepunct(size_t __refs = 0);
2847 explicit
2848 __timepunct(__cache_type* __cache, size_t __refs = 0);
2851 * @brief Internal constructor. Not for general use.
2853 * This is a constructor for use by the library itself to set up new
2854 * locales.
2856 * @param cloc The "C" locale.
2857 * @param s The name of a locale.
2858 * @param refs Passed to the base facet class.
2860 explicit
2861 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
2863 // FIXME: for error checking purposes _M_put should return the return
2864 // value of strftime/wcsftime.
2865 void
2866 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
2867 const tm* __tm) const;
2869 void
2870 _M_date_formats(const _CharT** __date) const
2872 // Always have default first.
2873 __date[0] = _M_data->_M_date_format;
2874 __date[1] = _M_data->_M_date_era_format;
2877 void
2878 _M_time_formats(const _CharT** __time) const
2880 // Always have default first.
2881 __time[0] = _M_data->_M_time_format;
2882 __time[1] = _M_data->_M_time_era_format;
2885 void
2886 _M_date_time_formats(const _CharT** __dt) const
2888 // Always have default first.
2889 __dt[0] = _M_data->_M_date_time_format;
2890 __dt[1] = _M_data->_M_date_time_era_format;
2893 void
2894 _M_am_pm_format(const _CharT* __ampm) const
2895 { __ampm = _M_data->_M_am_pm_format; }
2897 void
2898 _M_am_pm(const _CharT** __ampm) const
2900 __ampm[0] = _M_data->_M_am;
2901 __ampm[1] = _M_data->_M_pm;
2904 void
2905 _M_days(const _CharT** __days) const
2907 __days[0] = _M_data->_M_day1;
2908 __days[1] = _M_data->_M_day2;
2909 __days[2] = _M_data->_M_day3;
2910 __days[3] = _M_data->_M_day4;
2911 __days[4] = _M_data->_M_day5;
2912 __days[5] = _M_data->_M_day6;
2913 __days[6] = _M_data->_M_day7;
2916 void
2917 _M_days_abbreviated(const _CharT** __days) const
2919 __days[0] = _M_data->_M_aday1;
2920 __days[1] = _M_data->_M_aday2;
2921 __days[2] = _M_data->_M_aday3;
2922 __days[3] = _M_data->_M_aday4;
2923 __days[4] = _M_data->_M_aday5;
2924 __days[5] = _M_data->_M_aday6;
2925 __days[6] = _M_data->_M_aday7;
2928 void
2929 _M_months(const _CharT** __months) const
2931 __months[0] = _M_data->_M_month01;
2932 __months[1] = _M_data->_M_month02;
2933 __months[2] = _M_data->_M_month03;
2934 __months[3] = _M_data->_M_month04;
2935 __months[4] = _M_data->_M_month05;
2936 __months[5] = _M_data->_M_month06;
2937 __months[6] = _M_data->_M_month07;
2938 __months[7] = _M_data->_M_month08;
2939 __months[8] = _M_data->_M_month09;
2940 __months[9] = _M_data->_M_month10;
2941 __months[10] = _M_data->_M_month11;
2942 __months[11] = _M_data->_M_month12;
2945 void
2946 _M_months_abbreviated(const _CharT** __months) const
2948 __months[0] = _M_data->_M_amonth01;
2949 __months[1] = _M_data->_M_amonth02;
2950 __months[2] = _M_data->_M_amonth03;
2951 __months[3] = _M_data->_M_amonth04;
2952 __months[4] = _M_data->_M_amonth05;
2953 __months[5] = _M_data->_M_amonth06;
2954 __months[6] = _M_data->_M_amonth07;
2955 __months[7] = _M_data->_M_amonth08;
2956 __months[8] = _M_data->_M_amonth09;
2957 __months[9] = _M_data->_M_amonth10;
2958 __months[10] = _M_data->_M_amonth11;
2959 __months[11] = _M_data->_M_amonth12;
2962 protected:
2963 virtual
2964 ~__timepunct();
2966 // For use at construction time only.
2967 void
2968 _M_initialize_timepunct(__c_locale __cloc = NULL);
2971 template<typename _CharT>
2972 locale::id __timepunct<_CharT>::id;
2974 // Specializations.
2975 template<>
2976 void
2977 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
2979 template<>
2980 void
2981 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const;
2983 #ifdef _GLIBCXX_USE_WCHAR_T
2984 template<>
2985 void
2986 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
2988 template<>
2989 void
2990 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
2991 const tm*) const;
2992 #endif
2994 // Include host and configuration specific timepunct functions.
2995 #include <bits/time_members.h>
2998 * @brief Facet for parsing dates and times.
3000 * This facet encapsulates the code to parse and return a date or
3001 * time from a string. It is used by the istream numeric
3002 * extraction operators.
3004 * The time_get template uses protected virtual functions to provide the
3005 * actual results. The public accessors forward the call to the virtual
3006 * functions. These virtual functions are hooks for developers to
3007 * implement the behavior they require from the time_get facet.
3009 template<typename _CharT, typename _InIter>
3010 class time_get : public locale::facet, public time_base
3012 public:
3013 // Types:
3014 //@{
3015 /// Public typedefs
3016 typedef _CharT char_type;
3017 typedef _InIter iter_type;
3018 //@}
3019 typedef basic_string<_CharT> __string_type;
3021 /// Numpunct facet id.
3022 static locale::id id;
3025 * @brief Constructor performs initialization.
3027 * This is the constructor provided by the standard.
3029 * @param refs Passed to the base facet class.
3031 explicit
3032 time_get(size_t __refs = 0)
3033 : facet (__refs) { }
3036 * @brief Return preferred order of month, day, and year.
3038 * This function returns an enum from timebase::dateorder giving the
3039 * preferred ordering if the format "x" given to time_put::put() only
3040 * uses month, day, and year. If the format "x" for the associated
3041 * locale uses other fields, this function returns
3042 * timebase::dateorder::noorder.
3044 * NOTE: The library always returns noorder at the moment.
3046 * @return A member of timebase::dateorder.
3048 dateorder
3049 date_order() const
3050 { return this->do_date_order(); }
3053 * @brief Parse input time string.
3055 * This function parses a time according to the format "x" and puts the
3056 * results into a user-supplied struct tm. The result is returned by
3057 * calling time_get::do_get_time().
3059 * If there is a valid time string according to format "x", @a tm will
3060 * be filled in accordingly and the returned iterator will point to the
3061 * first character beyond the time string. If an error occurs before
3062 * the end, err |= ios_base::failbit. If parsing reads all the
3063 * characters, err |= ios_base::eofbit.
3065 * @param beg Start of string to parse.
3066 * @param end End of string to parse.
3067 * @param io Source of the locale.
3068 * @param err Error flags to set.
3069 * @param tm Pointer to struct tm to fill in.
3070 * @return Iterator to first char beyond time string.
3072 iter_type
3073 get_time(iter_type __beg, iter_type __end, ios_base& __io,
3074 ios_base::iostate& __err, tm* __tm) const
3075 { return this->do_get_time(__beg, __end, __io, __err, __tm); }
3078 * @brief Parse input date string.
3080 * This function parses a date according to the format "X" and puts the
3081 * results into a user-supplied struct tm. The result is returned by
3082 * calling time_get::do_get_date().
3084 * If there is a valid date string according to format "X", @a tm will
3085 * be filled in accordingly and the returned iterator will point to the
3086 * first character beyond the date string. If an error occurs before
3087 * the end, err |= ios_base::failbit. If parsing reads all the
3088 * characters, err |= ios_base::eofbit.
3090 * @param beg Start of string to parse.
3091 * @param end End of string to parse.
3092 * @param io Source of the locale.
3093 * @param err Error flags to set.
3094 * @param tm Pointer to struct tm to fill in.
3095 * @return Iterator to first char beyond date string.
3097 iter_type
3098 get_date(iter_type __beg, iter_type __end, ios_base& __io,
3099 ios_base::iostate& __err, tm* __tm) const
3100 { return this->do_get_date(__beg, __end, __io, __err, __tm); }
3103 * @brief Parse input weekday string.
3105 * This function parses a weekday name and puts the results into a
3106 * user-supplied struct tm. The result is returned by calling
3107 * time_get::do_get_weekday().
3109 * Parsing starts by parsing an abbreviated weekday name. If a valid
3110 * abbreviation is followed by a character that would lead to the full
3111 * weekday name, parsing continues until the full name is found or an
3112 * error occurs. Otherwise parsing finishes at the end of the
3113 * abbreviated name.
3115 * If an error occurs before the end, err |= ios_base::failbit. If
3116 * parsing reads all the characters, err |= ios_base::eofbit.
3118 * @param beg Start of string to parse.
3119 * @param end End of string to parse.
3120 * @param io Source of the locale.
3121 * @param err Error flags to set.
3122 * @param tm Pointer to struct tm to fill in.
3123 * @return Iterator to first char beyond weekday name.
3125 iter_type
3126 get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
3127 ios_base::iostate& __err, tm* __tm) const
3128 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
3131 * @brief Parse input month string.
3133 * This function parses a month name and puts the results into a
3134 * user-supplied struct tm. The result is returned by calling
3135 * time_get::do_get_monthname().
3137 * Parsing starts by parsing an abbreviated month name. If a valid
3138 * abbreviation is followed by a character that would lead to the full
3139 * month name, parsing continues until the full name is found or an
3140 * error occurs. Otherwise parsing finishes at the end of the
3141 * abbreviated name.
3143 * If an error occurs before the end, err |= ios_base::failbit. If
3144 * parsing reads all the characters, err |=
3145 * ios_base::eofbit.
3147 * @param beg Start of string to parse.
3148 * @param end End of string to parse.
3149 * @param io Source of the locale.
3150 * @param err Error flags to set.
3151 * @param tm Pointer to struct tm to fill in.
3152 * @return Iterator to first char beyond month name.
3154 iter_type
3155 get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
3156 ios_base::iostate& __err, tm* __tm) const
3157 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
3160 * @brief Parse input year string.
3162 * This function reads up to 4 characters to parse a year string and
3163 * puts the results into a user-supplied struct tm. The result is
3164 * returned by calling time_get::do_get_year().
3166 * 4 consecutive digits are interpreted as a full year. If there are
3167 * exactly 2 consecutive digits, the library interprets this as the
3168 * number of years since 1900.
3170 * If an error occurs before the end, err |= ios_base::failbit. If
3171 * parsing reads all the characters, err |= ios_base::eofbit.
3173 * @param beg Start of string to parse.
3174 * @param end End of string to parse.
3175 * @param io Source of the locale.
3176 * @param err Error flags to set.
3177 * @param tm Pointer to struct tm to fill in.
3178 * @return Iterator to first char beyond year.
3180 iter_type
3181 get_year(iter_type __beg, iter_type __end, ios_base& __io,
3182 ios_base::iostate& __err, tm* __tm) const
3183 { return this->do_get_year(__beg, __end, __io, __err, __tm); }
3185 protected:
3186 /// Destructor.
3187 virtual
3188 ~time_get() { }
3191 * @brief Return preferred order of month, day, and year.
3193 * This function returns an enum from timebase::dateorder giving the
3194 * preferred ordering if the format "x" given to time_put::put() only
3195 * uses month, day, and year. This function is a hook for derived
3196 * classes to change the value returned.
3198 * @return A member of timebase::dateorder.
3200 virtual dateorder
3201 do_date_order() const;
3204 * @brief Parse input time string.
3206 * This function parses a time according to the format "x" and puts the
3207 * results into a user-supplied struct tm. This function is a hook for
3208 * derived classes to change the value returned. @see get_time() for
3209 * details.
3211 * @param beg Start of string to parse.
3212 * @param end End of string to parse.
3213 * @param io Source of the locale.
3214 * @param err Error flags to set.
3215 * @param tm Pointer to struct tm to fill in.
3216 * @return Iterator to first char beyond time string.
3218 virtual iter_type
3219 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
3220 ios_base::iostate& __err, tm* __tm) const;
3223 * @brief Parse input date string.
3225 * This function parses a date according to the format "X" and puts the
3226 * results into a user-supplied struct tm. This function is a hook for
3227 * derived classes to change the value returned. @see get_date() for
3228 * details.
3230 * @param beg Start of string to parse.
3231 * @param end End of string to parse.
3232 * @param io Source of the locale.
3233 * @param err Error flags to set.
3234 * @param tm Pointer to struct tm to fill in.
3235 * @return Iterator to first char beyond date string.
3237 virtual iter_type
3238 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
3239 ios_base::iostate& __err, tm* __tm) const;
3242 * @brief Parse input weekday string.
3244 * This function parses a weekday name and puts the results into a
3245 * user-supplied struct tm. This function is a hook for derived
3246 * classes to change the value returned. @see get_weekday() for
3247 * details.
3249 * @param beg Start of string to parse.
3250 * @param end End of string to parse.
3251 * @param io Source of the locale.
3252 * @param err Error flags to set.
3253 * @param tm Pointer to struct tm to fill in.
3254 * @return Iterator to first char beyond weekday name.
3256 virtual iter_type
3257 do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
3258 ios_base::iostate& __err, tm* __tm) const;
3261 * @brief Parse input month string.
3263 * This function parses a month name and puts the results into a
3264 * user-supplied struct tm. This function is a hook for derived
3265 * classes to change the value returned. @see get_monthname() for
3266 * details.
3268 * @param beg Start of string to parse.
3269 * @param end End of string to parse.
3270 * @param io Source of the locale.
3271 * @param err Error flags to set.
3272 * @param tm Pointer to struct tm to fill in.
3273 * @return Iterator to first char beyond month name.
3275 virtual iter_type
3276 do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
3277 ios_base::iostate& __err, tm* __tm) const;
3280 * @brief Parse input year string.
3282 * This function reads up to 4 characters to parse a year string and
3283 * puts the results into a user-supplied struct tm. This function is a
3284 * hook for derived classes to change the value returned. @see
3285 * get_year() for details.
3287 * @param beg Start of string to parse.
3288 * @param end End of string to parse.
3289 * @param io Source of the locale.
3290 * @param err Error flags to set.
3291 * @param tm Pointer to struct tm to fill in.
3292 * @return Iterator to first char beyond year.
3294 virtual iter_type
3295 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
3296 ios_base::iostate& __err, tm* __tm) const;
3298 // Extract numeric component of length __len.
3299 iter_type
3300 _M_extract_num(iter_type __beg, iter_type __end, int& __member,
3301 int __min, int __max, size_t __len,
3302 ios_base& __io, ios_base::iostate& __err) const;
3304 // Extract day or month name, or any unique array of string
3305 // literals in a const _CharT* array.
3306 iter_type
3307 _M_extract_name(iter_type __beg, iter_type __end, int& __member,
3308 const _CharT** __names, size_t __indexlen,
3309 ios_base& __io, ios_base::iostate& __err) const;
3311 // Extract on a component-by-component basis, via __format argument.
3312 iter_type
3313 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
3314 ios_base::iostate& __err, tm* __tm,
3315 const _CharT* __format) const;
3318 template<typename _CharT, typename _InIter>
3319 locale::id time_get<_CharT, _InIter>::id;
3321 /// @brief class time_get_byname [22.2.5.2].
3322 template<typename _CharT, typename _InIter>
3323 class time_get_byname : public time_get<_CharT, _InIter>
3325 public:
3326 // Types:
3327 typedef _CharT char_type;
3328 typedef _InIter iter_type;
3330 explicit
3331 time_get_byname(const char*, size_t __refs = 0)
3332 : time_get<_CharT, _InIter>(__refs) { }
3334 protected:
3335 virtual
3336 ~time_get_byname() { }
3340 * @brief Facet for outputting dates and times.
3342 * This facet encapsulates the code to format and output dates and times
3343 * according to formats used by strftime().
3345 * The time_put template uses protected virtual functions to provide the
3346 * actual results. The public accessors forward the call to the virtual
3347 * functions. These virtual functions are hooks for developers to
3348 * implement the behavior they require from the time_put facet.
3350 template<typename _CharT, typename _OutIter>
3351 class time_put : public locale::facet
3353 public:
3354 // Types:
3355 //@{
3356 /// Public typedefs
3357 typedef _CharT char_type;
3358 typedef _OutIter iter_type;
3359 //@}
3361 /// Numpunct facet id.
3362 static locale::id id;
3365 * @brief Constructor performs initialization.
3367 * This is the constructor provided by the standard.
3369 * @param refs Passed to the base facet class.
3371 explicit
3372 time_put(size_t __refs = 0)
3373 : facet(__refs) { }
3376 * @brief Format and output a time or date.
3378 * This function formats the data in struct tm according to the
3379 * provided format string. The format string is interpreted as by
3380 * strftime().
3382 * @param s The stream to write to.
3383 * @param io Source of locale.
3384 * @param fill char_type to use for padding.
3385 * @param tm Struct tm with date and time info to format.
3386 * @param beg Start of format string.
3387 * @param end End of format string.
3388 * @return Iterator after writing.
3390 iter_type
3391 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
3392 const _CharT* __beg, const _CharT* __end) const;
3395 * @brief Format and output a time or date.
3397 * This function formats the data in struct tm according to the
3398 * provided format char and optional modifier. The format and modifier
3399 * are interpreted as by strftime(). It does so by returning
3400 * time_put::do_put().
3402 * @param s The stream to write to.
3403 * @param io Source of locale.
3404 * @param fill char_type to use for padding.
3405 * @param tm Struct tm with date and time info to format.
3406 * @param format Format char.
3407 * @param mod Optional modifier char.
3408 * @return Iterator after writing.
3410 iter_type
3411 put(iter_type __s, ios_base& __io, char_type __fill,
3412 const tm* __tm, char __format, char __mod = 0) const
3413 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
3415 protected:
3416 /// Destructor.
3417 virtual
3418 ~time_put()
3422 * @brief Format and output a time or date.
3424 * This function formats the data in struct tm according to the
3425 * provided format char and optional modifier. This function is a hook
3426 * for derived classes to change the value returned. @see put() for
3427 * more details.
3429 * @param s The stream to write to.
3430 * @param io Source of locale.
3431 * @param fill char_type to use for padding.
3432 * @param tm Struct tm with date and time info to format.
3433 * @param format Format char.
3434 * @param mod Optional modifier char.
3435 * @return Iterator after writing.
3437 virtual iter_type
3438 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
3439 char __format, char __mod) const;
3442 template<typename _CharT, typename _OutIter>
3443 locale::id time_put<_CharT, _OutIter>::id;
3445 /// @brief class time_put_byname [22.2.5.4].
3446 template<typename _CharT, typename _OutIter>
3447 class time_put_byname : public time_put<_CharT, _OutIter>
3449 public:
3450 // Types:
3451 typedef _CharT char_type;
3452 typedef _OutIter iter_type;
3454 explicit
3455 time_put_byname(const char*, size_t __refs = 0)
3456 : time_put<_CharT, _OutIter>(__refs)
3457 { };
3459 protected:
3460 virtual
3461 ~time_put_byname() { }
3466 * @brief Money format ordering data.
3468 * This class contains an ordered array of 4 fields to represent the
3469 * pattern for formatting a money amount. Each field may contain one entry
3470 * from the part enum. symbol, sign, and value must be present and the
3471 * remaining field must contain either none or space. @see
3472 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
3473 * these fields are interpreted.
3475 class money_base
3477 public:
3478 enum part { none, space, symbol, sign, value };
3479 struct pattern { char field[4]; };
3481 static const pattern _S_default_pattern;
3483 enum
3485 _S_minus,
3486 _S_zero,
3487 _S_end = 11
3490 // String literal of acceptable (narrow) input/output, for
3491 // money_get/money_put. "-0123456789"
3492 static const char* _S_atoms;
3494 // Construct and return valid pattern consisting of some combination of:
3495 // space none symbol sign value
3496 static pattern
3497 _S_construct_pattern(char __precedes, char __space, char __posn);
3500 template<typename _CharT, bool _Intl>
3501 struct __moneypunct_cache : public locale::facet
3503 const char* _M_grouping;
3504 size_t _M_grouping_size;
3505 bool _M_use_grouping;
3506 _CharT _M_decimal_point;
3507 _CharT _M_thousands_sep;
3508 const _CharT* _M_curr_symbol;
3509 size_t _M_curr_symbol_size;
3510 const _CharT* _M_positive_sign;
3511 size_t _M_positive_sign_size;
3512 const _CharT* _M_negative_sign;
3513 size_t _M_negative_sign_size;
3514 int _M_frac_digits;
3515 money_base::pattern _M_pos_format;
3516 money_base::pattern _M_neg_format;
3518 // A list of valid numeric literals for input and output: in the standard
3519 // "C" locale, this is "-0123456789". This array contains the chars after
3520 // having been passed through the current locale's ctype<_CharT>.widen().
3521 _CharT _M_atoms[money_base::_S_end];
3523 bool _M_allocated;
3525 __moneypunct_cache(size_t __refs = 0) : facet(__refs),
3526 _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
3527 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
3528 _M_curr_symbol(NULL), _M_curr_symbol_size(0),
3529 _M_positive_sign(NULL), _M_positive_sign_size(0),
3530 _M_negative_sign(NULL), _M_negative_sign_size(0),
3531 _M_frac_digits(0),
3532 _M_pos_format(money_base::pattern()),
3533 _M_neg_format(money_base::pattern()), _M_allocated(false)
3536 ~__moneypunct_cache();
3538 void
3539 _M_cache(const locale& __loc);
3541 private:
3542 __moneypunct_cache&
3543 operator=(const __moneypunct_cache&);
3545 explicit
3546 __moneypunct_cache(const __moneypunct_cache&);
3549 template<typename _CharT, bool _Intl>
3550 __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
3552 if (_M_allocated)
3554 delete [] _M_grouping;
3555 delete [] _M_curr_symbol;
3556 delete [] _M_positive_sign;
3557 delete [] _M_negative_sign;
3562 * @brief Facet for formatting data for money amounts.
3564 * This facet encapsulates the punctuation, grouping and other formatting
3565 * features of money amount string representations.
3567 template<typename _CharT, bool _Intl>
3568 class moneypunct : public locale::facet, public money_base
3570 public:
3571 // Types:
3572 //@{
3573 /// Public typedefs
3574 typedef _CharT char_type;
3575 typedef basic_string<_CharT> string_type;
3576 //@}
3577 typedef __moneypunct_cache<_CharT, _Intl> __cache_type;
3579 private:
3580 __cache_type* _M_data;
3582 public:
3583 /// This value is provided by the standard, but no reason for its
3584 /// existence.
3585 static const bool intl = _Intl;
3586 /// Numpunct facet id.
3587 static locale::id id;
3590 * @brief Constructor performs initialization.
3592 * This is the constructor provided by the standard.
3594 * @param refs Passed to the base facet class.
3596 explicit
3597 moneypunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
3598 { _M_initialize_moneypunct(); }
3601 * @brief Constructor performs initialization.
3603 * This is an internal constructor.
3605 * @param cache Cache for optimization.
3606 * @param refs Passed to the base facet class.
3608 explicit
3609 moneypunct(__cache_type* __cache, size_t __refs = 0)
3610 : facet(__refs), _M_data(__cache)
3611 { _M_initialize_moneypunct(); }
3614 * @brief Internal constructor. Not for general use.
3616 * This is a constructor for use by the library itself to set up new
3617 * locales.
3619 * @param cloc The "C" locale.
3620 * @param s The name of a locale.
3621 * @param refs Passed to the base facet class.
3623 explicit
3624 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
3625 : facet(__refs), _M_data(NULL)
3626 { _M_initialize_moneypunct(__cloc, __s); }
3629 * @brief Return decimal point character.
3631 * This function returns a char_type to use as a decimal point. It
3632 * does so by returning returning
3633 * moneypunct<char_type>::do_decimal_point().
3635 * @return @a char_type representing a decimal point.
3637 char_type
3638 decimal_point() const
3639 { return this->do_decimal_point(); }
3642 * @brief Return thousands separator character.
3644 * This function returns a char_type to use as a thousands
3645 * separator. It does so by returning returning
3646 * moneypunct<char_type>::do_thousands_sep().
3648 * @return char_type representing a thousands separator.
3650 char_type
3651 thousands_sep() const
3652 { return this->do_thousands_sep(); }
3655 * @brief Return grouping specification.
3657 * This function returns a string representing groupings for the
3658 * integer part of an amount. Groupings indicate where thousands
3659 * separators should be inserted.
3661 * Each char in the return string is interpret as an integer rather
3662 * than a character. These numbers represent the number of digits in a
3663 * group. The first char in the string represents the number of digits
3664 * in the least significant group. If a char is negative, it indicates
3665 * an unlimited number of digits for the group. If more chars from the
3666 * string are required to group a number, the last char is used
3667 * repeatedly.
3669 * For example, if the grouping() returns "\003\002" and is applied to
3670 * the number 123456789, this corresponds to 12,34,56,789. Note that
3671 * if the string was "32", this would put more than 50 digits into the
3672 * least significant group if the character set is ASCII.
3674 * The string is returned by calling
3675 * moneypunct<char_type>::do_grouping().
3677 * @return string representing grouping specification.
3679 string
3680 grouping() const
3681 { return this->do_grouping(); }
3684 * @brief Return currency symbol string.
3686 * This function returns a string_type to use as a currency symbol. It
3687 * does so by returning returning
3688 * moneypunct<char_type>::do_curr_symbol().
3690 * @return @a string_type representing a currency symbol.
3692 string_type
3693 curr_symbol() const
3694 { return this->do_curr_symbol(); }
3697 * @brief Return positive sign string.
3699 * This function returns a string_type to use as a sign for positive
3700 * amounts. It does so by returning returning
3701 * moneypunct<char_type>::do_positive_sign().
3703 * If the return value contains more than one character, the first
3704 * character appears in the position indicated by pos_format() and the
3705 * remainder appear at the end of the formatted string.
3707 * @return @a string_type representing a positive sign.
3709 string_type
3710 positive_sign() const
3711 { return this->do_positive_sign(); }
3714 * @brief Return negative sign string.
3716 * This function returns a string_type to use as a sign for negative
3717 * amounts. It does so by returning returning
3718 * moneypunct<char_type>::do_negative_sign().
3720 * If the return value contains more than one character, the first
3721 * character appears in the position indicated by neg_format() and the
3722 * remainder appear at the end of the formatted string.
3724 * @return @a string_type representing a negative sign.
3726 string_type
3727 negative_sign() const
3728 { return this->do_negative_sign(); }
3731 * @brief Return number of digits in fraction.
3733 * This function returns the exact number of digits that make up the
3734 * fractional part of a money amount. It does so by returning
3735 * returning moneypunct<char_type>::do_frac_digits().
3737 * The fractional part of a money amount is optional. But if it is
3738 * present, there must be frac_digits() digits.
3740 * @return Number of digits in amount fraction.
3743 frac_digits() const
3744 { return this->do_frac_digits(); }
3746 //@{
3748 * @brief Return pattern for money values.
3750 * This function returns a pattern describing the formatting of a
3751 * positive or negative valued money amount. It does so by returning
3752 * returning moneypunct<char_type>::do_pos_format() or
3753 * moneypunct<char_type>::do_neg_format().
3755 * The pattern has 4 fields describing the ordering of symbol, sign,
3756 * value, and none or space. There must be one of each in the pattern.
3757 * The none and space enums may not appear in the first field and space
3758 * may not appear in the final field.
3760 * The parts of a money string must appear in the order indicated by
3761 * the fields of the pattern. The symbol field indicates that the
3762 * value of curr_symbol() may be present. The sign field indicates
3763 * that the value of positive_sign() or negative_sign() must be
3764 * present. The value field indicates that the absolute value of the
3765 * money amount is present. none indicates 0 or more whitespace
3766 * characters, except at the end, where it permits no whitespace.
3767 * space indicates that 1 or more whitespace characters must be
3768 * present.
3770 * For example, for the US locale and pos_format() pattern
3771 * {symbol,sign,value,none}, curr_symbol() == '$' positive_sign() ==
3772 * '+', and value 10.01, and options set to force the symbol, the
3773 * corresponding string is "$+10.01".
3775 * @return Pattern for money values.
3777 pattern
3778 pos_format() const
3779 { return this->do_pos_format(); }
3781 pattern
3782 neg_format() const
3783 { return this->do_neg_format(); }
3784 //@}
3786 protected:
3787 /// Destructor.
3788 virtual
3789 ~moneypunct();
3792 * @brief Return decimal point character.
3794 * Returns a char_type to use as a decimal point. This function is a
3795 * hook for derived classes to change the value returned.
3797 * @return @a char_type representing a decimal point.
3799 virtual char_type
3800 do_decimal_point() const
3801 { return _M_data->_M_decimal_point; }
3804 * @brief Return thousands separator character.
3806 * Returns a char_type to use as a thousands separator. This function
3807 * is a hook for derived classes to change the value returned.
3809 * @return @a char_type representing a thousands separator.
3811 virtual char_type
3812 do_thousands_sep() const
3813 { return _M_data->_M_thousands_sep; }
3816 * @brief Return grouping specification.
3818 * Returns a string representing groupings for the integer part of a
3819 * number. This function is a hook for derived classes to change the
3820 * value returned. @see grouping() for details.
3822 * @return String representing grouping specification.
3824 virtual string
3825 do_grouping() const
3826 { return _M_data->_M_grouping; }
3829 * @brief Return currency symbol string.
3831 * This function returns a string_type to use as a currency symbol.
3832 * This function is a hook for derived classes to change the value
3833 * returned. @see curr_symbol() for details.
3835 * @return @a string_type representing a currency symbol.
3837 virtual string_type
3838 do_curr_symbol() const
3839 { return _M_data->_M_curr_symbol; }
3842 * @brief Return positive sign string.
3844 * This function returns a string_type to use as a sign for positive
3845 * amounts. This function is a hook for derived classes to change the
3846 * value returned. @see positive_sign() for details.
3848 * @return @a string_type representing a positive sign.
3850 virtual string_type
3851 do_positive_sign() const
3852 { return _M_data->_M_positive_sign; }
3855 * @brief Return negative sign string.
3857 * This function returns a string_type to use as a sign for negative
3858 * amounts. This function is a hook for derived classes to change the
3859 * value returned. @see negative_sign() for details.
3861 * @return @a string_type representing a negative sign.
3863 virtual string_type
3864 do_negative_sign() const
3865 { return _M_data->_M_negative_sign; }
3868 * @brief Return number of digits in fraction.
3870 * This function returns the exact number of digits that make up the
3871 * fractional part of a money amount. This function is a hook for
3872 * derived classes to change the value returned. @see frac_digits()
3873 * for details.
3875 * @return Number of digits in amount fraction.
3877 virtual int
3878 do_frac_digits() const
3879 { return _M_data->_M_frac_digits; }
3882 * @brief Return pattern for money values.
3884 * This function returns a pattern describing the formatting of a
3885 * positive valued money amount. This function is a hook for derived
3886 * classes to change the value returned. @see pos_format() for
3887 * details.
3889 * @return Pattern for money values.
3891 virtual pattern
3892 do_pos_format() const
3893 { return _M_data->_M_pos_format; }
3896 * @brief Return pattern for money values.
3898 * This function returns a pattern describing the formatting of a
3899 * negative valued money amount. This function is a hook for derived
3900 * classes to change the value returned. @see neg_format() for
3901 * details.
3903 * @return Pattern for money values.
3905 virtual pattern
3906 do_neg_format() const
3907 { return _M_data->_M_neg_format; }
3909 // For use at construction time only.
3910 void
3911 _M_initialize_moneypunct(__c_locale __cloc = NULL,
3912 const char* __name = NULL);
3915 template<typename _CharT, bool _Intl>
3916 locale::id moneypunct<_CharT, _Intl>::id;
3918 template<typename _CharT, bool _Intl>
3919 const bool moneypunct<_CharT, _Intl>::intl;
3921 template<>
3922 moneypunct<char, true>::~moneypunct();
3924 template<>
3925 moneypunct<char, false>::~moneypunct();
3927 template<>
3928 void
3929 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
3931 template<>
3932 void
3933 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
3935 #ifdef _GLIBCXX_USE_WCHAR_T
3936 template<>
3937 moneypunct<wchar_t, true>::~moneypunct();
3939 template<>
3940 moneypunct<wchar_t, false>::~moneypunct();
3942 template<>
3943 void
3944 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
3945 const char*);
3947 template<>
3948 void
3949 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
3950 const char*);
3951 #endif
3953 /// @brief class moneypunct_byname [22.2.6.4].
3954 template<typename _CharT, bool _Intl>
3955 class moneypunct_byname : public moneypunct<_CharT, _Intl>
3957 public:
3958 typedef _CharT char_type;
3959 typedef basic_string<_CharT> string_type;
3961 static const bool intl = _Intl;
3963 explicit
3964 moneypunct_byname(const char* __s, size_t __refs = 0)
3965 : moneypunct<_CharT, _Intl>(__refs)
3967 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
3969 __c_locale __tmp;
3970 this->_S_create_c_locale(__tmp, __s);
3971 this->_M_initialize_moneypunct(__tmp);
3972 this->_S_destroy_c_locale(__tmp);
3976 protected:
3977 virtual
3978 ~moneypunct_byname() { }
3981 template<typename _CharT, bool _Intl>
3982 const bool moneypunct_byname<_CharT, _Intl>::intl;
3984 _GLIBCXX_BEGIN_LDBL_NAMESPACE
3986 * @brief Facet for parsing monetary amounts.
3988 * This facet encapsulates the code to parse and return a monetary
3989 * amount from a string.
3991 * The money_get template uses protected virtual functions to
3992 * provide the actual results. The public accessors forward the
3993 * call to the virtual functions. These virtual functions are
3994 * hooks for developers to implement the behavior they require from
3995 * the money_get facet.
3997 template<typename _CharT, typename _InIter>
3998 class money_get : public locale::facet
4000 public:
4001 // Types:
4002 //@{
4003 /// Public typedefs
4004 typedef _CharT char_type;
4005 typedef _InIter iter_type;
4006 typedef basic_string<_CharT> string_type;
4007 //@}
4009 /// Numpunct facet id.
4010 static locale::id id;
4013 * @brief Constructor performs initialization.
4015 * This is the constructor provided by the standard.
4017 * @param refs Passed to the base facet class.
4019 explicit
4020 money_get(size_t __refs = 0) : facet(__refs) { }
4023 * @brief Read and parse a monetary value.
4025 * This function reads characters from @a s, interprets them as a
4026 * monetary value according to moneypunct and ctype facets retrieved
4027 * from io.getloc(), and returns the result in @a units as an integral
4028 * value moneypunct::frac_digits() * the actual amount. For example,
4029 * the string $10.01 in a US locale would store 1001 in @a units.
4031 * Any characters not part of a valid money amount are not consumed.
4033 * If a money value cannot be parsed from the input stream, sets
4034 * err=(err|io.failbit). If the stream is consumed before finishing
4035 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
4036 * unchanged if parsing fails.
4038 * This function works by returning the result of do_get().
4040 * @param s Start of characters to parse.
4041 * @param end End of characters to parse.
4042 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4043 * @param io Source of facets and io state.
4044 * @param err Error field to set if parsing fails.
4045 * @param units Place to store result of parsing.
4046 * @return Iterator referencing first character beyond valid money
4047 * amount.
4049 iter_type
4050 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4051 ios_base::iostate& __err, long double& __units) const
4052 { return this->do_get(__s, __end, __intl, __io, __err, __units); }
4055 * @brief Read and parse a monetary value.
4057 * This function reads characters from @a s, interprets them as a
4058 * monetary value according to moneypunct and ctype facets retrieved
4059 * from io.getloc(), and returns the result in @a digits. For example,
4060 * the string $10.01 in a US locale would store "1001" in @a digits.
4062 * Any characters not part of a valid money amount are not consumed.
4064 * If a money value cannot be parsed from the input stream, sets
4065 * err=(err|io.failbit). If the stream is consumed before finishing
4066 * parsing, sets err=(err|io.failbit|io.eofbit).
4068 * This function works by returning the result of do_get().
4070 * @param s Start of characters to parse.
4071 * @param end End of characters to parse.
4072 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4073 * @param io Source of facets and io state.
4074 * @param err Error field to set if parsing fails.
4075 * @param digits Place to store result of parsing.
4076 * @return Iterator referencing first character beyond valid money
4077 * amount.
4079 iter_type
4080 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4081 ios_base::iostate& __err, string_type& __digits) const
4082 { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
4084 protected:
4085 /// Destructor.
4086 virtual
4087 ~money_get() { }
4090 * @brief Read and parse a monetary value.
4092 * This function reads and parses characters representing a monetary
4093 * value. This function is a hook for derived classes to change the
4094 * value returned. @see get() for details.
4096 // XXX GLIBCXX_ABI Deprecated
4097 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4098 virtual iter_type
4099 __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4100 ios_base::iostate& __err, double& __units) const;
4101 #else
4102 virtual iter_type
4103 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4104 ios_base::iostate& __err, long double& __units) const;
4105 #endif
4108 * @brief Read and parse a monetary value.
4110 * This function reads and parses characters representing a monetary
4111 * value. This function is a hook for derived classes to change the
4112 * value returned. @see get() for details.
4114 virtual iter_type
4115 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4116 ios_base::iostate& __err, string_type& __digits) const;
4118 // XXX GLIBCXX_ABI Deprecated
4119 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4120 virtual iter_type
4121 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
4122 ios_base::iostate& __err, long double& __units) const;
4123 #endif
4125 template<bool _Intl>
4126 iter_type
4127 _M_extract(iter_type __s, iter_type __end, ios_base& __io,
4128 ios_base::iostate& __err, string& __digits) const;
4131 template<typename _CharT, typename _InIter>
4132 locale::id money_get<_CharT, _InIter>::id;
4135 * @brief Facet for outputting monetary amounts.
4137 * This facet encapsulates the code to format and output a monetary
4138 * amount.
4140 * The money_put template uses protected virtual functions to
4141 * provide the actual results. The public accessors forward the
4142 * call to the virtual functions. These virtual functions are
4143 * hooks for developers to implement the behavior they require from
4144 * the money_put facet.
4146 template<typename _CharT, typename _OutIter>
4147 class money_put : public locale::facet
4149 public:
4150 //@{
4151 /// Public typedefs
4152 typedef _CharT char_type;
4153 typedef _OutIter iter_type;
4154 typedef basic_string<_CharT> string_type;
4155 //@}
4157 /// Numpunct facet id.
4158 static locale::id id;
4161 * @brief Constructor performs initialization.
4163 * This is the constructor provided by the standard.
4165 * @param refs Passed to the base facet class.
4167 explicit
4168 money_put(size_t __refs = 0) : facet(__refs) { }
4171 * @brief Format and output a monetary value.
4173 * This function formats @a units as a monetary value according to
4174 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4175 * the resulting characters to @a s. For example, the value 1001 in a
4176 * US locale would write "$10.01" to @a s.
4178 * This function works by returning the result of do_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.
4187 iter_type
4188 put(iter_type __s, bool __intl, ios_base& __io,
4189 char_type __fill, long double __units) const
4190 { return this->do_put(__s, __intl, __io, __fill, __units); }
4193 * @brief Format and output a monetary value.
4195 * This function formats @a digits as a monetary value according to
4196 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4197 * the resulting characters to @a s. For example, the string "1001" in
4198 * a US locale would write "$10.01" to @a s.
4200 * This function works by returning the result of do_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.
4209 iter_type
4210 put(iter_type __s, bool __intl, ios_base& __io,
4211 char_type __fill, const string_type& __digits) const
4212 { return this->do_put(__s, __intl, __io, __fill, __digits); }
4214 protected:
4215 /// Destructor.
4216 virtual
4217 ~money_put() { }
4220 * @brief Format and output a monetary value.
4222 * This function formats @a units as a monetary value according to
4223 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4224 * the resulting characters to @a s. For example, the value 1001 in a
4225 * US locale would write "$10.01" to @a s.
4227 * This function is a hook for derived classes to change the value
4228 * returned. @see put().
4230 * @param s The stream to write to.
4231 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4232 * @param io Source of facets and io state.
4233 * @param fill char_type to use for padding.
4234 * @param units Place to store result of parsing.
4235 * @return Iterator after writing.
4237 // XXX GLIBCXX_ABI Deprecated
4238 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4239 virtual iter_type
4240 __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4241 double __units) const;
4242 #else
4243 virtual iter_type
4244 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4245 long double __units) const;
4246 #endif
4249 * @brief Format and output a monetary value.
4251 * This function formats @a digits as a monetary value according to
4252 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4253 * the resulting characters to @a s. For example, the string "1001" in
4254 * a US locale would write "$10.01" to @a s.
4256 * This function is a hook for derived classes to change the value
4257 * returned. @see put().
4259 * @param s The stream to write to.
4260 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4261 * @param io Source of facets and io state.
4262 * @param fill char_type to use for padding.
4263 * @param units Place to store result of parsing.
4264 * @return Iterator after writing.
4266 virtual iter_type
4267 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4268 const string_type& __digits) const;
4270 // XXX GLIBCXX_ABI Deprecated
4271 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
4272 virtual iter_type
4273 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4274 long double __units) const;
4275 #endif
4277 template<bool _Intl>
4278 iter_type
4279 _M_insert(iter_type __s, ios_base& __io, char_type __fill,
4280 const string_type& __digits) const;
4283 template<typename _CharT, typename _OutIter>
4284 locale::id money_put<_CharT, _OutIter>::id;
4286 _GLIBCXX_END_LDBL_NAMESPACE
4289 * @brief Messages facet base class providing catalog typedef.
4291 struct messages_base
4293 typedef int catalog;
4297 * @brief Facet for handling message catalogs
4299 * This facet encapsulates the code to retrieve messages from
4300 * message catalogs. The only thing defined by the standard for this facet
4301 * is the interface. All underlying functionality is
4302 * implementation-defined.
4304 * This library currently implements 3 versions of the message facet. The
4305 * first version (gnu) is a wrapper around gettext, provided by libintl.
4306 * The second version (ieee) is a wrapper around catgets. The final
4307 * version (default) does no actual translation. These implementations are
4308 * only provided for char and wchar_t instantiations.
4310 * The messages template uses protected virtual functions to
4311 * provide the actual results. The public accessors forward the
4312 * call to the virtual functions. These virtual functions are
4313 * hooks for developers to implement the behavior they require from
4314 * the messages facet.
4316 template<typename _CharT>
4317 class messages : public locale::facet, public messages_base
4319 public:
4320 // Types:
4321 //@{
4322 /// Public typedefs
4323 typedef _CharT char_type;
4324 typedef basic_string<_CharT> string_type;
4325 //@}
4327 protected:
4328 // Underlying "C" library locale information saved from
4329 // initialization, needed by messages_byname as well.
4330 __c_locale _M_c_locale_messages;
4331 const char* _M_name_messages;
4333 public:
4334 /// Numpunct facet id.
4335 static locale::id id;
4338 * @brief Constructor performs initialization.
4340 * This is the constructor provided by the standard.
4342 * @param refs Passed to the base facet class.
4344 explicit
4345 messages(size_t __refs = 0);
4347 // Non-standard.
4349 * @brief Internal constructor. Not for general use.
4351 * This is a constructor for use by the library itself to set up new
4352 * locales.
4354 * @param cloc The "C" locale.
4355 * @param s The name of a locale.
4356 * @param refs Refcount to pass to the base class.
4358 explicit
4359 messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
4362 * @brief Open a message catalog.
4364 * This function opens and returns a handle to a message catalog by
4365 * returning do_open(s, loc).
4367 * @param s The catalog to open.
4368 * @param loc Locale to use for character set conversions.
4369 * @return Handle to the catalog or value < 0 if open fails.
4371 catalog
4372 open(const basic_string<char>& __s, const locale& __loc) const
4373 { return this->do_open(__s, __loc); }
4375 // Non-standard and unorthodox, yet effective.
4377 * @brief Open a message catalog.
4379 * This non-standard function opens and returns a handle to a message
4380 * catalog by returning do_open(s, loc). The third argument provides a
4381 * message catalog root directory for gnu gettext and is ignored
4382 * otherwise.
4384 * @param s The catalog to open.
4385 * @param loc Locale to use for character set conversions.
4386 * @param dir Message catalog root directory.
4387 * @return Handle to the catalog or value < 0 if open fails.
4389 catalog
4390 open(const basic_string<char>&, const locale&, const char*) const;
4393 * @brief Look up a string in a message catalog.
4395 * This function retrieves and returns a message from a catalog by
4396 * returning do_get(c, set, msgid, s).
4398 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4399 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4401 * @param c The catalog to access.
4402 * @param set Implementation-defined.
4403 * @param msgid Implementation-defined.
4404 * @param s Default return value if retrieval fails.
4405 * @return Retrieved message or @a s if get fails.
4407 string_type
4408 get(catalog __c, int __set, int __msgid, const string_type& __s) const
4409 { return this->do_get(__c, __set, __msgid, __s); }
4412 * @brief Close a message catalog.
4414 * Closes catalog @a c by calling do_close(c).
4416 * @param c The catalog to close.
4418 void
4419 close(catalog __c) const
4420 { return this->do_close(__c); }
4422 protected:
4423 /// Destructor.
4424 virtual
4425 ~messages();
4428 * @brief Open a message catalog.
4430 * This function opens and returns a handle to a message catalog in an
4431 * implementation-defined manner. This function is a hook for derived
4432 * classes to change the value returned.
4434 * @param s The catalog to open.
4435 * @param loc Locale to use for character set conversions.
4436 * @return Handle to the opened catalog, value < 0 if open failed.
4438 virtual catalog
4439 do_open(const basic_string<char>&, const locale&) const;
4442 * @brief Look up a string in a message catalog.
4444 * This function retrieves and returns a message from a catalog in an
4445 * implementation-defined manner. This function is a hook for derived
4446 * classes to change the value returned.
4448 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4449 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4451 * @param c The catalog to access.
4452 * @param set Implementation-defined.
4453 * @param msgid Implementation-defined.
4454 * @param s Default return value if retrieval fails.
4455 * @return Retrieved message or @a s if get fails.
4457 virtual string_type
4458 do_get(catalog, int, int, const string_type& __dfault) const;
4461 * @brief Close a message catalog.
4463 * @param c The catalog to close.
4465 virtual void
4466 do_close(catalog) const;
4468 // Returns a locale and codeset-converted string, given a char* message.
4469 char*
4470 _M_convert_to_char(const string_type& __msg) const
4472 // XXX
4473 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
4476 // Returns a locale and codeset-converted string, given a char* message.
4477 string_type
4478 _M_convert_from_char(char*) const
4480 #if 0
4481 // Length of message string without terminating null.
4482 size_t __len = char_traits<char>::length(__msg) - 1;
4484 // "everybody can easily convert the string using
4485 // mbsrtowcs/wcsrtombs or with iconv()"
4487 // Convert char* to _CharT in locale used to open catalog.
4488 // XXX need additional template parameter on messages class for this..
4489 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
4490 typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;
4492 __codecvt_type::state_type __state;
4493 // XXX may need to initialize state.
4494 //initialize_state(__state._M_init());
4496 char* __from_next;
4497 // XXX what size for this string?
4498 _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
4499 const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
4500 __cvt.out(__state, __msg, __msg + __len, __from_next,
4501 __to, __to + __len + 1, __to_next);
4502 return string_type(__to);
4503 #endif
4504 #if 0
4505 typedef ctype<_CharT> __ctype_type;
4506 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
4507 const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
4508 // XXX Again, proper length of converted string an issue here.
4509 // For now, assume the converted length is not larger.
4510 _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
4511 __cvt.widen(__msg, __msg + __len, __dest);
4512 return basic_string<_CharT>(__dest);
4513 #endif
4514 return string_type();
4518 template<typename _CharT>
4519 locale::id messages<_CharT>::id;
4521 // Specializations for required instantiations.
4522 template<>
4523 string
4524 messages<char>::do_get(catalog, int, int, const string&) const;
4526 #ifdef _GLIBCXX_USE_WCHAR_T
4527 template<>
4528 wstring
4529 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
4530 #endif
4532 /// @brief class messages_byname [22.2.7.2].
4533 template<typename _CharT>
4534 class messages_byname : public messages<_CharT>
4536 public:
4537 typedef _CharT char_type;
4538 typedef basic_string<_CharT> string_type;
4540 explicit
4541 messages_byname(const char* __s, size_t __refs = 0);
4543 protected:
4544 virtual
4545 ~messages_byname()
4549 // Include host and configuration specific messages functions.
4550 #include <bits/messages_members.h>
4553 // Subclause convenience interfaces, inlines.
4554 // NB: These are inline because, when used in a loop, some compilers
4555 // can hoist the body out of the loop; then it's just as fast as the
4556 // C is*() function.
4558 /// Convenience interface to ctype.is(ctype_base::space, __c).
4559 template<typename _CharT>
4560 inline bool
4561 isspace(_CharT __c, const locale& __loc)
4562 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
4564 /// Convenience interface to ctype.is(ctype_base::print, __c).
4565 template<typename _CharT>
4566 inline bool
4567 isprint(_CharT __c, const locale& __loc)
4568 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
4570 /// Convenience interface to ctype.is(ctype_base::cntrl, __c).
4571 template<typename _CharT>
4572 inline bool
4573 iscntrl(_CharT __c, const locale& __loc)
4574 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
4576 /// Convenience interface to ctype.is(ctype_base::upper, __c).
4577 template<typename _CharT>
4578 inline bool
4579 isupper(_CharT __c, const locale& __loc)
4580 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
4582 /// Convenience interface to ctype.is(ctype_base::lower, __c).
4583 template<typename _CharT>
4584 inline bool
4585 islower(_CharT __c, const locale& __loc)
4586 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
4588 /// Convenience interface to ctype.is(ctype_base::alpha, __c).
4589 template<typename _CharT>
4590 inline bool
4591 isalpha(_CharT __c, const locale& __loc)
4592 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
4594 /// Convenience interface to ctype.is(ctype_base::digit, __c).
4595 template<typename _CharT>
4596 inline bool
4597 isdigit(_CharT __c, const locale& __loc)
4598 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
4600 /// Convenience interface to ctype.is(ctype_base::punct, __c).
4601 template<typename _CharT>
4602 inline bool
4603 ispunct(_CharT __c, const locale& __loc)
4604 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
4606 /// Convenience interface to ctype.is(ctype_base::xdigit, __c).
4607 template<typename _CharT>
4608 inline bool
4609 isxdigit(_CharT __c, const locale& __loc)
4610 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
4612 /// Convenience interface to ctype.is(ctype_base::alnum, __c).
4613 template<typename _CharT>
4614 inline bool
4615 isalnum(_CharT __c, const locale& __loc)
4616 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
4618 /// Convenience interface to ctype.is(ctype_base::graph, __c).
4619 template<typename _CharT>
4620 inline bool
4621 isgraph(_CharT __c, const locale& __loc)
4622 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
4624 /// Convenience interface to ctype.toupper(__c).
4625 template<typename _CharT>
4626 inline _CharT
4627 toupper(_CharT __c, const locale& __loc)
4628 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
4630 /// Convenience interface to ctype.tolower(__c).
4631 template<typename _CharT>
4632 inline _CharT
4633 tolower(_CharT __c, const locale& __loc)
4634 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
4636 _GLIBCXX_END_NAMESPACE
4638 #endif