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