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