1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file bits/locale_facets.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{locale}
31 // ISO C++ 14882: 22.1 Locales
34 #ifndef _LOCALE_FACETS_H
35 #define _LOCALE_FACETS_H 1
37 #pragma GCC system_header
39 #include <cwctype> // For wctype_t
41 #include <bits/ctype_base.h>
43 #include <bits/ios_base.h> // For ios_base, ios_base::iostate
45 #include <bits/cpp_type_traits.h>
46 #include <ext/type_traits.h>
47 #include <ext/numeric_traits.h>
48 #include <bits/streambuf_iterator.h>
50 namespace std
_GLIBCXX_VISIBILITY(default)
52 _GLIBCXX_BEGIN_NAMESPACE_VERSION
54 // Number of standard facets (for narrow characters only)
55 #define _GLIBCXX_NUM_FACETS 14
57 // Number of duplicated facets for cxx11 ABI
58 #define _GLIBCXX_NUM_CXX11_FACETS (_GLIBCXX_USE_DUAL_ABI ? 8 : 0)
60 // codecvt<char16_t> and codecvt<char32_t>
61 #ifdef _GLIBCXX_USE_CHAR8_T
62 # define _GLIBCXX_NUM_UNICODE_FACETS 4
64 # define _GLIBCXX_NUM_UNICODE_FACETS 2
67 // Facets duplicated for alt128 long double format
68 // num_get, num_put, money_get, money_put (+ cxx11 money_get, money_put)
69 #define _GLIBCXX_NUM_LBDL_ALT128_FACETS (4 + (_GLIBCXX_USE_DUAL_ABI ? 2 : 0))
71 // Convert string to numeric value of type _Tp and store results.
72 // NB: This is specialized for all required types, there is no
73 // generic definition.
74 template<typename _Tp
>
76 __convert_to_v(const char*, _Tp
&, ios_base::iostate
&,
77 const __c_locale
&) throw();
79 // Explicit specializations for required types.
82 __convert_to_v(const char*, float&, ios_base::iostate
&,
83 const __c_locale
&) throw();
87 __convert_to_v(const char*, double&, ios_base::iostate
&,
88 const __c_locale
&) throw();
92 __convert_to_v(const char*, long double&, ios_base::iostate
&,
93 const __c_locale
&) throw();
95 // NB: __pad is a struct, rather than a function, so it can be
96 // partially-specialized.
97 template<typename _CharT
, typename _Traits
>
101 _S_pad(ios_base
& __io
, _CharT __fill
, _CharT
* __news
,
102 const _CharT
* __olds
, streamsize __newlen
, streamsize __oldlen
);
105 // Used by both numeric and monetary facets.
106 // Inserts "group separator" characters into an array of characters.
107 // It's recursive, one iteration per group. It moves the characters
108 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
109 // only with __gsize != 0.
110 template<typename _CharT
>
112 __add_grouping(_CharT
* __s
, _CharT __sep
,
113 const char* __gbeg
, size_t __gsize
,
114 const _CharT
* __first
, const _CharT
* __last
);
116 // This template permits specializing facet output code for
117 // ostreambuf_iterator. For ostreambuf_iterator, sputn is
118 // significantly more efficient than incrementing iterators.
119 template<typename _CharT
>
121 ostreambuf_iterator
<_CharT
>
122 __write(ostreambuf_iterator
<_CharT
> __s
, const _CharT
* __ws
, int __len
)
124 __s
._M_put(__ws
, __len
);
128 // This is the unspecialized form of the template.
129 template<typename _CharT
, typename _OutIter
>
132 __write(_OutIter __s
, const _CharT
* __ws
, int __len
)
134 for (int __j
= 0; __j
< __len
; __j
++, ++__s
)
140 // 22.2.1.1 Template class ctype
141 // Include host and configuration specific ctype enums for ctype_base.
144 * @brief Common base for ctype facet
146 * This template class provides implementations of the public functions
147 * that forward to the protected virtual functions.
149 * This template also provides abstract stubs for the protected virtual
152 template<typename _CharT
>
153 class __ctype_abstract_base
: public locale::facet
, public ctype_base
157 /// Typedef for the template parameter
158 typedef _CharT char_type
;
161 * @brief Test char_type classification.
163 * This function finds a mask M for @a __c and compares it to
164 * mask @a __m. It does so by returning the value of
165 * ctype<char_type>::do_is().
167 * @param __c The char_type to compare the mask of.
168 * @param __m The mask to compare against.
169 * @return (M & __m) != 0.
172 is(mask __m
, char_type __c
) const
173 { return this->do_is(__m
, __c
); }
176 * @brief Return a mask array.
178 * This function finds the mask for each char_type in the range [lo,hi)
179 * and successively writes it to vec. vec must have as many elements
180 * as the char array. It does so by returning the value of
181 * ctype<char_type>::do_is().
183 * @param __lo Pointer to start of range.
184 * @param __hi Pointer to end of range.
185 * @param __vec Pointer to an array of mask storage.
189 is(const char_type
*__lo
, const char_type
*__hi
, mask
*__vec
) const
190 { return this->do_is(__lo
, __hi
, __vec
); }
193 * @brief Find char_type matching a mask
195 * This function searches for and returns the first char_type c in
196 * [lo,hi) for which is(m,c) is true. It does so by returning
197 * ctype<char_type>::do_scan_is().
199 * @param __m The mask to compare against.
200 * @param __lo Pointer to start of range.
201 * @param __hi Pointer to end of range.
202 * @return Pointer to matching char_type if found, else @a __hi.
205 scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
206 { return this->do_scan_is(__m
, __lo
, __hi
); }
209 * @brief Find char_type not matching a mask
211 * This function searches for and returns the first char_type c in
212 * [lo,hi) for which is(m,c) is false. It does so by returning
213 * ctype<char_type>::do_scan_not().
215 * @param __m The mask to compare against.
216 * @param __lo Pointer to first char in range.
217 * @param __hi Pointer to end of range.
218 * @return Pointer to non-matching char if found, else @a __hi.
221 scan_not(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
222 { return this->do_scan_not(__m
, __lo
, __hi
); }
225 * @brief Convert to uppercase.
227 * This function converts the argument to uppercase if possible.
228 * If not possible (for example, '2'), returns the argument. It does
229 * so by returning ctype<char_type>::do_toupper().
231 * @param __c The char_type to convert.
232 * @return The uppercase char_type if convertible, else @a __c.
235 toupper(char_type __c
) const
236 { return this->do_toupper(__c
); }
239 * @brief Convert array to uppercase.
241 * This function converts each char_type in the range [lo,hi) to
242 * uppercase if possible. Other elements remain untouched. It does so
243 * by returning ctype<char_type>:: do_toupper(lo, hi).
245 * @param __lo Pointer to start of range.
246 * @param __hi Pointer to end of range.
250 toupper(char_type
*__lo
, const char_type
* __hi
) const
251 { return this->do_toupper(__lo
, __hi
); }
254 * @brief Convert to lowercase.
256 * This function converts the argument to lowercase if possible. If
257 * not possible (for example, '2'), returns the argument. It does so
258 * by returning ctype<char_type>::do_tolower(c).
260 * @param __c The char_type to convert.
261 * @return The lowercase char_type if convertible, else @a __c.
264 tolower(char_type __c
) const
265 { return this->do_tolower(__c
); }
268 * @brief Convert array to lowercase.
270 * This function converts each char_type in the range [__lo,__hi) to
271 * lowercase if possible. Other elements remain untouched. It does so
272 * by returning ctype<char_type>:: do_tolower(__lo, __hi).
274 * @param __lo Pointer to start of range.
275 * @param __hi Pointer to end of range.
279 tolower(char_type
* __lo
, const char_type
* __hi
) const
280 { return this->do_tolower(__lo
, __hi
); }
283 * @brief Widen char to char_type
285 * This function converts the char argument to char_type using the
286 * simplest reasonable transformation. It does so by returning
287 * ctype<char_type>::do_widen(c).
289 * Note: this is not what you want for codepage conversions. See
292 * @param __c The char to convert.
293 * @return The converted char_type.
296 widen(char __c
) const
297 { return this->do_widen(__c
); }
300 * @brief Widen array to char_type
302 * This function converts each char in the input to char_type using the
303 * simplest reasonable transformation. It does so by returning
304 * ctype<char_type>::do_widen(c).
306 * Note: this is not what you want for codepage conversions. See
309 * @param __lo Pointer to start of range.
310 * @param __hi Pointer to end of range.
311 * @param __to Pointer to the destination array.
315 widen(const char* __lo
, const char* __hi
, char_type
* __to
) const
316 { return this->do_widen(__lo
, __hi
, __to
); }
319 * @brief Narrow char_type to char
321 * This function converts the char_type to char using the simplest
322 * reasonable transformation. If the conversion fails, dfault is
323 * returned instead. It does so by returning
324 * ctype<char_type>::do_narrow(__c).
326 * Note: this is not what you want for codepage conversions. See
329 * @param __c The char_type to convert.
330 * @param __dfault Char to return if conversion fails.
331 * @return The converted char.
334 narrow(char_type __c
, char __dfault
) const
335 { return this->do_narrow(__c
, __dfault
); }
338 * @brief Narrow array to char array
340 * This function converts each char_type in the input to char using the
341 * simplest reasonable transformation and writes the results to the
342 * destination array. For any char_type in the input that cannot be
343 * converted, @a dfault is used instead. It does so by returning
344 * ctype<char_type>::do_narrow(__lo, __hi, __dfault, __to).
346 * Note: this is not what you want for codepage conversions. See
349 * @param __lo Pointer to start of range.
350 * @param __hi Pointer to end of range.
351 * @param __dfault Char to use if conversion fails.
352 * @param __to Pointer to the destination array.
356 narrow(const char_type
* __lo
, const char_type
* __hi
,
357 char __dfault
, char* __to
) const
358 { return this->do_narrow(__lo
, __hi
, __dfault
, __to
); }
362 __ctype_abstract_base(size_t __refs
= 0): facet(__refs
) { }
365 ~__ctype_abstract_base() { }
368 * @brief Test char_type classification.
370 * This function finds a mask M for @a c and compares it to mask @a m.
372 * do_is() is a hook for a derived facet to change the behavior of
373 * classifying. do_is() must always return the same result for the
376 * @param __c The char_type to find the mask of.
377 * @param __m The mask to compare against.
378 * @return (M & __m) != 0.
381 do_is(mask __m
, char_type __c
) const = 0;
384 * @brief Return a mask array.
386 * This function finds the mask for each char_type in the range [lo,hi)
387 * and successively writes it to vec. vec must have as many elements
390 * do_is() is a hook for a derived facet to change the behavior of
391 * classifying. do_is() must always return the same result for the
394 * @param __lo Pointer to start of range.
395 * @param __hi Pointer to end of range.
396 * @param __vec Pointer to an array of mask storage.
399 virtual const char_type
*
400 do_is(const char_type
* __lo
, const char_type
* __hi
,
401 mask
* __vec
) const = 0;
404 * @brief Find char_type matching mask
406 * This function searches for and returns the first char_type c in
407 * [__lo,__hi) for which is(__m,c) is true.
409 * do_scan_is() is a hook for a derived facet to change the behavior of
410 * match searching. do_is() must always return the same result for the
413 * @param __m The mask to compare against.
414 * @param __lo Pointer to start of range.
415 * @param __hi Pointer to end of range.
416 * @return Pointer to a matching char_type if found, else @a __hi.
418 virtual const char_type
*
419 do_scan_is(mask __m
, const char_type
* __lo
,
420 const char_type
* __hi
) const = 0;
423 * @brief Find char_type not matching mask
425 * This function searches for and returns a pointer to the first
426 * char_type c of [lo,hi) for which is(m,c) is false.
428 * do_scan_is() is a hook for a derived facet to change the behavior of
429 * match searching. do_is() must always return the same result for the
432 * @param __m The mask to compare against.
433 * @param __lo Pointer to start of range.
434 * @param __hi Pointer to end of range.
435 * @return Pointer to a non-matching char_type if found, else @a __hi.
437 virtual const char_type
*
438 do_scan_not(mask __m
, const char_type
* __lo
,
439 const char_type
* __hi
) const = 0;
442 * @brief Convert to uppercase.
444 * This virtual function converts the char_type argument to uppercase
445 * if possible. If not possible (for example, '2'), returns the
448 * do_toupper() is a hook for a derived facet to change the behavior of
449 * uppercasing. do_toupper() must always return the same result for
452 * @param __c The char_type to convert.
453 * @return The uppercase char_type if convertible, else @a __c.
456 do_toupper(char_type __c
) const = 0;
459 * @brief Convert array to uppercase.
461 * This virtual function converts each char_type in the range [__lo,__hi)
462 * to uppercase if possible. Other elements remain untouched.
464 * do_toupper() is a hook for a derived facet to change the behavior of
465 * uppercasing. do_toupper() must always return the same result for
468 * @param __lo Pointer to start of range.
469 * @param __hi Pointer to end of range.
472 virtual const char_type
*
473 do_toupper(char_type
* __lo
, const char_type
* __hi
) const = 0;
476 * @brief Convert to lowercase.
478 * This virtual function converts the argument to lowercase if
479 * possible. If not possible (for example, '2'), returns the argument.
481 * do_tolower() is a hook for a derived facet to change the behavior of
482 * lowercasing. do_tolower() must always return the same result for
485 * @param __c The char_type to convert.
486 * @return The lowercase char_type if convertible, else @a __c.
489 do_tolower(char_type __c
) const = 0;
492 * @brief Convert array to lowercase.
494 * This virtual function converts each char_type in the range [__lo,__hi)
495 * to lowercase if possible. Other elements remain untouched.
497 * do_tolower() is a hook for a derived facet to change the behavior of
498 * lowercasing. do_tolower() must always return the same result for
501 * @param __lo Pointer to start of range.
502 * @param __hi Pointer to end of range.
505 virtual const char_type
*
506 do_tolower(char_type
* __lo
, const char_type
* __hi
) const = 0;
511 * This virtual function converts the char to char_type using the
512 * simplest reasonable transformation.
514 * do_widen() is a hook for a derived facet to change the behavior of
515 * widening. do_widen() must always return the same result for the
518 * Note: this is not what you want for codepage conversions. See
521 * @param __c The char to convert.
522 * @return The converted char_type
525 do_widen(char __c
) const = 0;
528 * @brief Widen char array
530 * This function converts each char in the input to char_type using the
531 * simplest reasonable transformation.
533 * do_widen() is a hook for a derived facet to change the behavior of
534 * widening. do_widen() must always return the same result for the
537 * Note: this is not what you want for codepage conversions. See
540 * @param __lo Pointer to start range.
541 * @param __hi Pointer to end of range.
542 * @param __to Pointer to the destination array.
546 do_widen(const char* __lo
, const char* __hi
, char_type
* __to
) const = 0;
549 * @brief Narrow char_type to char
551 * This virtual function converts the argument to char using the
552 * simplest reasonable transformation. If the conversion fails, dfault
553 * is returned instead.
555 * do_narrow() is a hook for a derived facet to change the behavior of
556 * narrowing. do_narrow() must always return the same result for the
559 * Note: this is not what you want for codepage conversions. See
562 * @param __c The char_type to convert.
563 * @param __dfault Char to return if conversion fails.
564 * @return The converted char.
567 do_narrow(char_type __c
, char __dfault
) const = 0;
570 * @brief Narrow char_type array to char
572 * This virtual function converts each char_type in the range
573 * [__lo,__hi) to char using the simplest reasonable
574 * transformation and writes the results to the destination
575 * array. For any element in the input that cannot be
576 * converted, @a __dfault is used instead.
578 * do_narrow() is a hook for a derived facet to change the behavior of
579 * narrowing. do_narrow() must always return the same result for the
582 * Note: this is not what you want for codepage conversions. See
585 * @param __lo Pointer to start of range.
586 * @param __hi Pointer to end of range.
587 * @param __dfault Char to use if conversion fails.
588 * @param __to Pointer to the destination array.
591 virtual const char_type
*
592 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
593 char __dfault
, char* __to
) const = 0;
597 * @brief Primary class template ctype facet.
600 * This template class defines classification and conversion functions for
601 * character sets. It wraps cctype functionality. Ctype gets used by
602 * streams for many I/O operations.
604 * This template provides the protected virtual functions the developer
605 * will have to replace in a derived class or specialization to make a
606 * working facet. The public functions that access them are defined in
607 * __ctype_abstract_base, to allow for implementation flexibility. See
608 * ctype<wchar_t> for an example. The functions are documented in
609 * __ctype_abstract_base.
611 * Note: implementations are provided for all the protected virtual
612 * functions, but will likely not be useful.
614 template<typename _CharT
>
615 class ctype
: public __ctype_abstract_base
<_CharT
>
619 typedef _CharT char_type
;
620 typedef typename __ctype_abstract_base
<_CharT
>::mask mask
;
622 /// The facet id for ctype<char_type>
623 static locale::id id
;
626 ctype(size_t __refs
= 0) : __ctype_abstract_base
<_CharT
>(__refs
) { }
633 do_is(mask __m
, char_type __c
) const;
635 virtual const char_type
*
636 do_is(const char_type
* __lo
, const char_type
* __hi
, mask
* __vec
) const;
638 virtual const char_type
*
639 do_scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const;
641 virtual const char_type
*
642 do_scan_not(mask __m
, const char_type
* __lo
,
643 const char_type
* __hi
) const;
646 do_toupper(char_type __c
) const;
648 virtual const char_type
*
649 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
652 do_tolower(char_type __c
) const;
654 virtual const char_type
*
655 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
658 do_widen(char __c
) const;
661 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const;
664 do_narrow(char_type
, char __dfault
) const;
666 virtual const char_type
*
667 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
668 char __dfault
, char* __to
) const;
671 template<typename _CharT
>
672 locale::id ctype
<_CharT
>::id
;
674 // Incomplete to provide a compile time diagnostics for common misuse
675 // of [locale.convenience] functions with basic_string as a character type.
676 template<typename _CharT
, typename _Traits
, typename _Alloc
>
677 class ctype
<basic_string
<_CharT
, _Traits
, _Alloc
> >;
680 * @brief The ctype<char> specialization.
683 * This class defines classification and conversion functions for
684 * the char type. It gets used by char streams for many I/O
685 * operations. The char specialization provides a number of
686 * optimizations as well.
689 class ctype
<char> : public locale::facet
, public ctype_base
693 /// Typedef for the template parameter char.
694 typedef char char_type
;
698 __c_locale _M_c_locale_ctype
;
700 __to_type _M_toupper
;
701 __to_type _M_tolower
;
702 const mask
* _M_table
;
703 mutable char _M_widen_ok
;
704 mutable char _M_widen
[1 + static_cast<unsigned char>(-1)];
705 mutable char _M_narrow
[1 + static_cast<unsigned char>(-1)];
706 mutable char _M_narrow_ok
; // 0 uninitialized, 1 init,
707 // 2 memcpy can't be used
710 /// The facet id for ctype<char>
711 static locale::id id
;
712 /// The size of the mask table. It is SCHAR_MAX + 1.
713 static const size_t table_size
= 1 + static_cast<unsigned char>(-1);
716 * @brief Constructor performs initialization.
718 * This is the constructor provided by the standard.
720 * @param __table If non-zero, table is used as the per-char mask.
721 * Else classic_table() is used.
722 * @param __del If true, passes ownership of table to this facet.
723 * @param __refs Passed to the base facet class.
726 ctype(const mask
* __table
= 0, bool __del
= false, size_t __refs
= 0);
729 * @brief Constructor performs static initialization.
731 * This constructor is used to construct the initial C locale facet.
733 * @param __cloc Handle to C locale data.
734 * @param __table If non-zero, table is used as the per-char mask.
735 * @param __del If true, passes ownership of table to this facet.
736 * @param __refs Passed to the base facet class.
739 ctype(__c_locale __cloc
, const mask
* __table
= 0, bool __del
= false,
743 * @brief Test char classification.
745 * This function compares the mask table[c] to @a __m.
747 * @param __c The char to compare the mask of.
748 * @param __m The mask to compare against.
749 * @return True if __m & table[__c] is true, false otherwise.
752 is(mask __m
, char __c
) const;
755 * @brief Return a mask array.
757 * This function finds the mask for each char in the range [lo, hi) and
758 * successively writes it to vec. vec must have as many elements as
761 * @param __lo Pointer to start of range.
762 * @param __hi Pointer to end of range.
763 * @param __vec Pointer to an array of mask storage.
767 is(const char* __lo
, const char* __hi
, mask
* __vec
) const;
770 * @brief Find char matching a mask
772 * This function searches for and returns the first char in [lo,hi) for
773 * which is(m,char) is true.
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 matching char if found, else @a __hi.
781 scan_is(mask __m
, const char* __lo
, const char* __hi
) const;
784 * @brief Find char not matching a mask
786 * This function searches for and returns a pointer to the first char
787 * in [__lo,__hi) for which is(m,char) is false.
789 * @param __m The mask to compare against.
790 * @param __lo Pointer to start of range.
791 * @param __hi Pointer to end of range.
792 * @return Pointer to a non-matching char if found, else @a __hi.
795 scan_not(mask __m
, const char* __lo
, const char* __hi
) const;
798 * @brief Convert to uppercase.
800 * This function converts the char argument to uppercase if possible.
801 * If not possible (for example, '2'), returns the argument.
803 * toupper() acts as if it returns ctype<char>::do_toupper(c).
804 * do_toupper() must always return the same result for the same input.
806 * @param __c The char to convert.
807 * @return The uppercase char if convertible, else @a __c.
810 toupper(char_type __c
) const
811 { return this->do_toupper(__c
); }
814 * @brief Convert array to uppercase.
816 * This function converts each char in the range [__lo,__hi) to uppercase
817 * if possible. Other chars remain untouched.
819 * toupper() acts as if it returns ctype<char>:: do_toupper(__lo, __hi).
820 * do_toupper() must always return the same result for the same input.
822 * @param __lo Pointer to first char in range.
823 * @param __hi Pointer to end of range.
827 toupper(char_type
*__lo
, const char_type
* __hi
) const
828 { return this->do_toupper(__lo
, __hi
); }
831 * @brief Convert to lowercase.
833 * This function converts the char argument to lowercase if possible.
834 * If not possible (for example, '2'), returns the argument.
836 * tolower() acts as if it returns ctype<char>::do_tolower(__c).
837 * do_tolower() must always return the same result for the same input.
839 * @param __c The char to convert.
840 * @return The lowercase char if convertible, else @a __c.
843 tolower(char_type __c
) const
844 { return this->do_tolower(__c
); }
847 * @brief Convert array to lowercase.
849 * This function converts each char in the range [lo,hi) to lowercase
850 * if possible. Other chars remain untouched.
852 * tolower() acts as if it returns ctype<char>:: do_tolower(__lo, __hi).
853 * do_tolower() must always return the same result for the same input.
855 * @param __lo Pointer to first char in range.
856 * @param __hi Pointer to end of range.
860 tolower(char_type
* __lo
, const char_type
* __hi
) const
861 { return this->do_tolower(__lo
, __hi
); }
866 * This function converts the char to char_type using the simplest
867 * reasonable transformation. For an underived ctype<char> facet, the
868 * argument will be returned unchanged.
870 * This function works as if it returns ctype<char>::do_widen(c).
871 * do_widen() must always return the same result for the same input.
873 * Note: this is not what you want for codepage conversions. See
876 * @param __c The char to convert.
877 * @return The converted character.
880 widen(char __c
) const
883 return _M_widen
[static_cast<unsigned char>(__c
)];
884 this->_M_widen_init();
885 return this->do_widen(__c
);
889 * @brief Widen char array
891 * This function converts each char in the input to char using the
892 * simplest reasonable transformation. For an underived ctype<char>
893 * facet, the argument will be copied unchanged.
895 * This function works as if it returns ctype<char>::do_widen(c).
896 * do_widen() must always return the same result for the same input.
898 * Note: this is not what you want for codepage conversions. See
901 * @param __lo Pointer to first char in range.
902 * @param __hi Pointer to end of range.
903 * @param __to Pointer to the destination array.
907 widen(const char* __lo
, const char* __hi
, char_type
* __to
) const
909 if (_M_widen_ok
== 1)
911 if (__builtin_expect(__hi
!= __lo
, true))
912 __builtin_memcpy(__to
, __lo
, __hi
- __lo
);
917 return this->do_widen(__lo
, __hi
, __to
);
923 * This function converts the char to char using the simplest
924 * reasonable transformation. If the conversion fails, dfault is
925 * returned instead. For an underived ctype<char> facet, @a c
926 * will be returned unchanged.
928 * This function works as if it returns ctype<char>::do_narrow(c).
929 * do_narrow() must always return the same result for the same input.
931 * Note: this is not what you want for codepage conversions. See
934 * @param __c The char to convert.
935 * @param __dfault Char to return if conversion fails.
936 * @return The converted character.
939 narrow(char_type __c
, char __dfault
) const
941 if (_M_narrow
[static_cast<unsigned char>(__c
)])
942 return _M_narrow
[static_cast<unsigned char>(__c
)];
943 const char __t
= do_narrow(__c
, __dfault
);
945 _M_narrow
[static_cast<unsigned char>(__c
)] = __t
;
950 * @brief Narrow char array
952 * This function converts each char in the input to char using the
953 * simplest reasonable transformation and writes the results to the
954 * destination array. For any char in the input that cannot be
955 * converted, @a dfault is used instead. For an underived ctype<char>
956 * facet, the argument will be copied unchanged.
958 * This function works as if it returns ctype<char>::do_narrow(lo, hi,
959 * dfault, to). do_narrow() must always return the same result for the
962 * Note: this is not what you want for codepage conversions. See
965 * @param __lo Pointer to start of range.
966 * @param __hi Pointer to end of range.
967 * @param __dfault Char to use if conversion fails.
968 * @param __to Pointer to the destination array.
972 narrow(const char_type
* __lo
, const char_type
* __hi
,
973 char __dfault
, char* __to
) const
975 if (__builtin_expect(_M_narrow_ok
== 1, true))
977 if (__builtin_expect(__hi
!= __lo
, true))
978 __builtin_memcpy(__to
, __lo
, __hi
- __lo
);
983 return this->do_narrow(__lo
, __hi
, __dfault
, __to
);
986 // _GLIBCXX_RESOLVE_LIB_DEFECTS
987 // DR 695. ctype<char>::classic_table() not accessible.
988 /// Returns a pointer to the mask table provided to the constructor, or
989 /// the default from classic_table() if none was provided.
991 table() const throw()
994 /// Returns a pointer to the C locale mask table.
996 classic_table() throw();
1000 * @brief Destructor.
1002 * This function deletes table() if @a del was true in the
1009 * @brief Convert to uppercase.
1011 * This virtual function converts the char argument to uppercase if
1012 * possible. If not possible (for example, '2'), returns the argument.
1014 * do_toupper() is a hook for a derived facet to change the behavior of
1015 * uppercasing. do_toupper() must always return the same result for
1018 * @param __c The char to convert.
1019 * @return The uppercase char if convertible, else @a __c.
1022 do_toupper(char_type __c
) const;
1025 * @brief Convert array to uppercase.
1027 * This virtual function converts each char in the range [lo,hi) to
1028 * uppercase if possible. Other chars remain untouched.
1030 * do_toupper() is a hook for a derived facet to change the behavior of
1031 * uppercasing. do_toupper() must always return the same result for
1034 * @param __lo Pointer to start of range.
1035 * @param __hi Pointer to end of range.
1038 virtual const char_type
*
1039 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
1042 * @brief Convert to lowercase.
1044 * This virtual function converts the char argument to lowercase if
1045 * possible. If not possible (for example, '2'), returns the argument.
1047 * do_tolower() is a hook for a derived facet to change the behavior of
1048 * lowercasing. do_tolower() must always return the same result for
1051 * @param __c The char to convert.
1052 * @return The lowercase char if convertible, else @a __c.
1055 do_tolower(char_type __c
) const;
1058 * @brief Convert array to lowercase.
1060 * This virtual function converts each char in the range [lo,hi) to
1061 * lowercase if possible. Other chars remain untouched.
1063 * do_tolower() is a hook for a derived facet to change the behavior of
1064 * lowercasing. do_tolower() must always return the same result for
1067 * @param __lo Pointer to first char in range.
1068 * @param __hi Pointer to end of range.
1071 virtual const char_type
*
1072 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
1077 * This virtual function converts the char to char using the simplest
1078 * reasonable transformation. For an underived ctype<char> facet, the
1079 * argument will be returned unchanged.
1081 * do_widen() is a hook for a derived facet to change the behavior of
1082 * widening. do_widen() must always return the same result for the
1085 * Note: this is not what you want for codepage conversions. See
1088 * @param __c The char to convert.
1089 * @return The converted character.
1092 do_widen(char __c
) const
1096 * @brief Widen char array
1098 * This function converts each char in the range [lo,hi) to char using
1099 * the simplest reasonable transformation. For an underived
1100 * ctype<char> facet, the argument will be copied unchanged.
1102 * do_widen() is a hook for a derived facet to change the behavior of
1103 * widening. do_widen() must always return the same result for the
1106 * Note: this is not what you want for codepage conversions. See
1109 * @param __lo Pointer to start of range.
1110 * @param __hi Pointer to end of range.
1111 * @param __to Pointer to the destination array.
1115 do_widen(const char* __lo
, const char* __hi
, char_type
* __to
) const
1117 if (__builtin_expect(__hi
!= __lo
, true))
1118 __builtin_memcpy(__to
, __lo
, __hi
- __lo
);
1123 * @brief Narrow char
1125 * This virtual function converts the char to char using the simplest
1126 * reasonable transformation. If the conversion fails, dfault is
1127 * returned instead. For an underived ctype<char> facet, @a c will be
1128 * returned unchanged.
1130 * do_narrow() is a hook for a derived facet to change the behavior of
1131 * narrowing. do_narrow() must always return the same result for the
1134 * Note: this is not what you want for codepage conversions. See
1137 * @param __c The char to convert.
1138 * @param __dfault Char to return if conversion fails.
1139 * @return The converted char.
1142 do_narrow(char_type __c
, char __dfault
__attribute__((__unused__
))) const
1146 * @brief Narrow char array to char array
1148 * This virtual function converts each char in the range [lo,hi) to
1149 * char using the simplest reasonable transformation and writes the
1150 * results to the destination array. For any char in the input that
1151 * cannot be converted, @a dfault is used instead. For an underived
1152 * ctype<char> facet, the argument will be copied unchanged.
1154 * do_narrow() is a hook for a derived facet to change the behavior of
1155 * narrowing. do_narrow() must always return the same result for the
1158 * Note: this is not what you want for codepage conversions. See
1161 * @param __lo Pointer to start of range.
1162 * @param __hi Pointer to end of range.
1163 * @param __dfault Char to use if conversion fails.
1164 * @param __to Pointer to the destination array.
1167 virtual const char_type
*
1168 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
1169 char __dfault
__attribute__((__unused__
)), char* __to
) const
1171 if (__builtin_expect(__hi
!= __lo
, true))
1172 __builtin_memcpy(__to
, __lo
, __hi
- __lo
);
1177 void _M_narrow_init() const;
1178 void _M_widen_init() const;
1181 #ifdef _GLIBCXX_USE_WCHAR_T
1183 * @brief The ctype<wchar_t> specialization.
1186 * This class defines classification and conversion functions for the
1187 * wchar_t type. It gets used by wchar_t streams for many I/O operations.
1188 * The wchar_t specialization provides a number of optimizations as well.
1190 * ctype<wchar_t> inherits its public methods from
1191 * __ctype_abstract_base<wchar_t>.
1194 class ctype
<wchar_t> : public __ctype_abstract_base
<wchar_t>
1198 /// Typedef for the template parameter wchar_t.
1199 typedef wchar_t char_type
;
1200 typedef wctype_t __wmask_type
;
1203 __c_locale _M_c_locale_ctype
;
1205 // Pre-computed narrowed and widened chars.
1207 char _M_narrow
[128];
1208 wint_t _M_widen
[1 + static_cast<unsigned char>(-1)];
1210 // Pre-computed elements for do_is.
1212 __wmask_type _M_wmask
[16];
1216 /// The facet id for ctype<wchar_t>
1217 static locale::id id
;
1220 * @brief Constructor performs initialization.
1222 * This is the constructor provided by the standard.
1224 * @param __refs Passed to the base facet class.
1227 ctype(size_t __refs
= 0);
1230 * @brief Constructor performs static initialization.
1232 * This constructor is used to construct the initial C locale facet.
1234 * @param __cloc Handle to C locale data.
1235 * @param __refs Passed to the base facet class.
1238 ctype(__c_locale __cloc
, size_t __refs
= 0);
1242 _M_convert_to_wmask(const mask __m
) const throw();
1249 * @brief Test wchar_t classification.
1251 * This function finds a mask M for @a c and compares it to mask @a m.
1253 * do_is() is a hook for a derived facet to change the behavior of
1254 * classifying. do_is() must always return the same result for the
1257 * @param __c The wchar_t to find the mask of.
1258 * @param __m The mask to compare against.
1259 * @return (M & __m) != 0.
1262 do_is(mask __m
, char_type __c
) const;
1265 * @brief Return a mask array.
1267 * This function finds the mask for each wchar_t in the range [lo,hi)
1268 * and successively writes it to vec. vec must have as many elements
1271 * do_is() is a hook for a derived facet to change the behavior of
1272 * classifying. do_is() must always return the same result for the
1275 * @param __lo Pointer to start of range.
1276 * @param __hi Pointer to end of range.
1277 * @param __vec Pointer to an array of mask storage.
1280 virtual const char_type
*
1281 do_is(const char_type
* __lo
, const char_type
* __hi
, mask
* __vec
) const;
1284 * @brief Find wchar_t matching mask
1286 * This function searches for and returns the first wchar_t c in
1287 * [__lo,__hi) for which is(__m,c) is true.
1289 * do_scan_is() is a hook for a derived facet to change the behavior of
1290 * match searching. do_is() must always return the same result for the
1293 * @param __m The mask to compare against.
1294 * @param __lo Pointer to start of range.
1295 * @param __hi Pointer to end of range.
1296 * @return Pointer to a matching wchar_t if found, else @a __hi.
1298 virtual const char_type
*
1299 do_scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const;
1302 * @brief Find wchar_t not matching mask
1304 * This function searches for and returns a pointer to the first
1305 * wchar_t c of [__lo,__hi) for which is(__m,c) is false.
1307 * do_scan_is() is a hook for a derived facet to change the behavior of
1308 * match searching. do_is() must always return the same result for the
1311 * @param __m The mask to compare against.
1312 * @param __lo Pointer to start of range.
1313 * @param __hi Pointer to end of range.
1314 * @return Pointer to a non-matching wchar_t if found, else @a __hi.
1316 virtual const char_type
*
1317 do_scan_not(mask __m
, const char_type
* __lo
,
1318 const char_type
* __hi
) const;
1321 * @brief Convert to uppercase.
1323 * This virtual function converts the wchar_t argument to uppercase if
1324 * possible. If not possible (for example, '2'), returns the argument.
1326 * do_toupper() is a hook for a derived facet to change the behavior of
1327 * uppercasing. do_toupper() must always return the same result for
1330 * @param __c The wchar_t to convert.
1331 * @return The uppercase wchar_t if convertible, else @a __c.
1334 do_toupper(char_type __c
) const;
1337 * @brief Convert array to uppercase.
1339 * This virtual function converts each wchar_t in the range [lo,hi) to
1340 * uppercase if possible. Other elements remain untouched.
1342 * do_toupper() is a hook for a derived facet to change the behavior of
1343 * uppercasing. do_toupper() must always return the same result for
1346 * @param __lo Pointer to start of range.
1347 * @param __hi Pointer to end of range.
1350 virtual const char_type
*
1351 do_toupper(char_type
* __lo
, const char_type
* __hi
) const;
1354 * @brief Convert to lowercase.
1356 * This virtual function converts the argument to lowercase if
1357 * possible. If not possible (for example, '2'), returns the argument.
1359 * do_tolower() is a hook for a derived facet to change the behavior of
1360 * lowercasing. do_tolower() must always return the same result for
1363 * @param __c The wchar_t to convert.
1364 * @return The lowercase wchar_t if convertible, else @a __c.
1367 do_tolower(char_type __c
) const;
1370 * @brief Convert array to lowercase.
1372 * This virtual function converts each wchar_t in the range [lo,hi) to
1373 * lowercase if possible. Other elements remain untouched.
1375 * do_tolower() is a hook for a derived facet to change the behavior of
1376 * lowercasing. do_tolower() must always return the same result for
1379 * @param __lo Pointer to start of range.
1380 * @param __hi Pointer to end of range.
1383 virtual const char_type
*
1384 do_tolower(char_type
* __lo
, const char_type
* __hi
) const;
1387 * @brief Widen char to wchar_t
1389 * This virtual function converts the char to wchar_t using the
1390 * simplest reasonable transformation. For an underived ctype<wchar_t>
1391 * facet, the argument will be cast to wchar_t.
1393 * do_widen() is a hook for a derived facet to change the behavior of
1394 * widening. do_widen() must always return the same result for the
1397 * Note: this is not what you want for codepage conversions. See
1400 * @param __c The char to convert.
1401 * @return The converted wchar_t.
1404 do_widen(char __c
) const;
1407 * @brief Widen char array to wchar_t array
1409 * This function converts each char in the input to wchar_t using the
1410 * simplest reasonable transformation. For an underived ctype<wchar_t>
1411 * facet, the argument will be copied, casting each element to wchar_t.
1413 * do_widen() is a hook for a derived facet to change the behavior of
1414 * widening. do_widen() must always return the same result for the
1417 * Note: this is not what you want for codepage conversions. See
1420 * @param __lo Pointer to start range.
1421 * @param __hi Pointer to end of range.
1422 * @param __to Pointer to the destination array.
1426 do_widen(const char* __lo
, const char* __hi
, char_type
* __to
) const;
1429 * @brief Narrow wchar_t to char
1431 * This virtual function converts the argument to char using
1432 * the simplest reasonable transformation. If the conversion
1433 * fails, dfault is returned instead. For an underived
1434 * ctype<wchar_t> facet, @a c will be cast to char and
1437 * do_narrow() is a hook for a derived facet to change the
1438 * behavior of narrowing. do_narrow() must always return the
1439 * same result for the same input.
1441 * Note: this is not what you want for codepage conversions. See
1444 * @param __c The wchar_t to convert.
1445 * @param __dfault Char to return if conversion fails.
1446 * @return The converted char.
1449 do_narrow(char_type __c
, char __dfault
) const;
1452 * @brief Narrow wchar_t array to char array
1454 * This virtual function converts each wchar_t in the range [lo,hi) to
1455 * char using the simplest reasonable transformation and writes the
1456 * results to the destination array. For any wchar_t in the input that
1457 * cannot be converted, @a dfault is used instead. For an underived
1458 * ctype<wchar_t> facet, the argument will be copied, casting each
1461 * do_narrow() is a hook for a derived facet to change the behavior of
1462 * narrowing. do_narrow() must always return the same result for the
1465 * Note: this is not what you want for codepage conversions. See
1468 * @param __lo Pointer to start of range.
1469 * @param __hi Pointer to end of range.
1470 * @param __dfault Char to use if conversion fails.
1471 * @param __to Pointer to the destination array.
1474 virtual const char_type
*
1475 do_narrow(const char_type
* __lo
, const char_type
* __hi
,
1476 char __dfault
, char* __to
) const;
1478 // For use at construction time only.
1480 _M_initialize_ctype() throw();
1482 #endif //_GLIBCXX_USE_WCHAR_T
1484 /// class ctype_byname [22.2.1.2].
1485 template<typename _CharT
>
1486 class ctype_byname
: public ctype
<_CharT
>
1489 typedef typename ctype
<_CharT
>::mask mask
;
1492 ctype_byname(const char* __s
, size_t __refs
= 0);
1494 #if __cplusplus >= 201103L
1496 ctype_byname(const string
& __s
, size_t __refs
= 0)
1497 : ctype_byname(__s
.c_str(), __refs
) { }
1505 /// 22.2.1.4 Class ctype_byname specializations.
1507 class ctype_byname
<char> : public ctype
<char>
1511 ctype_byname(const char* __s
, size_t __refs
= 0);
1513 #if __cplusplus >= 201103L
1515 ctype_byname(const string
& __s
, size_t __refs
= 0);
1523 #ifdef _GLIBCXX_USE_WCHAR_T
1525 class ctype_byname
<wchar_t> : public ctype
<wchar_t>
1529 ctype_byname(const char* __s
, size_t __refs
= 0);
1531 #if __cplusplus >= 201103L
1533 ctype_byname(const string
& __s
, size_t __refs
= 0);
1542 _GLIBCXX_END_NAMESPACE_VERSION
1545 // Include host and configuration specific ctype inlines.
1546 #include <bits/ctype_inline.h>
1548 namespace std
_GLIBCXX_VISIBILITY(default)
1550 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1552 // 22.2.2 The numeric category.
1556 // NB: Code depends on the order of _S_atoms_out elements.
1557 // Below are the indices into _S_atoms_out.
1565 _S_odigits_end
= _S_odigits
+ 16,
1566 _S_oudigits
= _S_odigits_end
,
1567 _S_oudigits_end
= _S_oudigits
+ 16,
1568 _S_oe
= _S_odigits
+ 14, // For scientific notation, 'e'
1569 _S_oE
= _S_oudigits
+ 14, // For scientific notation, 'E'
1570 _S_oend
= _S_oudigits_end
1573 // A list of valid numeric literals for output. This array
1574 // contains chars that will be passed through the current locale's
1575 // ctype<_CharT>.widen() and then used to render numbers.
1576 // For the standard "C" locale, this is
1577 // "-+xX0123456789abcdef0123456789ABCDEF".
1578 static const char* _S_atoms_out
;
1580 // String literal of acceptable (narrow) input, for num_get.
1581 // "-+xX0123456789abcdefABCDEF"
1582 static const char* _S_atoms_in
;
1591 _S_ie
= _S_izero
+ 14,
1592 _S_iE
= _S_izero
+ 20,
1597 // Construct and return valid scanf format for floating point types.
1599 _S_format_float(const ios_base
& __io
, char* __fptr
, char __mod
) throw();
1602 template<typename _CharT
>
1603 struct __numpunct_cache
: public locale::facet
1605 const char* _M_grouping
;
1606 size_t _M_grouping_size
;
1607 bool _M_use_grouping
;
1608 const _CharT
* _M_truename
;
1609 size_t _M_truename_size
;
1610 const _CharT
* _M_falsename
;
1611 size_t _M_falsename_size
;
1612 _CharT _M_decimal_point
;
1613 _CharT _M_thousands_sep
;
1615 // A list of valid numeric literals for output: in the standard
1616 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1617 // This array contains the chars after having been passed
1618 // through the current locale's ctype<_CharT>.widen().
1619 _CharT _M_atoms_out
[__num_base::_S_oend
];
1621 // A list of valid numeric literals for input: in the standard
1622 // "C" locale, this is "-+xX0123456789abcdefABCDEF"
1623 // This array contains the chars after having been passed
1624 // through the current locale's ctype<_CharT>.widen().
1625 _CharT _M_atoms_in
[__num_base::_S_iend
];
1629 __numpunct_cache(size_t __refs
= 0)
1630 : facet(__refs
), _M_grouping(0), _M_grouping_size(0),
1631 _M_use_grouping(false),
1632 _M_truename(0), _M_truename_size(0), _M_falsename(0),
1633 _M_falsename_size(0), _M_decimal_point(_CharT()),
1634 _M_thousands_sep(_CharT()), _M_allocated(false)
1637 ~__numpunct_cache();
1640 _M_cache(const locale
& __loc
);
1644 operator=(const __numpunct_cache
&);
1647 __numpunct_cache(const __numpunct_cache
&);
1650 template<typename _CharT
>
1651 __numpunct_cache
<_CharT
>::~__numpunct_cache()
1655 delete [] _M_grouping
;
1656 delete [] _M_truename
;
1657 delete [] _M_falsename
;
1661 _GLIBCXX_BEGIN_NAMESPACE_CXX11
1664 * @brief Primary class template numpunct.
1667 * This facet stores several pieces of information related to printing and
1668 * scanning numbers, such as the decimal point character. It takes a
1669 * template parameter specifying the char type. The numpunct facet is
1670 * used by streams for many I/O operations involving numbers.
1672 * The numpunct template uses protected virtual functions to provide the
1673 * actual results. The public accessors forward the call to the virtual
1674 * functions. These virtual functions are hooks for developers to
1675 * implement the behavior they require from a numpunct facet.
1677 template<typename _CharT
>
1678 class numpunct
: public locale::facet
1684 typedef _CharT char_type
;
1685 typedef basic_string
<_CharT
> string_type
;
1687 typedef __numpunct_cache
<_CharT
> __cache_type
;
1690 __cache_type
* _M_data
;
1693 /// Numpunct facet id.
1694 static locale::id id
;
1697 * @brief Numpunct constructor.
1699 * @param __refs Refcount to pass to the base class.
1702 numpunct(size_t __refs
= 0)
1703 : facet(__refs
), _M_data(0)
1704 { _M_initialize_numpunct(); }
1707 * @brief Internal constructor. Not for general use.
1709 * This is a constructor for use by the library itself to set up the
1710 * predefined locale facets.
1712 * @param __cache __numpunct_cache object.
1713 * @param __refs Refcount to pass to the base class.
1716 numpunct(__cache_type
* __cache
, size_t __refs
= 0)
1717 : facet(__refs
), _M_data(__cache
)
1718 { _M_initialize_numpunct(); }
1721 * @brief Internal constructor. Not for general use.
1723 * This is a constructor for use by the library itself to set up new
1726 * @param __cloc The C locale.
1727 * @param __refs Refcount to pass to the base class.
1730 numpunct(__c_locale __cloc
, size_t __refs
= 0)
1731 : facet(__refs
), _M_data(0)
1732 { _M_initialize_numpunct(__cloc
); }
1735 * @brief Return decimal point character.
1737 * This function returns a char_type to use as a decimal point. It
1738 * does so by returning returning
1739 * numpunct<char_type>::do_decimal_point().
1741 * @return @a char_type representing a decimal point.
1744 decimal_point() const
1745 { return this->do_decimal_point(); }
1748 * @brief Return thousands separator character.
1750 * This function returns a char_type to use as a thousands
1751 * separator. It does so by returning returning
1752 * numpunct<char_type>::do_thousands_sep().
1754 * @return char_type representing a thousands separator.
1757 thousands_sep() const
1758 { return this->do_thousands_sep(); }
1761 * @brief Return grouping specification.
1763 * This function returns a string representing groupings for the
1764 * integer part of a number. Groupings indicate where thousands
1765 * separators should be inserted in the integer part of a number.
1767 * Each char in the return string is interpret as an integer
1768 * rather than a character. These numbers represent the number
1769 * of digits in a group. The first char in the string
1770 * represents the number of digits in the least significant
1771 * group. If a char is negative, it indicates an unlimited
1772 * number of digits for the group. If more chars from the
1773 * string are required to group a number, the last char is used
1776 * For example, if the grouping() returns "\003\002" and is
1777 * applied to the number 123456789, this corresponds to
1778 * 12,34,56,789. Note that if the string was "32", this would
1779 * put more than 50 digits into the least significant group if
1780 * the character set is ASCII.
1782 * The string is returned by calling
1783 * numpunct<char_type>::do_grouping().
1785 * @return string representing grouping specification.
1789 { return this->do_grouping(); }
1792 * @brief Return string representation of bool true.
1794 * This function returns a string_type containing the text
1795 * representation for true bool variables. It does so by calling
1796 * numpunct<char_type>::do_truename().
1798 * @return string_type representing printed form of true.
1802 { return this->do_truename(); }
1805 * @brief Return string representation of bool false.
1807 * This function returns a string_type containing the text
1808 * representation for false bool variables. It does so by calling
1809 * numpunct<char_type>::do_falsename().
1811 * @return string_type representing printed form of false.
1815 { return this->do_falsename(); }
1823 * @brief Return decimal point character.
1825 * Returns a char_type to use as a decimal point. This function is a
1826 * hook for derived classes to change the value returned.
1828 * @return @a char_type representing a decimal point.
1831 do_decimal_point() const
1832 { return _M_data
->_M_decimal_point
; }
1835 * @brief Return thousands separator character.
1837 * Returns a char_type to use as a thousands separator. This function
1838 * is a hook for derived classes to change the value returned.
1840 * @return @a char_type representing a thousands separator.
1843 do_thousands_sep() const
1844 { return _M_data
->_M_thousands_sep
; }
1847 * @brief Return grouping specification.
1849 * Returns a string representing groupings for the integer part of a
1850 * number. This function is a hook for derived classes to change the
1851 * value returned. @see grouping() for details.
1853 * @return String representing grouping specification.
1857 { return _M_data
->_M_grouping
; }
1860 * @brief Return string representation of bool true.
1862 * Returns a string_type containing the text representation for true
1863 * bool variables. This function is a hook for derived classes to
1864 * change the value returned.
1866 * @return string_type representing printed form of true.
1870 { return _M_data
->_M_truename
; }
1873 * @brief Return string representation of bool false.
1875 * Returns a string_type containing the text representation for false
1876 * bool variables. This function is a hook for derived classes to
1877 * change the value returned.
1879 * @return string_type representing printed form of false.
1882 do_falsename() const
1883 { return _M_data
->_M_falsename
; }
1885 // For use at construction time only.
1887 _M_initialize_numpunct(__c_locale __cloc
= 0);
1890 template<typename _CharT
>
1891 locale::id numpunct
<_CharT
>::id
;
1894 numpunct
<char>::~numpunct();
1898 numpunct
<char>::_M_initialize_numpunct(__c_locale __cloc
);
1900 #ifdef _GLIBCXX_USE_WCHAR_T
1902 numpunct
<wchar_t>::~numpunct();
1906 numpunct
<wchar_t>::_M_initialize_numpunct(__c_locale __cloc
);
1909 /// class numpunct_byname [22.2.3.2].
1910 template<typename _CharT
>
1911 class numpunct_byname
: public numpunct
<_CharT
>
1914 typedef _CharT char_type
;
1915 typedef basic_string
<_CharT
> string_type
;
1918 numpunct_byname(const char* __s
, size_t __refs
= 0)
1919 : numpunct
<_CharT
>(__refs
)
1921 if (__builtin_strcmp(__s
, "C") != 0
1922 && __builtin_strcmp(__s
, "POSIX") != 0)
1925 this->_S_create_c_locale(__tmp
, __s
);
1926 this->_M_initialize_numpunct(__tmp
);
1927 this->_S_destroy_c_locale(__tmp
);
1931 #if __cplusplus >= 201103L
1933 numpunct_byname(const string
& __s
, size_t __refs
= 0)
1934 : numpunct_byname(__s
.c_str(), __refs
) { }
1939 ~numpunct_byname() { }
1942 _GLIBCXX_END_NAMESPACE_CXX11
1944 _GLIBCXX_BEGIN_NAMESPACE_LDBL
1947 * @brief Primary class template num_get.
1950 * This facet encapsulates the code to parse and return a number
1951 * from a string. It is used by the istream numeric extraction
1954 * The num_get template uses protected virtual functions to provide the
1955 * actual results. The public accessors forward the call to the virtual
1956 * functions. These virtual functions are hooks for developers to
1957 * implement the behavior they require from the num_get facet.
1959 template<typename _CharT
, typename _InIter
>
1960 class num_get
: public locale::facet
1966 typedef _CharT char_type
;
1967 typedef _InIter iter_type
;
1970 /// Numpunct facet id.
1971 static locale::id id
;
1974 * @brief Constructor performs initialization.
1976 * This is the constructor provided by the standard.
1978 * @param __refs Passed to the base facet class.
1981 num_get(size_t __refs
= 0) : facet(__refs
) { }
1984 * @brief Numeric parsing.
1986 * Parses the input stream into the bool @a v. It does so by calling
1987 * num_get::do_get().
1989 * If ios_base::boolalpha is set, attempts to read
1990 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
1991 * @a v to true or false if successful. Sets err to
1992 * ios_base::failbit if reading the string fails. Sets err to
1993 * ios_base::eofbit if the stream is emptied.
1995 * If ios_base::boolalpha is not set, proceeds as with reading a long,
1996 * except if the value is 1, sets @a v to true, if the value is 0, sets
1997 * @a v to false, and otherwise set err to ios_base::failbit.
1999 * @param __in Start of input stream.
2000 * @param __end End of input stream.
2001 * @param __io Source of locale and flags.
2002 * @param __err Error flags to set.
2003 * @param __v Value to format and insert.
2004 * @return Iterator after reading.
2007 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2008 ios_base::iostate
& __err
, bool& __v
) const
2009 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2013 * @brief Numeric parsing.
2015 * Parses the input stream into the integral variable @a v. It does so
2016 * by calling num_get::do_get().
2018 * Parsing is affected by the flag settings in @a io.
2020 * The basic parse is affected by the value of io.flags() &
2021 * ios_base::basefield. If equal to ios_base::oct, parses like the
2022 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X
2023 * specifier. Else if basefield equal to 0, parses like the %i
2024 * specifier. Otherwise, parses like %d for signed and %u for unsigned
2025 * types. The matching type length modifier is also used.
2027 * Digit grouping is interpreted according to
2028 * numpunct::grouping() and numpunct::thousands_sep(). If the
2029 * pattern of digit groups isn't consistent, sets err to
2030 * ios_base::failbit.
2032 * If parsing the string yields a valid value for @a v, @a v is set.
2033 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2034 * Sets err to ios_base::eofbit if the stream is emptied.
2036 * @param __in Start of input stream.
2037 * @param __end End of input stream.
2038 * @param __io Source of locale and flags.
2039 * @param __err Error flags to set.
2040 * @param __v Value to format and insert.
2041 * @return Iterator after reading.
2044 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2045 ios_base::iostate
& __err
, long& __v
) const
2046 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2049 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2050 ios_base::iostate
& __err
, unsigned short& __v
) const
2051 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2054 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2055 ios_base::iostate
& __err
, unsigned int& __v
) const
2056 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2059 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2060 ios_base::iostate
& __err
, unsigned long& __v
) const
2061 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2063 #ifdef _GLIBCXX_USE_LONG_LONG
2065 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2066 ios_base::iostate
& __err
, long long& __v
) const
2067 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2070 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2071 ios_base::iostate
& __err
, unsigned long long& __v
) const
2072 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2078 * @brief Numeric parsing.
2080 * Parses the input stream into the integral variable @a v. It does so
2081 * by calling num_get::do_get().
2083 * The input characters are parsed like the scanf %g specifier. The
2084 * matching type length modifier is also used.
2086 * The decimal point character used is numpunct::decimal_point().
2087 * Digit grouping is interpreted according to
2088 * numpunct::grouping() and numpunct::thousands_sep(). If the
2089 * pattern of digit groups isn't consistent, sets err to
2090 * ios_base::failbit.
2092 * If parsing the string yields a valid value for @a v, @a v is set.
2093 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2094 * Sets err to ios_base::eofbit if the stream is emptied.
2096 * @param __in Start of input stream.
2097 * @param __end End of input stream.
2098 * @param __io Source of locale and flags.
2099 * @param __err Error flags to set.
2100 * @param __v Value to format and insert.
2101 * @return Iterator after reading.
2104 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2105 ios_base::iostate
& __err
, float& __v
) const
2106 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2109 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2110 ios_base::iostate
& __err
, double& __v
) const
2111 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2114 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2115 ios_base::iostate
& __err
, long double& __v
) const
2116 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2120 * @brief Numeric parsing.
2122 * Parses the input stream into the pointer variable @a v. It does so
2123 * by calling num_get::do_get().
2125 * The input characters are parsed like the scanf %p specifier.
2127 * Digit grouping is interpreted according to
2128 * numpunct::grouping() and numpunct::thousands_sep(). If the
2129 * pattern of digit groups isn't consistent, sets err to
2130 * ios_base::failbit.
2132 * Note that the digit grouping effect for pointers is a bit ambiguous
2133 * in the standard and shouldn't be relied on. See DR 344.
2135 * If parsing the string yields a valid value for @a v, @a v is set.
2136 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2137 * Sets err to ios_base::eofbit if the stream is emptied.
2139 * @param __in Start of input stream.
2140 * @param __end End of input stream.
2141 * @param __io Source of locale and flags.
2142 * @param __err Error flags to set.
2143 * @param __v Value to format and insert.
2144 * @return Iterator after reading.
2147 get(iter_type __in
, iter_type __end
, ios_base
& __io
,
2148 ios_base::iostate
& __err
, void*& __v
) const
2149 { return this->do_get(__in
, __end
, __io
, __err
, __v
); }
2153 virtual ~num_get() { }
2155 _GLIBCXX_DEFAULT_ABI_TAG
2157 _M_extract_float(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2160 template<typename _ValueT
>
2161 _GLIBCXX_DEFAULT_ABI_TAG
2163 _M_extract_int(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2166 template<typename _CharT2
>
2167 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT2
>::__value
, int>::__type
2168 _M_find(const _CharT2
*, size_t __len
, _CharT2 __c
) const
2173 if (__c
>= _CharT2('0') && __c
< _CharT2(_CharT2('0') + __len
))
2174 __ret
= __c
- _CharT2('0');
2178 if (__c
>= _CharT2('0') && __c
<= _CharT2('9'))
2179 __ret
= __c
- _CharT2('0');
2180 else if (__c
>= _CharT2('a') && __c
<= _CharT2('f'))
2181 __ret
= 10 + (__c
- _CharT2('a'));
2182 else if (__c
>= _CharT2('A') && __c
<= _CharT2('F'))
2183 __ret
= 10 + (__c
- _CharT2('A'));
2188 template<typename _CharT2
>
2189 typename
__gnu_cxx::__enable_if
<!__is_char
<_CharT2
>::__value
,
2191 _M_find(const _CharT2
* __zero
, size_t __len
, _CharT2 __c
) const
2194 const char_type
* __q
= char_traits
<_CharT2
>::find(__zero
, __len
, __c
);
2197 __ret
= __q
- __zero
;
2206 * @brief Numeric parsing.
2208 * Parses the input stream into the variable @a v. This function is a
2209 * hook for derived classes to change the value returned. @see get()
2212 * @param __beg Start of input stream.
2213 * @param __end End of input stream.
2214 * @param __io Source of locale and flags.
2215 * @param __err Error flags to set.
2216 * @param __v Value to format and insert.
2217 * @return Iterator after reading.
2220 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, bool&) const;
2223 do_get(iter_type __beg
, iter_type __end
, ios_base
& __io
,
2224 ios_base::iostate
& __err
, long& __v
) const
2225 { return _M_extract_int(__beg
, __end
, __io
, __err
, __v
); }
2228 do_get(iter_type __beg
, iter_type __end
, ios_base
& __io
,
2229 ios_base::iostate
& __err
, unsigned short& __v
) const
2230 { return _M_extract_int(__beg
, __end
, __io
, __err
, __v
); }
2233 do_get(iter_type __beg
, iter_type __end
, ios_base
& __io
,
2234 ios_base::iostate
& __err
, unsigned int& __v
) const
2235 { return _M_extract_int(__beg
, __end
, __io
, __err
, __v
); }
2238 do_get(iter_type __beg
, iter_type __end
, ios_base
& __io
,
2239 ios_base::iostate
& __err
, unsigned long& __v
) const
2240 { return _M_extract_int(__beg
, __end
, __io
, __err
, __v
); }
2242 #ifdef _GLIBCXX_USE_LONG_LONG
2244 do_get(iter_type __beg
, iter_type __end
, ios_base
& __io
,
2245 ios_base::iostate
& __err
, long long& __v
) const
2246 { return _M_extract_int(__beg
, __end
, __io
, __err
, __v
); }
2249 do_get(iter_type __beg
, iter_type __end
, ios_base
& __io
,
2250 ios_base::iostate
& __err
, unsigned long long& __v
) const
2251 { return _M_extract_int(__beg
, __end
, __io
, __err
, __v
); }
2255 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, float&) const;
2258 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2261 // XXX GLIBCXX_ABI Deprecated
2262 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2263 // For __gnu_cxx_ldbl128::num_get and __gnu_cxx_ieee128::num_get
2264 // this entry in the vtable is for a 64-bit "long double" with the
2265 // same format as double. This keeps the vtable layout consistent
2266 // with std::num_get (visible when -mlong-double-64 is used).
2268 __do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2272 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2273 long double&) const;
2277 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, void*&) const;
2279 // XXX GLIBCXX_ABI Deprecated
2280 #if defined _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT \
2281 && defined __LONG_DOUBLE_IEEE128__
2282 // For __gnu_cxx_ieee128::num_get this entry in the vtable is for
2283 // the non-IEEE 128-bit "long double" (aka "double double"). This
2284 // is consistent with __gnu_cxx_ldbl128::num_get (-mabi=ibmlongdouble)
2286 __do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2290 // XXX GLIBCXX_ABI Deprecated
2291 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2292 // For __gnu_cxx_ldbl128::num_get and __gnu_cxx_ieee128::num_get
2293 // this entry in the vtable is for the 128-bit "long double" type.
2295 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
2296 long double&) const;
2301 template<typename _CharT
, typename _InIter
>
2302 locale::id num_get
<_CharT
, _InIter
>::id
;
2306 * @brief Primary class template num_put.
2309 * This facet encapsulates the code to convert a number to a string. It is
2310 * used by the ostream numeric insertion operators.
2312 * The num_put template uses protected virtual functions to provide the
2313 * actual results. The public accessors forward the call to the virtual
2314 * functions. These virtual functions are hooks for developers to
2315 * implement the behavior they require from the num_put facet.
2317 template<typename _CharT
, typename _OutIter
>
2318 class num_put
: public locale::facet
2324 typedef _CharT char_type
;
2325 typedef _OutIter iter_type
;
2328 /// Numpunct facet id.
2329 static locale::id id
;
2332 * @brief Constructor performs initialization.
2334 * This is the constructor provided by the standard.
2336 * @param __refs Passed to the base facet class.
2339 num_put(size_t __refs
= 0) : facet(__refs
) { }
2342 * @brief Numeric formatting.
2344 * Formats the boolean @a v and inserts it into a stream. It does so
2345 * by calling num_put::do_put().
2347 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2348 * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
2350 * @param __s Stream to write to.
2351 * @param __io Source of locale and flags.
2352 * @param __fill Char_type to use for filling.
2353 * @param __v Value to format and insert.
2354 * @return Iterator after writing.
2357 put(iter_type __s
, ios_base
& __io
, char_type __fill
, bool __v
) const
2358 { return this->do_put(__s
, __io
, __fill
, __v
); }
2362 * @brief Numeric formatting.
2364 * Formats the integral value @a v and inserts it into a
2365 * stream. It does so by calling num_put::do_put().
2367 * Formatting is affected by the flag settings in @a io.
2369 * The basic format is affected by the value of io.flags() &
2370 * ios_base::basefield. If equal to ios_base::oct, formats like the
2371 * printf %o specifier. Else if equal to ios_base::hex, formats like
2372 * %x or %X with ios_base::uppercase unset or set respectively.
2373 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2374 * for unsigned values. Note that if both oct and hex are set, neither
2377 * If ios_base::showpos is set, '+' is output before positive values.
2378 * If ios_base::showbase is set, '0' precedes octal values (except 0)
2379 * and '0[xX]' precedes hex values.
2381 * The decimal point character used is numpunct::decimal_point().
2382 * Thousands separators are inserted according to
2383 * numpunct::grouping() and numpunct::thousands_sep().
2385 * If io.width() is non-zero, enough @a fill characters are inserted to
2386 * make the result at least that wide. If
2387 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2388 * padded at the end. If ios_base::internal, then padding occurs
2389 * immediately after either a '+' or '-' or after '0x' or '0X'.
2390 * Otherwise, padding occurs at the beginning.
2392 * @param __s Stream to write to.
2393 * @param __io Source of locale and flags.
2394 * @param __fill Char_type to use for filling.
2395 * @param __v Value to format and insert.
2396 * @return Iterator after writing.
2399 put(iter_type __s
, ios_base
& __io
, char_type __fill
, long __v
) const
2400 { return this->do_put(__s
, __io
, __fill
, __v
); }
2403 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
2404 unsigned long __v
) const
2405 { return this->do_put(__s
, __io
, __fill
, __v
); }
2407 #ifdef _GLIBCXX_USE_LONG_LONG
2409 put(iter_type __s
, ios_base
& __io
, char_type __fill
, long long __v
) const
2410 { return this->do_put(__s
, __io
, __fill
, __v
); }
2413 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
2414 unsigned long long __v
) const
2415 { return this->do_put(__s
, __io
, __fill
, __v
); }
2421 * @brief Numeric formatting.
2423 * Formats the floating point value @a v and inserts it into a stream.
2424 * It does so by calling num_put::do_put().
2426 * Formatting is affected by the flag settings in @a io.
2428 * The basic format is affected by the value of io.flags() &
2429 * ios_base::floatfield. If equal to ios_base::fixed, formats like the
2430 * printf %f specifier. Else if equal to ios_base::scientific, formats
2431 * like %e or %E with ios_base::uppercase unset or set respectively.
2432 * Otherwise, formats like %g or %G depending on uppercase. Note that
2433 * if both fixed and scientific are set, the effect will also be like
2436 * The output precision is given by io.precision(). This precision is
2437 * capped at numeric_limits::digits10 + 2 (different for double and
2438 * long double). The default precision is 6.
2440 * If ios_base::showpos is set, '+' is output before positive values.
2441 * If ios_base::showpoint is set, a decimal point will always be
2444 * The decimal point character used is numpunct::decimal_point().
2445 * Thousands separators are inserted according to
2446 * numpunct::grouping() and numpunct::thousands_sep().
2448 * If io.width() is non-zero, enough @a fill characters are inserted to
2449 * make the result at least that wide. If
2450 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2451 * padded at the end. If ios_base::internal, then padding occurs
2452 * immediately after either a '+' or '-' or after '0x' or '0X'.
2453 * Otherwise, padding occurs at the beginning.
2455 * @param __s Stream to write to.
2456 * @param __io Source of locale and flags.
2457 * @param __fill Char_type to use for filling.
2458 * @param __v Value to format and insert.
2459 * @return Iterator after writing.
2462 put(iter_type __s
, ios_base
& __io
, char_type __fill
, double __v
) const
2463 { return this->do_put(__s
, __io
, __fill
, __v
); }
2466 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
2467 long double __v
) const
2468 { return this->do_put(__s
, __io
, __fill
, __v
); }
2472 * @brief Numeric formatting.
2474 * Formats the pointer value @a v and inserts it into a stream. It
2475 * does so by calling num_put::do_put().
2477 * This function formats @a v as an unsigned long with ios_base::hex
2478 * and ios_base::showbase set.
2480 * @param __s Stream to write to.
2481 * @param __io Source of locale and flags.
2482 * @param __fill Char_type to use for filling.
2483 * @param __v Value to format and insert.
2484 * @return Iterator after writing.
2487 put(iter_type __s
, ios_base
& __io
, char_type __fill
,
2488 const void* __v
) const
2489 { return this->do_put(__s
, __io
, __fill
, __v
); }
2492 template<typename _ValueT
>
2494 _M_insert_float(iter_type
, ios_base
& __io
, char_type __fill
,
2495 char __mod
, _ValueT __v
) const;
2498 _M_group_float(const char* __grouping
, size_t __grouping_size
,
2499 char_type __sep
, const char_type
* __p
, char_type
* __new
,
2500 char_type
* __cs
, int& __len
) const;
2502 template<typename _ValueT
>
2504 _M_insert_int(iter_type
, ios_base
& __io
, char_type __fill
,
2508 _M_group_int(const char* __grouping
, size_t __grouping_size
,
2509 char_type __sep
, ios_base
& __io
, char_type
* __new
,
2510 char_type
* __cs
, int& __len
) const;
2513 _M_pad(char_type __fill
, streamsize __w
, ios_base
& __io
,
2514 char_type
* __new
, const char_type
* __cs
, int& __len
) const;
2522 * @brief Numeric formatting.
2524 * These functions do the work of formatting numeric values and
2525 * inserting them into a stream. This function is a hook for derived
2526 * classes to change the value returned.
2528 * @param __s Stream to write to.
2529 * @param __io Source of locale and flags.
2530 * @param __fill Char_type to use for filling.
2531 * @param __v Value to format and insert.
2532 * @return Iterator after writing.
2535 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
, bool __v
) const;
2538 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
, long __v
) const
2539 { return _M_insert_int(__s
, __io
, __fill
, __v
); }
2542 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
,
2543 unsigned long __v
) const
2544 { return _M_insert_int(__s
, __io
, __fill
, __v
); }
2546 #ifdef _GLIBCXX_USE_LONG_LONG
2548 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
,
2549 long long __v
) const
2550 { return _M_insert_int(__s
, __io
, __fill
, __v
); }
2553 do_put(iter_type __s
, ios_base
& __io
, char_type __fill
,
2554 unsigned long long __v
) const
2555 { return _M_insert_int(__s
, __io
, __fill
, __v
); }
2559 do_put(iter_type
, ios_base
&, char_type
, double) const;
2561 // XXX GLIBCXX_ABI Deprecated
2562 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2564 __do_put(iter_type
, ios_base
&, char_type
, double) const;
2567 do_put(iter_type
, ios_base
&, char_type
, long double) const;
2571 do_put(iter_type
, ios_base
&, char_type
, const void*) const;
2573 // XXX GLIBCXX_ABI Deprecated
2574 #if defined _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT \
2575 && defined __LONG_DOUBLE_IEEE128__
2577 __do_put(iter_type
, ios_base
&, char_type
, __ibm128
) const;
2580 // XXX GLIBCXX_ABI Deprecated
2581 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2583 do_put(iter_type
, ios_base
&, char_type
, long double) const;
2588 template <typename _CharT
, typename _OutIter
>
2589 locale::id num_put
<_CharT
, _OutIter
>::id
;
2591 _GLIBCXX_END_NAMESPACE_LDBL
2593 // Subclause convenience interfaces, inlines.
2594 // NB: These are inline because, when used in a loop, some compilers
2595 // can hoist the body out of the loop; then it's just as fast as the
2596 // C is*() function.
2598 /// Convenience interface to ctype.is(ctype_base::space, __c).
2599 template<typename _CharT
>
2601 isspace(_CharT __c
, const locale
& __loc
)
2602 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::space
, __c
); }
2604 /// Convenience interface to ctype.is(ctype_base::print, __c).
2605 template<typename _CharT
>
2607 isprint(_CharT __c
, const locale
& __loc
)
2608 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::print
, __c
); }
2610 /// Convenience interface to ctype.is(ctype_base::cntrl, __c).
2611 template<typename _CharT
>
2613 iscntrl(_CharT __c
, const locale
& __loc
)
2614 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::cntrl
, __c
); }
2616 /// Convenience interface to ctype.is(ctype_base::upper, __c).
2617 template<typename _CharT
>
2619 isupper(_CharT __c
, const locale
& __loc
)
2620 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::upper
, __c
); }
2622 /// Convenience interface to ctype.is(ctype_base::lower, __c).
2623 template<typename _CharT
>
2625 islower(_CharT __c
, const locale
& __loc
)
2626 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::lower
, __c
); }
2628 /// Convenience interface to ctype.is(ctype_base::alpha, __c).
2629 template<typename _CharT
>
2631 isalpha(_CharT __c
, const locale
& __loc
)
2632 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alpha
, __c
); }
2634 /// Convenience interface to ctype.is(ctype_base::digit, __c).
2635 template<typename _CharT
>
2637 isdigit(_CharT __c
, const locale
& __loc
)
2638 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::digit
, __c
); }
2640 /// Convenience interface to ctype.is(ctype_base::punct, __c).
2641 template<typename _CharT
>
2643 ispunct(_CharT __c
, const locale
& __loc
)
2644 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::punct
, __c
); }
2646 /// Convenience interface to ctype.is(ctype_base::xdigit, __c).
2647 template<typename _CharT
>
2649 isxdigit(_CharT __c
, const locale
& __loc
)
2650 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::xdigit
, __c
); }
2652 /// Convenience interface to ctype.is(ctype_base::alnum, __c).
2653 template<typename _CharT
>
2655 isalnum(_CharT __c
, const locale
& __loc
)
2656 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::alnum
, __c
); }
2658 /// Convenience interface to ctype.is(ctype_base::graph, __c).
2659 template<typename _CharT
>
2661 isgraph(_CharT __c
, const locale
& __loc
)
2662 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::graph
, __c
); }
2664 #if __cplusplus >= 201103L
2665 /// Convenience interface to ctype.is(ctype_base::blank, __c).
2666 template<typename _CharT
>
2668 isblank(_CharT __c
, const locale
& __loc
)
2669 { return use_facet
<ctype
<_CharT
> >(__loc
).is(ctype_base::blank
, __c
); }
2672 /// Convenience interface to ctype.toupper(__c).
2673 template<typename _CharT
>
2675 toupper(_CharT __c
, const locale
& __loc
)
2676 { return use_facet
<ctype
<_CharT
> >(__loc
).toupper(__c
); }
2678 /// Convenience interface to ctype.tolower(__c).
2679 template<typename _CharT
>
2681 tolower(_CharT __c
, const locale
& __loc
)
2682 { return use_facet
<ctype
<_CharT
> >(__loc
).tolower(__c
); }
2684 _GLIBCXX_END_NAMESPACE_VERSION
2687 # include <bits/locale_facets.tcc>