Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / bits / locale_facets.h
blobcb9c021f3536d57f51906fb7158c342e9638445f
1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007
5 // Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 2, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING. If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // USA.
23 // As a special exception, you may use this file as part of a free software
24 // library without restriction. Specifically, if other files instantiate
25 // templates or use macros or inline functions from this file, or you compile
26 // this file and link it with other files to produce an executable, this
27 // file does not by itself cause the resulting executable to be covered by
28 // the GNU General Public License. This exception does not however
29 // invalidate any other reasons why the executable file might be covered by
30 // the GNU General Public License.
32 /** @file locale_facets.h
33 * This is an internal header file, included by other library headers.
34 * You should not attempt to use it directly.
38 // ISO C++ 14882: 22.1 Locales
41 #ifndef _LOCALE_FACETS_H
42 #define _LOCALE_FACETS_H 1
44 #pragma GCC system_header
46 #include <cwctype> // For wctype_t
47 #include <cctype>
48 #include <bits/ctype_base.h>
49 #include <iosfwd>
50 #include <bits/ios_base.h> // For ios_base, ios_base::iostate
51 #include <streambuf>
52 #include <bits/cpp_type_traits.h>
53 #include <ext/type_traits.h>
54 #include <ext/numeric_traits.h>
55 #include <bits/streambuf_iterator.h>
57 _GLIBCXX_BEGIN_NAMESPACE(std)
59 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
60 #ifdef _GLIBCXX_USE_WCHAR_T
61 # define _GLIBCXX_NUM_FACETS 28
62 #else
63 # define _GLIBCXX_NUM_FACETS 14
64 #endif
66 // Convert string to numeric value of type _Tv and store results.
67 // NB: This is specialized for all required types, there is no
68 // generic definition.
69 template<typename _Tv>
70 void
71 __convert_to_v(const char* __in, _Tv& __out, ios_base::iostate& __err,
72 const __c_locale& __cloc);
74 // Explicit specializations for required types.
75 template<>
76 void
77 __convert_to_v(const char*, float&, ios_base::iostate&,
78 const __c_locale&);
80 template<>
81 void
82 __convert_to_v(const char*, double&, ios_base::iostate&,
83 const __c_locale&);
85 template<>
86 void
87 __convert_to_v(const char*, long double&, ios_base::iostate&,
88 const __c_locale&);
90 // NB: __pad is a struct, rather than a function, so it can be
91 // partially-specialized.
92 template<typename _CharT, typename _Traits>
93 struct __pad
95 static void
96 _S_pad(ios_base& __io, _CharT __fill, _CharT* __news,
97 const _CharT* __olds, const streamsize __newlen,
98 const streamsize __oldlen);
101 // Used by both numeric and monetary facets.
102 // Inserts "group separator" characters into an array of characters.
103 // It's recursive, one iteration per group. It moves the characters
104 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
105 // only with __gsize != 0.
106 template<typename _CharT>
107 _CharT*
108 __add_grouping(_CharT* __s, _CharT __sep,
109 const char* __gbeg, size_t __gsize,
110 const _CharT* __first, const _CharT* __last);
112 // This template permits specializing facet output code for
113 // ostreambuf_iterator. For ostreambuf_iterator, sputn is
114 // significantly more efficient than incrementing iterators.
115 template<typename _CharT>
116 inline
117 ostreambuf_iterator<_CharT>
118 __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len)
120 __s._M_put(__ws, __len);
121 return __s;
124 // This is the unspecialized form of the template.
125 template<typename _CharT, typename _OutIter>
126 inline
127 _OutIter
128 __write(_OutIter __s, const _CharT* __ws, int __len)
130 for (int __j = 0; __j < __len; __j++, ++__s)
131 *__s = __ws[__j];
132 return __s;
136 // 22.2.1.1 Template class ctype
137 // Include host and configuration specific ctype enums for ctype_base.
139 // Common base for ctype<_CharT>.
141 * @brief Common base for ctype facet
143 * This template class provides implementations of the public functions
144 * that forward to the protected virtual functions.
146 * This template also provides abstract stubs for the protected virtual
147 * functions.
149 template<typename _CharT>
150 class __ctype_abstract_base : public locale::facet, public ctype_base
152 public:
153 // Types:
154 /// Typedef for the template parameter
155 typedef _CharT char_type;
158 * @brief Test char_type classification.
160 * This function finds a mask M for @a c and compares it to mask @a m.
161 * It does so by returning the value of ctype<char_type>::do_is().
163 * @param c The char_type to compare the mask of.
164 * @param m The mask to compare against.
165 * @return (M & m) != 0.
167 bool
168 is(mask __m, char_type __c) const
169 { return this->do_is(__m, __c); }
172 * @brief Return a mask array.
174 * This function finds the mask for each char_type in the range [lo,hi)
175 * and successively writes it to vec. vec must have as many elements
176 * as the char array. It does so by returning the value of
177 * ctype<char_type>::do_is().
179 * @param lo Pointer to start of range.
180 * @param hi Pointer to end of range.
181 * @param vec Pointer to an array of mask storage.
182 * @return @a hi.
184 const char_type*
185 is(const char_type *__lo, const char_type *__hi, mask *__vec) const
186 { return this->do_is(__lo, __hi, __vec); }
189 * @brief Find char_type matching a mask
191 * This function searches for and returns the first char_type c in
192 * [lo,hi) for which is(m,c) is true. It does so by returning
193 * ctype<char_type>::do_scan_is().
195 * @param m The mask to compare against.
196 * @param lo Pointer to start of range.
197 * @param hi Pointer to end of range.
198 * @return Pointer to matching char_type if found, else @a hi.
200 const char_type*
201 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
202 { return this->do_scan_is(__m, __lo, __hi); }
205 * @brief Find char_type not matching a mask
207 * This function searches for and returns the first char_type c in
208 * [lo,hi) for which is(m,c) is false. It does so by returning
209 * ctype<char_type>::do_scan_not().
211 * @param m The mask to compare against.
212 * @param lo Pointer to first char in range.
213 * @param hi Pointer to end of range.
214 * @return Pointer to non-matching char if found, else @a hi.
216 const char_type*
217 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
218 { return this->do_scan_not(__m, __lo, __hi); }
221 * @brief Convert to uppercase.
223 * This function converts the argument to uppercase if possible.
224 * If not possible (for example, '2'), returns the argument. It does
225 * so by returning ctype<char_type>::do_toupper().
227 * @param c The char_type to convert.
228 * @return The uppercase char_type if convertible, else @a c.
230 char_type
231 toupper(char_type __c) const
232 { return this->do_toupper(__c); }
235 * @brief Convert array to uppercase.
237 * This function converts each char_type in the range [lo,hi) to
238 * uppercase if possible. Other elements remain untouched. It does so
239 * by returning ctype<char_type>:: do_toupper(lo, hi).
241 * @param lo Pointer to start of range.
242 * @param hi Pointer to end of range.
243 * @return @a hi.
245 const char_type*
246 toupper(char_type *__lo, const char_type* __hi) const
247 { return this->do_toupper(__lo, __hi); }
250 * @brief Convert to lowercase.
252 * This function converts the argument to lowercase if possible. If
253 * not possible (for example, '2'), returns the argument. It does so
254 * by returning ctype<char_type>::do_tolower(c).
256 * @param c The char_type to convert.
257 * @return The lowercase char_type if convertible, else @a c.
259 char_type
260 tolower(char_type __c) const
261 { return this->do_tolower(__c); }
264 * @brief Convert array to lowercase.
266 * This function converts each char_type in the range [lo,hi) to
267 * lowercase if possible. Other elements remain untouched. It does so
268 * by returning ctype<char_type>:: do_tolower(lo, hi).
270 * @param lo Pointer to start of range.
271 * @param hi Pointer to end of range.
272 * @return @a hi.
274 const char_type*
275 tolower(char_type* __lo, const char_type* __hi) const
276 { return this->do_tolower(__lo, __hi); }
279 * @brief Widen char to char_type
281 * This function converts the char argument to char_type using the
282 * simplest reasonable transformation. It does so by returning
283 * ctype<char_type>::do_widen(c).
285 * Note: this is not what you want for codepage conversions. See
286 * codecvt for that.
288 * @param c The char to convert.
289 * @return The converted char_type.
291 char_type
292 widen(char __c) const
293 { return this->do_widen(__c); }
296 * @brief Widen array to char_type
298 * This function converts each char in the input to char_type using the
299 * simplest reasonable transformation. It does so by returning
300 * ctype<char_type>::do_widen(c).
302 * Note: this is not what you want for codepage conversions. See
303 * codecvt for that.
305 * @param lo Pointer to start of range.
306 * @param hi Pointer to end of range.
307 * @param to Pointer to the destination array.
308 * @return @a hi.
310 const char*
311 widen(const char* __lo, const char* __hi, char_type* __to) const
312 { return this->do_widen(__lo, __hi, __to); }
315 * @brief Narrow char_type to char
317 * This function converts the char_type to char using the simplest
318 * reasonable transformation. If the conversion fails, dfault is
319 * returned instead. It does so by returning
320 * ctype<char_type>::do_narrow(c).
322 * Note: this is not what you want for codepage conversions. See
323 * codecvt for that.
325 * @param c The char_type to convert.
326 * @param dfault Char to return if conversion fails.
327 * @return The converted char.
329 char
330 narrow(char_type __c, char __dfault) const
331 { return this->do_narrow(__c, __dfault); }
334 * @brief Narrow array to char array
336 * This function converts each char_type in the input to char using the
337 * simplest reasonable transformation and writes the results to the
338 * destination array. For any char_type in the input that cannot be
339 * converted, @a dfault is used instead. It does so by returning
340 * ctype<char_type>::do_narrow(lo, hi, dfault, to).
342 * Note: this is not what you want for codepage conversions. See
343 * codecvt for that.
345 * @param lo Pointer to start of range.
346 * @param hi Pointer to end of range.
347 * @param dfault Char to use if conversion fails.
348 * @param to Pointer to the destination array.
349 * @return @a hi.
351 const char_type*
352 narrow(const char_type* __lo, const char_type* __hi,
353 char __dfault, char *__to) const
354 { return this->do_narrow(__lo, __hi, __dfault, __to); }
356 protected:
357 explicit
358 __ctype_abstract_base(size_t __refs = 0): facet(__refs) { }
360 virtual
361 ~__ctype_abstract_base() { }
364 * @brief Test char_type classification.
366 * This function finds a mask M for @a c and compares it to mask @a m.
368 * do_is() is a hook for a derived facet to change the behavior of
369 * classifying. do_is() must always return the same result for the
370 * same input.
372 * @param c The char_type to find the mask of.
373 * @param m The mask to compare against.
374 * @return (M & m) != 0.
376 virtual bool
377 do_is(mask __m, char_type __c) const = 0;
380 * @brief Return a mask array.
382 * This function finds the mask for each char_type in the range [lo,hi)
383 * and successively writes it to vec. vec must have as many elements
384 * as the input.
386 * do_is() is a hook for a derived facet to change the behavior of
387 * classifying. do_is() must always return the same result for the
388 * same input.
390 * @param lo Pointer to start of range.
391 * @param hi Pointer to end of range.
392 * @param vec Pointer to an array of mask storage.
393 * @return @a hi.
395 virtual const char_type*
396 do_is(const char_type* __lo, const char_type* __hi,
397 mask* __vec) const = 0;
400 * @brief Find char_type matching mask
402 * This function searches for and returns the first char_type c in
403 * [lo,hi) for which is(m,c) is true.
405 * do_scan_is() is a hook for a derived facet to change the behavior of
406 * match searching. do_is() must always return the same result for the
407 * same input.
409 * @param m The mask to compare against.
410 * @param lo Pointer to start of range.
411 * @param hi Pointer to end of range.
412 * @return Pointer to a matching char_type if found, else @a hi.
414 virtual const char_type*
415 do_scan_is(mask __m, const char_type* __lo,
416 const char_type* __hi) const = 0;
419 * @brief Find char_type not matching mask
421 * This function searches for and returns a pointer to the first
422 * char_type c of [lo,hi) for which is(m,c) is false.
424 * do_scan_is() is a hook for a derived facet to change the behavior of
425 * match searching. do_is() must always return the same result for the
426 * same input.
428 * @param m The mask to compare against.
429 * @param lo Pointer to start of range.
430 * @param hi Pointer to end of range.
431 * @return Pointer to a non-matching char_type if found, else @a hi.
433 virtual const char_type*
434 do_scan_not(mask __m, const char_type* __lo,
435 const char_type* __hi) const = 0;
438 * @brief Convert to uppercase.
440 * This virtual function converts the char_type argument to uppercase
441 * if possible. If not possible (for example, '2'), returns the
442 * argument.
444 * do_toupper() is a hook for a derived facet to change the behavior of
445 * uppercasing. do_toupper() must always return the same result for
446 * the same input.
448 * @param c The char_type to convert.
449 * @return The uppercase char_type if convertible, else @a c.
451 virtual char_type
452 do_toupper(char_type) const = 0;
455 * @brief Convert array to uppercase.
457 * This virtual function converts each char_type in the range [lo,hi)
458 * to uppercase if possible. Other elements remain untouched.
460 * do_toupper() is a hook for a derived facet to change the behavior of
461 * uppercasing. do_toupper() must always return the same result for
462 * the same input.
464 * @param lo Pointer to start of range.
465 * @param hi Pointer to end of range.
466 * @return @a hi.
468 virtual const char_type*
469 do_toupper(char_type* __lo, const char_type* __hi) const = 0;
472 * @brief Convert to lowercase.
474 * This virtual function converts the argument to lowercase if
475 * possible. If not possible (for example, '2'), returns the argument.
477 * do_tolower() is a hook for a derived facet to change the behavior of
478 * lowercasing. do_tolower() must always return the same result for
479 * the same input.
481 * @param c The char_type to convert.
482 * @return The lowercase char_type if convertible, else @a c.
484 virtual char_type
485 do_tolower(char_type) const = 0;
488 * @brief Convert array to lowercase.
490 * This virtual function converts each char_type in the range [lo,hi)
491 * to lowercase if possible. Other elements remain untouched.
493 * do_tolower() is a hook for a derived facet to change the behavior of
494 * lowercasing. do_tolower() must always return the same result for
495 * the same input.
497 * @param lo Pointer to start of range.
498 * @param hi Pointer to end of range.
499 * @return @a hi.
501 virtual const char_type*
502 do_tolower(char_type* __lo, const char_type* __hi) const = 0;
505 * @brief Widen char
507 * This virtual function converts the char to char_type using the
508 * simplest reasonable transformation.
510 * do_widen() is a hook for a derived facet to change the behavior of
511 * widening. do_widen() must always return the same result for the
512 * same input.
514 * Note: this is not what you want for codepage conversions. See
515 * codecvt for that.
517 * @param c The char to convert.
518 * @return The converted char_type
520 virtual char_type
521 do_widen(char) const = 0;
524 * @brief Widen char array
526 * This function converts each char in the input to char_type using the
527 * simplest reasonable transformation.
529 * do_widen() is a hook for a derived facet to change the behavior of
530 * widening. do_widen() must always return the same result for the
531 * same input.
533 * Note: this is not what you want for codepage conversions. See
534 * codecvt for that.
536 * @param lo Pointer to start range.
537 * @param hi Pointer to end of range.
538 * @param to Pointer to the destination array.
539 * @return @a hi.
541 virtual const char*
542 do_widen(const char* __lo, const char* __hi,
543 char_type* __dest) const = 0;
546 * @brief Narrow char_type to char
548 * This virtual function converts the argument to char using the
549 * simplest reasonable transformation. If the conversion fails, dfault
550 * is returned instead.
552 * do_narrow() is a hook for a derived facet to change the behavior of
553 * narrowing. do_narrow() must always return the same result for the
554 * same input.
556 * Note: this is not what you want for codepage conversions. See
557 * codecvt for that.
559 * @param c The char_type to convert.
560 * @param dfault Char to return if conversion fails.
561 * @return The converted char.
563 virtual char
564 do_narrow(char_type, char __dfault) const = 0;
567 * @brief Narrow char_type array to char
569 * This virtual function converts each char_type in the range [lo,hi) to
570 * char using the simplest reasonable transformation and writes the
571 * results to the destination array. For any element in the input that
572 * cannot be converted, @a dfault is used instead.
574 * do_narrow() is a hook for a derived facet to change the behavior of
575 * narrowing. do_narrow() must always return the same result for the
576 * same input.
578 * Note: this is not what you want for codepage conversions. See
579 * codecvt for that.
581 * @param lo Pointer to start of range.
582 * @param hi Pointer to end of range.
583 * @param dfault Char to use if conversion fails.
584 * @param to Pointer to the destination array.
585 * @return @a hi.
587 virtual const char_type*
588 do_narrow(const char_type* __lo, const char_type* __hi,
589 char __dfault, char* __dest) const = 0;
592 // NB: Generic, mostly useless implementation.
594 * @brief Template ctype facet
596 * This template class defines classification and conversion functions for
597 * character sets. It wraps <cctype> functionality. Ctype gets used by
598 * streams for many I/O operations.
600 * This template provides the protected virtual functions the developer
601 * will have to replace in a derived class or specialization to make a
602 * working facet. The public functions that access them are defined in
603 * __ctype_abstract_base, to allow for implementation flexibility. See
604 * ctype<wchar_t> for an example. The functions are documented in
605 * __ctype_abstract_base.
607 * Note: implementations are provided for all the protected virtual
608 * functions, but will likely not be useful.
610 template<typename _CharT>
611 class ctype : public __ctype_abstract_base<_CharT>
613 public:
614 // Types:
615 typedef _CharT char_type;
616 typedef typename __ctype_abstract_base<_CharT>::mask mask;
618 /// The facet id for ctype<char_type>
619 static locale::id id;
621 explicit
622 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
624 protected:
625 virtual
626 ~ctype();
628 virtual bool
629 do_is(mask __m, char_type __c) const;
631 virtual const char_type*
632 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
634 virtual const char_type*
635 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
637 virtual const char_type*
638 do_scan_not(mask __m, const char_type* __lo,
639 const char_type* __hi) const;
641 virtual char_type
642 do_toupper(char_type __c) const;
644 virtual const char_type*
645 do_toupper(char_type* __lo, const char_type* __hi) const;
647 virtual char_type
648 do_tolower(char_type __c) const;
650 virtual const char_type*
651 do_tolower(char_type* __lo, const char_type* __hi) const;
653 virtual char_type
654 do_widen(char __c) const;
656 virtual const char*
657 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
659 virtual char
660 do_narrow(char_type, char __dfault) const;
662 virtual const char_type*
663 do_narrow(const char_type* __lo, const char_type* __hi,
664 char __dfault, char* __dest) const;
667 template<typename _CharT>
668 locale::id ctype<_CharT>::id;
670 // 22.2.1.3 ctype<char> specialization.
672 * @brief The ctype<char> specialization.
674 * This class defines classification and conversion functions for
675 * the char type. It gets used by char streams for many I/O
676 * operations. The char specialization provides a number of
677 * optimizations as well.
679 template<>
680 class ctype<char> : public locale::facet, public ctype_base
682 public:
683 // Types:
684 /// Typedef for the template parameter char.
685 typedef char char_type;
687 protected:
688 // Data Members:
689 __c_locale _M_c_locale_ctype;
690 bool _M_del;
691 __to_type _M_toupper;
692 __to_type _M_tolower;
693 const mask* _M_table;
694 mutable char _M_widen_ok;
695 mutable char _M_widen[1 + static_cast<unsigned char>(-1)];
696 mutable char _M_narrow[1 + static_cast<unsigned char>(-1)];
697 mutable char _M_narrow_ok; // 0 uninitialized, 1 init,
698 // 2 memcpy can't be used
700 public:
701 /// The facet id for ctype<char>
702 static locale::id id;
703 /// The size of the mask table. It is SCHAR_MAX + 1.
704 static const size_t table_size = 1 + static_cast<unsigned char>(-1);
707 * @brief Constructor performs initialization.
709 * This is the constructor provided by the standard.
711 * @param table If non-zero, table is used as the per-char mask.
712 * Else classic_table() is used.
713 * @param del If true, passes ownership of table to this facet.
714 * @param refs Passed to the base facet class.
716 explicit
717 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
720 * @brief Constructor performs static initialization.
722 * This constructor is used to construct the initial C locale facet.
724 * @param cloc Handle to C locale data.
725 * @param table If non-zero, table is used as the per-char mask.
726 * @param del If true, passes ownership of table to this facet.
727 * @param refs Passed to the base facet class.
729 explicit
730 ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
731 size_t __refs = 0);
734 * @brief Test char classification.
736 * This function compares the mask table[c] to @a m.
738 * @param c The char to compare the mask of.
739 * @param m The mask to compare against.
740 * @return True if m & table[c] is true, false otherwise.
742 inline bool
743 is(mask __m, char __c) const;
746 * @brief Return a mask array.
748 * This function finds the mask for each char in the range [lo, hi) and
749 * successively writes it to vec. vec must have as many elements as
750 * the char array.
752 * @param lo Pointer to start of range.
753 * @param hi Pointer to end of range.
754 * @param vec Pointer to an array of mask storage.
755 * @return @a hi.
757 inline const char*
758 is(const char* __lo, const char* __hi, mask* __vec) const;
761 * @brief Find char matching a mask
763 * This function searches for and returns the first char in [lo,hi) for
764 * which is(m,char) is true.
766 * @param m The mask to compare against.
767 * @param lo Pointer to start of range.
768 * @param hi Pointer to end of range.
769 * @return Pointer to a matching char if found, else @a hi.
771 inline const char*
772 scan_is(mask __m, const char* __lo, const char* __hi) const;
775 * @brief Find char not matching a mask
777 * This function searches for and returns a pointer to the first char
778 * in [lo,hi) for which is(m,char) is false.
780 * @param m The mask to compare against.
781 * @param lo Pointer to start of range.
782 * @param hi Pointer to end of range.
783 * @return Pointer to a non-matching char if found, else @a hi.
785 inline const char*
786 scan_not(mask __m, const char* __lo, const char* __hi) const;
789 * @brief Convert to uppercase.
791 * This function converts the char argument to uppercase if possible.
792 * If not possible (for example, '2'), returns the argument.
794 * toupper() acts as if it returns ctype<char>::do_toupper(c).
795 * do_toupper() must always return the same result for the same input.
797 * @param c The char to convert.
798 * @return The uppercase char if convertible, else @a c.
800 char_type
801 toupper(char_type __c) const
802 { return this->do_toupper(__c); }
805 * @brief Convert array to uppercase.
807 * This function converts each char in the range [lo,hi) to uppercase
808 * if possible. Other chars remain untouched.
810 * toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi).
811 * do_toupper() must always return the same result for the same input.
813 * @param lo Pointer to first char in range.
814 * @param hi Pointer to end of range.
815 * @return @a hi.
817 const char_type*
818 toupper(char_type *__lo, const char_type* __hi) const
819 { return this->do_toupper(__lo, __hi); }
822 * @brief Convert to lowercase.
824 * This function converts the char argument to lowercase if possible.
825 * If not possible (for example, '2'), returns the argument.
827 * tolower() acts as if it returns ctype<char>::do_tolower(c).
828 * do_tolower() must always return the same result for the same input.
830 * @param c The char to convert.
831 * @return The lowercase char if convertible, else @a c.
833 char_type
834 tolower(char_type __c) const
835 { return this->do_tolower(__c); }
838 * @brief Convert array to lowercase.
840 * This function converts each char in the range [lo,hi) to lowercase
841 * if possible. Other chars remain untouched.
843 * tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi).
844 * do_tolower() must always return the same result for the same input.
846 * @param lo Pointer to first char in range.
847 * @param hi Pointer to end of range.
848 * @return @a hi.
850 const char_type*
851 tolower(char_type* __lo, const char_type* __hi) const
852 { return this->do_tolower(__lo, __hi); }
855 * @brief Widen char
857 * This function converts the char to char_type using the simplest
858 * reasonable transformation. For an underived ctype<char> facet, the
859 * argument will be returned unchanged.
861 * This function works as if it returns ctype<char>::do_widen(c).
862 * do_widen() must always return the same result for the same input.
864 * Note: this is not what you want for codepage conversions. See
865 * codecvt for that.
867 * @param c The char to convert.
868 * @return The converted character.
870 char_type
871 widen(char __c) const
873 if (_M_widen_ok)
874 return _M_widen[static_cast<unsigned char>(__c)];
875 this->_M_widen_init();
876 return this->do_widen(__c);
880 * @brief Widen char array
882 * This function converts each char in the input to char using the
883 * simplest reasonable transformation. For an underived ctype<char>
884 * facet, the argument will be copied unchanged.
886 * This function works as if it returns ctype<char>::do_widen(c).
887 * do_widen() must always return the same result for the same input.
889 * Note: this is not what you want for codepage conversions. See
890 * codecvt for that.
892 * @param lo Pointer to first char in range.
893 * @param hi Pointer to end of range.
894 * @param to Pointer to the destination array.
895 * @return @a hi.
897 const char*
898 widen(const char* __lo, const char* __hi, char_type* __to) const
900 if (_M_widen_ok == 1)
902 __builtin_memcpy(__to, __lo, __hi - __lo);
903 return __hi;
905 if (!_M_widen_ok)
906 _M_widen_init();
907 return this->do_widen(__lo, __hi, __to);
911 * @brief Narrow char
913 * This function converts the char to char using the simplest
914 * reasonable transformation. If the conversion fails, dfault is
915 * returned instead. For an underived ctype<char> facet, @a c
916 * will be returned unchanged.
918 * This function works as if it returns ctype<char>::do_narrow(c).
919 * do_narrow() must always return the same result for the same input.
921 * Note: this is not what you want for codepage conversions. See
922 * codecvt for that.
924 * @param c The char to convert.
925 * @param dfault Char to return if conversion fails.
926 * @return The converted character.
928 char
929 narrow(char_type __c, char __dfault) const
931 if (_M_narrow[static_cast<unsigned char>(__c)])
932 return _M_narrow[static_cast<unsigned char>(__c)];
933 const char __t = do_narrow(__c, __dfault);
934 if (__t != __dfault)
935 _M_narrow[static_cast<unsigned char>(__c)] = __t;
936 return __t;
940 * @brief Narrow char array
942 * This function converts each char in the input to char using the
943 * simplest reasonable transformation and writes the results to the
944 * destination array. For any char in the input that cannot be
945 * converted, @a dfault is used instead. For an underived ctype<char>
946 * facet, the argument will be copied unchanged.
948 * This function works as if it returns ctype<char>::do_narrow(lo, hi,
949 * dfault, to). do_narrow() must always return the same result for the
950 * same input.
952 * Note: this is not what you want for codepage conversions. See
953 * codecvt for that.
955 * @param lo Pointer to start of range.
956 * @param hi Pointer to end of range.
957 * @param dfault Char to use if conversion fails.
958 * @param to Pointer to the destination array.
959 * @return @a hi.
961 const char_type*
962 narrow(const char_type* __lo, const char_type* __hi,
963 char __dfault, char *__to) const
965 if (__builtin_expect(_M_narrow_ok == 1, true))
967 __builtin_memcpy(__to, __lo, __hi - __lo);
968 return __hi;
970 if (!_M_narrow_ok)
971 _M_narrow_init();
972 return this->do_narrow(__lo, __hi, __dfault, __to);
975 // _GLIBCXX_RESOLVE_LIB_DEFECTS
976 // DR 695. ctype<char>::classic_table() not accessible.
977 /// Returns a pointer to the mask table provided to the constructor, or
978 /// the default from classic_table() if none was provided.
979 const mask*
980 table() const throw()
981 { return _M_table; }
983 /// Returns a pointer to the C locale mask table.
984 static const mask*
985 classic_table() throw();
986 protected:
989 * @brief Destructor.
991 * This function deletes table() if @a del was true in the
992 * constructor.
994 virtual
995 ~ctype();
998 * @brief Convert to uppercase.
1000 * This virtual function converts the char argument to uppercase if
1001 * possible. If not possible (for example, '2'), returns the argument.
1003 * do_toupper() is a hook for a derived facet to change the behavior of
1004 * uppercasing. do_toupper() must always return the same result for
1005 * the same input.
1007 * @param c The char to convert.
1008 * @return The uppercase char if convertible, else @a c.
1010 virtual char_type
1011 do_toupper(char_type) const;
1014 * @brief Convert array to uppercase.
1016 * This virtual function converts each char in the range [lo,hi) to
1017 * uppercase if possible. Other chars remain untouched.
1019 * do_toupper() is a hook for a derived facet to change the behavior of
1020 * uppercasing. do_toupper() must always return the same result for
1021 * the same input.
1023 * @param lo Pointer to start of range.
1024 * @param hi Pointer to end of range.
1025 * @return @a hi.
1027 virtual const char_type*
1028 do_toupper(char_type* __lo, const char_type* __hi) const;
1031 * @brief Convert to lowercase.
1033 * This virtual function converts the char argument to lowercase if
1034 * possible. If not possible (for example, '2'), returns the argument.
1036 * do_tolower() is a hook for a derived facet to change the behavior of
1037 * lowercasing. do_tolower() must always return the same result for
1038 * the same input.
1040 * @param c The char to convert.
1041 * @return The lowercase char if convertible, else @a c.
1043 virtual char_type
1044 do_tolower(char_type) const;
1047 * @brief Convert array to lowercase.
1049 * This virtual function converts each char in the range [lo,hi) to
1050 * lowercase if possible. Other chars remain untouched.
1052 * do_tolower() is a hook for a derived facet to change the behavior of
1053 * lowercasing. do_tolower() must always return the same result for
1054 * the same input.
1056 * @param lo Pointer to first char in range.
1057 * @param hi Pointer to end of range.
1058 * @return @a hi.
1060 virtual const char_type*
1061 do_tolower(char_type* __lo, const char_type* __hi) const;
1064 * @brief Widen char
1066 * This virtual function converts the char to char using the simplest
1067 * reasonable transformation. For an underived ctype<char> facet, the
1068 * argument will be returned unchanged.
1070 * do_widen() is a hook for a derived facet to change the behavior of
1071 * widening. do_widen() must always return the same result for the
1072 * same input.
1074 * Note: this is not what you want for codepage conversions. See
1075 * codecvt for that.
1077 * @param c The char to convert.
1078 * @return The converted character.
1080 virtual char_type
1081 do_widen(char __c) const
1082 { return __c; }
1085 * @brief Widen char array
1087 * This function converts each char in the range [lo,hi) to char using
1088 * the simplest reasonable transformation. For an underived
1089 * ctype<char> facet, the argument will be copied unchanged.
1091 * do_widen() is a hook for a derived facet to change the behavior of
1092 * widening. do_widen() must always return the same result for the
1093 * same input.
1095 * Note: this is not what you want for codepage conversions. See
1096 * codecvt for that.
1098 * @param lo Pointer to start of range.
1099 * @param hi Pointer to end of range.
1100 * @param to Pointer to the destination array.
1101 * @return @a hi.
1103 virtual const char*
1104 do_widen(const char* __lo, const char* __hi, char_type* __dest) const
1106 __builtin_memcpy(__dest, __lo, __hi - __lo);
1107 return __hi;
1111 * @brief Narrow char
1113 * This virtual function converts the char to char using the simplest
1114 * reasonable transformation. If the conversion fails, dfault is
1115 * returned instead. For an underived ctype<char> facet, @a c will be
1116 * returned unchanged.
1118 * do_narrow() is a hook for a derived facet to change the behavior of
1119 * narrowing. do_narrow() must always return the same result for the
1120 * same input.
1122 * Note: this is not what you want for codepage conversions. See
1123 * codecvt for that.
1125 * @param c The char to convert.
1126 * @param dfault Char to return if conversion fails.
1127 * @return The converted char.
1129 virtual char
1130 do_narrow(char_type __c, char) const
1131 { return __c; }
1134 * @brief Narrow char array to char array
1136 * This virtual function converts each char in the range [lo,hi) to
1137 * char using the simplest reasonable transformation and writes the
1138 * results to the destination array. For any char in the input that
1139 * cannot be converted, @a dfault is used instead. For an underived
1140 * ctype<char> facet, the argument will be copied unchanged.
1142 * do_narrow() is a hook for a derived facet to change the behavior of
1143 * narrowing. do_narrow() must always return the same result for the
1144 * same input.
1146 * Note: this is not what you want for codepage conversions. See
1147 * codecvt for that.
1149 * @param lo Pointer to start of range.
1150 * @param hi Pointer to end of range.
1151 * @param dfault Char to use if conversion fails.
1152 * @param to Pointer to the destination array.
1153 * @return @a hi.
1155 virtual const char_type*
1156 do_narrow(const char_type* __lo, const char_type* __hi,
1157 char, char* __dest) const
1159 __builtin_memcpy(__dest, __lo, __hi - __lo);
1160 return __hi;
1163 private:
1165 void _M_widen_init() const
1167 char __tmp[sizeof(_M_widen)];
1168 for (size_t __i = 0; __i < sizeof(_M_widen); ++__i)
1169 __tmp[__i] = __i;
1170 do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen);
1172 _M_widen_ok = 1;
1173 // Set _M_widen_ok to 2 if memcpy can't be used.
1174 if (__builtin_memcmp(__tmp, _M_widen, sizeof(_M_widen)))
1175 _M_widen_ok = 2;
1178 // Fill in the narrowing cache and flag whether all values are
1179 // valid or not. _M_narrow_ok is set to 2 if memcpy can't
1180 // be used.
1181 void _M_narrow_init() const
1183 char __tmp[sizeof(_M_narrow)];
1184 for (size_t __i = 0; __i < sizeof(_M_narrow); ++__i)
1185 __tmp[__i] = __i;
1186 do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow);
1188 _M_narrow_ok = 1;
1189 if (__builtin_memcmp(__tmp, _M_narrow, sizeof(_M_narrow)))
1190 _M_narrow_ok = 2;
1191 else
1193 // Deal with the special case of zero: renarrow with a
1194 // different default and compare.
1195 char __c;
1196 do_narrow(__tmp, __tmp + 1, 1, &__c);
1197 if (__c == 1)
1198 _M_narrow_ok = 2;
1203 template<>
1204 const ctype<char>&
1205 use_facet<ctype<char> >(const locale& __loc);
1207 #ifdef _GLIBCXX_USE_WCHAR_T
1208 // 22.2.1.3 ctype<wchar_t> specialization
1210 * @brief The ctype<wchar_t> specialization.
1212 * This class defines classification and conversion functions for the
1213 * wchar_t type. It gets used by wchar_t streams for many I/O operations.
1214 * The wchar_t specialization provides a number of optimizations as well.
1216 * ctype<wchar_t> inherits its public methods from
1217 * __ctype_abstract_base<wchar_t>.
1219 template<>
1220 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
1222 public:
1223 // Types:
1224 /// Typedef for the template parameter wchar_t.
1225 typedef wchar_t char_type;
1226 typedef wctype_t __wmask_type;
1228 protected:
1229 __c_locale _M_c_locale_ctype;
1231 // Pre-computed narrowed and widened chars.
1232 bool _M_narrow_ok;
1233 char _M_narrow[128];
1234 wint_t _M_widen[1 + static_cast<unsigned char>(-1)];
1236 // Pre-computed elements for do_is.
1237 mask _M_bit[16];
1238 __wmask_type _M_wmask[16];
1240 public:
1241 // Data Members:
1242 /// The facet id for ctype<wchar_t>
1243 static locale::id id;
1246 * @brief Constructor performs initialization.
1248 * This is the constructor provided by the standard.
1250 * @param refs Passed to the base facet class.
1252 explicit
1253 ctype(size_t __refs = 0);
1256 * @brief Constructor performs static initialization.
1258 * This constructor is used to construct the initial C locale facet.
1260 * @param cloc Handle to C locale data.
1261 * @param refs Passed to the base facet class.
1263 explicit
1264 ctype(__c_locale __cloc, size_t __refs = 0);
1266 protected:
1267 __wmask_type
1268 _M_convert_to_wmask(const mask __m) const;
1270 /// Destructor
1271 virtual
1272 ~ctype();
1275 * @brief Test wchar_t classification.
1277 * This function finds a mask M for @a c and compares it to mask @a m.
1279 * do_is() is a hook for a derived facet to change the behavior of
1280 * classifying. do_is() must always return the same result for the
1281 * same input.
1283 * @param c The wchar_t to find the mask of.
1284 * @param m The mask to compare against.
1285 * @return (M & m) != 0.
1287 virtual bool
1288 do_is(mask __m, char_type __c) const;
1291 * @brief Return a mask array.
1293 * This function finds the mask for each wchar_t in the range [lo,hi)
1294 * and successively writes it to vec. vec must have as many elements
1295 * as the input.
1297 * do_is() is a hook for a derived facet to change the behavior of
1298 * classifying. do_is() must always return the same result for the
1299 * same input.
1301 * @param lo Pointer to start of range.
1302 * @param hi Pointer to end of range.
1303 * @param vec Pointer to an array of mask storage.
1304 * @return @a hi.
1306 virtual const char_type*
1307 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
1310 * @brief Find wchar_t matching mask
1312 * This function searches for and returns the first wchar_t c in
1313 * [lo,hi) for which is(m,c) is true.
1315 * do_scan_is() is a hook for a derived facet to change the behavior of
1316 * match searching. do_is() must always return the same result for the
1317 * same input.
1319 * @param m The mask to compare against.
1320 * @param lo Pointer to start of range.
1321 * @param hi Pointer to end of range.
1322 * @return Pointer to a matching wchar_t if found, else @a hi.
1324 virtual const char_type*
1325 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
1328 * @brief Find wchar_t not matching mask
1330 * This function searches for and returns a pointer to the first
1331 * wchar_t c of [lo,hi) for which is(m,c) is false.
1333 * do_scan_is() is a hook for a derived facet to change the behavior of
1334 * match searching. do_is() must always return the same result for the
1335 * same input.
1337 * @param m The mask to compare against.
1338 * @param lo Pointer to start of range.
1339 * @param hi Pointer to end of range.
1340 * @return Pointer to a non-matching wchar_t if found, else @a hi.
1342 virtual const char_type*
1343 do_scan_not(mask __m, const char_type* __lo,
1344 const char_type* __hi) const;
1347 * @brief Convert to uppercase.
1349 * This virtual function converts the wchar_t argument to uppercase if
1350 * possible. If not possible (for example, '2'), returns the argument.
1352 * do_toupper() is a hook for a derived facet to change the behavior of
1353 * uppercasing. do_toupper() must always return the same result for
1354 * the same input.
1356 * @param c The wchar_t to convert.
1357 * @return The uppercase wchar_t if convertible, else @a c.
1359 virtual char_type
1360 do_toupper(char_type) const;
1363 * @brief Convert array to uppercase.
1365 * This virtual function converts each wchar_t in the range [lo,hi) to
1366 * uppercase if possible. Other elements remain untouched.
1368 * do_toupper() is a hook for a derived facet to change the behavior of
1369 * uppercasing. do_toupper() must always return the same result for
1370 * the same input.
1372 * @param lo Pointer to start of range.
1373 * @param hi Pointer to end of range.
1374 * @return @a hi.
1376 virtual const char_type*
1377 do_toupper(char_type* __lo, const char_type* __hi) const;
1380 * @brief Convert to lowercase.
1382 * This virtual function converts the argument to lowercase if
1383 * possible. If not possible (for example, '2'), returns the argument.
1385 * do_tolower() is a hook for a derived facet to change the behavior of
1386 * lowercasing. do_tolower() must always return the same result for
1387 * the same input.
1389 * @param c The wchar_t to convert.
1390 * @return The lowercase wchar_t if convertible, else @a c.
1392 virtual char_type
1393 do_tolower(char_type) const;
1396 * @brief Convert array to lowercase.
1398 * This virtual function converts each wchar_t in the range [lo,hi) to
1399 * lowercase if possible. Other elements remain untouched.
1401 * do_tolower() is a hook for a derived facet to change the behavior of
1402 * lowercasing. do_tolower() must always return the same result for
1403 * the same input.
1405 * @param lo Pointer to start of range.
1406 * @param hi Pointer to end of range.
1407 * @return @a hi.
1409 virtual const char_type*
1410 do_tolower(char_type* __lo, const char_type* __hi) const;
1413 * @brief Widen char to wchar_t
1415 * This virtual function converts the char to wchar_t using the
1416 * simplest reasonable transformation. For an underived ctype<wchar_t>
1417 * facet, the argument will be cast to wchar_t.
1419 * do_widen() is a hook for a derived facet to change the behavior of
1420 * widening. do_widen() must always return the same result for the
1421 * same input.
1423 * Note: this is not what you want for codepage conversions. See
1424 * codecvt for that.
1426 * @param c The char to convert.
1427 * @return The converted wchar_t.
1429 virtual char_type
1430 do_widen(char) const;
1433 * @brief Widen char array to wchar_t array
1435 * This function converts each char in the input to wchar_t using the
1436 * simplest reasonable transformation. For an underived ctype<wchar_t>
1437 * facet, the argument will be copied, casting each element to wchar_t.
1439 * do_widen() is a hook for a derived facet to change the behavior of
1440 * widening. do_widen() must always return the same result for the
1441 * same input.
1443 * Note: this is not what you want for codepage conversions. See
1444 * codecvt for that.
1446 * @param lo Pointer to start range.
1447 * @param hi Pointer to end of range.
1448 * @param to Pointer to the destination array.
1449 * @return @a hi.
1451 virtual const char*
1452 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
1455 * @brief Narrow wchar_t to char
1457 * This virtual function converts the argument to char using
1458 * the simplest reasonable transformation. If the conversion
1459 * fails, dfault is returned instead. For an underived
1460 * ctype<wchar_t> facet, @a c will be cast to char and
1461 * returned.
1463 * do_narrow() is a hook for a derived facet to change the
1464 * behavior of narrowing. do_narrow() must always return the
1465 * same result for the same input.
1467 * Note: this is not what you want for codepage conversions. See
1468 * codecvt for that.
1470 * @param c The wchar_t to convert.
1471 * @param dfault Char to return if conversion fails.
1472 * @return The converted char.
1474 virtual char
1475 do_narrow(char_type, char __dfault) const;
1478 * @brief Narrow wchar_t array to char array
1480 * This virtual function converts each wchar_t in the range [lo,hi) to
1481 * char using the simplest reasonable transformation and writes the
1482 * results to the destination array. For any wchar_t in the input that
1483 * cannot be converted, @a dfault is used instead. For an underived
1484 * ctype<wchar_t> facet, the argument will be copied, casting each
1485 * element to char.
1487 * do_narrow() is a hook for a derived facet to change the behavior of
1488 * narrowing. do_narrow() must always return the same result for the
1489 * same input.
1491 * Note: this is not what you want for codepage conversions. See
1492 * codecvt for that.
1494 * @param lo Pointer to start of range.
1495 * @param hi Pointer to end of range.
1496 * @param dfault Char to use if conversion fails.
1497 * @param to Pointer to the destination array.
1498 * @return @a hi.
1500 virtual const char_type*
1501 do_narrow(const char_type* __lo, const char_type* __hi,
1502 char __dfault, char* __dest) const;
1504 // For use at construction time only.
1505 void
1506 _M_initialize_ctype();
1509 template<>
1510 const ctype<wchar_t>&
1511 use_facet<ctype<wchar_t> >(const locale& __loc);
1512 #endif //_GLIBCXX_USE_WCHAR_T
1514 /// class ctype_byname [22.2.1.2].
1515 template<typename _CharT>
1516 class ctype_byname : public ctype<_CharT>
1518 public:
1519 typedef typename ctype<_CharT>::mask mask;
1521 explicit
1522 ctype_byname(const char* __s, size_t __refs = 0);
1524 protected:
1525 virtual
1526 ~ctype_byname() { };
1529 /// 22.2.1.4 Class ctype_byname specializations.
1530 template<>
1531 class ctype_byname<char> : public ctype<char>
1533 public:
1534 explicit
1535 ctype_byname(const char* __s, size_t __refs = 0);
1537 protected:
1538 virtual
1539 ~ctype_byname();
1542 #ifdef _GLIBCXX_USE_WCHAR_T
1543 template<>
1544 class ctype_byname<wchar_t> : public ctype<wchar_t>
1546 public:
1547 explicit
1548 ctype_byname(const char* __s, size_t __refs = 0);
1550 protected:
1551 virtual
1552 ~ctype_byname();
1554 #endif
1556 _GLIBCXX_END_NAMESPACE
1558 // Include host and configuration specific ctype inlines.
1559 #include <bits/ctype_inline.h>
1561 _GLIBCXX_BEGIN_NAMESPACE(std)
1563 // 22.2.2 The numeric category.
1564 class __num_base
1566 public:
1567 // NB: Code depends on the order of _S_atoms_out elements.
1568 // Below are the indices into _S_atoms_out.
1569 enum
1571 _S_ominus,
1572 _S_oplus,
1573 _S_ox,
1574 _S_oX,
1575 _S_odigits,
1576 _S_odigits_end = _S_odigits + 16,
1577 _S_oudigits = _S_odigits_end,
1578 _S_oudigits_end = _S_oudigits + 16,
1579 _S_oe = _S_odigits + 14, // For scientific notation, 'e'
1580 _S_oE = _S_oudigits + 14, // For scientific notation, 'E'
1581 _S_oend = _S_oudigits_end
1584 // A list of valid numeric literals for output. This array
1585 // contains chars that will be passed through the current locale's
1586 // ctype<_CharT>.widen() and then used to render numbers.
1587 // For the standard "C" locale, this is
1588 // "-+xX0123456789abcdef0123456789ABCDEF".
1589 static const char* _S_atoms_out;
1591 // String literal of acceptable (narrow) input, for num_get.
1592 // "-+xX0123456789abcdefABCDEF"
1593 static const char* _S_atoms_in;
1595 enum
1597 _S_iminus,
1598 _S_iplus,
1599 _S_ix,
1600 _S_iX,
1601 _S_izero,
1602 _S_ie = _S_izero + 14,
1603 _S_iE = _S_izero + 20,
1604 _S_iend = 26
1607 // num_put
1608 // Construct and return valid scanf format for floating point types.
1609 static void
1610 _S_format_float(const ios_base& __io, char* __fptr, char __mod);
1613 template<typename _CharT>
1614 struct __numpunct_cache : public locale::facet
1616 const char* _M_grouping;
1617 size_t _M_grouping_size;
1618 bool _M_use_grouping;
1619 const _CharT* _M_truename;
1620 size_t _M_truename_size;
1621 const _CharT* _M_falsename;
1622 size_t _M_falsename_size;
1623 _CharT _M_decimal_point;
1624 _CharT _M_thousands_sep;
1626 // A list of valid numeric literals for output: in the standard
1627 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1628 // This array contains the chars after having been passed
1629 // through the current locale's ctype<_CharT>.widen().
1630 _CharT _M_atoms_out[__num_base::_S_oend];
1632 // A list of valid numeric literals for input: in the standard
1633 // "C" locale, this is "-+xX0123456789abcdefABCDEF"
1634 // This array contains the chars after having been passed
1635 // through the current locale's ctype<_CharT>.widen().
1636 _CharT _M_atoms_in[__num_base::_S_iend];
1638 bool _M_allocated;
1640 __numpunct_cache(size_t __refs = 0) : facet(__refs),
1641 _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
1642 _M_truename(NULL), _M_truename_size(0), _M_falsename(NULL),
1643 _M_falsename_size(0), _M_decimal_point(_CharT()),
1644 _M_thousands_sep(_CharT()), _M_allocated(false)
1647 ~__numpunct_cache();
1649 void
1650 _M_cache(const locale& __loc);
1652 private:
1653 __numpunct_cache&
1654 operator=(const __numpunct_cache&);
1656 explicit
1657 __numpunct_cache(const __numpunct_cache&);
1660 template<typename _CharT>
1661 __numpunct_cache<_CharT>::~__numpunct_cache()
1663 if (_M_allocated)
1665 delete [] _M_grouping;
1666 delete [] _M_truename;
1667 delete [] _M_falsename;
1672 * @brief Numpunct facet.
1674 * This facet stores several pieces of information related to printing and
1675 * scanning numbers, such as the decimal point character. It takes a
1676 * template parameter specifying the char type. The numpunct facet is
1677 * used by streams for many I/O operations involving numbers.
1679 * The numpunct template uses protected virtual functions to provide the
1680 * actual results. The public accessors forward the call to the virtual
1681 * functions. These virtual functions are hooks for developers to
1682 * implement the behavior they require from a numpunct facet.
1684 template<typename _CharT>
1685 class numpunct : public locale::facet
1687 public:
1688 // Types:
1689 //@{
1690 /// Public typedefs
1691 typedef _CharT char_type;
1692 typedef basic_string<_CharT> string_type;
1693 //@}
1694 typedef __numpunct_cache<_CharT> __cache_type;
1696 protected:
1697 __cache_type* _M_data;
1699 public:
1700 /// Numpunct facet id.
1701 static locale::id id;
1704 * @brief Numpunct constructor.
1706 * @param refs Refcount to pass to the base class.
1708 explicit
1709 numpunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
1710 { _M_initialize_numpunct(); }
1713 * @brief Internal constructor. Not for general use.
1715 * This is a constructor for use by the library itself to set up the
1716 * predefined locale facets.
1718 * @param cache __numpunct_cache object.
1719 * @param refs Refcount to pass to the base class.
1721 explicit
1722 numpunct(__cache_type* __cache, size_t __refs = 0)
1723 : facet(__refs), _M_data(__cache)
1724 { _M_initialize_numpunct(); }
1727 * @brief Internal constructor. Not for general use.
1729 * This is a constructor for use by the library itself to set up new
1730 * locales.
1732 * @param cloc The "C" locale.
1733 * @param refs Refcount to pass to the base class.
1735 explicit
1736 numpunct(__c_locale __cloc, size_t __refs = 0)
1737 : facet(__refs), _M_data(NULL)
1738 { _M_initialize_numpunct(__cloc); }
1741 * @brief Return decimal point character.
1743 * This function returns a char_type to use as a decimal point. It
1744 * does so by returning returning
1745 * numpunct<char_type>::do_decimal_point().
1747 * @return @a char_type representing a decimal point.
1749 char_type
1750 decimal_point() const
1751 { return this->do_decimal_point(); }
1754 * @brief Return thousands separator character.
1756 * This function returns a char_type to use as a thousands
1757 * separator. It does so by returning returning
1758 * numpunct<char_type>::do_thousands_sep().
1760 * @return char_type representing a thousands separator.
1762 char_type
1763 thousands_sep() const
1764 { return this->do_thousands_sep(); }
1767 * @brief Return grouping specification.
1769 * This function returns a string representing groupings for the
1770 * integer part of a number. Groupings indicate where thousands
1771 * separators should be inserted in the integer part of a number.
1773 * Each char in the return string is interpret as an integer
1774 * rather than a character. These numbers represent the number
1775 * of digits in a group. The first char in the string
1776 * represents the number of digits in the least significant
1777 * group. If a char is negative, it indicates an unlimited
1778 * number of digits for the group. If more chars from the
1779 * string are required to group a number, the last char is used
1780 * repeatedly.
1782 * For example, if the grouping() returns "\003\002" and is
1783 * applied to the number 123456789, this corresponds to
1784 * 12,34,56,789. Note that if the string was "32", this would
1785 * put more than 50 digits into the least significant group if
1786 * the character set is ASCII.
1788 * The string is returned by calling
1789 * numpunct<char_type>::do_grouping().
1791 * @return string representing grouping specification.
1793 string
1794 grouping() const
1795 { return this->do_grouping(); }
1798 * @brief Return string representation of bool true.
1800 * This function returns a string_type containing the text
1801 * representation for true bool variables. It does so by calling
1802 * numpunct<char_type>::do_truename().
1804 * @return string_type representing printed form of true.
1806 string_type
1807 truename() const
1808 { return this->do_truename(); }
1811 * @brief Return string representation of bool false.
1813 * This function returns a string_type containing the text
1814 * representation for false bool variables. It does so by calling
1815 * numpunct<char_type>::do_falsename().
1817 * @return string_type representing printed form of false.
1819 string_type
1820 falsename() const
1821 { return this->do_falsename(); }
1823 protected:
1824 /// Destructor.
1825 virtual
1826 ~numpunct();
1829 * @brief Return decimal point character.
1831 * Returns a char_type to use as a decimal point. This function is a
1832 * hook for derived classes to change the value returned.
1834 * @return @a char_type representing a decimal point.
1836 virtual char_type
1837 do_decimal_point() const
1838 { return _M_data->_M_decimal_point; }
1841 * @brief Return thousands separator character.
1843 * Returns a char_type to use as a thousands separator. This function
1844 * is a hook for derived classes to change the value returned.
1846 * @return @a char_type representing a thousands separator.
1848 virtual char_type
1849 do_thousands_sep() const
1850 { return _M_data->_M_thousands_sep; }
1853 * @brief Return grouping specification.
1855 * Returns a string representing groupings for the integer part of a
1856 * number. This function is a hook for derived classes to change the
1857 * value returned. @see grouping() for details.
1859 * @return String representing grouping specification.
1861 virtual string
1862 do_grouping() const
1863 { return _M_data->_M_grouping; }
1866 * @brief Return string representation of bool true.
1868 * Returns a string_type containing the text representation for true
1869 * bool variables. This function is a hook for derived classes to
1870 * change the value returned.
1872 * @return string_type representing printed form of true.
1874 virtual string_type
1875 do_truename() const
1876 { return _M_data->_M_truename; }
1879 * @brief Return string representation of bool false.
1881 * Returns a string_type containing the text representation for false
1882 * bool variables. This function is a hook for derived classes to
1883 * change the value returned.
1885 * @return string_type representing printed form of false.
1887 virtual string_type
1888 do_falsename() const
1889 { return _M_data->_M_falsename; }
1891 // For use at construction time only.
1892 void
1893 _M_initialize_numpunct(__c_locale __cloc = NULL);
1896 template<typename _CharT>
1897 locale::id numpunct<_CharT>::id;
1899 template<>
1900 numpunct<char>::~numpunct();
1902 template<>
1903 void
1904 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
1906 #ifdef _GLIBCXX_USE_WCHAR_T
1907 template<>
1908 numpunct<wchar_t>::~numpunct();
1910 template<>
1911 void
1912 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
1913 #endif
1915 /// class numpunct_byname [22.2.3.2].
1916 template<typename _CharT>
1917 class numpunct_byname : public numpunct<_CharT>
1919 public:
1920 typedef _CharT char_type;
1921 typedef basic_string<_CharT> string_type;
1923 explicit
1924 numpunct_byname(const char* __s, size_t __refs = 0)
1925 : numpunct<_CharT>(__refs)
1927 if (__builtin_strcmp(__s, "C") != 0
1928 && __builtin_strcmp(__s, "POSIX") != 0)
1930 __c_locale __tmp;
1931 this->_S_create_c_locale(__tmp, __s);
1932 this->_M_initialize_numpunct(__tmp);
1933 this->_S_destroy_c_locale(__tmp);
1937 protected:
1938 virtual
1939 ~numpunct_byname() { }
1942 _GLIBCXX_BEGIN_LDBL_NAMESPACE
1945 * @brief Facet for parsing number strings.
1947 * This facet encapsulates the code to parse and return a number
1948 * from a string. It is used by the istream numeric extraction
1949 * operators.
1951 * The num_get template uses protected virtual functions to provide the
1952 * actual results. The public accessors forward the call to the virtual
1953 * functions. These virtual functions are hooks for developers to
1954 * implement the behavior they require from the num_get facet.
1956 template<typename _CharT, typename _InIter>
1957 class num_get : public locale::facet
1959 public:
1960 // Types:
1961 //@{
1962 /// Public typedefs
1963 typedef _CharT char_type;
1964 typedef _InIter iter_type;
1965 //@}
1967 /// Numpunct facet id.
1968 static locale::id id;
1971 * @brief Constructor performs initialization.
1973 * This is the constructor provided by the standard.
1975 * @param refs Passed to the base facet class.
1977 explicit
1978 num_get(size_t __refs = 0) : facet(__refs) { }
1981 * @brief Numeric parsing.
1983 * Parses the input stream into the bool @a v. It does so by calling
1984 * num_get::do_get().
1986 * If ios_base::boolalpha is set, attempts to read
1987 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
1988 * @a v to true or false if successful. Sets err to
1989 * ios_base::failbit if reading the string fails. Sets err to
1990 * ios_base::eofbit if the stream is emptied.
1992 * If ios_base::boolalpha is not set, proceeds as with reading a long,
1993 * except if the value is 1, sets @a v to true, if the value is 0, sets
1994 * @a v to false, and otherwise set err to ios_base::failbit.
1996 * @param in Start of input stream.
1997 * @param end End of input stream.
1998 * @param io Source of locale and flags.
1999 * @param err Error flags to set.
2000 * @param v Value to format and insert.
2001 * @return Iterator after reading.
2003 iter_type
2004 get(iter_type __in, iter_type __end, ios_base& __io,
2005 ios_base::iostate& __err, bool& __v) const
2006 { return this->do_get(__in, __end, __io, __err, __v); }
2008 //@{
2010 * @brief Numeric parsing.
2012 * Parses the input stream into the integral variable @a v. It does so
2013 * by calling num_get::do_get().
2015 * Parsing is affected by the flag settings in @a io.
2017 * The basic parse is affected by the value of io.flags() &
2018 * ios_base::basefield. If equal to ios_base::oct, parses like the
2019 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X
2020 * specifier. Else if basefield equal to 0, parses like the %i
2021 * specifier. Otherwise, parses like %d for signed and %u for unsigned
2022 * types. The matching type length modifier is also used.
2024 * Digit grouping is interpreted according to numpunct::grouping() and
2025 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2026 * consistent, sets err to ios_base::failbit.
2028 * If parsing the string yields a valid value for @a v, @a v is set.
2029 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2030 * Sets err to ios_base::eofbit if the stream is emptied.
2032 * @param in Start of input stream.
2033 * @param end End of input stream.
2034 * @param io Source of locale and flags.
2035 * @param err Error flags to set.
2036 * @param v Value to format and insert.
2037 * @return Iterator after reading.
2039 iter_type
2040 get(iter_type __in, iter_type __end, ios_base& __io,
2041 ios_base::iostate& __err, long& __v) const
2042 { return this->do_get(__in, __end, __io, __err, __v); }
2044 iter_type
2045 get(iter_type __in, iter_type __end, ios_base& __io,
2046 ios_base::iostate& __err, unsigned short& __v) const
2047 { return this->do_get(__in, __end, __io, __err, __v); }
2049 iter_type
2050 get(iter_type __in, iter_type __end, ios_base& __io,
2051 ios_base::iostate& __err, unsigned int& __v) const
2052 { return this->do_get(__in, __end, __io, __err, __v); }
2054 iter_type
2055 get(iter_type __in, iter_type __end, ios_base& __io,
2056 ios_base::iostate& __err, unsigned long& __v) const
2057 { return this->do_get(__in, __end, __io, __err, __v); }
2059 #ifdef _GLIBCXX_USE_LONG_LONG
2060 iter_type
2061 get(iter_type __in, iter_type __end, ios_base& __io,
2062 ios_base::iostate& __err, long long& __v) const
2063 { return this->do_get(__in, __end, __io, __err, __v); }
2065 iter_type
2066 get(iter_type __in, iter_type __end, ios_base& __io,
2067 ios_base::iostate& __err, unsigned long long& __v) const
2068 { return this->do_get(__in, __end, __io, __err, __v); }
2069 #endif
2070 //@}
2072 //@{
2074 * @brief Numeric parsing.
2076 * Parses the input stream into the integral variable @a v. It does so
2077 * by calling num_get::do_get().
2079 * The input characters are parsed like the scanf %g specifier. The
2080 * matching type length modifier is also used.
2082 * The decimal point character used is numpunct::decimal_point().
2083 * Digit grouping is interpreted according to numpunct::grouping() and
2084 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2085 * consistent, sets err to ios_base::failbit.
2087 * If parsing the string yields a valid value for @a v, @a v is set.
2088 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2089 * Sets err to ios_base::eofbit if the stream is emptied.
2091 * @param in Start of input stream.
2092 * @param end End of input stream.
2093 * @param io Source of locale and flags.
2094 * @param err Error flags to set.
2095 * @param v Value to format and insert.
2096 * @return Iterator after reading.
2098 iter_type
2099 get(iter_type __in, iter_type __end, ios_base& __io,
2100 ios_base::iostate& __err, float& __v) const
2101 { return this->do_get(__in, __end, __io, __err, __v); }
2103 iter_type
2104 get(iter_type __in, iter_type __end, ios_base& __io,
2105 ios_base::iostate& __err, double& __v) const
2106 { return this->do_get(__in, __end, __io, __err, __v); }
2108 iter_type
2109 get(iter_type __in, iter_type __end, ios_base& __io,
2110 ios_base::iostate& __err, long double& __v) const
2111 { return this->do_get(__in, __end, __io, __err, __v); }
2112 //@}
2115 * @brief Numeric parsing.
2117 * Parses the input stream into the pointer variable @a v. It does so
2118 * by calling num_get::do_get().
2120 * The input characters are parsed like the scanf %p specifier.
2122 * Digit grouping is interpreted according to numpunct::grouping() and
2123 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2124 * consistent, sets err to ios_base::failbit.
2126 * Note that the digit grouping effect for pointers is a bit ambiguous
2127 * in the standard and shouldn't be relied on. See DR 344.
2129 * If parsing the string yields a valid value for @a v, @a v is set.
2130 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2131 * Sets err to ios_base::eofbit if the stream is emptied.
2133 * @param in Start of input stream.
2134 * @param end End of input stream.
2135 * @param io Source of locale and flags.
2136 * @param err Error flags to set.
2137 * @param v Value to format and insert.
2138 * @return Iterator after reading.
2140 iter_type
2141 get(iter_type __in, iter_type __end, ios_base& __io,
2142 ios_base::iostate& __err, void*& __v) const
2143 { return this->do_get(__in, __end, __io, __err, __v); }
2145 protected:
2146 /// Destructor.
2147 virtual ~num_get() { }
2149 iter_type
2150 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
2151 string& __xtrc) const;
2153 template<typename _ValueT>
2154 iter_type
2155 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
2156 _ValueT& __v) const;
2158 template<typename _CharT2>
2159 typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, int>::__type
2160 _M_find(const _CharT2*, size_t __len, _CharT2 __c) const
2162 int __ret = -1;
2163 if (__len <= 10)
2165 if (__c >= _CharT2('0') && __c < _CharT2(_CharT2('0') + __len))
2166 __ret = __c - _CharT2('0');
2168 else
2170 if (__c >= _CharT2('0') && __c <= _CharT2('9'))
2171 __ret = __c - _CharT2('0');
2172 else if (__c >= _CharT2('a') && __c <= _CharT2('f'))
2173 __ret = 10 + (__c - _CharT2('a'));
2174 else if (__c >= _CharT2('A') && __c <= _CharT2('F'))
2175 __ret = 10 + (__c - _CharT2('A'));
2177 return __ret;
2180 template<typename _CharT2>
2181 typename __gnu_cxx::__enable_if<!__is_char<_CharT2>::__value,
2182 int>::__type
2183 _M_find(const _CharT2* __zero, size_t __len, _CharT2 __c) const
2185 int __ret = -1;
2186 const char_type* __q = char_traits<_CharT2>::find(__zero, __len, __c);
2187 if (__q)
2189 __ret = __q - __zero;
2190 if (__ret > 15)
2191 __ret -= 6;
2193 return __ret;
2196 //@{
2198 * @brief Numeric parsing.
2200 * Parses the input stream into the variable @a v. This function is a
2201 * hook for derived classes to change the value returned. @see get()
2202 * for more details.
2204 * @param in Start of input stream.
2205 * @param end End of input stream.
2206 * @param io Source of locale and flags.
2207 * @param err Error flags to set.
2208 * @param v Value to format and insert.
2209 * @return Iterator after reading.
2211 virtual iter_type
2212 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
2215 virtual iter_type
2216 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
2218 virtual iter_type
2219 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2220 unsigned short&) const;
2222 virtual iter_type
2223 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2224 unsigned int&) const;
2226 virtual iter_type
2227 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2228 unsigned long&) const;
2230 #ifdef _GLIBCXX_USE_LONG_LONG
2231 virtual iter_type
2232 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2233 long long&) const;
2235 virtual iter_type
2236 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2237 unsigned long long&) const;
2238 #endif
2240 virtual iter_type
2241 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2242 float&) const;
2244 virtual iter_type
2245 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2246 double&) const;
2248 // XXX GLIBCXX_ABI Deprecated
2249 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2250 virtual iter_type
2251 __do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2252 double&) const;
2253 #else
2254 virtual iter_type
2255 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2256 long double&) const;
2257 #endif
2259 virtual iter_type
2260 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2261 void*&) const;
2263 // XXX GLIBCXX_ABI Deprecated
2264 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2265 virtual iter_type
2266 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2267 long double&) const;
2268 #endif
2269 //@}
2272 template<typename _CharT, typename _InIter>
2273 locale::id num_get<_CharT, _InIter>::id;
2277 * @brief Facet for converting numbers to strings.
2279 * This facet encapsulates the code to convert a number to a string. It is
2280 * used by the ostream numeric insertion operators.
2282 * The num_put template uses protected virtual functions to provide the
2283 * actual results. The public accessors forward the call to the virtual
2284 * functions. These virtual functions are hooks for developers to
2285 * implement the behavior they require from the num_put facet.
2287 template<typename _CharT, typename _OutIter>
2288 class num_put : public locale::facet
2290 public:
2291 // Types:
2292 //@{
2293 /// Public typedefs
2294 typedef _CharT char_type;
2295 typedef _OutIter iter_type;
2296 //@}
2298 /// Numpunct facet id.
2299 static locale::id id;
2302 * @brief Constructor performs initialization.
2304 * This is the constructor provided by the standard.
2306 * @param refs Passed to the base facet class.
2308 explicit
2309 num_put(size_t __refs = 0) : facet(__refs) { }
2312 * @brief Numeric formatting.
2314 * Formats the boolean @a v and inserts it into a stream. It does so
2315 * by calling num_put::do_put().
2317 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2318 * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
2320 * @param s Stream to write to.
2321 * @param io Source of locale and flags.
2322 * @param fill Char_type to use for filling.
2323 * @param v Value to format and insert.
2324 * @return Iterator after writing.
2326 iter_type
2327 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
2328 { return this->do_put(__s, __f, __fill, __v); }
2330 //@{
2332 * @brief Numeric formatting.
2334 * Formats the integral value @a v and inserts it into a
2335 * stream. It does so by calling num_put::do_put().
2337 * Formatting is affected by the flag settings in @a io.
2339 * The basic format is affected by the value of io.flags() &
2340 * ios_base::basefield. If equal to ios_base::oct, formats like the
2341 * printf %o specifier. Else if equal to ios_base::hex, formats like
2342 * %x or %X with ios_base::uppercase unset or set respectively.
2343 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2344 * for unsigned values. Note that if both oct and hex are set, neither
2345 * will take effect.
2347 * If ios_base::showpos is set, '+' is output before positive values.
2348 * If ios_base::showbase is set, '0' precedes octal values (except 0)
2349 * and '0[xX]' precedes hex values.
2351 * Thousands separators are inserted according to numpunct::grouping()
2352 * and numpunct::thousands_sep(). The decimal point character used is
2353 * numpunct::decimal_point().
2355 * If io.width() is non-zero, enough @a fill characters are inserted to
2356 * make the result at least that wide. If
2357 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2358 * padded at the end. If ios_base::internal, then padding occurs
2359 * immediately after either a '+' or '-' or after '0x' or '0X'.
2360 * Otherwise, padding occurs at the beginning.
2362 * @param s Stream to write to.
2363 * @param io Source of locale and flags.
2364 * @param fill Char_type to use for filling.
2365 * @param v Value to format and insert.
2366 * @return Iterator after writing.
2368 iter_type
2369 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
2370 { return this->do_put(__s, __f, __fill, __v); }
2372 iter_type
2373 put(iter_type __s, ios_base& __f, char_type __fill,
2374 unsigned long __v) const
2375 { return this->do_put(__s, __f, __fill, __v); }
2377 #ifdef _GLIBCXX_USE_LONG_LONG
2378 iter_type
2379 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
2380 { return this->do_put(__s, __f, __fill, __v); }
2382 iter_type
2383 put(iter_type __s, ios_base& __f, char_type __fill,
2384 unsigned long long __v) const
2385 { return this->do_put(__s, __f, __fill, __v); }
2386 #endif
2387 //@}
2389 //@{
2391 * @brief Numeric formatting.
2393 * Formats the floating point value @a v and inserts it into a stream.
2394 * It does so by calling num_put::do_put().
2396 * Formatting is affected by the flag settings in @a io.
2398 * The basic format is affected by the value of io.flags() &
2399 * ios_base::floatfield. If equal to ios_base::fixed, formats like the
2400 * printf %f specifier. Else if equal to ios_base::scientific, formats
2401 * like %e or %E with ios_base::uppercase unset or set respectively.
2402 * Otherwise, formats like %g or %G depending on uppercase. Note that
2403 * if both fixed and scientific are set, the effect will also be like
2404 * %g or %G.
2406 * The output precision is given by io.precision(). This precision is
2407 * capped at numeric_limits::digits10 + 2 (different for double and
2408 * long double). The default precision is 6.
2410 * If ios_base::showpos is set, '+' is output before positive values.
2411 * If ios_base::showpoint is set, a decimal point will always be
2412 * output.
2414 * Thousands separators are inserted according to numpunct::grouping()
2415 * and numpunct::thousands_sep(). The decimal point character used is
2416 * numpunct::decimal_point().
2418 * If io.width() is non-zero, enough @a fill characters are inserted to
2419 * make the result at least that wide. If
2420 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2421 * padded at the end. If ios_base::internal, then padding occurs
2422 * immediately after either a '+' or '-' or after '0x' or '0X'.
2423 * Otherwise, padding occurs at the beginning.
2425 * @param s Stream to write to.
2426 * @param io Source of locale and flags.
2427 * @param fill Char_type to use for filling.
2428 * @param v Value to format and insert.
2429 * @return Iterator after writing.
2431 iter_type
2432 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
2433 { return this->do_put(__s, __f, __fill, __v); }
2435 iter_type
2436 put(iter_type __s, ios_base& __f, char_type __fill,
2437 long double __v) const
2438 { return this->do_put(__s, __f, __fill, __v); }
2439 //@}
2442 * @brief Numeric formatting.
2444 * Formats the pointer value @a v and inserts it into a stream. It
2445 * does so by calling num_put::do_put().
2447 * This function formats @a v as an unsigned long with ios_base::hex
2448 * and ios_base::showbase set.
2450 * @param s Stream to write to.
2451 * @param io Source of locale and flags.
2452 * @param fill Char_type to use for filling.
2453 * @param v Value to format and insert.
2454 * @return Iterator after writing.
2456 iter_type
2457 put(iter_type __s, ios_base& __f, char_type __fill,
2458 const void* __v) const
2459 { return this->do_put(__s, __f, __fill, __v); }
2461 protected:
2462 template<typename _ValueT>
2463 iter_type
2464 _M_insert_float(iter_type, ios_base& __io, char_type __fill,
2465 char __mod, _ValueT __v) const;
2467 void
2468 _M_group_float(const char* __grouping, size_t __grouping_size,
2469 char_type __sep, const char_type* __p, char_type* __new,
2470 char_type* __cs, int& __len) const;
2472 template<typename _ValueT>
2473 iter_type
2474 _M_insert_int(iter_type, ios_base& __io, char_type __fill,
2475 _ValueT __v) const;
2477 void
2478 _M_group_int(const char* __grouping, size_t __grouping_size,
2479 char_type __sep, ios_base& __io, char_type* __new,
2480 char_type* __cs, int& __len) const;
2482 void
2483 _M_pad(char_type __fill, streamsize __w, ios_base& __io,
2484 char_type* __new, const char_type* __cs, int& __len) const;
2486 /// Destructor.
2487 virtual
2488 ~num_put() { };
2490 //@{
2492 * @brief Numeric formatting.
2494 * These functions do the work of formatting numeric values and
2495 * inserting them into a stream. This function is a hook for derived
2496 * classes to change the value returned.
2498 * @param s Stream to write to.
2499 * @param io Source of locale and flags.
2500 * @param fill Char_type to use for filling.
2501 * @param v Value to format and insert.
2502 * @return Iterator after writing.
2504 virtual iter_type
2505 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
2507 virtual iter_type
2508 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
2510 virtual iter_type
2511 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
2513 #ifdef _GLIBCXX_USE_LONG_LONG
2514 virtual iter_type
2515 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
2517 virtual iter_type
2518 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
2519 #endif
2521 virtual iter_type
2522 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2524 // XXX GLIBCXX_ABI Deprecated
2525 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2526 virtual iter_type
2527 __do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2528 #else
2529 virtual iter_type
2530 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2531 #endif
2533 virtual iter_type
2534 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
2536 // XXX GLIBCXX_ABI Deprecated
2537 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2538 virtual iter_type
2539 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2540 #endif
2541 //@}
2544 template <typename _CharT, typename _OutIter>
2545 locale::id num_put<_CharT, _OutIter>::id;
2547 _GLIBCXX_END_LDBL_NAMESPACE
2549 // Subclause convenience interfaces, inlines.
2550 // NB: These are inline because, when used in a loop, some compilers
2551 // can hoist the body out of the loop; then it's just as fast as the
2552 // C is*() function.
2554 /// Convenience interface to ctype.is(ctype_base::space, __c).
2555 template<typename _CharT>
2556 inline bool
2557 isspace(_CharT __c, const locale& __loc)
2558 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
2560 /// Convenience interface to ctype.is(ctype_base::print, __c).
2561 template<typename _CharT>
2562 inline bool
2563 isprint(_CharT __c, const locale& __loc)
2564 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
2566 /// Convenience interface to ctype.is(ctype_base::cntrl, __c).
2567 template<typename _CharT>
2568 inline bool
2569 iscntrl(_CharT __c, const locale& __loc)
2570 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
2572 /// Convenience interface to ctype.is(ctype_base::upper, __c).
2573 template<typename _CharT>
2574 inline bool
2575 isupper(_CharT __c, const locale& __loc)
2576 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
2578 /// Convenience interface to ctype.is(ctype_base::lower, __c).
2579 template<typename _CharT>
2580 inline bool
2581 islower(_CharT __c, const locale& __loc)
2582 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
2584 /// Convenience interface to ctype.is(ctype_base::alpha, __c).
2585 template<typename _CharT>
2586 inline bool
2587 isalpha(_CharT __c, const locale& __loc)
2588 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
2590 /// Convenience interface to ctype.is(ctype_base::digit, __c).
2591 template<typename _CharT>
2592 inline bool
2593 isdigit(_CharT __c, const locale& __loc)
2594 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
2596 /// Convenience interface to ctype.is(ctype_base::punct, __c).
2597 template<typename _CharT>
2598 inline bool
2599 ispunct(_CharT __c, const locale& __loc)
2600 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
2602 /// Convenience interface to ctype.is(ctype_base::xdigit, __c).
2603 template<typename _CharT>
2604 inline bool
2605 isxdigit(_CharT __c, const locale& __loc)
2606 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
2608 /// Convenience interface to ctype.is(ctype_base::alnum, __c).
2609 template<typename _CharT>
2610 inline bool
2611 isalnum(_CharT __c, const locale& __loc)
2612 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
2614 /// Convenience interface to ctype.is(ctype_base::graph, __c).
2615 template<typename _CharT>
2616 inline bool
2617 isgraph(_CharT __c, const locale& __loc)
2618 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
2620 /// Convenience interface to ctype.toupper(__c).
2621 template<typename _CharT>
2622 inline _CharT
2623 toupper(_CharT __c, const locale& __loc)
2624 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
2626 /// Convenience interface to ctype.tolower(__c).
2627 template<typename _CharT>
2628 inline _CharT
2629 tolower(_CharT __c, const locale& __loc)
2630 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
2632 _GLIBCXX_END_NAMESPACE
2634 #ifndef _GLIBCXX_EXPORT_TEMPLATE
2635 # include <bits/locale_facets.tcc>
2636 #endif
2638 #endif