]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/locale_facets.h
locale_facets.tcc (__pad<>::_S_pad): Don't use const by value parameters.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / locale_facets.h
1 // Locale support -*- C++ -*-
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008
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.
12
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.
17
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.
22
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.
31
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.
35 */
36
37 //
38 // ISO C++ 14882: 22.1 Locales
39 //
40
41 #ifndef _LOCALE_FACETS_H
42 #define _LOCALE_FACETS_H 1
43
44 #pragma GCC system_header
45
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>
56
57 _GLIBCXX_BEGIN_NAMESPACE(std)
58
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
65
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);
73
74 // Explicit specializations for required types.
75 template<>
76 void
77 __convert_to_v(const char*, float&, ios_base::iostate&,
78 const __c_locale&);
79
80 template<>
81 void
82 __convert_to_v(const char*, double&, ios_base::iostate&,
83 const __c_locale&);
84
85 template<>
86 void
87 __convert_to_v(const char*, long double&, ios_base::iostate&,
88 const __c_locale&);
89
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
94 {
95 static void
96 _S_pad(ios_base& __io, _CharT __fill, _CharT* __news,
97 const _CharT* __olds, streamsize __newlen, streamsize __oldlen);
98 };
99
100 // Used by both numeric and monetary facets.
101 // Inserts "group separator" characters into an array of characters.
102 // It's recursive, one iteration per group. It moves the characters
103 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
104 // only with __gsize != 0.
105 template<typename _CharT>
106 _CharT*
107 __add_grouping(_CharT* __s, _CharT __sep,
108 const char* __gbeg, size_t __gsize,
109 const _CharT* __first, const _CharT* __last);
110
111 // This template permits specializing facet output code for
112 // ostreambuf_iterator. For ostreambuf_iterator, sputn is
113 // significantly more efficient than incrementing iterators.
114 template<typename _CharT>
115 inline
116 ostreambuf_iterator<_CharT>
117 __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len)
118 {
119 __s._M_put(__ws, __len);
120 return __s;
121 }
122
123 // This is the unspecialized form of the template.
124 template<typename _CharT, typename _OutIter>
125 inline
126 _OutIter
127 __write(_OutIter __s, const _CharT* __ws, int __len)
128 {
129 for (int __j = 0; __j < __len; __j++, ++__s)
130 *__s = __ws[__j];
131 return __s;
132 }
133
134
135 // 22.2.1.1 Template class ctype
136 // Include host and configuration specific ctype enums for ctype_base.
137
138 // Common base for ctype<_CharT>.
139 /**
140 * @brief Common base for ctype facet
141 *
142 * This template class provides implementations of the public functions
143 * that forward to the protected virtual functions.
144 *
145 * This template also provides abstract stubs for the protected virtual
146 * functions.
147 */
148 template<typename _CharT>
149 class __ctype_abstract_base : public locale::facet, public ctype_base
150 {
151 public:
152 // Types:
153 /// Typedef for the template parameter
154 typedef _CharT char_type;
155
156 /**
157 * @brief Test char_type classification.
158 *
159 * This function finds a mask M for @a c and compares it to mask @a m.
160 * It does so by returning the value of ctype<char_type>::do_is().
161 *
162 * @param c The char_type to compare the mask of.
163 * @param m The mask to compare against.
164 * @return (M & m) != 0.
165 */
166 bool
167 is(mask __m, char_type __c) const
168 { return this->do_is(__m, __c); }
169
170 /**
171 * @brief Return a mask array.
172 *
173 * This function finds the mask for each char_type in the range [lo,hi)
174 * and successively writes it to vec. vec must have as many elements
175 * as the char array. It does so by returning the value of
176 * ctype<char_type>::do_is().
177 *
178 * @param lo Pointer to start of range.
179 * @param hi Pointer to end of range.
180 * @param vec Pointer to an array of mask storage.
181 * @return @a hi.
182 */
183 const char_type*
184 is(const char_type *__lo, const char_type *__hi, mask *__vec) const
185 { return this->do_is(__lo, __hi, __vec); }
186
187 /**
188 * @brief Find char_type matching a mask
189 *
190 * This function searches for and returns the first char_type c in
191 * [lo,hi) for which is(m,c) is true. It does so by returning
192 * ctype<char_type>::do_scan_is().
193 *
194 * @param m The mask to compare against.
195 * @param lo Pointer to start of range.
196 * @param hi Pointer to end of range.
197 * @return Pointer to matching char_type if found, else @a hi.
198 */
199 const char_type*
200 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
201 { return this->do_scan_is(__m, __lo, __hi); }
202
203 /**
204 * @brief Find char_type not matching a mask
205 *
206 * This function searches for and returns the first char_type c in
207 * [lo,hi) for which is(m,c) is false. It does so by returning
208 * ctype<char_type>::do_scan_not().
209 *
210 * @param m The mask to compare against.
211 * @param lo Pointer to first char in range.
212 * @param hi Pointer to end of range.
213 * @return Pointer to non-matching char if found, else @a hi.
214 */
215 const char_type*
216 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
217 { return this->do_scan_not(__m, __lo, __hi); }
218
219 /**
220 * @brief Convert to uppercase.
221 *
222 * This function converts the argument to uppercase if possible.
223 * If not possible (for example, '2'), returns the argument. It does
224 * so by returning ctype<char_type>::do_toupper().
225 *
226 * @param c The char_type to convert.
227 * @return The uppercase char_type if convertible, else @a c.
228 */
229 char_type
230 toupper(char_type __c) const
231 { return this->do_toupper(__c); }
232
233 /**
234 * @brief Convert array to uppercase.
235 *
236 * This function converts each char_type in the range [lo,hi) to
237 * uppercase if possible. Other elements remain untouched. It does so
238 * by returning ctype<char_type>:: do_toupper(lo, hi).
239 *
240 * @param lo Pointer to start of range.
241 * @param hi Pointer to end of range.
242 * @return @a hi.
243 */
244 const char_type*
245 toupper(char_type *__lo, const char_type* __hi) const
246 { return this->do_toupper(__lo, __hi); }
247
248 /**
249 * @brief Convert to lowercase.
250 *
251 * This function converts the argument to lowercase if possible. If
252 * not possible (for example, '2'), returns the argument. It does so
253 * by returning ctype<char_type>::do_tolower(c).
254 *
255 * @param c The char_type to convert.
256 * @return The lowercase char_type if convertible, else @a c.
257 */
258 char_type
259 tolower(char_type __c) const
260 { return this->do_tolower(__c); }
261
262 /**
263 * @brief Convert array to lowercase.
264 *
265 * This function converts each char_type in the range [lo,hi) to
266 * lowercase if possible. Other elements remain untouched. It does so
267 * by returning ctype<char_type>:: do_tolower(lo, hi).
268 *
269 * @param lo Pointer to start of range.
270 * @param hi Pointer to end of range.
271 * @return @a hi.
272 */
273 const char_type*
274 tolower(char_type* __lo, const char_type* __hi) const
275 { return this->do_tolower(__lo, __hi); }
276
277 /**
278 * @brief Widen char to char_type
279 *
280 * This function converts the char argument to char_type using the
281 * simplest reasonable transformation. It does so by returning
282 * ctype<char_type>::do_widen(c).
283 *
284 * Note: this is not what you want for codepage conversions. See
285 * codecvt for that.
286 *
287 * @param c The char to convert.
288 * @return The converted char_type.
289 */
290 char_type
291 widen(char __c) const
292 { return this->do_widen(__c); }
293
294 /**
295 * @brief Widen array to char_type
296 *
297 * This function converts each char in the input to char_type using the
298 * simplest reasonable transformation. It does so by returning
299 * ctype<char_type>::do_widen(c).
300 *
301 * Note: this is not what you want for codepage conversions. See
302 * codecvt for that.
303 *
304 * @param lo Pointer to start of range.
305 * @param hi Pointer to end of range.
306 * @param to Pointer to the destination array.
307 * @return @a hi.
308 */
309 const char*
310 widen(const char* __lo, const char* __hi, char_type* __to) const
311 { return this->do_widen(__lo, __hi, __to); }
312
313 /**
314 * @brief Narrow char_type to char
315 *
316 * This function converts the char_type to char using the simplest
317 * reasonable transformation. If the conversion fails, dfault is
318 * returned instead. It does so by returning
319 * ctype<char_type>::do_narrow(c).
320 *
321 * Note: this is not what you want for codepage conversions. See
322 * codecvt for that.
323 *
324 * @param c The char_type to convert.
325 * @param dfault Char to return if conversion fails.
326 * @return The converted char.
327 */
328 char
329 narrow(char_type __c, char __dfault) const
330 { return this->do_narrow(__c, __dfault); }
331
332 /**
333 * @brief Narrow array to char array
334 *
335 * This function converts each char_type in the input to char using the
336 * simplest reasonable transformation and writes the results to the
337 * destination array. For any char_type in the input that cannot be
338 * converted, @a dfault is used instead. It does so by returning
339 * ctype<char_type>::do_narrow(lo, hi, dfault, to).
340 *
341 * Note: this is not what you want for codepage conversions. See
342 * codecvt for that.
343 *
344 * @param lo Pointer to start of range.
345 * @param hi Pointer to end of range.
346 * @param dfault Char to use if conversion fails.
347 * @param to Pointer to the destination array.
348 * @return @a hi.
349 */
350 const char_type*
351 narrow(const char_type* __lo, const char_type* __hi,
352 char __dfault, char *__to) const
353 { return this->do_narrow(__lo, __hi, __dfault, __to); }
354
355 protected:
356 explicit
357 __ctype_abstract_base(size_t __refs = 0): facet(__refs) { }
358
359 virtual
360 ~__ctype_abstract_base() { }
361
362 /**
363 * @brief Test char_type classification.
364 *
365 * This function finds a mask M for @a c and compares it to mask @a m.
366 *
367 * do_is() is a hook for a derived facet to change the behavior of
368 * classifying. do_is() must always return the same result for the
369 * same input.
370 *
371 * @param c The char_type to find the mask of.
372 * @param m The mask to compare against.
373 * @return (M & m) != 0.
374 */
375 virtual bool
376 do_is(mask __m, char_type __c) const = 0;
377
378 /**
379 * @brief Return a mask array.
380 *
381 * This function finds the mask for each char_type in the range [lo,hi)
382 * and successively writes it to vec. vec must have as many elements
383 * as the input.
384 *
385 * do_is() is a hook for a derived facet to change the behavior of
386 * classifying. do_is() must always return the same result for the
387 * same input.
388 *
389 * @param lo Pointer to start of range.
390 * @param hi Pointer to end of range.
391 * @param vec Pointer to an array of mask storage.
392 * @return @a hi.
393 */
394 virtual const char_type*
395 do_is(const char_type* __lo, const char_type* __hi,
396 mask* __vec) const = 0;
397
398 /**
399 * @brief Find char_type matching mask
400 *
401 * This function searches for and returns the first char_type c in
402 * [lo,hi) for which is(m,c) is true.
403 *
404 * do_scan_is() is a hook for a derived facet to change the behavior of
405 * match searching. do_is() must always return the same result for the
406 * same input.
407 *
408 * @param m The mask to compare against.
409 * @param lo Pointer to start of range.
410 * @param hi Pointer to end of range.
411 * @return Pointer to a matching char_type if found, else @a hi.
412 */
413 virtual const char_type*
414 do_scan_is(mask __m, const char_type* __lo,
415 const char_type* __hi) const = 0;
416
417 /**
418 * @brief Find char_type not matching mask
419 *
420 * This function searches for and returns a pointer to the first
421 * char_type c of [lo,hi) for which is(m,c) is false.
422 *
423 * do_scan_is() is a hook for a derived facet to change the behavior of
424 * match searching. do_is() must always return the same result for the
425 * same input.
426 *
427 * @param m The mask to compare against.
428 * @param lo Pointer to start of range.
429 * @param hi Pointer to end of range.
430 * @return Pointer to a non-matching char_type if found, else @a hi.
431 */
432 virtual const char_type*
433 do_scan_not(mask __m, const char_type* __lo,
434 const char_type* __hi) const = 0;
435
436 /**
437 * @brief Convert to uppercase.
438 *
439 * This virtual function converts the char_type argument to uppercase
440 * if possible. If not possible (for example, '2'), returns the
441 * argument.
442 *
443 * do_toupper() is a hook for a derived facet to change the behavior of
444 * uppercasing. do_toupper() must always return the same result for
445 * the same input.
446 *
447 * @param c The char_type to convert.
448 * @return The uppercase char_type if convertible, else @a c.
449 */
450 virtual char_type
451 do_toupper(char_type) const = 0;
452
453 /**
454 * @brief Convert array to uppercase.
455 *
456 * This virtual function converts each char_type in the range [lo,hi)
457 * to uppercase if possible. Other elements remain untouched.
458 *
459 * do_toupper() is a hook for a derived facet to change the behavior of
460 * uppercasing. do_toupper() must always return the same result for
461 * the same input.
462 *
463 * @param lo Pointer to start of range.
464 * @param hi Pointer to end of range.
465 * @return @a hi.
466 */
467 virtual const char_type*
468 do_toupper(char_type* __lo, const char_type* __hi) const = 0;
469
470 /**
471 * @brief Convert to lowercase.
472 *
473 * This virtual function converts the argument to lowercase if
474 * possible. If not possible (for example, '2'), returns the argument.
475 *
476 * do_tolower() is a hook for a derived facet to change the behavior of
477 * lowercasing. do_tolower() must always return the same result for
478 * the same input.
479 *
480 * @param c The char_type to convert.
481 * @return The lowercase char_type if convertible, else @a c.
482 */
483 virtual char_type
484 do_tolower(char_type) const = 0;
485
486 /**
487 * @brief Convert array to lowercase.
488 *
489 * This virtual function converts each char_type in the range [lo,hi)
490 * to lowercase if possible. Other elements remain untouched.
491 *
492 * do_tolower() is a hook for a derived facet to change the behavior of
493 * lowercasing. do_tolower() must always return the same result for
494 * the same input.
495 *
496 * @param lo Pointer to start of range.
497 * @param hi Pointer to end of range.
498 * @return @a hi.
499 */
500 virtual const char_type*
501 do_tolower(char_type* __lo, const char_type* __hi) const = 0;
502
503 /**
504 * @brief Widen char
505 *
506 * This virtual function converts the char to char_type using the
507 * simplest reasonable transformation.
508 *
509 * do_widen() is a hook for a derived facet to change the behavior of
510 * widening. do_widen() must always return the same result for the
511 * same input.
512 *
513 * Note: this is not what you want for codepage conversions. See
514 * codecvt for that.
515 *
516 * @param c The char to convert.
517 * @return The converted char_type
518 */
519 virtual char_type
520 do_widen(char) const = 0;
521
522 /**
523 * @brief Widen char array
524 *
525 * This function converts each char in the input to char_type using the
526 * simplest reasonable transformation.
527 *
528 * do_widen() is a hook for a derived facet to change the behavior of
529 * widening. do_widen() must always return the same result for the
530 * same input.
531 *
532 * Note: this is not what you want for codepage conversions. See
533 * codecvt for that.
534 *
535 * @param lo Pointer to start range.
536 * @param hi Pointer to end of range.
537 * @param to Pointer to the destination array.
538 * @return @a hi.
539 */
540 virtual const char*
541 do_widen(const char* __lo, const char* __hi,
542 char_type* __dest) const = 0;
543
544 /**
545 * @brief Narrow char_type to char
546 *
547 * This virtual function converts the argument to char using the
548 * simplest reasonable transformation. If the conversion fails, dfault
549 * is returned instead.
550 *
551 * do_narrow() is a hook for a derived facet to change the behavior of
552 * narrowing. do_narrow() must always return the same result for the
553 * same input.
554 *
555 * Note: this is not what you want for codepage conversions. See
556 * codecvt for that.
557 *
558 * @param c The char_type to convert.
559 * @param dfault Char to return if conversion fails.
560 * @return The converted char.
561 */
562 virtual char
563 do_narrow(char_type, char __dfault) const = 0;
564
565 /**
566 * @brief Narrow char_type array to char
567 *
568 * This virtual function converts each char_type in the range [lo,hi) to
569 * char using the simplest reasonable transformation and writes the
570 * results to the destination array. For any element in the input that
571 * cannot be converted, @a dfault is used instead.
572 *
573 * do_narrow() is a hook for a derived facet to change the behavior of
574 * narrowing. do_narrow() must always return the same result for the
575 * same input.
576 *
577 * Note: this is not what you want for codepage conversions. See
578 * codecvt for that.
579 *
580 * @param lo Pointer to start of range.
581 * @param hi Pointer to end of range.
582 * @param dfault Char to use if conversion fails.
583 * @param to Pointer to the destination array.
584 * @return @a hi.
585 */
586 virtual const char_type*
587 do_narrow(const char_type* __lo, const char_type* __hi,
588 char __dfault, char* __dest) const = 0;
589 };
590
591 // NB: Generic, mostly useless implementation.
592 /**
593 * @brief Template ctype facet
594 *
595 * This template class defines classification and conversion functions for
596 * character sets. It wraps <cctype> functionality. Ctype gets used by
597 * streams for many I/O operations.
598 *
599 * This template provides the protected virtual functions the developer
600 * will have to replace in a derived class or specialization to make a
601 * working facet. The public functions that access them are defined in
602 * __ctype_abstract_base, to allow for implementation flexibility. See
603 * ctype<wchar_t> for an example. The functions are documented in
604 * __ctype_abstract_base.
605 *
606 * Note: implementations are provided for all the protected virtual
607 * functions, but will likely not be useful.
608 */
609 template<typename _CharT>
610 class ctype : public __ctype_abstract_base<_CharT>
611 {
612 public:
613 // Types:
614 typedef _CharT char_type;
615 typedef typename __ctype_abstract_base<_CharT>::mask mask;
616
617 /// The facet id for ctype<char_type>
618 static locale::id id;
619
620 explicit
621 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
622
623 protected:
624 virtual
625 ~ctype();
626
627 virtual bool
628 do_is(mask __m, char_type __c) const;
629
630 virtual const char_type*
631 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
632
633 virtual const char_type*
634 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
635
636 virtual const char_type*
637 do_scan_not(mask __m, const char_type* __lo,
638 const char_type* __hi) const;
639
640 virtual char_type
641 do_toupper(char_type __c) const;
642
643 virtual const char_type*
644 do_toupper(char_type* __lo, const char_type* __hi) const;
645
646 virtual char_type
647 do_tolower(char_type __c) const;
648
649 virtual const char_type*
650 do_tolower(char_type* __lo, const char_type* __hi) const;
651
652 virtual char_type
653 do_widen(char __c) const;
654
655 virtual const char*
656 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
657
658 virtual char
659 do_narrow(char_type, char __dfault) const;
660
661 virtual const char_type*
662 do_narrow(const char_type* __lo, const char_type* __hi,
663 char __dfault, char* __dest) const;
664 };
665
666 template<typename _CharT>
667 locale::id ctype<_CharT>::id;
668
669 // 22.2.1.3 ctype<char> specialization.
670 /**
671 * @brief The ctype<char> specialization.
672 *
673 * This class defines classification and conversion functions for
674 * the char type. It gets used by char streams for many I/O
675 * operations. The char specialization provides a number of
676 * optimizations as well.
677 */
678 template<>
679 class ctype<char> : public locale::facet, public ctype_base
680 {
681 public:
682 // Types:
683 /// Typedef for the template parameter char.
684 typedef char char_type;
685
686 protected:
687 // Data Members:
688 __c_locale _M_c_locale_ctype;
689 bool _M_del;
690 __to_type _M_toupper;
691 __to_type _M_tolower;
692 const mask* _M_table;
693 mutable char _M_widen_ok;
694 mutable char _M_widen[1 + static_cast<unsigned char>(-1)];
695 mutable char _M_narrow[1 + static_cast<unsigned char>(-1)];
696 mutable char _M_narrow_ok; // 0 uninitialized, 1 init,
697 // 2 memcpy can't be used
698
699 public:
700 /// The facet id for ctype<char>
701 static locale::id id;
702 /// The size of the mask table. It is SCHAR_MAX + 1.
703 static const size_t table_size = 1 + static_cast<unsigned char>(-1);
704
705 /**
706 * @brief Constructor performs initialization.
707 *
708 * This is the constructor provided by the standard.
709 *
710 * @param table If non-zero, table is used as the per-char mask.
711 * Else classic_table() is used.
712 * @param del If true, passes ownership of table to this facet.
713 * @param refs Passed to the base facet class.
714 */
715 explicit
716 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
717
718 /**
719 * @brief Constructor performs static initialization.
720 *
721 * This constructor is used to construct the initial C locale facet.
722 *
723 * @param cloc Handle to C locale data.
724 * @param table If non-zero, table is used as the per-char mask.
725 * @param del If true, passes ownership of table to this facet.
726 * @param refs Passed to the base facet class.
727 */
728 explicit
729 ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
730 size_t __refs = 0);
731
732 /**
733 * @brief Test char classification.
734 *
735 * This function compares the mask table[c] to @a m.
736 *
737 * @param c The char to compare the mask of.
738 * @param m The mask to compare against.
739 * @return True if m & table[c] is true, false otherwise.
740 */
741 inline bool
742 is(mask __m, char __c) const;
743
744 /**
745 * @brief Return a mask array.
746 *
747 * This function finds the mask for each char in the range [lo, hi) and
748 * successively writes it to vec. vec must have as many elements as
749 * the char array.
750 *
751 * @param lo Pointer to start of range.
752 * @param hi Pointer to end of range.
753 * @param vec Pointer to an array of mask storage.
754 * @return @a hi.
755 */
756 inline const char*
757 is(const char* __lo, const char* __hi, mask* __vec) const;
758
759 /**
760 * @brief Find char matching a mask
761 *
762 * This function searches for and returns the first char in [lo,hi) for
763 * which is(m,char) is true.
764 *
765 * @param m The mask to compare against.
766 * @param lo Pointer to start of range.
767 * @param hi Pointer to end of range.
768 * @return Pointer to a matching char if found, else @a hi.
769 */
770 inline const char*
771 scan_is(mask __m, const char* __lo, const char* __hi) const;
772
773 /**
774 * @brief Find char not matching a mask
775 *
776 * This function searches for and returns a pointer to the first char
777 * in [lo,hi) for which is(m,char) is false.
778 *
779 * @param m The mask to compare against.
780 * @param lo Pointer to start of range.
781 * @param hi Pointer to end of range.
782 * @return Pointer to a non-matching char if found, else @a hi.
783 */
784 inline const char*
785 scan_not(mask __m, const char* __lo, const char* __hi) const;
786
787 /**
788 * @brief Convert to uppercase.
789 *
790 * This function converts the char argument to uppercase if possible.
791 * If not possible (for example, '2'), returns the argument.
792 *
793 * toupper() acts as if it returns ctype<char>::do_toupper(c).
794 * do_toupper() must always return the same result for the same input.
795 *
796 * @param c The char to convert.
797 * @return The uppercase char if convertible, else @a c.
798 */
799 char_type
800 toupper(char_type __c) const
801 { return this->do_toupper(__c); }
802
803 /**
804 * @brief Convert array to uppercase.
805 *
806 * This function converts each char in the range [lo,hi) to uppercase
807 * if possible. Other chars remain untouched.
808 *
809 * toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi).
810 * do_toupper() must always return the same result for the same input.
811 *
812 * @param lo Pointer to first char in range.
813 * @param hi Pointer to end of range.
814 * @return @a hi.
815 */
816 const char_type*
817 toupper(char_type *__lo, const char_type* __hi) const
818 { return this->do_toupper(__lo, __hi); }
819
820 /**
821 * @brief Convert to lowercase.
822 *
823 * This function converts the char argument to lowercase if possible.
824 * If not possible (for example, '2'), returns the argument.
825 *
826 * tolower() acts as if it returns ctype<char>::do_tolower(c).
827 * do_tolower() must always return the same result for the same input.
828 *
829 * @param c The char to convert.
830 * @return The lowercase char if convertible, else @a c.
831 */
832 char_type
833 tolower(char_type __c) const
834 { return this->do_tolower(__c); }
835
836 /**
837 * @brief Convert array to lowercase.
838 *
839 * This function converts each char in the range [lo,hi) to lowercase
840 * if possible. Other chars remain untouched.
841 *
842 * tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi).
843 * do_tolower() must always return the same result for the same input.
844 *
845 * @param lo Pointer to first char in range.
846 * @param hi Pointer to end of range.
847 * @return @a hi.
848 */
849 const char_type*
850 tolower(char_type* __lo, const char_type* __hi) const
851 { return this->do_tolower(__lo, __hi); }
852
853 /**
854 * @brief Widen char
855 *
856 * This function converts the char to char_type using the simplest
857 * reasonable transformation. For an underived ctype<char> facet, the
858 * argument will be returned unchanged.
859 *
860 * This function works as if it returns ctype<char>::do_widen(c).
861 * do_widen() must always return the same result for the same input.
862 *
863 * Note: this is not what you want for codepage conversions. See
864 * codecvt for that.
865 *
866 * @param c The char to convert.
867 * @return The converted character.
868 */
869 char_type
870 widen(char __c) const
871 {
872 if (_M_widen_ok)
873 return _M_widen[static_cast<unsigned char>(__c)];
874 this->_M_widen_init();
875 return this->do_widen(__c);
876 }
877
878 /**
879 * @brief Widen char array
880 *
881 * This function converts each char in the input to char using the
882 * simplest reasonable transformation. For an underived ctype<char>
883 * facet, the argument will be copied unchanged.
884 *
885 * This function works as if it returns ctype<char>::do_widen(c).
886 * do_widen() must always return the same result for the same input.
887 *
888 * Note: this is not what you want for codepage conversions. See
889 * codecvt for that.
890 *
891 * @param lo Pointer to first char in range.
892 * @param hi Pointer to end of range.
893 * @param to Pointer to the destination array.
894 * @return @a hi.
895 */
896 const char*
897 widen(const char* __lo, const char* __hi, char_type* __to) const
898 {
899 if (_M_widen_ok == 1)
900 {
901 __builtin_memcpy(__to, __lo, __hi - __lo);
902 return __hi;
903 }
904 if (!_M_widen_ok)
905 _M_widen_init();
906 return this->do_widen(__lo, __hi, __to);
907 }
908
909 /**
910 * @brief Narrow char
911 *
912 * This function converts the char to char using the simplest
913 * reasonable transformation. If the conversion fails, dfault is
914 * returned instead. For an underived ctype<char> facet, @a c
915 * will be returned unchanged.
916 *
917 * This function works as if it returns ctype<char>::do_narrow(c).
918 * do_narrow() must always return the same result for the same input.
919 *
920 * Note: this is not what you want for codepage conversions. See
921 * codecvt for that.
922 *
923 * @param c The char to convert.
924 * @param dfault Char to return if conversion fails.
925 * @return The converted character.
926 */
927 char
928 narrow(char_type __c, char __dfault) const
929 {
930 if (_M_narrow[static_cast<unsigned char>(__c)])
931 return _M_narrow[static_cast<unsigned char>(__c)];
932 const char __t = do_narrow(__c, __dfault);
933 if (__t != __dfault)
934 _M_narrow[static_cast<unsigned char>(__c)] = __t;
935 return __t;
936 }
937
938 /**
939 * @brief Narrow char array
940 *
941 * This function converts each char in the input to char using the
942 * simplest reasonable transformation and writes the results to the
943 * destination array. For any char in the input that cannot be
944 * converted, @a dfault is used instead. For an underived ctype<char>
945 * facet, the argument will be copied unchanged.
946 *
947 * This function works as if it returns ctype<char>::do_narrow(lo, hi,
948 * dfault, to). do_narrow() must always return the same result for the
949 * same input.
950 *
951 * Note: this is not what you want for codepage conversions. See
952 * codecvt for that.
953 *
954 * @param lo Pointer to start of range.
955 * @param hi Pointer to end of range.
956 * @param dfault Char to use if conversion fails.
957 * @param to Pointer to the destination array.
958 * @return @a hi.
959 */
960 const char_type*
961 narrow(const char_type* __lo, const char_type* __hi,
962 char __dfault, char *__to) const
963 {
964 if (__builtin_expect(_M_narrow_ok == 1, true))
965 {
966 __builtin_memcpy(__to, __lo, __hi - __lo);
967 return __hi;
968 }
969 if (!_M_narrow_ok)
970 _M_narrow_init();
971 return this->do_narrow(__lo, __hi, __dfault, __to);
972 }
973
974 // _GLIBCXX_RESOLVE_LIB_DEFECTS
975 // DR 695. ctype<char>::classic_table() not accessible.
976 /// Returns a pointer to the mask table provided to the constructor, or
977 /// the default from classic_table() if none was provided.
978 const mask*
979 table() const throw()
980 { return _M_table; }
981
982 /// Returns a pointer to the C locale mask table.
983 static const mask*
984 classic_table() throw();
985 protected:
986
987 /**
988 * @brief Destructor.
989 *
990 * This function deletes table() if @a del was true in the
991 * constructor.
992 */
993 virtual
994 ~ctype();
995
996 /**
997 * @brief Convert to uppercase.
998 *
999 * This virtual function converts the char argument to uppercase if
1000 * possible. If not possible (for example, '2'), returns the argument.
1001 *
1002 * do_toupper() is a hook for a derived facet to change the behavior of
1003 * uppercasing. do_toupper() must always return the same result for
1004 * the same input.
1005 *
1006 * @param c The char to convert.
1007 * @return The uppercase char if convertible, else @a c.
1008 */
1009 virtual char_type
1010 do_toupper(char_type) const;
1011
1012 /**
1013 * @brief Convert array to uppercase.
1014 *
1015 * This virtual function converts each char in the range [lo,hi) to
1016 * uppercase if possible. Other chars remain untouched.
1017 *
1018 * do_toupper() is a hook for a derived facet to change the behavior of
1019 * uppercasing. do_toupper() must always return the same result for
1020 * the same input.
1021 *
1022 * @param lo Pointer to start of range.
1023 * @param hi Pointer to end of range.
1024 * @return @a hi.
1025 */
1026 virtual const char_type*
1027 do_toupper(char_type* __lo, const char_type* __hi) const;
1028
1029 /**
1030 * @brief Convert to lowercase.
1031 *
1032 * This virtual function converts the char argument to lowercase if
1033 * possible. If not possible (for example, '2'), returns the argument.
1034 *
1035 * do_tolower() is a hook for a derived facet to change the behavior of
1036 * lowercasing. do_tolower() must always return the same result for
1037 * the same input.
1038 *
1039 * @param c The char to convert.
1040 * @return The lowercase char if convertible, else @a c.
1041 */
1042 virtual char_type
1043 do_tolower(char_type) const;
1044
1045 /**
1046 * @brief Convert array to lowercase.
1047 *
1048 * This virtual function converts each char in the range [lo,hi) to
1049 * lowercase if possible. Other chars remain untouched.
1050 *
1051 * do_tolower() is a hook for a derived facet to change the behavior of
1052 * lowercasing. do_tolower() must always return the same result for
1053 * the same input.
1054 *
1055 * @param lo Pointer to first char in range.
1056 * @param hi Pointer to end of range.
1057 * @return @a hi.
1058 */
1059 virtual const char_type*
1060 do_tolower(char_type* __lo, const char_type* __hi) const;
1061
1062 /**
1063 * @brief Widen char
1064 *
1065 * This virtual function converts the char to char using the simplest
1066 * reasonable transformation. For an underived ctype<char> facet, the
1067 * argument will be returned unchanged.
1068 *
1069 * do_widen() is a hook for a derived facet to change the behavior of
1070 * widening. do_widen() must always return the same result for the
1071 * same input.
1072 *
1073 * Note: this is not what you want for codepage conversions. See
1074 * codecvt for that.
1075 *
1076 * @param c The char to convert.
1077 * @return The converted character.
1078 */
1079 virtual char_type
1080 do_widen(char __c) const
1081 { return __c; }
1082
1083 /**
1084 * @brief Widen char array
1085 *
1086 * This function converts each char in the range [lo,hi) to char using
1087 * the simplest reasonable transformation. For an underived
1088 * ctype<char> facet, the argument will be copied unchanged.
1089 *
1090 * do_widen() is a hook for a derived facet to change the behavior of
1091 * widening. do_widen() must always return the same result for the
1092 * same input.
1093 *
1094 * Note: this is not what you want for codepage conversions. See
1095 * codecvt for that.
1096 *
1097 * @param lo Pointer to start of range.
1098 * @param hi Pointer to end of range.
1099 * @param to Pointer to the destination array.
1100 * @return @a hi.
1101 */
1102 virtual const char*
1103 do_widen(const char* __lo, const char* __hi, char_type* __dest) const
1104 {
1105 __builtin_memcpy(__dest, __lo, __hi - __lo);
1106 return __hi;
1107 }
1108
1109 /**
1110 * @brief Narrow char
1111 *
1112 * This virtual function converts the char to char using the simplest
1113 * reasonable transformation. If the conversion fails, dfault is
1114 * returned instead. For an underived ctype<char> facet, @a c will be
1115 * returned unchanged.
1116 *
1117 * do_narrow() is a hook for a derived facet to change the behavior of
1118 * narrowing. do_narrow() must always return the same result for the
1119 * same input.
1120 *
1121 * Note: this is not what you want for codepage conversions. See
1122 * codecvt for that.
1123 *
1124 * @param c The char to convert.
1125 * @param dfault Char to return if conversion fails.
1126 * @return The converted char.
1127 */
1128 virtual char
1129 do_narrow(char_type __c, char) const
1130 { return __c; }
1131
1132 /**
1133 * @brief Narrow char array to char array
1134 *
1135 * This virtual function converts each char in the range [lo,hi) to
1136 * char using the simplest reasonable transformation and writes the
1137 * results to the destination array. For any char in the input that
1138 * cannot be converted, @a dfault is used instead. For an underived
1139 * ctype<char> facet, the argument will be copied unchanged.
1140 *
1141 * do_narrow() is a hook for a derived facet to change the behavior of
1142 * narrowing. do_narrow() must always return the same result for the
1143 * same input.
1144 *
1145 * Note: this is not what you want for codepage conversions. See
1146 * codecvt for that.
1147 *
1148 * @param lo Pointer to start of range.
1149 * @param hi Pointer to end of range.
1150 * @param dfault Char to use if conversion fails.
1151 * @param to Pointer to the destination array.
1152 * @return @a hi.
1153 */
1154 virtual const char_type*
1155 do_narrow(const char_type* __lo, const char_type* __hi,
1156 char, char* __dest) const
1157 {
1158 __builtin_memcpy(__dest, __lo, __hi - __lo);
1159 return __hi;
1160 }
1161
1162 private:
1163 void _M_narrow_init() const;
1164 void _M_widen_init() const;
1165 };
1166
1167 #ifdef _GLIBCXX_USE_WCHAR_T
1168 // 22.2.1.3 ctype<wchar_t> specialization
1169 /**
1170 * @brief The ctype<wchar_t> specialization.
1171 *
1172 * This class defines classification and conversion functions for the
1173 * wchar_t type. It gets used by wchar_t streams for many I/O operations.
1174 * The wchar_t specialization provides a number of optimizations as well.
1175 *
1176 * ctype<wchar_t> inherits its public methods from
1177 * __ctype_abstract_base<wchar_t>.
1178 */
1179 template<>
1180 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
1181 {
1182 public:
1183 // Types:
1184 /// Typedef for the template parameter wchar_t.
1185 typedef wchar_t char_type;
1186 typedef wctype_t __wmask_type;
1187
1188 protected:
1189 __c_locale _M_c_locale_ctype;
1190
1191 // Pre-computed narrowed and widened chars.
1192 bool _M_narrow_ok;
1193 char _M_narrow[128];
1194 wint_t _M_widen[1 + static_cast<unsigned char>(-1)];
1195
1196 // Pre-computed elements for do_is.
1197 mask _M_bit[16];
1198 __wmask_type _M_wmask[16];
1199
1200 public:
1201 // Data Members:
1202 /// The facet id for ctype<wchar_t>
1203 static locale::id id;
1204
1205 /**
1206 * @brief Constructor performs initialization.
1207 *
1208 * This is the constructor provided by the standard.
1209 *
1210 * @param refs Passed to the base facet class.
1211 */
1212 explicit
1213 ctype(size_t __refs = 0);
1214
1215 /**
1216 * @brief Constructor performs static initialization.
1217 *
1218 * This constructor is used to construct the initial C locale facet.
1219 *
1220 * @param cloc Handle to C locale data.
1221 * @param refs Passed to the base facet class.
1222 */
1223 explicit
1224 ctype(__c_locale __cloc, size_t __refs = 0);
1225
1226 protected:
1227 __wmask_type
1228 _M_convert_to_wmask(const mask __m) const;
1229
1230 /// Destructor
1231 virtual
1232 ~ctype();
1233
1234 /**
1235 * @brief Test wchar_t classification.
1236 *
1237 * This function finds a mask M for @a c and compares it to mask @a m.
1238 *
1239 * do_is() is a hook for a derived facet to change the behavior of
1240 * classifying. do_is() must always return the same result for the
1241 * same input.
1242 *
1243 * @param c The wchar_t to find the mask of.
1244 * @param m The mask to compare against.
1245 * @return (M & m) != 0.
1246 */
1247 virtual bool
1248 do_is(mask __m, char_type __c) const;
1249
1250 /**
1251 * @brief Return a mask array.
1252 *
1253 * This function finds the mask for each wchar_t in the range [lo,hi)
1254 * and successively writes it to vec. vec must have as many elements
1255 * as the input.
1256 *
1257 * do_is() is a hook for a derived facet to change the behavior of
1258 * classifying. do_is() must always return the same result for the
1259 * same input.
1260 *
1261 * @param lo Pointer to start of range.
1262 * @param hi Pointer to end of range.
1263 * @param vec Pointer to an array of mask storage.
1264 * @return @a hi.
1265 */
1266 virtual const char_type*
1267 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
1268
1269 /**
1270 * @brief Find wchar_t matching mask
1271 *
1272 * This function searches for and returns the first wchar_t c in
1273 * [lo,hi) for which is(m,c) is true.
1274 *
1275 * do_scan_is() is a hook for a derived facet to change the behavior of
1276 * match searching. do_is() must always return the same result for the
1277 * same input.
1278 *
1279 * @param m The mask to compare against.
1280 * @param lo Pointer to start of range.
1281 * @param hi Pointer to end of range.
1282 * @return Pointer to a matching wchar_t if found, else @a hi.
1283 */
1284 virtual const char_type*
1285 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
1286
1287 /**
1288 * @brief Find wchar_t not matching mask
1289 *
1290 * This function searches for and returns a pointer to the first
1291 * wchar_t c of [lo,hi) for which is(m,c) is false.
1292 *
1293 * do_scan_is() is a hook for a derived facet to change the behavior of
1294 * match searching. do_is() must always return the same result for the
1295 * same input.
1296 *
1297 * @param m The mask to compare against.
1298 * @param lo Pointer to start of range.
1299 * @param hi Pointer to end of range.
1300 * @return Pointer to a non-matching wchar_t if found, else @a hi.
1301 */
1302 virtual const char_type*
1303 do_scan_not(mask __m, const char_type* __lo,
1304 const char_type* __hi) const;
1305
1306 /**
1307 * @brief Convert to uppercase.
1308 *
1309 * This virtual function converts the wchar_t argument to uppercase if
1310 * possible. If not possible (for example, '2'), returns the argument.
1311 *
1312 * do_toupper() is a hook for a derived facet to change the behavior of
1313 * uppercasing. do_toupper() must always return the same result for
1314 * the same input.
1315 *
1316 * @param c The wchar_t to convert.
1317 * @return The uppercase wchar_t if convertible, else @a c.
1318 */
1319 virtual char_type
1320 do_toupper(char_type) const;
1321
1322 /**
1323 * @brief Convert array to uppercase.
1324 *
1325 * This virtual function converts each wchar_t in the range [lo,hi) to
1326 * uppercase if possible. Other elements remain untouched.
1327 *
1328 * do_toupper() is a hook for a derived facet to change the behavior of
1329 * uppercasing. do_toupper() must always return the same result for
1330 * the same input.
1331 *
1332 * @param lo Pointer to start of range.
1333 * @param hi Pointer to end of range.
1334 * @return @a hi.
1335 */
1336 virtual const char_type*
1337 do_toupper(char_type* __lo, const char_type* __hi) const;
1338
1339 /**
1340 * @brief Convert to lowercase.
1341 *
1342 * This virtual function converts the argument to lowercase if
1343 * possible. If not possible (for example, '2'), returns the argument.
1344 *
1345 * do_tolower() is a hook for a derived facet to change the behavior of
1346 * lowercasing. do_tolower() must always return the same result for
1347 * the same input.
1348 *
1349 * @param c The wchar_t to convert.
1350 * @return The lowercase wchar_t if convertible, else @a c.
1351 */
1352 virtual char_type
1353 do_tolower(char_type) const;
1354
1355 /**
1356 * @brief Convert array to lowercase.
1357 *
1358 * This virtual function converts each wchar_t in the range [lo,hi) to
1359 * lowercase if possible. Other elements remain untouched.
1360 *
1361 * do_tolower() is a hook for a derived facet to change the behavior of
1362 * lowercasing. do_tolower() must always return the same result for
1363 * the same input.
1364 *
1365 * @param lo Pointer to start of range.
1366 * @param hi Pointer to end of range.
1367 * @return @a hi.
1368 */
1369 virtual const char_type*
1370 do_tolower(char_type* __lo, const char_type* __hi) const;
1371
1372 /**
1373 * @brief Widen char to wchar_t
1374 *
1375 * This virtual function converts the char to wchar_t using the
1376 * simplest reasonable transformation. For an underived ctype<wchar_t>
1377 * facet, the argument will be cast to wchar_t.
1378 *
1379 * do_widen() is a hook for a derived facet to change the behavior of
1380 * widening. do_widen() must always return the same result for the
1381 * same input.
1382 *
1383 * Note: this is not what you want for codepage conversions. See
1384 * codecvt for that.
1385 *
1386 * @param c The char to convert.
1387 * @return The converted wchar_t.
1388 */
1389 virtual char_type
1390 do_widen(char) const;
1391
1392 /**
1393 * @brief Widen char array to wchar_t array
1394 *
1395 * This function converts each char in the input to wchar_t using the
1396 * simplest reasonable transformation. For an underived ctype<wchar_t>
1397 * facet, the argument will be copied, casting each element to wchar_t.
1398 *
1399 * do_widen() is a hook for a derived facet to change the behavior of
1400 * widening. do_widen() must always return the same result for the
1401 * same input.
1402 *
1403 * Note: this is not what you want for codepage conversions. See
1404 * codecvt for that.
1405 *
1406 * @param lo Pointer to start range.
1407 * @param hi Pointer to end of range.
1408 * @param to Pointer to the destination array.
1409 * @return @a hi.
1410 */
1411 virtual const char*
1412 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
1413
1414 /**
1415 * @brief Narrow wchar_t to char
1416 *
1417 * This virtual function converts the argument to char using
1418 * the simplest reasonable transformation. If the conversion
1419 * fails, dfault is returned instead. For an underived
1420 * ctype<wchar_t> facet, @a c will be cast to char and
1421 * returned.
1422 *
1423 * do_narrow() is a hook for a derived facet to change the
1424 * behavior of narrowing. do_narrow() must always return the
1425 * same result for the same input.
1426 *
1427 * Note: this is not what you want for codepage conversions. See
1428 * codecvt for that.
1429 *
1430 * @param c The wchar_t to convert.
1431 * @param dfault Char to return if conversion fails.
1432 * @return The converted char.
1433 */
1434 virtual char
1435 do_narrow(char_type, char __dfault) const;
1436
1437 /**
1438 * @brief Narrow wchar_t array to char array
1439 *
1440 * This virtual function converts each wchar_t in the range [lo,hi) to
1441 * char using the simplest reasonable transformation and writes the
1442 * results to the destination array. For any wchar_t in the input that
1443 * cannot be converted, @a dfault is used instead. For an underived
1444 * ctype<wchar_t> facet, the argument will be copied, casting each
1445 * element to char.
1446 *
1447 * do_narrow() is a hook for a derived facet to change the behavior of
1448 * narrowing. do_narrow() must always return the same result for the
1449 * same input.
1450 *
1451 * Note: this is not what you want for codepage conversions. See
1452 * codecvt for that.
1453 *
1454 * @param lo Pointer to start of range.
1455 * @param hi Pointer to end of range.
1456 * @param dfault Char to use if conversion fails.
1457 * @param to Pointer to the destination array.
1458 * @return @a hi.
1459 */
1460 virtual const char_type*
1461 do_narrow(const char_type* __lo, const char_type* __hi,
1462 char __dfault, char* __dest) const;
1463
1464 // For use at construction time only.
1465 void
1466 _M_initialize_ctype();
1467 };
1468 #endif //_GLIBCXX_USE_WCHAR_T
1469
1470 /// class ctype_byname [22.2.1.2].
1471 template<typename _CharT>
1472 class ctype_byname : public ctype<_CharT>
1473 {
1474 public:
1475 typedef typename ctype<_CharT>::mask mask;
1476
1477 explicit
1478 ctype_byname(const char* __s, size_t __refs = 0);
1479
1480 protected:
1481 virtual
1482 ~ctype_byname() { };
1483 };
1484
1485 /// 22.2.1.4 Class ctype_byname specializations.
1486 template<>
1487 class ctype_byname<char> : public ctype<char>
1488 {
1489 public:
1490 explicit
1491 ctype_byname(const char* __s, size_t __refs = 0);
1492
1493 protected:
1494 virtual
1495 ~ctype_byname();
1496 };
1497
1498 #ifdef _GLIBCXX_USE_WCHAR_T
1499 template<>
1500 class ctype_byname<wchar_t> : public ctype<wchar_t>
1501 {
1502 public:
1503 explicit
1504 ctype_byname(const char* __s, size_t __refs = 0);
1505
1506 protected:
1507 virtual
1508 ~ctype_byname();
1509 };
1510 #endif
1511
1512 _GLIBCXX_END_NAMESPACE
1513
1514 // Include host and configuration specific ctype inlines.
1515 #include <bits/ctype_inline.h>
1516
1517 _GLIBCXX_BEGIN_NAMESPACE(std)
1518
1519 // 22.2.2 The numeric category.
1520 class __num_base
1521 {
1522 public:
1523 // NB: Code depends on the order of _S_atoms_out elements.
1524 // Below are the indices into _S_atoms_out.
1525 enum
1526 {
1527 _S_ominus,
1528 _S_oplus,
1529 _S_ox,
1530 _S_oX,
1531 _S_odigits,
1532 _S_odigits_end = _S_odigits + 16,
1533 _S_oudigits = _S_odigits_end,
1534 _S_oudigits_end = _S_oudigits + 16,
1535 _S_oe = _S_odigits + 14, // For scientific notation, 'e'
1536 _S_oE = _S_oudigits + 14, // For scientific notation, 'E'
1537 _S_oend = _S_oudigits_end
1538 };
1539
1540 // A list of valid numeric literals for output. This array
1541 // contains chars that will be passed through the current locale's
1542 // ctype<_CharT>.widen() and then used to render numbers.
1543 // For the standard "C" locale, this is
1544 // "-+xX0123456789abcdef0123456789ABCDEF".
1545 static const char* _S_atoms_out;
1546
1547 // String literal of acceptable (narrow) input, for num_get.
1548 // "-+xX0123456789abcdefABCDEF"
1549 static const char* _S_atoms_in;
1550
1551 enum
1552 {
1553 _S_iminus,
1554 _S_iplus,
1555 _S_ix,
1556 _S_iX,
1557 _S_izero,
1558 _S_ie = _S_izero + 14,
1559 _S_iE = _S_izero + 20,
1560 _S_iend = 26
1561 };
1562
1563 // num_put
1564 // Construct and return valid scanf format for floating point types.
1565 static void
1566 _S_format_float(const ios_base& __io, char* __fptr, char __mod);
1567 };
1568
1569 template<typename _CharT>
1570 struct __numpunct_cache : public locale::facet
1571 {
1572 const char* _M_grouping;
1573 size_t _M_grouping_size;
1574 bool _M_use_grouping;
1575 const _CharT* _M_truename;
1576 size_t _M_truename_size;
1577 const _CharT* _M_falsename;
1578 size_t _M_falsename_size;
1579 _CharT _M_decimal_point;
1580 _CharT _M_thousands_sep;
1581
1582 // A list of valid numeric literals for output: in the standard
1583 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1584 // This array contains the chars after having been passed
1585 // through the current locale's ctype<_CharT>.widen().
1586 _CharT _M_atoms_out[__num_base::_S_oend];
1587
1588 // A list of valid numeric literals for input: in the standard
1589 // "C" locale, this is "-+xX0123456789abcdefABCDEF"
1590 // This array contains the chars after having been passed
1591 // through the current locale's ctype<_CharT>.widen().
1592 _CharT _M_atoms_in[__num_base::_S_iend];
1593
1594 bool _M_allocated;
1595
1596 __numpunct_cache(size_t __refs = 0) : facet(__refs),
1597 _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
1598 _M_truename(NULL), _M_truename_size(0), _M_falsename(NULL),
1599 _M_falsename_size(0), _M_decimal_point(_CharT()),
1600 _M_thousands_sep(_CharT()), _M_allocated(false)
1601 { }
1602
1603 ~__numpunct_cache();
1604
1605 void
1606 _M_cache(const locale& __loc);
1607
1608 private:
1609 __numpunct_cache&
1610 operator=(const __numpunct_cache&);
1611
1612 explicit
1613 __numpunct_cache(const __numpunct_cache&);
1614 };
1615
1616 template<typename _CharT>
1617 __numpunct_cache<_CharT>::~__numpunct_cache()
1618 {
1619 if (_M_allocated)
1620 {
1621 delete [] _M_grouping;
1622 delete [] _M_truename;
1623 delete [] _M_falsename;
1624 }
1625 }
1626
1627 /**
1628 * @brief Numpunct facet.
1629 *
1630 * This facet stores several pieces of information related to printing and
1631 * scanning numbers, such as the decimal point character. It takes a
1632 * template parameter specifying the char type. The numpunct facet is
1633 * used by streams for many I/O operations involving numbers.
1634 *
1635 * The numpunct template uses protected virtual functions to provide the
1636 * actual results. The public accessors forward the call to the virtual
1637 * functions. These virtual functions are hooks for developers to
1638 * implement the behavior they require from a numpunct facet.
1639 */
1640 template<typename _CharT>
1641 class numpunct : public locale::facet
1642 {
1643 public:
1644 // Types:
1645 //@{
1646 /// Public typedefs
1647 typedef _CharT char_type;
1648 typedef basic_string<_CharT> string_type;
1649 //@}
1650 typedef __numpunct_cache<_CharT> __cache_type;
1651
1652 protected:
1653 __cache_type* _M_data;
1654
1655 public:
1656 /// Numpunct facet id.
1657 static locale::id id;
1658
1659 /**
1660 * @brief Numpunct constructor.
1661 *
1662 * @param refs Refcount to pass to the base class.
1663 */
1664 explicit
1665 numpunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
1666 { _M_initialize_numpunct(); }
1667
1668 /**
1669 * @brief Internal constructor. Not for general use.
1670 *
1671 * This is a constructor for use by the library itself to set up the
1672 * predefined locale facets.
1673 *
1674 * @param cache __numpunct_cache object.
1675 * @param refs Refcount to pass to the base class.
1676 */
1677 explicit
1678 numpunct(__cache_type* __cache, size_t __refs = 0)
1679 : facet(__refs), _M_data(__cache)
1680 { _M_initialize_numpunct(); }
1681
1682 /**
1683 * @brief Internal constructor. Not for general use.
1684 *
1685 * This is a constructor for use by the library itself to set up new
1686 * locales.
1687 *
1688 * @param cloc The "C" locale.
1689 * @param refs Refcount to pass to the base class.
1690 */
1691 explicit
1692 numpunct(__c_locale __cloc, size_t __refs = 0)
1693 : facet(__refs), _M_data(NULL)
1694 { _M_initialize_numpunct(__cloc); }
1695
1696 /**
1697 * @brief Return decimal point character.
1698 *
1699 * This function returns a char_type to use as a decimal point. It
1700 * does so by returning returning
1701 * numpunct<char_type>::do_decimal_point().
1702 *
1703 * @return @a char_type representing a decimal point.
1704 */
1705 char_type
1706 decimal_point() const
1707 { return this->do_decimal_point(); }
1708
1709 /**
1710 * @brief Return thousands separator character.
1711 *
1712 * This function returns a char_type to use as a thousands
1713 * separator. It does so by returning returning
1714 * numpunct<char_type>::do_thousands_sep().
1715 *
1716 * @return char_type representing a thousands separator.
1717 */
1718 char_type
1719 thousands_sep() const
1720 { return this->do_thousands_sep(); }
1721
1722 /**
1723 * @brief Return grouping specification.
1724 *
1725 * This function returns a string representing groupings for the
1726 * integer part of a number. Groupings indicate where thousands
1727 * separators should be inserted in the integer part of a number.
1728 *
1729 * Each char in the return string is interpret as an integer
1730 * rather than a character. These numbers represent the number
1731 * of digits in a group. The first char in the string
1732 * represents the number of digits in the least significant
1733 * group. If a char is negative, it indicates an unlimited
1734 * number of digits for the group. If more chars from the
1735 * string are required to group a number, the last char is used
1736 * repeatedly.
1737 *
1738 * For example, if the grouping() returns "\003\002" and is
1739 * applied to the number 123456789, this corresponds to
1740 * 12,34,56,789. Note that if the string was "32", this would
1741 * put more than 50 digits into the least significant group if
1742 * the character set is ASCII.
1743 *
1744 * The string is returned by calling
1745 * numpunct<char_type>::do_grouping().
1746 *
1747 * @return string representing grouping specification.
1748 */
1749 string
1750 grouping() const
1751 { return this->do_grouping(); }
1752
1753 /**
1754 * @brief Return string representation of bool true.
1755 *
1756 * This function returns a string_type containing the text
1757 * representation for true bool variables. It does so by calling
1758 * numpunct<char_type>::do_truename().
1759 *
1760 * @return string_type representing printed form of true.
1761 */
1762 string_type
1763 truename() const
1764 { return this->do_truename(); }
1765
1766 /**
1767 * @brief Return string representation of bool false.
1768 *
1769 * This function returns a string_type containing the text
1770 * representation for false bool variables. It does so by calling
1771 * numpunct<char_type>::do_falsename().
1772 *
1773 * @return string_type representing printed form of false.
1774 */
1775 string_type
1776 falsename() const
1777 { return this->do_falsename(); }
1778
1779 protected:
1780 /// Destructor.
1781 virtual
1782 ~numpunct();
1783
1784 /**
1785 * @brief Return decimal point character.
1786 *
1787 * Returns a char_type to use as a decimal point. This function is a
1788 * hook for derived classes to change the value returned.
1789 *
1790 * @return @a char_type representing a decimal point.
1791 */
1792 virtual char_type
1793 do_decimal_point() const
1794 { return _M_data->_M_decimal_point; }
1795
1796 /**
1797 * @brief Return thousands separator character.
1798 *
1799 * Returns a char_type to use as a thousands separator. This function
1800 * is a hook for derived classes to change the value returned.
1801 *
1802 * @return @a char_type representing a thousands separator.
1803 */
1804 virtual char_type
1805 do_thousands_sep() const
1806 { return _M_data->_M_thousands_sep; }
1807
1808 /**
1809 * @brief Return grouping specification.
1810 *
1811 * Returns a string representing groupings for the integer part of a
1812 * number. This function is a hook for derived classes to change the
1813 * value returned. @see grouping() for details.
1814 *
1815 * @return String representing grouping specification.
1816 */
1817 virtual string
1818 do_grouping() const
1819 { return _M_data->_M_grouping; }
1820
1821 /**
1822 * @brief Return string representation of bool true.
1823 *
1824 * Returns a string_type containing the text representation for true
1825 * bool variables. This function is a hook for derived classes to
1826 * change the value returned.
1827 *
1828 * @return string_type representing printed form of true.
1829 */
1830 virtual string_type
1831 do_truename() const
1832 { return _M_data->_M_truename; }
1833
1834 /**
1835 * @brief Return string representation of bool false.
1836 *
1837 * Returns a string_type containing the text representation for false
1838 * bool variables. This function is a hook for derived classes to
1839 * change the value returned.
1840 *
1841 * @return string_type representing printed form of false.
1842 */
1843 virtual string_type
1844 do_falsename() const
1845 { return _M_data->_M_falsename; }
1846
1847 // For use at construction time only.
1848 void
1849 _M_initialize_numpunct(__c_locale __cloc = NULL);
1850 };
1851
1852 template<typename _CharT>
1853 locale::id numpunct<_CharT>::id;
1854
1855 template<>
1856 numpunct<char>::~numpunct();
1857
1858 template<>
1859 void
1860 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
1861
1862 #ifdef _GLIBCXX_USE_WCHAR_T
1863 template<>
1864 numpunct<wchar_t>::~numpunct();
1865
1866 template<>
1867 void
1868 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
1869 #endif
1870
1871 /// class numpunct_byname [22.2.3.2].
1872 template<typename _CharT>
1873 class numpunct_byname : public numpunct<_CharT>
1874 {
1875 public:
1876 typedef _CharT char_type;
1877 typedef basic_string<_CharT> string_type;
1878
1879 explicit
1880 numpunct_byname(const char* __s, size_t __refs = 0)
1881 : numpunct<_CharT>(__refs)
1882 {
1883 if (__builtin_strcmp(__s, "C") != 0
1884 && __builtin_strcmp(__s, "POSIX") != 0)
1885 {
1886 __c_locale __tmp;
1887 this->_S_create_c_locale(__tmp, __s);
1888 this->_M_initialize_numpunct(__tmp);
1889 this->_S_destroy_c_locale(__tmp);
1890 }
1891 }
1892
1893 protected:
1894 virtual
1895 ~numpunct_byname() { }
1896 };
1897
1898 _GLIBCXX_BEGIN_LDBL_NAMESPACE
1899
1900 /**
1901 * @brief Facet for parsing number strings.
1902 *
1903 * This facet encapsulates the code to parse and return a number
1904 * from a string. It is used by the istream numeric extraction
1905 * operators.
1906 *
1907 * The num_get template uses protected virtual functions to provide the
1908 * actual results. The public accessors forward the call to the virtual
1909 * functions. These virtual functions are hooks for developers to
1910 * implement the behavior they require from the num_get facet.
1911 */
1912 template<typename _CharT, typename _InIter>
1913 class num_get : public locale::facet
1914 {
1915 public:
1916 // Types:
1917 //@{
1918 /// Public typedefs
1919 typedef _CharT char_type;
1920 typedef _InIter iter_type;
1921 //@}
1922
1923 /// Numpunct facet id.
1924 static locale::id id;
1925
1926 /**
1927 * @brief Constructor performs initialization.
1928 *
1929 * This is the constructor provided by the standard.
1930 *
1931 * @param refs Passed to the base facet class.
1932 */
1933 explicit
1934 num_get(size_t __refs = 0) : facet(__refs) { }
1935
1936 /**
1937 * @brief Numeric parsing.
1938 *
1939 * Parses the input stream into the bool @a v. It does so by calling
1940 * num_get::do_get().
1941 *
1942 * If ios_base::boolalpha is set, attempts to read
1943 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
1944 * @a v to true or false if successful. Sets err to
1945 * ios_base::failbit if reading the string fails. Sets err to
1946 * ios_base::eofbit if the stream is emptied.
1947 *
1948 * If ios_base::boolalpha is not set, proceeds as with reading a long,
1949 * except if the value is 1, sets @a v to true, if the value is 0, sets
1950 * @a v to false, and otherwise set err to ios_base::failbit.
1951 *
1952 * @param in Start of input stream.
1953 * @param end End of input stream.
1954 * @param io Source of locale and flags.
1955 * @param err Error flags to set.
1956 * @param v Value to format and insert.
1957 * @return Iterator after reading.
1958 */
1959 iter_type
1960 get(iter_type __in, iter_type __end, ios_base& __io,
1961 ios_base::iostate& __err, bool& __v) const
1962 { return this->do_get(__in, __end, __io, __err, __v); }
1963
1964 //@{
1965 /**
1966 * @brief Numeric parsing.
1967 *
1968 * Parses the input stream into the integral variable @a v. It does so
1969 * by calling num_get::do_get().
1970 *
1971 * Parsing is affected by the flag settings in @a io.
1972 *
1973 * The basic parse is affected by the value of io.flags() &
1974 * ios_base::basefield. If equal to ios_base::oct, parses like the
1975 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X
1976 * specifier. Else if basefield equal to 0, parses like the %i
1977 * specifier. Otherwise, parses like %d for signed and %u for unsigned
1978 * types. The matching type length modifier is also used.
1979 *
1980 * Digit grouping is interpreted according to numpunct::grouping() and
1981 * numpunct::thousands_sep(). If the pattern of digit groups isn't
1982 * consistent, sets err to ios_base::failbit.
1983 *
1984 * If parsing the string yields a valid value for @a v, @a v is set.
1985 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
1986 * Sets err to ios_base::eofbit if the stream is emptied.
1987 *
1988 * @param in Start of input stream.
1989 * @param end End of input stream.
1990 * @param io Source of locale and flags.
1991 * @param err Error flags to set.
1992 * @param v Value to format and insert.
1993 * @return Iterator after reading.
1994 */
1995 iter_type
1996 get(iter_type __in, iter_type __end, ios_base& __io,
1997 ios_base::iostate& __err, long& __v) const
1998 { return this->do_get(__in, __end, __io, __err, __v); }
1999
2000 iter_type
2001 get(iter_type __in, iter_type __end, ios_base& __io,
2002 ios_base::iostate& __err, unsigned short& __v) const
2003 { return this->do_get(__in, __end, __io, __err, __v); }
2004
2005 iter_type
2006 get(iter_type __in, iter_type __end, ios_base& __io,
2007 ios_base::iostate& __err, unsigned int& __v) const
2008 { return this->do_get(__in, __end, __io, __err, __v); }
2009
2010 iter_type
2011 get(iter_type __in, iter_type __end, ios_base& __io,
2012 ios_base::iostate& __err, unsigned long& __v) const
2013 { return this->do_get(__in, __end, __io, __err, __v); }
2014
2015 #ifdef _GLIBCXX_USE_LONG_LONG
2016 iter_type
2017 get(iter_type __in, iter_type __end, ios_base& __io,
2018 ios_base::iostate& __err, long long& __v) const
2019 { return this->do_get(__in, __end, __io, __err, __v); }
2020
2021 iter_type
2022 get(iter_type __in, iter_type __end, ios_base& __io,
2023 ios_base::iostate& __err, unsigned long long& __v) const
2024 { return this->do_get(__in, __end, __io, __err, __v); }
2025 #endif
2026 //@}
2027
2028 //@{
2029 /**
2030 * @brief Numeric parsing.
2031 *
2032 * Parses the input stream into the integral variable @a v. It does so
2033 * by calling num_get::do_get().
2034 *
2035 * The input characters are parsed like the scanf %g specifier. The
2036 * matching type length modifier is also used.
2037 *
2038 * The decimal point character used is numpunct::decimal_point().
2039 * Digit grouping is interpreted according to numpunct::grouping() and
2040 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2041 * consistent, sets err to ios_base::failbit.
2042 *
2043 * If parsing the string yields a valid value for @a v, @a v is set.
2044 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2045 * Sets err to ios_base::eofbit if the stream is emptied.
2046 *
2047 * @param in Start of input stream.
2048 * @param end End of input stream.
2049 * @param io Source of locale and flags.
2050 * @param err Error flags to set.
2051 * @param v Value to format and insert.
2052 * @return Iterator after reading.
2053 */
2054 iter_type
2055 get(iter_type __in, iter_type __end, ios_base& __io,
2056 ios_base::iostate& __err, float& __v) const
2057 { return this->do_get(__in, __end, __io, __err, __v); }
2058
2059 iter_type
2060 get(iter_type __in, iter_type __end, ios_base& __io,
2061 ios_base::iostate& __err, double& __v) const
2062 { return this->do_get(__in, __end, __io, __err, __v); }
2063
2064 iter_type
2065 get(iter_type __in, iter_type __end, ios_base& __io,
2066 ios_base::iostate& __err, long double& __v) const
2067 { return this->do_get(__in, __end, __io, __err, __v); }
2068 //@}
2069
2070 /**
2071 * @brief Numeric parsing.
2072 *
2073 * Parses the input stream into the pointer variable @a v. It does so
2074 * by calling num_get::do_get().
2075 *
2076 * The input characters are parsed like the scanf %p specifier.
2077 *
2078 * Digit grouping is interpreted according to numpunct::grouping() and
2079 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2080 * consistent, sets err to ios_base::failbit.
2081 *
2082 * Note that the digit grouping effect for pointers is a bit ambiguous
2083 * in the standard and shouldn't be relied on. See DR 344.
2084 *
2085 * If parsing the string yields a valid value for @a v, @a v is set.
2086 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2087 * Sets err to ios_base::eofbit if the stream is emptied.
2088 *
2089 * @param in Start of input stream.
2090 * @param end End of input stream.
2091 * @param io Source of locale and flags.
2092 * @param err Error flags to set.
2093 * @param v Value to format and insert.
2094 * @return Iterator after reading.
2095 */
2096 iter_type
2097 get(iter_type __in, iter_type __end, ios_base& __io,
2098 ios_base::iostate& __err, void*& __v) const
2099 { return this->do_get(__in, __end, __io, __err, __v); }
2100
2101 protected:
2102 /// Destructor.
2103 virtual ~num_get() { }
2104
2105 iter_type
2106 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
2107 string& __xtrc) const;
2108
2109 template<typename _ValueT>
2110 iter_type
2111 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
2112 _ValueT& __v) const;
2113
2114 template<typename _CharT2>
2115 typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, int>::__type
2116 _M_find(const _CharT2*, size_t __len, _CharT2 __c) const
2117 {
2118 int __ret = -1;
2119 if (__len <= 10)
2120 {
2121 if (__c >= _CharT2('0') && __c < _CharT2(_CharT2('0') + __len))
2122 __ret = __c - _CharT2('0');
2123 }
2124 else
2125 {
2126 if (__c >= _CharT2('0') && __c <= _CharT2('9'))
2127 __ret = __c - _CharT2('0');
2128 else if (__c >= _CharT2('a') && __c <= _CharT2('f'))
2129 __ret = 10 + (__c - _CharT2('a'));
2130 else if (__c >= _CharT2('A') && __c <= _CharT2('F'))
2131 __ret = 10 + (__c - _CharT2('A'));
2132 }
2133 return __ret;
2134 }
2135
2136 template<typename _CharT2>
2137 typename __gnu_cxx::__enable_if<!__is_char<_CharT2>::__value,
2138 int>::__type
2139 _M_find(const _CharT2* __zero, size_t __len, _CharT2 __c) const
2140 {
2141 int __ret = -1;
2142 const char_type* __q = char_traits<_CharT2>::find(__zero, __len, __c);
2143 if (__q)
2144 {
2145 __ret = __q - __zero;
2146 if (__ret > 15)
2147 __ret -= 6;
2148 }
2149 return __ret;
2150 }
2151
2152 //@{
2153 /**
2154 * @brief Numeric parsing.
2155 *
2156 * Parses the input stream into the variable @a v. This function is a
2157 * hook for derived classes to change the value returned. @see get()
2158 * for more details.
2159 *
2160 * @param in Start of input stream.
2161 * @param end End of input stream.
2162 * @param io Source of locale and flags.
2163 * @param err Error flags to set.
2164 * @param v Value to format and insert.
2165 * @return Iterator after reading.
2166 */
2167 virtual iter_type
2168 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
2169
2170
2171 virtual iter_type
2172 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
2173
2174 virtual iter_type
2175 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2176 unsigned short&) const;
2177
2178 virtual iter_type
2179 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2180 unsigned int&) const;
2181
2182 virtual iter_type
2183 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2184 unsigned long&) const;
2185
2186 #ifdef _GLIBCXX_USE_LONG_LONG
2187 virtual iter_type
2188 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2189 long long&) const;
2190
2191 virtual iter_type
2192 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2193 unsigned long long&) const;
2194 #endif
2195
2196 virtual iter_type
2197 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2198 float&) const;
2199
2200 virtual iter_type
2201 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2202 double&) const;
2203
2204 // XXX GLIBCXX_ABI Deprecated
2205 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2206 virtual iter_type
2207 __do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2208 double&) const;
2209 #else
2210 virtual iter_type
2211 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2212 long double&) const;
2213 #endif
2214
2215 virtual iter_type
2216 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2217 void*&) const;
2218
2219 // XXX GLIBCXX_ABI Deprecated
2220 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2221 virtual iter_type
2222 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
2223 long double&) const;
2224 #endif
2225 //@}
2226 };
2227
2228 template<typename _CharT, typename _InIter>
2229 locale::id num_get<_CharT, _InIter>::id;
2230
2231
2232 /**
2233 * @brief Facet for converting numbers to strings.
2234 *
2235 * This facet encapsulates the code to convert a number to a string. It is
2236 * used by the ostream numeric insertion operators.
2237 *
2238 * The num_put template uses protected virtual functions to provide the
2239 * actual results. The public accessors forward the call to the virtual
2240 * functions. These virtual functions are hooks for developers to
2241 * implement the behavior they require from the num_put facet.
2242 */
2243 template<typename _CharT, typename _OutIter>
2244 class num_put : public locale::facet
2245 {
2246 public:
2247 // Types:
2248 //@{
2249 /// Public typedefs
2250 typedef _CharT char_type;
2251 typedef _OutIter iter_type;
2252 //@}
2253
2254 /// Numpunct facet id.
2255 static locale::id id;
2256
2257 /**
2258 * @brief Constructor performs initialization.
2259 *
2260 * This is the constructor provided by the standard.
2261 *
2262 * @param refs Passed to the base facet class.
2263 */
2264 explicit
2265 num_put(size_t __refs = 0) : facet(__refs) { }
2266
2267 /**
2268 * @brief Numeric formatting.
2269 *
2270 * Formats the boolean @a v and inserts it into a stream. It does so
2271 * by calling num_put::do_put().
2272 *
2273 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2274 * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
2275 *
2276 * @param s Stream to write to.
2277 * @param io Source of locale and flags.
2278 * @param fill Char_type to use for filling.
2279 * @param v Value to format and insert.
2280 * @return Iterator after writing.
2281 */
2282 iter_type
2283 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
2284 { return this->do_put(__s, __f, __fill, __v); }
2285
2286 //@{
2287 /**
2288 * @brief Numeric formatting.
2289 *
2290 * Formats the integral value @a v and inserts it into a
2291 * stream. It does so by calling num_put::do_put().
2292 *
2293 * Formatting is affected by the flag settings in @a io.
2294 *
2295 * The basic format is affected by the value of io.flags() &
2296 * ios_base::basefield. If equal to ios_base::oct, formats like the
2297 * printf %o specifier. Else if equal to ios_base::hex, formats like
2298 * %x or %X with ios_base::uppercase unset or set respectively.
2299 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2300 * for unsigned values. Note that if both oct and hex are set, neither
2301 * will take effect.
2302 *
2303 * If ios_base::showpos is set, '+' is output before positive values.
2304 * If ios_base::showbase is set, '0' precedes octal values (except 0)
2305 * and '0[xX]' precedes hex values.
2306 *
2307 * Thousands separators are inserted according to numpunct::grouping()
2308 * and numpunct::thousands_sep(). The decimal point character used is
2309 * numpunct::decimal_point().
2310 *
2311 * If io.width() is non-zero, enough @a fill characters are inserted to
2312 * make the result at least that wide. If
2313 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2314 * padded at the end. If ios_base::internal, then padding occurs
2315 * immediately after either a '+' or '-' or after '0x' or '0X'.
2316 * Otherwise, padding occurs at the beginning.
2317 *
2318 * @param s Stream to write to.
2319 * @param io Source of locale and flags.
2320 * @param fill Char_type to use for filling.
2321 * @param v Value to format and insert.
2322 * @return Iterator after writing.
2323 */
2324 iter_type
2325 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
2326 { return this->do_put(__s, __f, __fill, __v); }
2327
2328 iter_type
2329 put(iter_type __s, ios_base& __f, char_type __fill,
2330 unsigned long __v) const
2331 { return this->do_put(__s, __f, __fill, __v); }
2332
2333 #ifdef _GLIBCXX_USE_LONG_LONG
2334 iter_type
2335 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
2336 { return this->do_put(__s, __f, __fill, __v); }
2337
2338 iter_type
2339 put(iter_type __s, ios_base& __f, char_type __fill,
2340 unsigned long long __v) const
2341 { return this->do_put(__s, __f, __fill, __v); }
2342 #endif
2343 //@}
2344
2345 //@{
2346 /**
2347 * @brief Numeric formatting.
2348 *
2349 * Formats the floating point value @a v and inserts it into a stream.
2350 * It does so by calling num_put::do_put().
2351 *
2352 * Formatting is affected by the flag settings in @a io.
2353 *
2354 * The basic format is affected by the value of io.flags() &
2355 * ios_base::floatfield. If equal to ios_base::fixed, formats like the
2356 * printf %f specifier. Else if equal to ios_base::scientific, formats
2357 * like %e or %E with ios_base::uppercase unset or set respectively.
2358 * Otherwise, formats like %g or %G depending on uppercase. Note that
2359 * if both fixed and scientific are set, the effect will also be like
2360 * %g or %G.
2361 *
2362 * The output precision is given by io.precision(). This precision is
2363 * capped at numeric_limits::digits10 + 2 (different for double and
2364 * long double). The default precision is 6.
2365 *
2366 * If ios_base::showpos is set, '+' is output before positive values.
2367 * If ios_base::showpoint is set, a decimal point will always be
2368 * output.
2369 *
2370 * Thousands separators are inserted according to numpunct::grouping()
2371 * and numpunct::thousands_sep(). The decimal point character used is
2372 * numpunct::decimal_point().
2373 *
2374 * If io.width() is non-zero, enough @a fill characters are inserted to
2375 * make the result at least that wide. If
2376 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2377 * padded at the end. If ios_base::internal, then padding occurs
2378 * immediately after either a '+' or '-' or after '0x' or '0X'.
2379 * Otherwise, padding occurs at the beginning.
2380 *
2381 * @param s Stream to write to.
2382 * @param io Source of locale and flags.
2383 * @param fill Char_type to use for filling.
2384 * @param v Value to format and insert.
2385 * @return Iterator after writing.
2386 */
2387 iter_type
2388 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
2389 { return this->do_put(__s, __f, __fill, __v); }
2390
2391 iter_type
2392 put(iter_type __s, ios_base& __f, char_type __fill,
2393 long double __v) const
2394 { return this->do_put(__s, __f, __fill, __v); }
2395 //@}
2396
2397 /**
2398 * @brief Numeric formatting.
2399 *
2400 * Formats the pointer value @a v and inserts it into a stream. It
2401 * does so by calling num_put::do_put().
2402 *
2403 * This function formats @a v as an unsigned long with ios_base::hex
2404 * and ios_base::showbase set.
2405 *
2406 * @param s Stream to write to.
2407 * @param io Source of locale and flags.
2408 * @param fill Char_type to use for filling.
2409 * @param v Value to format and insert.
2410 * @return Iterator after writing.
2411 */
2412 iter_type
2413 put(iter_type __s, ios_base& __f, char_type __fill,
2414 const void* __v) const
2415 { return this->do_put(__s, __f, __fill, __v); }
2416
2417 protected:
2418 template<typename _ValueT>
2419 iter_type
2420 _M_insert_float(iter_type, ios_base& __io, char_type __fill,
2421 char __mod, _ValueT __v) const;
2422
2423 void
2424 _M_group_float(const char* __grouping, size_t __grouping_size,
2425 char_type __sep, const char_type* __p, char_type* __new,
2426 char_type* __cs, int& __len) const;
2427
2428 template<typename _ValueT>
2429 iter_type
2430 _M_insert_int(iter_type, ios_base& __io, char_type __fill,
2431 _ValueT __v) const;
2432
2433 void
2434 _M_group_int(const char* __grouping, size_t __grouping_size,
2435 char_type __sep, ios_base& __io, char_type* __new,
2436 char_type* __cs, int& __len) const;
2437
2438 void
2439 _M_pad(char_type __fill, streamsize __w, ios_base& __io,
2440 char_type* __new, const char_type* __cs, int& __len) const;
2441
2442 /// Destructor.
2443 virtual
2444 ~num_put() { };
2445
2446 //@{
2447 /**
2448 * @brief Numeric formatting.
2449 *
2450 * These functions do the work of formatting numeric values and
2451 * inserting them into a stream. This function is a hook for derived
2452 * classes to change the value returned.
2453 *
2454 * @param s Stream to write to.
2455 * @param io Source of locale and flags.
2456 * @param fill Char_type to use for filling.
2457 * @param v Value to format and insert.
2458 * @return Iterator after writing.
2459 */
2460 virtual iter_type
2461 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
2462
2463 virtual iter_type
2464 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
2465
2466 virtual iter_type
2467 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
2468
2469 #ifdef _GLIBCXX_USE_LONG_LONG
2470 virtual iter_type
2471 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
2472
2473 virtual iter_type
2474 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
2475 #endif
2476
2477 virtual iter_type
2478 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2479
2480 // XXX GLIBCXX_ABI Deprecated
2481 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2482 virtual iter_type
2483 __do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2484 #else
2485 virtual iter_type
2486 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2487 #endif
2488
2489 virtual iter_type
2490 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
2491
2492 // XXX GLIBCXX_ABI Deprecated
2493 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
2494 virtual iter_type
2495 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2496 #endif
2497 //@}
2498 };
2499
2500 template <typename _CharT, typename _OutIter>
2501 locale::id num_put<_CharT, _OutIter>::id;
2502
2503 _GLIBCXX_END_LDBL_NAMESPACE
2504
2505 // Subclause convenience interfaces, inlines.
2506 // NB: These are inline because, when used in a loop, some compilers
2507 // can hoist the body out of the loop; then it's just as fast as the
2508 // C is*() function.
2509
2510 /// Convenience interface to ctype.is(ctype_base::space, __c).
2511 template<typename _CharT>
2512 inline bool
2513 isspace(_CharT __c, const locale& __loc)
2514 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
2515
2516 /// Convenience interface to ctype.is(ctype_base::print, __c).
2517 template<typename _CharT>
2518 inline bool
2519 isprint(_CharT __c, const locale& __loc)
2520 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
2521
2522 /// Convenience interface to ctype.is(ctype_base::cntrl, __c).
2523 template<typename _CharT>
2524 inline bool
2525 iscntrl(_CharT __c, const locale& __loc)
2526 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
2527
2528 /// Convenience interface to ctype.is(ctype_base::upper, __c).
2529 template<typename _CharT>
2530 inline bool
2531 isupper(_CharT __c, const locale& __loc)
2532 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
2533
2534 /// Convenience interface to ctype.is(ctype_base::lower, __c).
2535 template<typename _CharT>
2536 inline bool
2537 islower(_CharT __c, const locale& __loc)
2538 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
2539
2540 /// Convenience interface to ctype.is(ctype_base::alpha, __c).
2541 template<typename _CharT>
2542 inline bool
2543 isalpha(_CharT __c, const locale& __loc)
2544 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
2545
2546 /// Convenience interface to ctype.is(ctype_base::digit, __c).
2547 template<typename _CharT>
2548 inline bool
2549 isdigit(_CharT __c, const locale& __loc)
2550 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
2551
2552 /// Convenience interface to ctype.is(ctype_base::punct, __c).
2553 template<typename _CharT>
2554 inline bool
2555 ispunct(_CharT __c, const locale& __loc)
2556 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
2557
2558 /// Convenience interface to ctype.is(ctype_base::xdigit, __c).
2559 template<typename _CharT>
2560 inline bool
2561 isxdigit(_CharT __c, const locale& __loc)
2562 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
2563
2564 /// Convenience interface to ctype.is(ctype_base::alnum, __c).
2565 template<typename _CharT>
2566 inline bool
2567 isalnum(_CharT __c, const locale& __loc)
2568 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
2569
2570 /// Convenience interface to ctype.is(ctype_base::graph, __c).
2571 template<typename _CharT>
2572 inline bool
2573 isgraph(_CharT __c, const locale& __loc)
2574 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
2575
2576 /// Convenience interface to ctype.toupper(__c).
2577 template<typename _CharT>
2578 inline _CharT
2579 toupper(_CharT __c, const locale& __loc)
2580 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
2581
2582 /// Convenience interface to ctype.tolower(__c).
2583 template<typename _CharT>
2584 inline _CharT
2585 tolower(_CharT __c, const locale& __loc)
2586 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
2587
2588 _GLIBCXX_END_NAMESPACE
2589
2590 #ifndef _GLIBCXX_EXPORT_TEMPLATE
2591 # include <bits/locale_facets.tcc>
2592 #endif
2593
2594 #endif