]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/locale_facets.h
c++config: Add in revised namespace associations.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / locale_facets.h
CommitLineData
725dc051
BK
1// Locale support -*- C++ -*-
2
82ce2a94 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4b9aaf63 4// Free Software Foundation, Inc.
725dc051
BK
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING. If not, write to the Free
83f51799 19// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
725dc051
BK
20// USA.
21
22// As a special exception, you may use this file as part of a free software
23// library without restriction. Specifically, if other files instantiate
24// templates or use macros or inline functions from this file, or you compile
25// this file and link it with other files to produce an executable, this
26// file does not by itself cause the resulting executable to be covered by
27// the GNU General Public License. This exception does not however
28// invalidate any other reasons why the executable file might be covered by
29// the GNU General Public License.
30
31//
32// ISO C++ 14882: 22.1 Locales
33//
34
729e3d3f
PE
35/** @file locale_facets.h
36 * This is an internal header file, included by other library headers.
37 * You should not attempt to use it directly.
38 */
725dc051 39
3d7c150e
BK
40#ifndef _LOCALE_FACETS_H
41#define _LOCALE_FACETS_H 1
725dc051 42
b0a85b86
GDR
43#pragma GCC system_header
44
54c1bf78 45#include <ctime> // For struct tm
d3a193e3 46#include <cwctype> // For wctype_t
e6686813
BK
47#include <iosfwd>
48#include <bits/ios_base.h> // For ios_base, ios_base::iostate
49#include <streambuf>
725dc051 50
3cbc7af0
BK
51_GLIBCXX_BEGIN_NAMESPACE(std)
52
d3a193e3 53 // NB: Don't instantiate required wchar_t facets if no wchar_t support.
3d7c150e
BK
54#ifdef _GLIBCXX_USE_WCHAR_T
55# define _GLIBCXX_NUM_FACETS 28
d3a193e3 56#else
3d7c150e 57# define _GLIBCXX_NUM_FACETS 14
d3a193e3
BK
58#endif
59
ed6814f7 60 // Convert string to numeric value of type _Tv and store results.
e6686813
BK
61 // NB: This is specialized for all required types, there is no
62 // generic definition.
63 template<typename _Tv>
64 void
ed6814f7 65 __convert_to_v(const char* __in, _Tv& __out, ios_base::iostate& __err,
0fa96a60 66 const __c_locale& __cloc);
e6686813
BK
67
68 // Explicit specializations for required types.
e6686813
BK
69 template<>
70 void
ed6814f7 71 __convert_to_v(const char*, float&, ios_base::iostate&,
0fa96a60 72 const __c_locale&);
e6686813
BK
73
74 template<>
75 void
ed6814f7 76 __convert_to_v(const char*, double&, ios_base::iostate&,
0fa96a60 77 const __c_locale&);
e6686813 78
0fa96a60 79 template<>
e6686813 80 void
ed6814f7 81 __convert_to_v(const char*, long double&, ios_base::iostate&,
0fa96a60 82 const __c_locale&);
e6686813 83
2e2a38cd
BK
84 // NB: __pad is a struct, rather than a function, so it can be
85 // partially-specialized.
f13a69ec 86 template<typename _CharT, typename _Traits>
e6686813
BK
87 struct __pad
88 {
89 static void
ed6814f7
BI
90 _S_pad(ios_base& __io, _CharT __fill, _CharT* __news,
91 const _CharT* __olds, const streamsize __newlen,
e6686813
BK
92 const streamsize __oldlen, const bool __num);
93 };
94
2e2a38cd
BK
95 // Used by both numeric and monetary facets.
96 // Inserts "group separator" characters into an array of characters.
97 // It's recursive, one iteration per group. It moves the characters
98 // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
47f62b27 99 // only with __glen != 0.
e6686813
BK
100 template<typename _CharT>
101 _CharT*
ed6814f7
BI
102 __add_grouping(_CharT* __s, _CharT __sep,
103 const char* __gbeg, size_t __gsize,
e6686813 104 const _CharT* __first, const _CharT* __last);
f13a69ec 105
2e2a38cd
BK
106 // This template permits specializing facet output code for
107 // ostreambuf_iterator. For ostreambuf_iterator, sputn is
108 // significantly more efficient than incrementing iterators.
109 template<typename _CharT>
110 inline
111 ostreambuf_iterator<_CharT>
112 __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len)
113 {
114 __s._M_put(__ws, __len);
115 return __s;
116 }
117
118 // This is the unspecialized form of the template.
119 template<typename _CharT, typename _OutIter>
120 inline
121 _OutIter
122 __write(_OutIter __s, const _CharT* __ws, int __len)
123 {
124 for (int __j = 0; __j < __len; __j++, ++__s)
125 *__s = __ws[__j];
126 return __s;
127 }
128
6067bea4 129
0a31609b 130 // 22.2.1.1 Template class ctype
33590f13 131 // Include host and configuration specific ctype enums for ctype_base.
725dc051
BK
132 #include <bits/ctype_base.h>
133
ed6814f7 134 // Common base for ctype<_CharT>.
2dbd0234
JQ
135 /**
136 * @brief Common base for ctype facet
137 *
138 * This template class provides implementations of the public functions
139 * that forward to the protected virtual functions.
140 *
141 * This template also provides abtract stubs for the protected virtual
142 * functions.
143 */
725dc051 144 template<typename _CharT>
167ed88f 145 class __ctype_abstract_base : public locale::facet, public ctype_base
725dc051
BK
146 {
147 public:
148 // Types:
2dbd0234 149 /// Typedef for the template parameter
725dc051
BK
150 typedef _CharT char_type;
151
2dbd0234
JQ
152 /**
153 * @brief Test char_type classification.
154 *
155 * This function finds a mask M for @a c and compares it to mask @a m.
156 * It does so by returning the value of ctype<char_type>::do_is().
157 *
158 * @param c The char_type to compare the mask of.
159 * @param m The mask to compare against.
160 * @return (M & m) != 0.
161 */
ed6814f7 162 bool
167ed88f
BK
163 is(mask __m, char_type __c) const
164 { return this->do_is(__m, __c); }
165
2dbd0234
JQ
166 /**
167 * @brief Return a mask array.
168 *
169 * This function finds the mask for each char_type in the range [lo,hi)
170 * and successively writes it to vec. vec must have as many elements
171 * as the char array. It does so by returning the value of
172 * ctype<char_type>::do_is().
173 *
174 * @param lo Pointer to start of range.
175 * @param hi Pointer to end of range.
176 * @param vec Pointer to an array of mask storage.
177 * @return @a hi.
178 */
167ed88f 179 const char_type*
ed6814f7 180 is(const char_type *__lo, const char_type *__hi, mask *__vec) const
167ed88f
BK
181 { return this->do_is(__lo, __hi, __vec); }
182
2dbd0234
JQ
183 /**
184 * @brief Find char_type matching a mask
185 *
186 * This function searches for and returns the first char_type c in
187 * [lo,hi) for which is(m,c) is true. It does so by returning
188 * ctype<char_type>::do_scan_is().
189 *
190 * @param m The mask to compare against.
191 * @param lo Pointer to start of range.
192 * @param hi Pointer to end of range.
193 * @return Pointer to matching char_type if found, else @a hi.
194 */
167ed88f
BK
195 const char_type*
196 scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
197 { return this->do_scan_is(__m, __lo, __hi); }
198
2dbd0234
JQ
199 /**
200 * @brief Find char_type not matching a mask
201 *
202 * This function searches for and returns the first char_type c in
203 * [lo,hi) for which is(m,c) is false. It does so by returning
204 * ctype<char_type>::do_scan_not().
205 *
206 * @param m The mask to compare against.
207 * @param lo Pointer to first char in range.
208 * @param hi Pointer to end of range.
209 * @return Pointer to non-matching char if found, else @a hi.
210 */
167ed88f
BK
211 const char_type*
212 scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
213 { return this->do_scan_not(__m, __lo, __hi); }
214
2dbd0234
JQ
215 /**
216 * @brief Convert to uppercase.
217 *
218 * This function converts the argument to uppercase if possible.
219 * If not possible (for example, '2'), returns the argument. It does
220 * so by returning ctype<char_type>::do_toupper().
221 *
222 * @param c The char_type to convert.
223 * @return The uppercase char_type if convertible, else @a c.
224 */
ed6814f7 225 char_type
725dc051
BK
226 toupper(char_type __c) const
227 { return this->do_toupper(__c); }
228
2dbd0234
JQ
229 /**
230 * @brief Convert array to uppercase.
231 *
232 * This function converts each char_type in the range [lo,hi) to
233 * uppercase if possible. Other elements remain untouched. It does so
234 * by returning ctype<char_type>:: do_toupper(lo, hi).
235 *
236 * @param lo Pointer to start of range.
237 * @param hi Pointer to end of range.
238 * @return @a hi.
239 */
725dc051 240 const char_type*
fdf1b60d
BK
241 toupper(char_type *__lo, const char_type* __hi) const
242 { return this->do_toupper(__lo, __hi); }
725dc051 243
2dbd0234
JQ
244 /**
245 * @brief Convert to lowercase.
246 *
247 * This function converts the argument to lowercase if possible. If
248 * not possible (for example, '2'), returns the argument. It does so
249 * by returning ctype<char_type>::do_tolower(c).
250 *
251 * @param c The char_type to convert.
252 * @return The lowercase char_type if convertible, else @a c.
253 */
254 char_type
725dc051
BK
255 tolower(char_type __c) const
256 { return this->do_tolower(__c); }
257
2dbd0234
JQ
258 /**
259 * @brief Convert array to lowercase.
260 *
261 * This function converts each char_type in the range [lo,hi) to
262 * lowercase if possible. Other elements remain untouched. It does so
263 * by returning ctype<char_type>:: do_tolower(lo, hi).
264 *
265 * @param lo Pointer to start of range.
266 * @param hi Pointer to end of range.
267 * @return @a hi.
268 */
725dc051 269 const char_type*
fdf1b60d
BK
270 tolower(char_type* __lo, const char_type* __hi) const
271 { return this->do_tolower(__lo, __hi); }
725dc051 272
2dbd0234
JQ
273 /**
274 * @brief Widen char to char_type
275 *
276 * This function converts the char argument to char_type using the
277 * simplest reasonable transformation. It does so by returning
278 * ctype<char_type>::do_widen(c).
279 *
280 * Note: this is not what you want for codepage conversions. See
281 * codecvt for that.
282 *
283 * @param c The char to convert.
284 * @return The converted char_type.
285 */
286 char_type
725dc051
BK
287 widen(char __c) const
288 { return this->do_widen(__c); }
289
2dbd0234
JQ
290 /**
291 * @brief Widen array to char_type
292 *
293 * This function converts each char in the input to char_type using the
294 * simplest reasonable transformation. It does so by returning
295 * ctype<char_type>::do_widen(c).
296 *
297 * Note: this is not what you want for codepage conversions. See
298 * codecvt for that.
299 *
300 * @param lo Pointer to start of range.
301 * @param hi Pointer to end of range.
302 * @param to Pointer to the destination array.
303 * @return @a hi.
304 */
725dc051 305 const char*
fdf1b60d
BK
306 widen(const char* __lo, const char* __hi, char_type* __to) const
307 { return this->do_widen(__lo, __hi, __to); }
725dc051 308
2dbd0234
JQ
309 /**
310 * @brief Narrow char_type to char
311 *
312 * This function converts the char_type to char using the simplest
313 * reasonable transformation. If the conversion fails, dfault is
314 * returned instead. It does so by returning
315 * ctype<char_type>::do_narrow(c).
316 *
317 * Note: this is not what you want for codepage conversions. See
318 * codecvt for that.
319 *
320 * @param c The char_type to convert.
321 * @param dfault Char to return if conversion fails.
322 * @return The converted char.
323 */
ed6814f7 324 char
725dc051
BK
325 narrow(char_type __c, char __dfault) const
326 { return this->do_narrow(__c, __dfault); }
327
2dbd0234
JQ
328 /**
329 * @brief Narrow array to char array
330 *
331 * This function converts each char_type in the input to char using the
332 * simplest reasonable transformation and writes the results to the
333 * destination array. For any char_type in the input that cannot be
334 * converted, @a dfault is used instead. It does so by returning
335 * ctype<char_type>::do_narrow(lo, hi, dfault, to).
336 *
337 * Note: this is not what you want for codepage conversions. See
338 * codecvt for that.
339 *
340 * @param lo Pointer to start of range.
341 * @param hi Pointer to end of range.
342 * @param dfault Char to use if conversion fails.
343 * @param to Pointer to the destination array.
344 * @return @a hi.
345 */
725dc051 346 const char_type*
fdf1b60d 347 narrow(const char_type* __lo, const char_type* __hi,
725dc051 348 char __dfault, char *__to) const
fdf1b60d 349 { return this->do_narrow(__lo, __hi, __dfault, __to); }
725dc051
BK
350
351 protected:
ed6814f7 352 explicit
fea4065d 353 __ctype_abstract_base(size_t __refs = 0): facet(__refs) { }
725dc051 354
ed6814f7 355 virtual
167ed88f 356 ~__ctype_abstract_base() { }
ed6814f7 357
2dbd0234
JQ
358 /**
359 * @brief Test char_type classification.
360 *
361 * This function finds a mask M for @a c and compares it to mask @a m.
362 *
363 * do_is() is a hook for a derived facet to change the behavior of
364 * classifying. do_is() must always return the same result for the
365 * same input.
366 *
367 * @param c The char_type to find the mask of.
368 * @param m The mask to compare against.
369 * @return (M & m) != 0.
370 */
371 virtual bool
167ed88f
BK
372 do_is(mask __m, char_type __c) const = 0;
373
2dbd0234
JQ
374 /**
375 * @brief Return a mask array.
376 *
377 * This function finds the mask for each char_type in the range [lo,hi)
378 * and successively writes it to vec. vec must have as many elements
379 * as the input.
380 *
381 * do_is() is a hook for a derived facet to change the behavior of
382 * classifying. do_is() must always return the same result for the
383 * same input.
384 *
385 * @param lo Pointer to start of range.
386 * @param hi Pointer to end of range.
387 * @param vec Pointer to an array of mask storage.
388 * @return @a hi.
389 */
167ed88f 390 virtual const char_type*
ed6814f7 391 do_is(const char_type* __lo, const char_type* __hi,
167ed88f
BK
392 mask* __vec) const = 0;
393
2dbd0234
JQ
394 /**
395 * @brief Find char_type matching mask
396 *
397 * This function searches for and returns the first char_type c in
398 * [lo,hi) for which is(m,c) is true.
399 *
400 * do_scan_is() is a hook for a derived facet to change the behavior of
401 * match searching. do_is() must always return the same result for the
402 * same input.
403 *
404 * @param m The mask to compare against.
405 * @param lo Pointer to start of range.
406 * @param hi Pointer to end of range.
407 * @return Pointer to a matching char_type if found, else @a hi.
408 */
167ed88f 409 virtual const char_type*
fdf1b60d 410 do_scan_is(mask __m, const char_type* __lo,
167ed88f
BK
411 const char_type* __hi) const = 0;
412
2dbd0234
JQ
413 /**
414 * @brief Find char_type not matching mask
415 *
416 * This function searches for and returns a pointer to the first
417 * char_type c of [lo,hi) for which is(m,c) is false.
418 *
419 * do_scan_is() is a hook for a derived facet to change the behavior of
420 * match searching. do_is() must always return the same result for the
421 * same input.
422 *
423 * @param m The mask to compare against.
424 * @param lo Pointer to start of range.
425 * @param hi Pointer to end of range.
426 * @return Pointer to a non-matching char_type if found, else @a hi.
427 */
167ed88f 428 virtual const char_type*
ed6814f7 429 do_scan_not(mask __m, const char_type* __lo,
167ed88f
BK
430 const char_type* __hi) const = 0;
431
2dbd0234
JQ
432 /**
433 * @brief Convert to uppercase.
434 *
435 * This virtual function converts the char_type argument to uppercase
436 * if possible. If not possible (for example, '2'), returns the
437 * argument.
438 *
439 * do_toupper() is a hook for a derived facet to change the behavior of
440 * uppercasing. do_toupper() must always return the same result for
441 * the same input.
442 *
443 * @param c The char_type to convert.
444 * @return The uppercase char_type if convertible, else @a c.
445 */
ed6814f7 446 virtual char_type
725dc051
BK
447 do_toupper(char_type) const = 0;
448
2dbd0234
JQ
449 /**
450 * @brief Convert array to uppercase.
451 *
452 * This virtual function converts each char_type in the range [lo,hi)
453 * to uppercase if possible. Other elements remain untouched.
454 *
455 * do_toupper() is a hook for a derived facet to change the behavior of
456 * uppercasing. do_toupper() must always return the same result for
457 * the same input.
458 *
459 * @param lo Pointer to start of range.
460 * @param hi Pointer to end of range.
461 * @return @a hi.
462 */
725dc051 463 virtual const char_type*
fdf1b60d 464 do_toupper(char_type* __lo, const char_type* __hi) const = 0;
725dc051 465
2dbd0234
JQ
466 /**
467 * @brief Convert to lowercase.
468 *
469 * This virtual function converts the argument to lowercase if
470 * possible. If not possible (for example, '2'), returns the argument.
471 *
472 * do_tolower() is a hook for a derived facet to change the behavior of
473 * lowercasing. do_tolower() must always return the same result for
474 * the same input.
475 *
476 * @param c The char_type to convert.
477 * @return The lowercase char_type if convertible, else @a c.
478 */
479 virtual char_type
725dc051
BK
480 do_tolower(char_type) const = 0;
481
2dbd0234
JQ
482 /**
483 * @brief Convert array to lowercase.
484 *
485 * This virtual function converts each char_type in the range [lo,hi)
486 * to lowercase if possible. Other elements remain untouched.
487 *
488 * do_tolower() is a hook for a derived facet to change the behavior of
489 * lowercasing. do_tolower() must always return the same result for
490 * the same input.
491 *
492 * @param lo Pointer to start of range.
493 * @param hi Pointer to end of range.
494 * @return @a hi.
495 */
725dc051 496 virtual const char_type*
fdf1b60d 497 do_tolower(char_type* __lo, const char_type* __hi) const = 0;
ed6814f7 498
2dbd0234
JQ
499 /**
500 * @brief Widen char
501 *
502 * This virtual function converts the char to char_type using the
503 * simplest reasonable transformation.
504 *
505 * do_widen() is a hook for a derived facet to change the behavior of
506 * widening. do_widen() must always return the same result for the
507 * same input.
508 *
509 * Note: this is not what you want for codepage conversions. See
510 * codecvt for that.
511 *
512 * @param c The char to convert.
513 * @return The converted char_type
514 */
ed6814f7 515 virtual char_type
725dc051
BK
516 do_widen(char) const = 0;
517
2dbd0234
JQ
518 /**
519 * @brief Widen char array
520 *
521 * This function converts each char in the input to char_type using the
522 * simplest reasonable transformation.
523 *
524 * do_widen() is a hook for a derived facet to change the behavior of
525 * widening. do_widen() must always return the same result for the
526 * same input.
527 *
528 * Note: this is not what you want for codepage conversions. See
529 * codecvt for that.
530 *
531 * @param lo Pointer to start range.
532 * @param hi Pointer to end of range.
533 * @param to Pointer to the destination array.
534 * @return @a hi.
535 */
725dc051 536 virtual const char*
ed6814f7 537 do_widen(const char* __lo, const char* __hi,
725dc051
BK
538 char_type* __dest) const = 0;
539
2dbd0234
JQ
540 /**
541 * @brief Narrow char_type to char
542 *
543 * This virtual function converts the argument to char using the
544 * simplest reasonable transformation. If the conversion fails, dfault
545 * is returned instead.
546 *
547 * do_narrow() is a hook for a derived facet to change the behavior of
548 * narrowing. do_narrow() must always return the same result for the
549 * same input.
550 *
551 * Note: this is not what you want for codepage conversions. See
552 * codecvt for that.
553 *
554 * @param c The char_type to convert.
555 * @param dfault Char to return if conversion fails.
556 * @return The converted char.
557 */
ed6814f7 558 virtual char
725dc051
BK
559 do_narrow(char_type, char __dfault) const = 0;
560
2dbd0234
JQ
561 /**
562 * @brief Narrow char_type array to char
563 *
564 * This virtual function converts each char_type in the range [lo,hi) to
565 * char using the simplest reasonable transformation and writes the
566 * results to the destination array. For any element in the input that
567 * cannot be converted, @a dfault is used instead.
568 *
569 * do_narrow() is a hook for a derived facet to change the behavior of
570 * narrowing. do_narrow() must always return the same result for the
571 * same input.
572 *
573 * Note: this is not what you want for codepage conversions. See
574 * codecvt for that.
575 *
576 * @param lo Pointer to start of range.
577 * @param hi Pointer to end of range.
578 * @param dfault Char to use if conversion fails.
579 * @param to Pointer to the destination array.
580 * @return @a hi.
581 */
725dc051 582 virtual const char_type*
fdf1b60d 583 do_narrow(const char_type* __lo, const char_type* __hi,
9a1349b9 584 char __dfault, char* __dest) const = 0;
725dc051
BK
585 };
586
167ed88f 587 // NB: Generic, mostly useless implementation.
2dbd0234
JQ
588 /**
589 * @brief Template ctype facet
590 *
591 * This template class defines classification and conversion functions for
592 * character sets. It wraps <cctype> functionality. Ctype gets used by
593 * streams for many I/O operations.
594 *
595 * This template provides the protected virtual functions the developer
596 * will have to replace in a derived class or specialization to make a
597 * working facet. The public functions that access them are defined in
598 * __ctype_abstract_base, to allow for implementation flexibility. See
599 * ctype<wchar_t> for an example. The functions are documented in
600 * __ctype_abstract_base.
601 *
602 * Note: implementations are provided for all the protected virtual
603 * functions, but will likely not be useful.
604 */
725dc051 605 template<typename _CharT>
167ed88f 606 class ctype : public __ctype_abstract_base<_CharT>
725dc051
BK
607 {
608 public:
609 // Types:
ed6814f7 610 typedef _CharT char_type;
f88e4715 611 typedef typename __ctype_abstract_base<_CharT>::mask mask;
725dc051 612
2dbd0234 613 /// The facet id for ctype<char_type>
ed6814f7 614 static locale::id id;
d3a193e3 615
ed6814f7 616 explicit
167ed88f 617 ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
725dc051 618
725dc051 619 protected:
ed6814f7 620 virtual
9e5c7dba 621 ~ctype();
fdf1b60d 622
ed6814f7 623 virtual bool
9e5c7dba 624 do_is(mask __m, char_type __c) const;
fdf1b60d
BK
625
626 virtual const char_type*
9e5c7dba 627 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
fdf1b60d
BK
628
629 virtual const char_type*
9e5c7dba 630 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
fdf1b60d
BK
631
632 virtual const char_type*
633 do_scan_not(mask __m, const char_type* __lo,
9e5c7dba 634 const char_type* __hi) const;
fdf1b60d 635
ed6814f7 636 virtual char_type
9e5c7dba 637 do_toupper(char_type __c) const;
fdf1b60d
BK
638
639 virtual const char_type*
9e5c7dba 640 do_toupper(char_type* __lo, const char_type* __hi) const;
fdf1b60d 641
ed6814f7 642 virtual char_type
9e5c7dba 643 do_tolower(char_type __c) const;
fdf1b60d
BK
644
645 virtual const char_type*
9e5c7dba
BK
646 do_tolower(char_type* __lo, const char_type* __hi) const;
647
ed6814f7 648 virtual char_type
9e5c7dba 649 do_widen(char __c) const;
fdf1b60d
BK
650
651 virtual const char*
9e5c7dba 652 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
fdf1b60d 653
ed6814f7 654 virtual char
9e5c7dba 655 do_narrow(char_type, char __dfault) const;
fdf1b60d
BK
656
657 virtual const char_type*
658 do_narrow(const char_type* __lo, const char_type* __hi,
9e5c7dba 659 char __dfault, char* __dest) const;
725dc051
BK
660 };
661
0a31609b
BK
662 template<typename _CharT>
663 locale::id ctype<_CharT>::id;
664
9e5c7dba 665 // 22.2.1.3 ctype<char> specialization.
2dbd0234
JQ
666 /**
667 * @brief The ctype<char> specialization.
668 *
669 * This class defines classification and conversion functions for
670 * the char type. It gets used by char streams for many I/O
671 * operations. The char specialization provides a number of
672 * optimizations as well.
673 */
725dc051 674 template<>
82c2e3d4 675 class ctype<char> : public locale::facet, public ctype_base
725dc051
BK
676 {
677 public:
678 // Types:
2dbd0234 679 /// Typedef for the template parameter char.
ed6814f7 680 typedef char char_type;
725dc051 681
def9790d 682 protected:
725dc051 683 // Data Members:
def9790d 684 __c_locale _M_c_locale_ctype;
ed6814f7
BI
685 bool _M_del;
686 __to_type _M_toupper;
687 __to_type _M_tolower;
688 const mask* _M_table;
3fc63c15
JQ
689 mutable char _M_widen_ok;
690 mutable char _M_widen[1 + static_cast<unsigned char>(-1)];
691 mutable char _M_narrow[1 + static_cast<unsigned char>(-1)];
692 mutable char _M_narrow_ok; // 0 uninitialized, 1 init,
82ce2a94 693 // 2 memcpy can't be used
ed6814f7 694
725dc051 695 public:
2dbd0234 696 /// The facet id for ctype<char>
725dc051 697 static locale::id id;
2dbd0234 698 /// The size of the mask table. It is SCHAR_MAX + 1.
725dc051
BK
699 static const size_t table_size = 1 + static_cast<unsigned char>(-1);
700
2dbd0234
JQ
701 /**
702 * @brief Constructor performs initialization.
703 *
704 * This is the constructor provided by the standard.
705 *
706 * @param table If non-zero, table is used as the per-char mask.
707 * Else classic_table() is used.
708 * @param del If true, passes ownership of table to this facet.
709 * @param refs Passed to the base facet class.
710 */
ed6814f7 711 explicit
725dc051
BK
712 ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
713
2dbd0234
JQ
714 /**
715 * @brief Constructor performs static initialization.
716 *
717 * This constructor is used to construct the initial C locale facet.
718 *
719 * @param cloc Handle to C locale data.
720 * @param table If non-zero, table is used as the per-char mask.
721 * @param del If true, passes ownership of table to this facet.
722 * @param refs Passed to the base facet class.
723 */
ed6814f7
BI
724 explicit
725 ctype(__c_locale __cloc, const mask* __table = 0, bool __del = false,
9e5c7dba
BK
726 size_t __refs = 0);
727
2dbd0234
JQ
728 /**
729 * @brief Test char classification.
730 *
731 * This function compares the mask table[c] to @a m.
732 *
733 * @param c The char to compare the mask of.
734 * @param m The mask to compare against.
735 * @return True if m & table[c] is true, false otherwise.
736 */
737 inline bool
65b66e1f 738 is(mask __m, char __c) const;
ed6814f7 739
2dbd0234
JQ
740 /**
741 * @brief Return a mask array.
742 *
743 * This function finds the mask for each char in the range [lo, hi) and
744 * successively writes it to vec. vec must have as many elements as
745 * the char array.
746 *
747 * @param lo Pointer to start of range.
748 * @param hi Pointer to end of range.
749 * @param vec Pointer to an array of mask storage.
750 * @return @a hi.
751 */
725dc051 752 inline const char*
fdf1b60d 753 is(const char* __lo, const char* __hi, mask* __vec) const;
ed6814f7 754
2dbd0234
JQ
755 /**
756 * @brief Find char matching a mask
757 *
758 * This function searches for and returns the first char in [lo,hi) for
759 * which is(m,char) is true.
760 *
761 * @param m The mask to compare against.
762 * @param lo Pointer to start of range.
763 * @param hi Pointer to end of range.
764 * @return Pointer to a matching char if found, else @a hi.
765 */
725dc051 766 inline const char*
fdf1b60d 767 scan_is(mask __m, const char* __lo, const char* __hi) const;
725dc051 768
2dbd0234
JQ
769 /**
770 * @brief Find char not matching a mask
771 *
772 * This function searches for and returns a pointer to the first char
773 * in [lo,hi) for which is(m,char) is false.
774 *
775 * @param m The mask to compare against.
776 * @param lo Pointer to start of range.
777 * @param hi Pointer to end of range.
778 * @return Pointer to a non-matching char if found, else @a hi.
779 */
725dc051 780 inline const char*
fdf1b60d 781 scan_not(mask __m, const char* __lo, const char* __hi) const;
ed6814f7 782
2dbd0234
JQ
783 /**
784 * @brief Convert to uppercase.
785 *
786 * This function converts the char argument to uppercase if possible.
787 * If not possible (for example, '2'), returns the argument.
788 *
789 * toupper() acts as if it returns ctype<char>::do_toupper(c).
790 * do_toupper() must always return the same result for the same input.
791 *
792 * @param c The char to convert.
793 * @return The uppercase char if convertible, else @a c.
794 */
ed6814f7 795 char_type
82c2e3d4
BK
796 toupper(char_type __c) const
797 { return this->do_toupper(__c); }
798
2dbd0234
JQ
799 /**
800 * @brief Convert array to uppercase.
801 *
802 * This function converts each char in the range [lo,hi) to uppercase
803 * if possible. Other chars remain untouched.
804 *
805 * toupper() acts as if it returns ctype<char>:: do_toupper(lo, hi).
806 * do_toupper() must always return the same result for the same input.
807 *
808 * @param lo Pointer to first char in range.
809 * @param hi Pointer to end of range.
810 * @return @a hi.
811 */
82c2e3d4
BK
812 const char_type*
813 toupper(char_type *__lo, const char_type* __hi) const
814 { return this->do_toupper(__lo, __hi); }
815
2dbd0234
JQ
816 /**
817 * @brief Convert to lowercase.
818 *
819 * This function converts the char argument to lowercase if possible.
820 * If not possible (for example, '2'), returns the argument.
821 *
822 * tolower() acts as if it returns ctype<char>::do_tolower(c).
823 * do_tolower() must always return the same result for the same input.
824 *
825 * @param c The char to convert.
826 * @return The lowercase char if convertible, else @a c.
827 */
ed6814f7 828 char_type
82c2e3d4
BK
829 tolower(char_type __c) const
830 { return this->do_tolower(__c); }
831
2dbd0234
JQ
832 /**
833 * @brief Convert array to lowercase.
834 *
835 * This function converts each char in the range [lo,hi) to lowercase
836 * if possible. Other chars remain untouched.
837 *
838 * tolower() acts as if it returns ctype<char>:: do_tolower(lo, hi).
839 * do_tolower() must always return the same result for the same input.
840 *
841 * @param lo Pointer to first char in range.
842 * @param hi Pointer to end of range.
843 * @return @a hi.
844 */
82c2e3d4
BK
845 const char_type*
846 tolower(char_type* __lo, const char_type* __hi) const
847 { return this->do_tolower(__lo, __hi); }
848
2dbd0234
JQ
849 /**
850 * @brief Widen char
851 *
852 * This function converts the char to char_type using the simplest
853 * reasonable transformation. For an underived ctype<char> facet, the
854 * argument will be returned unchanged.
855 *
856 * This function works as if it returns ctype<char>::do_widen(c).
857 * do_widen() must always return the same result for the same input.
858 *
859 * Note: this is not what you want for codepage conversions. See
860 * codecvt for that.
861 *
862 * @param c The char to convert.
863 * @return The converted character.
864 */
ed6814f7 865 char_type
82c2e3d4 866 widen(char __c) const
ed6814f7 867 {
82ce2a94
PC
868 if (_M_widen_ok)
869 return _M_widen[static_cast<unsigned char>(__c)];
84cea626 870 this->_M_widen_init();
3fc63c15
JQ
871 return this->do_widen(__c);
872 }
82c2e3d4 873
2dbd0234
JQ
874 /**
875 * @brief Widen char array
876 *
877 * This function converts each char in the input to char using the
878 * simplest reasonable transformation. For an underived ctype<char>
879 * facet, the argument will be copied unchanged.
880 *
881 * This function works as if it returns ctype<char>::do_widen(c).
882 * do_widen() must always return the same result for the same input.
883 *
884 * Note: this is not what you want for codepage conversions. See
885 * codecvt for that.
886 *
887 * @param lo Pointer to first char in range.
888 * @param hi Pointer to end of range.
889 * @param to Pointer to the destination array.
890 * @return @a hi.
891 */
82c2e3d4
BK
892 const char*
893 widen(const char* __lo, const char* __hi, char_type* __to) const
3fc63c15 894 {
84cea626
JQ
895 if (_M_widen_ok == 1)
896 {
897 memcpy(__to, __lo, __hi - __lo);
898 return __hi;
899 }
82ce2a94
PC
900 if (!_M_widen_ok)
901 _M_widen_init();
3fc63c15
JQ
902 return this->do_widen(__lo, __hi, __to);
903 }
82c2e3d4 904
2dbd0234
JQ
905 /**
906 * @brief Narrow char
907 *
908 * This function converts the char to char using the simplest
909 * reasonable transformation. If the conversion fails, dfault is
910 * returned instead. For an underived ctype<char> facet, @a c
911 * will be returned unchanged.
912 *
913 * This function works as if it returns ctype<char>::do_narrow(c).
914 * do_narrow() must always return the same result for the same input.
915 *
916 * Note: this is not what you want for codepage conversions. See
917 * codecvt for that.
918 *
919 * @param c The char to convert.
920 * @param dfault Char to return if conversion fails.
921 * @return The converted character.
922 */
ed6814f7 923 char
82c2e3d4 924 narrow(char_type __c, char __dfault) const
3fc63c15 925 {
a043b1f5
JQ
926 if (_M_narrow[static_cast<unsigned char>(__c)])
927 return _M_narrow[static_cast<unsigned char>(__c)];
9a1349b9 928 const char __t = do_narrow(__c, __dfault);
82ce2a94
PC
929 if (__t != __dfault)
930 _M_narrow[static_cast<unsigned char>(__c)] = __t;
3fc63c15
JQ
931 return __t;
932 }
82c2e3d4 933
2dbd0234
JQ
934 /**
935 * @brief Narrow char array
936 *
937 * This function converts each char in the input to char using the
938 * simplest reasonable transformation and writes the results to the
939 * destination array. For any char in the input that cannot be
940 * converted, @a dfault is used instead. For an underived ctype<char>
941 * facet, the argument will be copied unchanged.
942 *
943 * This function works as if it returns ctype<char>::do_narrow(lo, hi,
944 * dfault, to). do_narrow() must always return the same result for the
945 * same input.
946 *
947 * Note: this is not what you want for codepage conversions. See
948 * codecvt for that.
949 *
950 * @param lo Pointer to start of range.
951 * @param hi Pointer to end of range.
952 * @param dfault Char to use if conversion fails.
953 * @param to Pointer to the destination array.
954 * @return @a hi.
955 */
82c2e3d4
BK
956 const char_type*
957 narrow(const char_type* __lo, const char_type* __hi,
9a1349b9 958 char __dfault, char *__to) const
3fc63c15 959 {
82ce2a94 960 if (__builtin_expect(_M_narrow_ok == 1, true))
84cea626
JQ
961 {
962 memcpy(__to, __lo, __hi - __lo);
963 return __hi;
964 }
965 if (!_M_narrow_ok)
966 _M_narrow_init();
3fc63c15
JQ
967 return this->do_narrow(__lo, __hi, __dfault, __to);
968 }
82c2e3d4 969
725dc051 970 protected:
2dbd0234
JQ
971 /// Returns a pointer to the mask table provided to the constructor, or
972 /// the default from classic_table() if none was provided.
ed6814f7 973 const mask*
725dc051
BK
974 table() const throw()
975 { return _M_table; }
976
2dbd0234 977 /// Returns a pointer to the C locale mask table.
ed6814f7 978 static const mask*
93dbe8d7 979 classic_table() throw();
725dc051 980
2dbd0234
JQ
981 /**
982 * @brief Destructor.
983 *
984 * This function deletes table() if @a del was true in the
985 * constructor.
986 */
ed6814f7 987 virtual
def9790d
BK
988 ~ctype();
989
2dbd0234
JQ
990 /**
991 * @brief Convert to uppercase.
992 *
993 * This virtual function converts the char argument to uppercase if
994 * possible. If not possible (for example, '2'), returns the argument.
995 *
996 * do_toupper() is a hook for a derived facet to change the behavior of
997 * uppercasing. do_toupper() must always return the same result for
998 * the same input.
999 *
1000 * @param c The char to convert.
1001 * @return The uppercase char if convertible, else @a c.
1002 */
ed6814f7 1003 virtual char_type
725dc051
BK
1004 do_toupper(char_type) const;
1005
2dbd0234
JQ
1006 /**
1007 * @brief Convert array to uppercase.
1008 *
1009 * This virtual function converts each char in the range [lo,hi) to
1010 * uppercase if possible. Other chars remain untouched.
1011 *
1012 * do_toupper() is a hook for a derived facet to change the behavior of
1013 * uppercasing. do_toupper() must always return the same result for
1014 * the same input.
1015 *
1016 * @param lo Pointer to start of range.
1017 * @param hi Pointer to end of range.
1018 * @return @a hi.
1019 */
725dc051 1020 virtual const char_type*
fdf1b60d 1021 do_toupper(char_type* __lo, const char_type* __hi) const;
725dc051 1022
2dbd0234
JQ
1023 /**
1024 * @brief Convert to lowercase.
1025 *
1026 * This virtual function converts the char argument to lowercase if
1027 * possible. If not possible (for example, '2'), returns the argument.
1028 *
1029 * do_tolower() is a hook for a derived facet to change the behavior of
1030 * lowercasing. do_tolower() must always return the same result for
1031 * the same input.
1032 *
1033 * @param c The char to convert.
1034 * @return The lowercase char if convertible, else @a c.
1035 */
ed6814f7 1036 virtual char_type
725dc051
BK
1037 do_tolower(char_type) const;
1038
2dbd0234
JQ
1039 /**
1040 * @brief Convert array to lowercase.
1041 *
1042 * This virtual function converts each char in the range [lo,hi) to
1043 * lowercase if possible. Other chars remain untouched.
1044 *
1045 * do_tolower() is a hook for a derived facet to change the behavior of
1046 * lowercasing. do_tolower() must always return the same result for
1047 * the same input.
1048 *
1049 * @param lo Pointer to first char in range.
1050 * @param hi Pointer to end of range.
1051 * @return @a hi.
1052 */
725dc051 1053 virtual const char_type*
fdf1b60d 1054 do_tolower(char_type* __lo, const char_type* __hi) const;
ed6814f7 1055
2dbd0234
JQ
1056 /**
1057 * @brief Widen char
1058 *
1059 * This virtual function converts the char to char using the simplest
1060 * reasonable transformation. For an underived ctype<char> facet, the
1061 * argument will be returned unchanged.
1062 *
1063 * do_widen() is a hook for a derived facet to change the behavior of
1064 * widening. do_widen() must always return the same result for the
1065 * same input.
1066 *
1067 * Note: this is not what you want for codepage conversions. See
1068 * codecvt for that.
1069 *
1070 * @param c The char to convert.
1071 * @return The converted character.
1072 */
ed6814f7 1073 virtual char_type
82c2e3d4
BK
1074 do_widen(char __c) const
1075 { return __c; }
725dc051 1076
2dbd0234
JQ
1077 /**
1078 * @brief Widen char array
1079 *
1080 * This function converts each char in the range [lo,hi) to char using
1081 * the simplest reasonable transformation. For an underived
1082 * ctype<char> facet, the argument will be copied unchanged.
1083 *
1084 * do_widen() is a hook for a derived facet to change the behavior of
1085 * widening. do_widen() must always return the same result for the
1086 * same input.
1087 *
1088 * Note: this is not what you want for codepage conversions. See
1089 * codecvt for that.
1090 *
1091 * @param lo Pointer to start of range.
1092 * @param hi Pointer to end of range.
1093 * @param to Pointer to the destination array.
1094 * @return @a hi.
1095 */
725dc051 1096 virtual const char*
82c2e3d4
BK
1097 do_widen(const char* __lo, const char* __hi, char_type* __dest) const
1098 {
1099 memcpy(__dest, __lo, __hi - __lo);
1100 return __hi;
1101 }
725dc051 1102
2dbd0234
JQ
1103 /**
1104 * @brief Narrow char
1105 *
1106 * This virtual function converts the char to char using the simplest
1107 * reasonable transformation. If the conversion fails, dfault is
1108 * returned instead. For an underived ctype<char> facet, @a c will be
1109 * returned unchanged.
1110 *
1111 * do_narrow() is a hook for a derived facet to change the behavior of
1112 * narrowing. do_narrow() must always return the same result for the
1113 * same input.
1114 *
1115 * Note: this is not what you want for codepage conversions. See
1116 * codecvt for that.
1117 *
1118 * @param c The char to convert.
1119 * @param dfault Char to return if conversion fails.
1120 * @return The converted char.
1121 */
ed6814f7 1122 virtual char
82c2e3d4
BK
1123 do_narrow(char_type __c, char) const
1124 { return __c; }
725dc051 1125
2dbd0234
JQ
1126 /**
1127 * @brief Narrow char array to char array
1128 *
1129 * This virtual function converts each char in the range [lo,hi) to
1130 * char using the simplest reasonable transformation and writes the
1131 * results to the destination array. For any char in the input that
1132 * cannot be converted, @a dfault is used instead. For an underived
1133 * ctype<char> facet, the argument will be copied unchanged.
1134 *
1135 * do_narrow() is a hook for a derived facet to change the behavior of
1136 * narrowing. do_narrow() must always return the same result for the
1137 * same input.
1138 *
1139 * Note: this is not what you want for codepage conversions. See
1140 * codecvt for that.
1141 *
1142 * @param lo Pointer to start of range.
1143 * @param hi Pointer to end of range.
1144 * @param dfault Char to use if conversion fails.
1145 * @param to Pointer to the destination array.
1146 * @return @a hi.
1147 */
725dc051 1148 virtual const char_type*
fdf1b60d 1149 do_narrow(const char_type* __lo, const char_type* __hi,
82c2e3d4
BK
1150 char, char* __dest) const
1151 {
1152 memcpy(__dest, __lo, __hi - __lo);
1153 return __hi;
1154 }
3fc63c15
JQ
1155
1156 private:
1157
1158 void _M_widen_init() const
1159 {
1160 char __tmp[sizeof(_M_widen)];
9a1349b9 1161 for (size_t __i = 0; __i < sizeof(_M_widen); ++__i)
3fc63c15
JQ
1162 __tmp[__i] = __i;
1163 do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen);
ed6814f7 1164
3fc63c15
JQ
1165 _M_widen_ok = 1;
1166 // Set _M_widen_ok to 2 if memcpy can't be used.
82ce2a94
PC
1167 if (memcmp(__tmp, _M_widen, sizeof(_M_widen)))
1168 _M_widen_ok = 2;
3fc63c15
JQ
1169 }
1170
1171 // Fill in the narrowing cache and flag whether all values are
82ce2a94
PC
1172 // valid or not. _M_narrow_ok is set to 2 if memcpy can't
1173 // be used.
3fc63c15
JQ
1174 void _M_narrow_init() const
1175 {
1176 char __tmp[sizeof(_M_narrow)];
9a1349b9 1177 for (size_t __i = 0; __i < sizeof(_M_narrow); ++__i)
84cea626 1178 __tmp[__i] = __i;
3fc63c15
JQ
1179 do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow);
1180
82ce2a94
PC
1181 _M_narrow_ok = 1;
1182 if (memcmp(__tmp, _M_narrow, sizeof(_M_narrow)))
1183 _M_narrow_ok = 2;
1184 else
1185 {
1186 // Deal with the special case of zero: renarrow with a
1187 // different default and compare.
1188 char __c;
1189 do_narrow(__tmp, __tmp + 1, 1, &__c);
1190 if (__c == 1)
1191 _M_narrow_ok = 2;
1192 }
3fc63c15 1193 }
725dc051 1194 };
ed6814f7 1195
725dc051
BK
1196 template<>
1197 const ctype<char>&
697649ea 1198 use_facet<ctype<char> >(const locale& __loc);
725dc051 1199
3d7c150e 1200#ifdef _GLIBCXX_USE_WCHAR_T
9e5c7dba 1201 // 22.2.1.3 ctype<wchar_t> specialization
2dbd0234
JQ
1202 /**
1203 * @brief The ctype<wchar_t> specialization.
1204 *
1205 * This class defines classification and conversion functions for the
1206 * wchar_t type. It gets used by wchar_t streams for many I/O operations.
1207 * The wchar_t specialization provides a number of optimizations as well.
1208 *
1209 * ctype<wchar_t> inherits its public methods from
1210 * __ctype_abstract_base<wchar_t>.
1211 */
725dc051 1212 template<>
167ed88f 1213 class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
725dc051
BK
1214 {
1215 public:
1216 // Types:
2dbd0234 1217 /// Typedef for the template parameter wchar_t.
ed6814f7
BI
1218 typedef wchar_t char_type;
1219 typedef wctype_t __wmask_type;
725dc051 1220
def9790d
BK
1221 protected:
1222 __c_locale _M_c_locale_ctype;
1223
ca13fb7f
PC
1224 // Pre-computed narrowed and widened chars.
1225 bool _M_narrow_ok;
e3c0c098 1226 char _M_narrow[128];
ca13fb7f 1227 wint_t _M_widen[1 + static_cast<unsigned char>(-1)];
e3c0c098 1228
9a1349b9
PC
1229 // Pre-computed elements for do_is.
1230 mask _M_bit[16];
1231 __wmask_type _M_wmask[16];
1232
def9790d 1233 public:
725dc051 1234 // Data Members:
2dbd0234 1235 /// The facet id for ctype<wchar_t>
ed6814f7 1236 static locale::id id;
725dc051 1237
2dbd0234
JQ
1238 /**
1239 * @brief Constructor performs initialization.
1240 *
1241 * This is the constructor provided by the standard.
1242 *
1243 * @param refs Passed to the base facet class.
1244 */
ed6814f7 1245 explicit
725dc051 1246 ctype(size_t __refs = 0);
9e5c7dba 1247
2dbd0234
JQ
1248 /**
1249 * @brief Constructor performs static initialization.
1250 *
1251 * This constructor is used to construct the initial C locale facet.
1252 *
1253 * @param cloc Handle to C locale data.
1254 * @param refs Passed to the base facet class.
1255 */
ed6814f7 1256 explicit
9e5c7dba 1257 ctype(__c_locale __cloc, size_t __refs = 0);
725dc051
BK
1258
1259 protected:
1260 __wmask_type
167ed88f 1261 _M_convert_to_wmask(const mask __m) const;
725dc051 1262
2dbd0234 1263 /// Destructor
ed6814f7 1264 virtual
725dc051
BK
1265 ~ctype();
1266
2dbd0234
JQ
1267 /**
1268 * @brief Test wchar_t classification.
1269 *
1270 * This function finds a mask M for @a c and compares it to mask @a m.
1271 *
1272 * do_is() is a hook for a derived facet to change the behavior of
1273 * classifying. do_is() must always return the same result for the
1274 * same input.
1275 *
1276 * @param c The wchar_t to find the mask of.
1277 * @param m The mask to compare against.
1278 * @return (M & m) != 0.
1279 */
ed6814f7 1280 virtual bool
725dc051
BK
1281 do_is(mask __m, char_type __c) const;
1282
2dbd0234
JQ
1283 /**
1284 * @brief Return a mask array.
1285 *
1286 * This function finds the mask for each wchar_t in the range [lo,hi)
1287 * and successively writes it to vec. vec must have as many elements
1288 * as the input.
1289 *
1290 * do_is() is a hook for a derived facet to change the behavior of
1291 * classifying. do_is() must always return the same result for the
1292 * same input.
1293 *
1294 * @param lo Pointer to start of range.
1295 * @param hi Pointer to end of range.
1296 * @param vec Pointer to an array of mask storage.
1297 * @return @a hi.
1298 */
725dc051 1299 virtual const char_type*
fdf1b60d 1300 do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const;
725dc051 1301
2dbd0234
JQ
1302 /**
1303 * @brief Find wchar_t matching mask
1304 *
1305 * This function searches for and returns the first wchar_t c in
1306 * [lo,hi) for which is(m,c) is true.
1307 *
1308 * do_scan_is() is a hook for a derived facet to change the behavior of
1309 * match searching. do_is() must always return the same result for the
1310 * same input.
1311 *
1312 * @param m The mask to compare against.
1313 * @param lo Pointer to start of range.
1314 * @param hi Pointer to end of range.
1315 * @return Pointer to a matching wchar_t if found, else @a hi.
1316 */
725dc051 1317 virtual const char_type*
fdf1b60d 1318 do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const;
725dc051 1319
2dbd0234
JQ
1320 /**
1321 * @brief Find wchar_t not matching mask
1322 *
1323 * This function searches for and returns a pointer to the first
1324 * wchar_t c of [lo,hi) for which is(m,c) is false.
1325 *
1326 * do_scan_is() is a hook for a derived facet to change the behavior of
1327 * match searching. do_is() must always return the same result for the
1328 * same input.
1329 *
1330 * @param m The mask to compare against.
1331 * @param lo Pointer to start of range.
1332 * @param hi Pointer to end of range.
1333 * @return Pointer to a non-matching wchar_t if found, else @a hi.
1334 */
725dc051 1335 virtual const char_type*
ed6814f7 1336 do_scan_not(mask __m, const char_type* __lo,
725dc051
BK
1337 const char_type* __hi) const;
1338
2dbd0234
JQ
1339 /**
1340 * @brief Convert to uppercase.
1341 *
1342 * This virtual function converts the wchar_t argument to uppercase if
1343 * possible. If not possible (for example, '2'), returns the argument.
1344 *
1345 * do_toupper() is a hook for a derived facet to change the behavior of
1346 * uppercasing. do_toupper() must always return the same result for
1347 * the same input.
1348 *
1349 * @param c The wchar_t to convert.
1350 * @return The uppercase wchar_t if convertible, else @a c.
1351 */
ed6814f7 1352 virtual char_type
725dc051
BK
1353 do_toupper(char_type) const;
1354
2dbd0234
JQ
1355 /**
1356 * @brief Convert array to uppercase.
1357 *
1358 * This virtual function converts each wchar_t in the range [lo,hi) to
1359 * uppercase if possible. Other elements remain untouched.
1360 *
1361 * do_toupper() is a hook for a derived facet to change the behavior of
1362 * uppercasing. do_toupper() must always return the same result for
1363 * the same input.
1364 *
1365 * @param lo Pointer to start of range.
1366 * @param hi Pointer to end of range.
1367 * @return @a hi.
1368 */
725dc051 1369 virtual const char_type*
fdf1b60d 1370 do_toupper(char_type* __lo, const char_type* __hi) const;
725dc051 1371
2dbd0234
JQ
1372 /**
1373 * @brief Convert to lowercase.
1374 *
1375 * This virtual function converts the argument to lowercase if
1376 * possible. If not possible (for example, '2'), returns the argument.
1377 *
1378 * do_tolower() is a hook for a derived facet to change the behavior of
1379 * lowercasing. do_tolower() must always return the same result for
1380 * the same input.
1381 *
1382 * @param c The wchar_t to convert.
1383 * @return The lowercase wchar_t if convertible, else @a c.
1384 */
ed6814f7 1385 virtual char_type
725dc051
BK
1386 do_tolower(char_type) const;
1387
2dbd0234
JQ
1388 /**
1389 * @brief Convert array to lowercase.
1390 *
1391 * This virtual function converts each wchar_t in the range [lo,hi) to
1392 * lowercase if possible. Other elements remain untouched.
1393 *
1394 * do_tolower() is a hook for a derived facet to change the behavior of
1395 * lowercasing. do_tolower() must always return the same result for
1396 * the same input.
1397 *
1398 * @param lo Pointer to start of range.
1399 * @param hi Pointer to end of range.
1400 * @return @a hi.
1401 */
725dc051 1402 virtual const char_type*
fdf1b60d 1403 do_tolower(char_type* __lo, const char_type* __hi) const;
ed6814f7 1404
2dbd0234
JQ
1405 /**
1406 * @brief Widen char to wchar_t
1407 *
1408 * This virtual function converts the char to wchar_t using the
1409 * simplest reasonable transformation. For an underived ctype<wchar_t>
1410 * facet, the argument will be cast to wchar_t.
1411 *
1412 * do_widen() is a hook for a derived facet to change the behavior of
1413 * widening. do_widen() must always return the same result for the
1414 * same input.
1415 *
1416 * Note: this is not what you want for codepage conversions. See
1417 * codecvt for that.
1418 *
1419 * @param c The char to convert.
1420 * @return The converted wchar_t.
1421 */
ed6814f7 1422 virtual char_type
725dc051
BK
1423 do_widen(char) const;
1424
2dbd0234
JQ
1425 /**
1426 * @brief Widen char array to wchar_t array
1427 *
1428 * This function converts each char in the input to wchar_t using the
1429 * simplest reasonable transformation. For an underived ctype<wchar_t>
1430 * facet, the argument will be copied, casting each element to wchar_t.
1431 *
1432 * do_widen() is a hook for a derived facet to change the behavior of
1433 * widening. do_widen() must always return the same result for the
1434 * same input.
1435 *
1436 * Note: this is not what you want for codepage conversions. See
1437 * codecvt for that.
1438 *
1439 * @param lo Pointer to start range.
1440 * @param hi Pointer to end of range.
1441 * @param to Pointer to the destination array.
1442 * @return @a hi.
1443 */
725dc051 1444 virtual const char*
fdf1b60d 1445 do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
725dc051 1446
2dbd0234
JQ
1447 /**
1448 * @brief Narrow wchar_t to char
1449 *
586b5f20
BK
1450 * This virtual function converts the argument to char using
1451 * the simplest reasonable transformation. If the conversion
1452 * fails, dfault is returned instead. For an underived
1453 * ctype<wchar_t> facet, @a c will be cast to char and
1454 * returned.
2dbd0234 1455 *
586b5f20
BK
1456 * do_narrow() is a hook for a derived facet to change the
1457 * behavior of narrowing. do_narrow() must always return the
1458 * same result for the same input.
2dbd0234
JQ
1459 *
1460 * Note: this is not what you want for codepage conversions. See
1461 * codecvt for that.
1462 *
1463 * @param c The wchar_t to convert.
1464 * @param dfault Char to return if conversion fails.
1465 * @return The converted char.
1466 */
ed6814f7 1467 virtual char
725dc051
BK
1468 do_narrow(char_type, char __dfault) const;
1469
2dbd0234
JQ
1470 /**
1471 * @brief Narrow wchar_t array to char array
1472 *
1473 * This virtual function converts each wchar_t in the range [lo,hi) to
1474 * char using the simplest reasonable transformation and writes the
1475 * results to the destination array. For any wchar_t in the input that
1476 * cannot be converted, @a dfault is used instead. For an underived
1477 * ctype<wchar_t> facet, the argument will be copied, casting each
1478 * element to char.
1479 *
1480 * do_narrow() is a hook for a derived facet to change the behavior of
1481 * narrowing. do_narrow() must always return the same result for the
1482 * same input.
1483 *
1484 * Note: this is not what you want for codepage conversions. See
1485 * codecvt for that.
1486 *
1487 * @param lo Pointer to start of range.
1488 * @param hi Pointer to end of range.
1489 * @param dfault Char to use if conversion fails.
1490 * @param to Pointer to the destination array.
1491 * @return @a hi.
1492 */
725dc051 1493 virtual const char_type*
fdf1b60d 1494 do_narrow(const char_type* __lo, const char_type* __hi,
def9790d 1495 char __dfault, char* __dest) const;
e3c0c098
PC
1496
1497 // For use at construction time only.
ed6814f7 1498 void
e3c0c098 1499 _M_initialize_ctype();
725dc051
BK
1500 };
1501
1502 template<>
1503 const ctype<wchar_t>&
697649ea 1504 use_facet<ctype<wchar_t> >(const locale& __loc);
3d7c150e 1505#endif //_GLIBCXX_USE_WCHAR_T
725dc051 1506
33590f13 1507 // Include host and configuration specific ctype inlines.
e974e9cc 1508 #include <bits/ctype_inline.h>
725dc051 1509
00aca6e8 1510 /// @brief class ctype_byname [22.2.1.2].
725dc051
BK
1511 template<typename _CharT>
1512 class ctype_byname : public ctype<_CharT>
1513 {
1514 public:
ed6814f7 1515 typedef _CharT char_type;
725dc051 1516
ed6814f7 1517 explicit
def9790d 1518 ctype_byname(const char* __s, size_t __refs = 0);
725dc051
BK
1519
1520 protected:
ed6814f7 1521 virtual
def9790d 1522 ~ctype_byname() { };
725dc051
BK
1523 };
1524
00aca6e8 1525 /// 22.2.1.4 Class ctype_byname specializations.
725dc051
BK
1526 template<>
1527 ctype_byname<char>::ctype_byname(const char*, size_t refs);
725dc051 1528
def9790d
BK
1529 template<>
1530 ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs);
725dc051 1531
0a31609b
BK
1532 // 22.2.1.5 Template class codecvt
1533 #include <bits/codecvt.h>
1534
def9790d 1535 // 22.2.2 The numeric category.
ed6814f7 1536 class __num_base
86ade44c 1537 {
ce3039af 1538 public:
6067bea4
BK
1539 // NB: Code depends on the order of _S_atoms_out elements.
1540 // Below are the indices into _S_atoms_out.
ed6814f7
BI
1541 enum
1542 {
1543 _S_ominus,
1544 _S_oplus,
1545 _S_ox,
1546 _S_oX,
655d7821
BK
1547 _S_odigits,
1548 _S_odigits_end = _S_odigits + 16,
ed6814f7 1549 _S_oudigits = _S_odigits_end,
655d7821
BK
1550 _S_oudigits_end = _S_oudigits + 16,
1551 _S_oe = _S_odigits + 14, // For scientific notation, 'e'
1552 _S_oE = _S_oudigits + 14, // For scientific notation, 'E'
1553 _S_oend = _S_oudigits_end
ce3039af 1554 };
ed6814f7 1555
6067bea4
BK
1556 // A list of valid numeric literals for output. This array
1557 // contains chars that will be passed through the current locale's
1558 // ctype<_CharT>.widen() and then used to render numbers.
1559 // For the standard "C" locale, this is
ce3039af
JQ
1560 // "-+xX0123456789abcdef0123456789ABCDEF".
1561 static const char* _S_atoms_out;
1562
86ade44c 1563 // String literal of acceptable (narrow) input, for num_get.
0fa96a60 1564 // "-+xX0123456789abcdefABCDEF"
ce3039af 1565 static const char* _S_atoms_in;
86ade44c 1566
ed6814f7
BI
1567 enum
1568 {
1569 _S_iminus,
1570 _S_iplus,
1571 _S_ix,
1572 _S_iX,
655d7821 1573 _S_izero,
0fa96a60
PC
1574 _S_ie = _S_izero + 14,
1575 _S_iE = _S_izero + 20,
7942afdc 1576 _S_iend = 26
86ade44c
BK
1577 };
1578
4b9aaf63 1579 // num_put
86ade44c 1580 // Construct and return valid scanf format for floating point types.
5dc91152
PC
1581 static void
1582 _S_format_float(const ios_base& __io, char* __fptr, char __mod);
86ade44c
BK
1583 };
1584
215f9e28
BK
1585 template<typename _CharT>
1586 struct __numpunct_cache : public locale::facet
1587 {
ed6814f7 1588 const char* _M_grouping;
47f62b27 1589 size_t _M_grouping_size;
215f9e28 1590 bool _M_use_grouping;
ed6814f7 1591 const _CharT* _M_truename;
47f62b27 1592 size_t _M_truename_size;
cde63840 1593 const _CharT* _M_falsename;
ed6814f7
BI
1594 size_t _M_falsename_size;
1595 _CharT _M_decimal_point;
1596 _CharT _M_thousands_sep;
1597
215f9e28
BK
1598 // A list of valid numeric literals for output: in the standard
1599 // "C" locale, this is "-+xX0123456789abcdef0123456789ABCDEF".
1600 // This array contains the chars after having been passed
1601 // through the current locale's ctype<_CharT>.widen().
ed6814f7 1602 _CharT _M_atoms_out[__num_base::_S_oend];
215f9e28 1603
7942afdc 1604 // A list of valid numeric literals for input: in the standard
0fa96a60 1605 // "C" locale, this is "-+xX0123456789abcdefABCDEF"
215f9e28
BK
1606 // This array contains the chars after having been passed
1607 // through the current locale's ctype<_CharT>.widen().
ed6814f7 1608 _CharT _M_atoms_in[__num_base::_S_iend];
215f9e28
BK
1609
1610 bool _M_allocated;
1611
ed6814f7 1612 __numpunct_cache(size_t __refs = 0) : facet(__refs),
47f62b27
PC
1613 _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
1614 _M_truename(NULL), _M_truename_size(0), _M_falsename(NULL),
1615 _M_falsename_size(0), _M_decimal_point(_CharT()),
1616 _M_thousands_sep(_CharT()), _M_allocated(false)
ed6814f7 1617 { }
215f9e28
BK
1618
1619 ~__numpunct_cache();
1620
1621 void
1622 _M_cache(const locale& __loc);
26c691a8
BK
1623
1624 private:
1625 __numpunct_cache&
1626 operator=(const __numpunct_cache&);
1627
1628 explicit
1629 __numpunct_cache(const __numpunct_cache&);
215f9e28
BK
1630 };
1631
215f9e28
BK
1632 template<typename _CharT>
1633 __numpunct_cache<_CharT>::~__numpunct_cache()
1634 {
1635 if (_M_allocated)
1636 {
1637 delete [] _M_grouping;
1638 delete [] _M_truename;
1639 delete [] _M_falsename;
1640 }
1641 }
4b9aaf63 1642
9a01c9b0
JQ
1643 /**
1644 * @brief Numpunct facet.
1645 *
1646 * This facet stores several pieces of information related to printing and
1647 * scanning numbers, such as the decimal point character. It takes a
1648 * template parameter specifying the char type. The numpunct facet is
1649 * used by streams for many I/O operations involving numbers.
1650 *
1651 * The numpunct template uses protected virtual functions to provide the
1652 * actual results. The public accessors forward the call to the virtual
1653 * functions. These virtual functions are hooks for developers to
1654 * implement the behavior they require from a numpunct facet.
1655 */
725dc051 1656 template<typename _CharT>
86ade44c 1657 class numpunct : public locale::facet
725dc051 1658 {
86ade44c 1659 public:
725dc051 1660 // Types:
9a01c9b0
JQ
1661 //@{
1662 /// Public typedefs
ed6814f7
BI
1663 typedef _CharT char_type;
1664 typedef basic_string<_CharT> string_type;
9a01c9b0 1665 //@}
215f9e28
BK
1666 typedef __numpunct_cache<_CharT> __cache_type;
1667
1668 protected:
1669 __cache_type* _M_data;
725dc051 1670
215f9e28 1671 public:
9a01c9b0 1672 /// Numpunct facet id.
ed6814f7 1673 static locale::id id;
725dc051 1674
9a01c9b0
JQ
1675 /**
1676 * @brief Numpunct constructor.
1677 *
1678 * @param refs Refcount to pass to the base class.
1679 */
ed6814f7 1680 explicit
215f9e28
BK
1681 numpunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
1682 { _M_initialize_numpunct(); }
725dc051 1683
9a01c9b0
JQ
1684 /**
1685 * @brief Internal constructor. Not for general use.
1686 *
1687 * This is a constructor for use by the library itself to set up the
1688 * predefined locale facets.
1689 *
1690 * @param cache __numpunct_cache object.
1691 * @param refs Refcount to pass to the base class.
1692 */
ed6814f7
BI
1693 explicit
1694 numpunct(__cache_type* __cache, size_t __refs = 0)
215f9e28 1695 : facet(__refs), _M_data(__cache)
86ade44c
BK
1696 { _M_initialize_numpunct(); }
1697
9a01c9b0
JQ
1698 /**
1699 * @brief Internal constructor. Not for general use.
1700 *
1701 * This is a constructor for use by the library itself to set up new
1702 * locales.
1703 *
1704 * @param cloc The "C" locale.
1705 * @param refs Refcount to pass to the base class.
1706 */
ed6814f7
BI
1707 explicit
1708 numpunct(__c_locale __cloc, size_t __refs = 0)
fea4065d 1709 : facet(__refs), _M_data(NULL)
86ade44c
BK
1710 { _M_initialize_numpunct(__cloc); }
1711
9a01c9b0
JQ
1712 /**
1713 * @brief Return decimal point character.
1714 *
1715 * This function returns a char_type to use as a decimal point. It
1716 * does so by returning returning
1717 * numpunct<char_type>::do_decimal_point().
1718 *
1719 * @return @a char_type representing a decimal point.
1720 */
ed6814f7 1721 char_type
86ade44c
BK
1722 decimal_point() const
1723 { return this->do_decimal_point(); }
1724
9a01c9b0
JQ
1725 /**
1726 * @brief Return thousands separator character.
1727 *
586b5f20
BK
1728 * This function returns a char_type to use as a thousands
1729 * separator. It does so by returning returning
9a01c9b0
JQ
1730 * numpunct<char_type>::do_thousands_sep().
1731 *
1732 * @return char_type representing a thousands separator.
1733 */
ed6814f7 1734 char_type
86ade44c
BK
1735 thousands_sep() const
1736 { return this->do_thousands_sep(); }
1737
9a01c9b0
JQ
1738 /**
1739 * @brief Return grouping specification.
1740 *
1741 * This function returns a string representing groupings for the
1742 * integer part of a number. Groupings indicate where thousands
1743 * separators should be inserted in the integer part of a number.
1744 *
586b5f20
BK
1745 * Each char in the return string is interpret as an integer
1746 * rather than a character. These numbers represent the number
1747 * of digits in a group. The first char in the string
1748 * represents the number of digits in the least significant
1749 * group. If a char is negative, it indicates an unlimited
1750 * number of digits for the group. If more chars from the
9a01c9b0
JQ
1751 * string are required to group a number, the last char is used
1752 * repeatedly.
1753 *
586b5f20
BK
1754 * For example, if the grouping() returns "\003\002" and is
1755 * applied to the number 123456789, this corresponds to
1756 * 12,34,56,789. Note that if the string was "32", this would
1757 * put more than 50 digits into the least significant group if
1758 * the character set is ASCII.
9a01c9b0
JQ
1759 *
1760 * The string is returned by calling
1761 * numpunct<char_type>::do_grouping().
1762 *
1763 * @return string representing grouping specification.
1764 */
ed6814f7 1765 string
86ade44c
BK
1766 grouping() const
1767 { return this->do_grouping(); }
1768
9a01c9b0
JQ
1769 /**
1770 * @brief Return string representation of bool true.
1771 *
1772 * This function returns a string_type containing the text
1773 * representation for true bool variables. It does so by calling
1774 * numpunct<char_type>::do_truename().
1775 *
1776 * @return string_type representing printed form of true.
1777 */
ed6814f7 1778 string_type
86ade44c
BK
1779 truename() const
1780 { return this->do_truename(); }
1781
9a01c9b0
JQ
1782 /**
1783 * @brief Return string representation of bool false.
1784 *
1785 * This function returns a string_type containing the text
1786 * representation for false bool variables. It does so by calling
1787 * numpunct<char_type>::do_falsename().
1788 *
1789 * @return string_type representing printed form of false.
1790 */
ed6814f7 1791 string_type
86ade44c
BK
1792 falsename() const
1793 { return this->do_falsename(); }
1794
1795 protected:
9a01c9b0 1796 /// Destructor.
ed6814f7 1797 virtual
d3a193e3 1798 ~numpunct();
86ade44c 1799
9a01c9b0
JQ
1800 /**
1801 * @brief Return decimal point character.
1802 *
1803 * Returns a char_type to use as a decimal point. This function is a
1804 * hook for derived classes to change the value returned.
1805 *
1806 * @return @a char_type representing a decimal point.
1807 */
ed6814f7 1808 virtual char_type
86ade44c 1809 do_decimal_point() const
215f9e28 1810 { return _M_data->_M_decimal_point; }
725dc051 1811
9a01c9b0
JQ
1812 /**
1813 * @brief Return thousands separator character.
1814 *
1815 * Returns a char_type to use as a thousands separator. This function
1816 * is a hook for derived classes to change the value returned.
1817 *
1818 * @return @a char_type representing a thousands separator.
1819 */
ed6814f7 1820 virtual char_type
86ade44c 1821 do_thousands_sep() const
215f9e28 1822 { return _M_data->_M_thousands_sep; }
86ade44c 1823
9a01c9b0
JQ
1824 /**
1825 * @brief Return grouping specification.
1826 *
1827 * Returns a string representing groupings for the integer part of a
1828 * number. This function is a hook for derived classes to change the
1829 * value returned. @see grouping() for details.
1830 *
1831 * @return String representing grouping specification.
1832 */
86ade44c
BK
1833 virtual string
1834 do_grouping() const
215f9e28 1835 { return _M_data->_M_grouping; }
86ade44c 1836
9a01c9b0
JQ
1837 /**
1838 * @brief Return string representation of bool true.
1839 *
1840 * Returns a string_type containing the text representation for true
1841 * bool variables. This function is a hook for derived classes to
1842 * change the value returned.
1843 *
1844 * @return string_type representing printed form of true.
1845 */
1846 virtual string_type
86ade44c 1847 do_truename() const
215f9e28 1848 { return _M_data->_M_truename; }
86ade44c 1849
9a01c9b0
JQ
1850 /**
1851 * @brief Return string representation of bool false.
1852 *
1853 * Returns a string_type containing the text representation for false
1854 * bool variables. This function is a hook for derived classes to
1855 * change the value returned.
1856 *
1857 * @return string_type representing printed form of false.
1858 */
1859 virtual string_type
86ade44c 1860 do_falsename() const
215f9e28 1861 { return _M_data->_M_falsename; }
86ade44c
BK
1862
1863 // For use at construction time only.
ed6814f7 1864 void
aa53f832 1865 _M_initialize_numpunct(__c_locale __cloc = NULL);
725dc051
BK
1866 };
1867
0a31609b 1868 template<typename _CharT>
86ade44c 1869 locale::id numpunct<_CharT>::id;
0a31609b 1870
ed6814f7 1871 template<>
d3a193e3
BK
1872 numpunct<char>::~numpunct();
1873
ed6814f7 1874 template<>
86ade44c
BK
1875 void
1876 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
ea0c0b6e 1877
3d7c150e 1878#ifdef _GLIBCXX_USE_WCHAR_T
ed6814f7 1879 template<>
d3a193e3
BK
1880 numpunct<wchar_t>::~numpunct();
1881
ed6814f7 1882 template<>
86ade44c
BK
1883 void
1884 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
725dc051
BK
1885#endif
1886
00aca6e8 1887 /// @brief class numpunct_byname [22.2.3.2].
86ade44c
BK
1888 template<typename _CharT>
1889 class numpunct_byname : public numpunct<_CharT>
725dc051
BK
1890 {
1891 public:
ed6814f7
BI
1892 typedef _CharT char_type;
1893 typedef basic_string<_CharT> string_type;
725dc051 1894
ed6814f7 1895 explicit
86ade44c
BK
1896 numpunct_byname(const char* __s, size_t __refs = 0)
1897 : numpunct<_CharT>(__refs)
1898 {
bf5fe473
BK
1899 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
1900 {
1901 __c_locale __tmp;
1902 this->_S_create_c_locale(__tmp, __s);
ed6814f7
BI
1903 this->_M_initialize_numpunct(__tmp);
1904 this->_S_destroy_c_locale(__tmp);
bf5fe473 1905 }
86ade44c 1906 }
725dc051 1907
86ade44c 1908 protected:
ed6814f7
BI
1909 virtual
1910 ~numpunct_byname() { }
725dc051
BK
1911 };
1912
9a01c9b0
JQ
1913 /**
1914 * @brief Facet for parsing number strings.
1915 *
1916 * This facet encapsulates the code to parse and return a number
1917 * from a string. It is used by the istream numeric extraction
1918 * operators.
1919 *
1920 * The num_get template uses protected virtual functions to provide the
1921 * actual results. The public accessors forward the call to the virtual
1922 * functions. These virtual functions are hooks for developers to
1923 * implement the behavior they require from the num_get facet.
1924 */
725dc051 1925 template<typename _CharT, typename _InIter>
586b5f20 1926 class num_get : public locale::facet
725dc051
BK
1927 {
1928 public:
1929 // Types:
9a01c9b0
JQ
1930 //@{
1931 /// Public typedefs
ed6814f7
BI
1932 typedef _CharT char_type;
1933 typedef _InIter iter_type;
9a01c9b0 1934 //@}
725dc051 1935
9a01c9b0 1936 /// Numpunct facet id.
ed6814f7 1937 static locale::id id;
725dc051 1938
9a01c9b0
JQ
1939 /**
1940 * @brief Constructor performs initialization.
1941 *
1942 * This is the constructor provided by the standard.
1943 *
1944 * @param refs Passed to the base facet class.
1945 */
ed6814f7 1946 explicit
fea4065d 1947 num_get(size_t __refs = 0) : facet(__refs) { }
725dc051 1948
9a01c9b0
JQ
1949 /**
1950 * @brief Numeric parsing.
1951 *
1952 * Parses the input stream into the bool @a v. It does so by calling
a65da37d 1953 * num_get::do_get().
9a01c9b0 1954 *
586b5f20
BK
1955 * If ios_base::boolalpha is set, attempts to read
1956 * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
1957 * @a v to true or false if successful. Sets err to
1958 * ios_base::failbit if reading the string fails. Sets err to
1959 * ios_base::eofbit if the stream is emptied.
9a01c9b0
JQ
1960 *
1961 * If ios_base::boolalpha is not set, proceeds as with reading a long,
1962 * except if the value is 1, sets @a v to true, if the value is 0, sets
1963 * @a v to false, and otherwise set err to ios_base::failbit.
1964 *
1965 * @param in Start of input stream.
1966 * @param end End of input stream.
1967 * @param io Source of locale and flags.
1968 * @param err Error flags to set.
1969 * @param v Value to format and insert.
1970 * @return Iterator after reading.
1971 */
ed6814f7 1972 iter_type
725dc051
BK
1973 get(iter_type __in, iter_type __end, ios_base& __io,
1974 ios_base::iostate& __err, bool& __v) const
86ade44c 1975 { return this->do_get(__in, __end, __io, __err, __v); }
725dc051 1976
9a01c9b0
JQ
1977 //@{
1978 /**
1979 * @brief Numeric parsing.
1980 *
1981 * Parses the input stream into the integral variable @a v. It does so
a65da37d 1982 * by calling num_get::do_get().
9a01c9b0
JQ
1983 *
1984 * Parsing is affected by the flag settings in @a io.
1985 *
1986 * The basic parse is affected by the value of io.flags() &
1987 * ios_base::basefield. If equal to ios_base::oct, parses like the
1988 * scanf %o specifier. Else if equal to ios_base::hex, parses like %X
1989 * specifier. Else if basefield equal to 0, parses like the %i
1990 * specifier. Otherwise, parses like %d for signed and %u for unsigned
1991 * types. The matching type length modifier is also used.
1992 *
1993 * Digit grouping is intrepreted according to numpunct::grouping() and
1994 * numpunct::thousands_sep(). If the pattern of digit groups isn't
1995 * consistent, sets err to ios_base::failbit.
1996 *
1997 * If parsing the string yields a valid value for @a v, @a v is set.
1998 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
1999 * Sets err to ios_base::eofbit if the stream is emptied.
2000 *
2001 * @param in Start of input stream.
2002 * @param end End of input stream.
2003 * @param io Source of locale and flags.
2004 * @param err Error flags to set.
2005 * @param v Value to format and insert.
2006 * @return Iterator after reading.
2007 */
725dc051 2008 iter_type
ed6814f7 2009 get(iter_type __in, iter_type __end, ios_base& __io,
725dc051 2010 ios_base::iostate& __err, long& __v) const
86ade44c 2011 { return this->do_get(__in, __end, __io, __err, __v); }
725dc051 2012
ed6814f7 2013 iter_type
725dc051
BK
2014 get(iter_type __in, iter_type __end, ios_base& __io,
2015 ios_base::iostate& __err, unsigned short& __v) const
86ade44c 2016 { return this->do_get(__in, __end, __io, __err, __v); }
725dc051 2017
ed6814f7 2018 iter_type
725dc051
BK
2019 get(iter_type __in, iter_type __end, ios_base& __io,
2020 ios_base::iostate& __err, unsigned int& __v) const
86ade44c 2021 { return this->do_get(__in, __end, __io, __err, __v); }
725dc051 2022
ed6814f7 2023 iter_type
725dc051
BK
2024 get(iter_type __in, iter_type __end, ios_base& __io,
2025 ios_base::iostate& __err, unsigned long& __v) const
86ade44c 2026 { return this->do_get(__in, __end, __io, __err, __v); }
725dc051 2027
3d7c150e 2028#ifdef _GLIBCXX_USE_LONG_LONG
ed6814f7 2029 iter_type
86ade44c
BK
2030 get(iter_type __in, iter_type __end, ios_base& __io,
2031 ios_base::iostate& __err, long long& __v) const
2032 { return this->do_get(__in, __end, __io, __err, __v); }
2033
ed6814f7 2034 iter_type
725dc051
BK
2035 get(iter_type __in, iter_type __end, ios_base& __io,
2036 ios_base::iostate& __err, unsigned long long& __v) const
86ade44c 2037 { return this->do_get(__in, __end, __io, __err, __v); }
725dc051 2038#endif
9a01c9b0 2039 //@}
725dc051 2040
9a01c9b0
JQ
2041 //@{
2042 /**
2043 * @brief Numeric parsing.
2044 *
2045 * Parses the input stream into the integral variable @a v. It does so
a65da37d 2046 * by calling num_get::do_get().
9a01c9b0
JQ
2047 *
2048 * The input characters are parsed like the scanf %g specifier. The
2049 * matching type length modifier is also used.
2050 *
2051 * The decimal point character used is numpunct::decimal_point().
2052 * Digit grouping is intrepreted according to numpunct::grouping() and
2053 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2054 * consistent, sets err to ios_base::failbit.
2055 *
2056 * If parsing the string yields a valid value for @a v, @a v is set.
2057 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2058 * Sets err to ios_base::eofbit if the stream is emptied.
2059 *
2060 * @param in Start of input stream.
2061 * @param end End of input stream.
2062 * @param io Source of locale and flags.
2063 * @param err Error flags to set.
2064 * @param v Value to format and insert.
2065 * @return Iterator after reading.
2066 */
ed6814f7 2067 iter_type
725dc051
BK
2068 get(iter_type __in, iter_type __end, ios_base& __io,
2069 ios_base::iostate& __err, float& __v) const
86ade44c 2070 { return this->do_get(__in, __end, __io, __err, __v); }
725dc051 2071
ed6814f7 2072 iter_type
725dc051
BK
2073 get(iter_type __in, iter_type __end, ios_base& __io,
2074 ios_base::iostate& __err, double& __v) const
86ade44c 2075 { return this->do_get(__in, __end, __io, __err, __v); }
725dc051 2076
ed6814f7 2077 iter_type
725dc051
BK
2078 get(iter_type __in, iter_type __end, ios_base& __io,
2079 ios_base::iostate& __err, long double& __v) const
86ade44c 2080 { return this->do_get(__in, __end, __io, __err, __v); }
9a01c9b0 2081 //@}
725dc051 2082
9a01c9b0
JQ
2083 /**
2084 * @brief Numeric parsing.
2085 *
2086 * Parses the input stream into the pointer variable @a v. It does so
a65da37d 2087 * by calling num_get::do_get().
9a01c9b0
JQ
2088 *
2089 * The input characters are parsed like the scanf %p specifier.
2090 *
2091 * Digit grouping is intrepreted according to numpunct::grouping() and
2092 * numpunct::thousands_sep(). If the pattern of digit groups isn't
2093 * consistent, sets err to ios_base::failbit.
2094 *
2095 * Note that the digit grouping effect for pointers is a bit ambiguous
2096 * in the standard and shouldn't be relied on. See DR 344.
2097 *
2098 * If parsing the string yields a valid value for @a v, @a v is set.
2099 * Otherwise, sets err to ios_base::failbit and leaves @a v unaltered.
2100 * Sets err to ios_base::eofbit if the stream is emptied.
2101 *
2102 * @param in Start of input stream.
2103 * @param end End of input stream.
2104 * @param io Source of locale and flags.
2105 * @param err Error flags to set.
2106 * @param v Value to format and insert.
2107 * @return Iterator after reading.
2108 */
ed6814f7 2109 iter_type
725dc051
BK
2110 get(iter_type __in, iter_type __end, ios_base& __io,
2111 ios_base::iostate& __err, void*& __v) const
ed6814f7 2112 { return this->do_get(__in, __end, __io, __err, __v); }
725dc051
BK
2113
2114 protected:
9a01c9b0 2115 /// Destructor.
725dc051
BK
2116 virtual ~num_get() { }
2117
ed6814f7
BI
2118 iter_type
2119 _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&,
823b4f7d 2120 string& __xtrc) const;
86ade44c 2121
0fa96a60 2122 template<typename _ValueT>
ed6814f7
BI
2123 iter_type
2124 _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&,
0fa96a60 2125 _ValueT& __v) const;
725dc051 2126
9a01c9b0
JQ
2127 //@{
2128 /**
2129 * @brief Numeric parsing.
2130 *
2131 * Parses the input stream into the variable @a v. This function is a
2132 * hook for derived classes to change the value returned. @see get()
2133 * for more details.
2134 *
2135 * @param in Start of input stream.
2136 * @param end End of input stream.
2137 * @param io Source of locale and flags.
2138 * @param err Error flags to set.
2139 * @param v Value to format and insert.
2140 * @return Iterator after reading.
2141 */
ed6814f7 2142 virtual iter_type
725dc051
BK
2143 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
2144
f13a69ec 2145
ed6814f7 2146 virtual iter_type
86ade44c
BK
2147 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
2148
ed6814f7
BI
2149 virtual iter_type
2150 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
86ade44c
BK
2151 unsigned short&) const;
2152
ed6814f7
BI
2153 virtual iter_type
2154 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
86ade44c
BK
2155 unsigned int&) const;
2156
ed6814f7
BI
2157 virtual iter_type
2158 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
86ade44c
BK
2159 unsigned long&) const;
2160
ed6814f7
BI
2161#ifdef _GLIBCXX_USE_LONG_LONG
2162 virtual iter_type
2163 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
725dc051 2164 long long&) const;
86ade44c 2165
ed6814f7
BI
2166 virtual iter_type
2167 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
86ade44c 2168 unsigned long long&) const;
725dc051 2169#endif
86ade44c 2170
ed6814f7
BI
2171 virtual iter_type
2172 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
725dc051
BK
2173 float&) const;
2174
ed6814f7
BI
2175 virtual iter_type
2176 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
725dc051
BK
2177 double&) const;
2178
ed6814f7
BI
2179 virtual iter_type
2180 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
86ade44c 2181 long double&) const;
725dc051 2182
ed6814f7
BI
2183 virtual iter_type
2184 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
725dc051 2185 void*&) const;
9a01c9b0 2186 //@}
725dc051
BK
2187 };
2188
0a31609b
BK
2189 template<typename _CharT, typename _InIter>
2190 locale::id num_get<_CharT, _InIter>::id;
2191
f13a69ec 2192
9a01c9b0
JQ
2193 /**
2194 * @brief Facet for converting numbers to strings.
2195 *
2196 * This facet encapsulates the code to convert a number to a string. It is
2197 * used by the ostream numeric insertion operators.
2198 *
2199 * The num_put template uses protected virtual functions to provide the
2200 * actual results. The public accessors forward the call to the virtual
2201 * functions. These virtual functions are hooks for developers to
2202 * implement the behavior they require from the num_put facet.
2203 */
725dc051 2204 template<typename _CharT, typename _OutIter>
586b5f20 2205 class num_put : public locale::facet
725dc051
BK
2206 {
2207 public:
2208 // Types:
9a01c9b0
JQ
2209 //@{
2210 /// Public typedefs
ed6814f7
BI
2211 typedef _CharT char_type;
2212 typedef _OutIter iter_type;
9a01c9b0
JQ
2213 //@}
2214
2215 /// Numpunct facet id.
1ab65677 2216 static locale::id id;
725dc051 2217
9a01c9b0
JQ
2218 /**
2219 * @brief Constructor performs initialization.
2220 *
2221 * This is the constructor provided by the standard.
2222 *
2223 * @param refs Passed to the base facet class.
2224 */
ed6814f7 2225 explicit
fea4065d 2226 num_put(size_t __refs = 0) : facet(__refs) { }
725dc051 2227
9a01c9b0
JQ
2228 /**
2229 * @brief Numeric formatting.
2230 *
2231 * Formats the boolean @a v and inserts it into a stream. It does so
2232 * by calling num_put::do_put().
2233 *
2234 * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
2235 * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
2236 *
2237 * @param s Stream to write to.
2238 * @param io Source of locale and flags.
2239 * @param fill Char_type to use for filling.
2240 * @param v Value to format and insert.
2241 * @return Iterator after writing.
2242 */
ed6814f7 2243 iter_type
725dc051 2244 put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
86ade44c 2245 { return this->do_put(__s, __f, __fill, __v); }
725dc051 2246
9a01c9b0
JQ
2247 //@{
2248 /**
2249 * @brief Numeric formatting.
2250 *
586b5f20
BK
2251 * Formats the integral value @a v and inserts it into a
2252 * stream. It does so by calling num_put::do_put().
9a01c9b0
JQ
2253 *
2254 * Formatting is affected by the flag settings in @a io.
2255 *
2256 * The basic format is affected by the value of io.flags() &
2257 * ios_base::basefield. If equal to ios_base::oct, formats like the
2258 * printf %o specifier. Else if equal to ios_base::hex, formats like
2259 * %x or %X with ios_base::uppercase unset or set respectively.
2260 * Otherwise, formats like %d, %ld, %lld for signed and %u, %lu, %llu
2261 * for unsigned values. Note that if both oct and hex are set, neither
2262 * will take effect.
2263 *
2264 * If ios_base::showpos is set, '+' is output before positive values.
2265 * If ios_base::showbase is set, '0' precedes octal values (except 0)
2266 * and '0[xX]' precedes hex values.
2267 *
2268 * Thousands separators are inserted according to numpunct::grouping()
2269 * and numpunct::thousands_sep(). The decimal point character used is
2270 * numpunct::decimal_point().
2271 *
2272 * If io.width() is non-zero, enough @a fill characters are inserted to
2273 * make the result at least that wide. If
2274 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2275 * padded at the end. If ios_base::internal, then padding occurs
2276 * immediately after either a '+' or '-' or after '0x' or '0X'.
2277 * Otherwise, padding occurs at the beginning.
2278 *
2279 * @param s Stream to write to.
2280 * @param io Source of locale and flags.
2281 * @param fill Char_type to use for filling.
2282 * @param v Value to format and insert.
2283 * @return Iterator after writing.
2284 */
ed6814f7 2285 iter_type
725dc051 2286 put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
86ade44c 2287 { return this->do_put(__s, __f, __fill, __v); }
725dc051 2288
ed6814f7
BI
2289 iter_type
2290 put(iter_type __s, ios_base& __f, char_type __fill,
725dc051 2291 unsigned long __v) const
86ade44c 2292 { return this->do_put(__s, __f, __fill, __v); }
725dc051 2293
ed6814f7
BI
2294#ifdef _GLIBCXX_USE_LONG_LONG
2295 iter_type
725dc051 2296 put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
86ade44c 2297 { return this->do_put(__s, __f, __fill, __v); }
725dc051 2298
ed6814f7
BI
2299 iter_type
2300 put(iter_type __s, ios_base& __f, char_type __fill,
725dc051 2301 unsigned long long __v) const
86ade44c 2302 { return this->do_put(__s, __f, __fill, __v); }
725dc051 2303#endif
9a01c9b0 2304 //@}
725dc051 2305
9a01c9b0
JQ
2306 //@{
2307 /**
2308 * @brief Numeric formatting.
2309 *
2310 * Formats the floating point value @a v and inserts it into a stream.
2311 * It does so by calling num_put::do_put().
2312 *
2313 * Formatting is affected by the flag settings in @a io.
2314 *
2315 * The basic format is affected by the value of io.flags() &
2316 * ios_base::floatfield. If equal to ios_base::fixed, formats like the
2317 * printf %f specifier. Else if equal to ios_base::scientific, formats
2318 * like %e or %E with ios_base::uppercase unset or set respectively.
2319 * Otherwise, formats like %g or %G depending on uppercase. Note that
2320 * if both fixed and scientific are set, the effect will also be like
2321 * %g or %G.
2322 *
2323 * The output precision is given by io.precision(). This precision is
2324 * capped at numeric_limits::digits10 + 2 (different for double and
2325 * long double). The default precision is 6.
2326 *
2327 * If ios_base::showpos is set, '+' is output before positive values.
2328 * If ios_base::showpoint is set, a decimal point will always be
2329 * output.
2330 *
2331 * Thousands separators are inserted according to numpunct::grouping()
2332 * and numpunct::thousands_sep(). The decimal point character used is
2333 * numpunct::decimal_point().
2334 *
2335 * If io.width() is non-zero, enough @a fill characters are inserted to
2336 * make the result at least that wide. If
2337 * (io.flags() & ios_base::adjustfield) == ios_base::left, result is
2338 * padded at the end. If ios_base::internal, then padding occurs
2339 * immediately after either a '+' or '-' or after '0x' or '0X'.
2340 * Otherwise, padding occurs at the beginning.
2341 *
2342 * @param s Stream to write to.
2343 * @param io Source of locale and flags.
2344 * @param fill Char_type to use for filling.
2345 * @param v Value to format and insert.
2346 * @return Iterator after writing.
2347 */
ed6814f7 2348 iter_type
725dc051 2349 put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
86ade44c 2350 { return this->do_put(__s, __f, __fill, __v); }
725dc051 2351
ed6814f7
BI
2352 iter_type
2353 put(iter_type __s, ios_base& __f, char_type __fill,
725dc051 2354 long double __v) const
86ade44c 2355 { return this->do_put(__s, __f, __fill, __v); }
9a01c9b0 2356 //@}
725dc051 2357
9a01c9b0
JQ
2358 /**
2359 * @brief Numeric formatting.
2360 *
2361 * Formats the pointer value @a v and inserts it into a stream. It
2362 * does so by calling num_put::do_put().
2363 *
2364 * This function formats @a v as an unsigned long with ios_base::hex
2365 * and ios_base::showbase set.
2366 *
2367 * @param s Stream to write to.
2368 * @param io Source of locale and flags.
2369 * @param fill Char_type to use for filling.
2370 * @param v Value to format and insert.
2371 * @return Iterator after writing.
2372 */
ed6814f7
BI
2373 iter_type
2374 put(iter_type __s, ios_base& __f, char_type __fill,
725dc051 2375 const void* __v) const
86ade44c 2376 { return this->do_put(__s, __f, __fill, __v); }
725dc051
BK
2377
2378 protected:
86ade44c
BK
2379 template<typename _ValueT>
2380 iter_type
ed6814f7 2381 _M_insert_float(iter_type, ios_base& __io, char_type __fill,
7942afdc 2382 char __mod, _ValueT __v) const;
86ade44c 2383
ce3039af 2384 void
47f62b27
PC
2385 _M_group_float(const char* __grouping, size_t __grouping_size,
2386 char_type __sep, const char_type* __p, char_type* __new,
2387 char_type* __cs, int& __len) const;
ce3039af 2388
86ade44c
BK
2389 template<typename _ValueT>
2390 iter_type
ed6814f7 2391 _M_insert_int(iter_type, ios_base& __io, char_type __fill,
7942afdc 2392 _ValueT __v) const;
86ade44c 2393
ce3039af 2394 void
47f62b27
PC
2395 _M_group_int(const char* __grouping, size_t __grouping_size,
2396 char_type __sep, ios_base& __io, char_type* __new,
2397 char_type* __cs, int& __len) const;
86ade44c 2398
ce3039af 2399 void
ed6814f7 2400 _M_pad(char_type __fill, streamsize __w, ios_base& __io,
ce3039af 2401 char_type* __new, const char_type* __cs, int& __len) const;
86ade44c 2402
9a01c9b0 2403 /// Destructor.
ed6814f7 2404 virtual
725dc051
BK
2405 ~num_put() { };
2406
9a01c9b0
JQ
2407 //@{
2408 /**
2409 * @brief Numeric formatting.
2410 *
2411 * These functions do the work of formatting numeric values and
2412 * inserting them into a stream. This function is a hook for derived
2413 * classes to change the value returned.
2414 *
2415 * @param s Stream to write to.
2416 * @param io Source of locale and flags.
2417 * @param fill Char_type to use for filling.
2418 * @param v Value to format and insert.
2419 * @return Iterator after writing.
2420 */
ed6814f7 2421 virtual iter_type
725dc051
BK
2422 do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
2423
ed6814f7 2424 virtual iter_type
725dc051
BK
2425 do_put(iter_type, ios_base&, char_type __fill, long __v) const;
2426
ed6814f7 2427 virtual iter_type
86ade44c 2428 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
725dc051 2429
ed6814f7
BI
2430#ifdef _GLIBCXX_USE_LONG_LONG
2431 virtual iter_type
86ade44c 2432 do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
725dc051 2433
725dc051
BK
2434 virtual iter_type
2435 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
2436#endif
2437
ed6814f7 2438 virtual iter_type
725dc051
BK
2439 do_put(iter_type, ios_base&, char_type __fill, double __v) const;
2440
ed6814f7 2441 virtual iter_type
725dc051
BK
2442 do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
2443
ed6814f7 2444 virtual iter_type
725dc051 2445 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
9a01c9b0 2446 //@}
725dc051
BK
2447 };
2448
0a31609b
BK
2449 template <typename _CharT, typename _OutIter>
2450 locale::id num_put<_CharT, _OutIter>::id;
2451
33590f13 2452
9a01c9b0
JQ
2453 /**
2454 * @brief Facet for localized string comparison.
2455 *
2456 * This facet encapsulates the code to compare strings in a localized
2457 * manner.
2458 *
2459 * The collate template uses protected virtual functions to provide
2460 * the actual results. The public accessors forward the call to
2461 * the virtual functions. These virtual functions are hooks for
2462 * developers to implement the behavior they require from the
2463 * collate facet.
2464 */
725dc051 2465 template<typename _CharT>
0214010c 2466 class collate : public locale::facet
725dc051
BK
2467 {
2468 public:
2469 // Types:
9a01c9b0
JQ
2470 //@{
2471 /// Public typedefs
ed6814f7
BI
2472 typedef _CharT char_type;
2473 typedef basic_string<_CharT> string_type;
9a01c9b0 2474 //@}
725dc051 2475
ea0c0b6e
BK
2476 protected:
2477 // Underlying "C" library locale information saved from
2478 // initialization, needed by collate_byname as well.
2479 __c_locale _M_c_locale_collate;
ed6814f7 2480
ea0c0b6e 2481 public:
9a01c9b0 2482 /// Numpunct facet id.
ed6814f7 2483 static locale::id id;
0214010c 2484
9a01c9b0
JQ
2485 /**
2486 * @brief Constructor performs initialization.
2487 *
2488 * This is the constructor provided by the standard.
2489 *
2490 * @param refs Passed to the base facet class.
2491 */
ed6814f7 2492 explicit
ea0c0b6e 2493 collate(size_t __refs = 0)
26c691a8
BK
2494 : facet(__refs), _M_c_locale_collate(_S_get_c_locale())
2495 { }
ea0c0b6e 2496
9a01c9b0
JQ
2497 /**
2498 * @brief Internal constructor. Not for general use.
2499 *
2500 * This is a constructor for use by the library itself to set up new
2501 * locales.
2502 *
2503 * @param cloc The "C" locale.
2504 * @param refs Passed to the base facet class.
2505 */
ed6814f7
BI
2506 explicit
2507 collate(__c_locale __cloc, size_t __refs = 0)
26c691a8
BK
2508 : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc))
2509 { }
0214010c 2510
9a01c9b0
JQ
2511 /**
2512 * @brief Compare two strings.
2513 *
2514 * This function compares two strings and returns the result by calling
2515 * collate::do_compare().
2516 *
2517 * @param lo1 Start of string 1.
2518 * @param hi1 End of string 1.
2519 * @param lo2 Start of string 2.
2520 * @param hi2 End of string 2.
2521 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2522 */
ed6814f7 2523 int
725dc051
BK
2524 compare(const _CharT* __lo1, const _CharT* __hi1,
2525 const _CharT* __lo2, const _CharT* __hi2) const
0a1cceea 2526 { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
725dc051 2527
9a01c9b0
JQ
2528 /**
2529 * @brief Transform string to comparable form.
2530 *
2531 * This function is a wrapper for strxfrm functionality. It takes the
2532 * input string and returns a modified string that can be directly
2533 * compared to other transformed strings. In the "C" locale, this
2534 * function just returns a copy of the input string. In some other
2535 * locales, it may replace two chars with one, change a char for
2536 * another, etc. It does so by returning collate::do_transform().
2537 *
2538 * @param lo Start of string.
2539 * @param hi End of string.
2540 * @return Transformed string_type.
2541 */
ed6814f7 2542 string_type
725dc051 2543 transform(const _CharT* __lo, const _CharT* __hi) const
0a1cceea 2544 { return this->do_transform(__lo, __hi); }
725dc051 2545
9a01c9b0
JQ
2546 /**
2547 * @brief Return hash of a string.
2548 *
2549 * This function computes and returns a hash on the input string. It
2550 * does so by returning collate::do_hash().
2551 *
2552 * @param lo Start of string.
2553 * @param hi End of string.
2554 * @return Hash value.
2555 */
ed6814f7 2556 long
725dc051 2557 hash(const _CharT* __lo, const _CharT* __hi) const
0a1cceea 2558 { return this->do_hash(__lo, __hi); }
ed6814f7 2559
ea0c0b6e
BK
2560 // Used to abstract out _CharT bits in virtual member functions, below.
2561 int
d3a193e3 2562 _M_compare(const _CharT*, const _CharT*) const;
ea0c0b6e
BK
2563
2564 size_t
d3a193e3 2565 _M_transform(_CharT*, const _CharT*, size_t) const;
ea0c0b6e 2566
725dc051 2567 protected:
9a01c9b0 2568 /// Destructor.
ea0c0b6e 2569 virtual
ed6814f7 2570 ~collate()
aa53f832 2571 { _S_destroy_c_locale(_M_c_locale_collate); }
725dc051 2572
9a01c9b0
JQ
2573 /**
2574 * @brief Compare two strings.
2575 *
2576 * This function is a hook for derived classes to change the value
2577 * returned. @see compare().
2578 *
2579 * @param lo1 Start of string 1.
2580 * @param hi1 End of string 1.
2581 * @param lo2 Start of string 2.
2582 * @param hi2 End of string 2.
2583 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2584 */
ed6814f7 2585 virtual int
725dc051 2586 do_compare(const _CharT* __lo1, const _CharT* __hi1,
0214010c 2587 const _CharT* __lo2, const _CharT* __hi2) const;
725dc051 2588
9a01c9b0
JQ
2589 /**
2590 * @brief Transform string to comparable form.
2591 *
2592 * This function is a hook for derived classes to change the value
2593 * returned.
2594 *
2595 * @param lo1 Start of string 1.
2596 * @param hi1 End of string 1.
2597 * @param lo2 Start of string 2.
2598 * @param hi2 End of string 2.
2599 * @return 1 if string1 > string2, -1 if string1 < string2, else 0.
2600 */
ed6814f7 2601 virtual string_type
0214010c 2602 do_transform(const _CharT* __lo, const _CharT* __hi) const;
725dc051 2603
9a01c9b0
JQ
2604 /**
2605 * @brief Return hash of a string.
2606 *
2607 * This function computes and returns a hash on the input string. This
2608 * function is a hook for derived classes to change the value returned.
2609 *
2610 * @param lo Start of string.
2611 * @param hi End of string.
2612 * @return Hash value.
2613 */
ed6814f7 2614 virtual long
0214010c 2615 do_hash(const _CharT* __lo, const _CharT* __hi) const;
725dc051
BK
2616 };
2617
0a31609b
BK
2618 template<typename _CharT>
2619 locale::id collate<_CharT>::id;
2620
ea0c0b6e 2621 // Specializations.
725dc051 2622 template<>
ed6814f7 2623 int
d3a193e3 2624 collate<char>::_M_compare(const char*, const char*) const;
725dc051 2625
0214010c 2626 template<>
ea0c0b6e 2627 size_t
d3a193e3 2628 collate<char>::_M_transform(char*, const char*, size_t) const;
725dc051 2629
3d7c150e 2630#ifdef _GLIBCXX_USE_WCHAR_T
725dc051 2631 template<>
ed6814f7 2632 int
d3a193e3 2633 collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
725dc051 2634
0214010c 2635 template<>
ea0c0b6e 2636 size_t
d3a193e3 2637 collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
725dc051
BK
2638#endif
2639
00aca6e8 2640 /// @brief class collate_byname [22.2.4.2].
725dc051
BK
2641 template<typename _CharT>
2642 class collate_byname : public collate<_CharT>
2643 {
2644 public:
9a01c9b0
JQ
2645 //@{
2646 /// Public typedefs
725dc051
BK
2647 typedef _CharT char_type;
2648 typedef basic_string<_CharT> string_type;
9a01c9b0 2649 //@}
725dc051 2650
ed6814f7 2651 explicit
ea0c0b6e 2652 collate_byname(const char* __s, size_t __refs = 0)
ed6814f7
BI
2653 : collate<_CharT>(__refs)
2654 {
bf5fe473
BK
2655 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
2656 {
2657 this->_S_destroy_c_locale(this->_M_c_locale_collate);
ed6814f7 2658 this->_S_create_c_locale(this->_M_c_locale_collate, __s);
bf5fe473 2659 }
def9790d 2660 }
725dc051
BK
2661
2662 protected:
ed6814f7 2663 virtual
725dc051
BK
2664 ~collate_byname() { }
2665 };
2666
725dc051 2667
9a01c9b0
JQ
2668 /**
2669 * @brief Time format ordering data.
2670 *
2671 * This class provides an enum representing different orderings of day,
2672 * month, and year.
2673 */
725dc051
BK
2674 class time_base
2675 {
2676 public:
2677 enum dateorder { no_order, dmy, mdy, ymd, ydm };
2678 };
2679
e08138aa 2680 template<typename _CharT>
fea4065d 2681 struct __timepunct_cache : public locale::facet
e08138aa 2682 {
1ab65677 2683 // List of all known timezones, with GMT first.
ed6814f7 2684 static const _CharT* _S_timezones[14];
e08138aa 2685
ed6814f7
BI
2686 const _CharT* _M_date_format;
2687 const _CharT* _M_date_era_format;
2688 const _CharT* _M_time_format;
2689 const _CharT* _M_time_era_format;
da5c0f6e
BK
2690 const _CharT* _M_date_time_format;
2691 const _CharT* _M_date_time_era_format;
ed6814f7
BI
2692 const _CharT* _M_am;
2693 const _CharT* _M_pm;
da5c0f6e
BK
2694 const _CharT* _M_am_pm_format;
2695
1ab65677 2696 // Day names, starting with "C"'s Sunday.
ed6814f7
BI
2697 const _CharT* _M_day1;
2698 const _CharT* _M_day2;
2699 const _CharT* _M_day3;
2700 const _CharT* _M_day4;
2701 const _CharT* _M_day5;
2702 const _CharT* _M_day6;
2703 const _CharT* _M_day7;
1ab65677
BK
2704
2705 // Abbreviated day names, starting with "C"'s Sun.
ed6814f7
BI
2706 const _CharT* _M_aday1;
2707 const _CharT* _M_aday2;
2708 const _CharT* _M_aday3;
2709 const _CharT* _M_aday4;
2710 const _CharT* _M_aday5;
2711 const _CharT* _M_aday6;
2712 const _CharT* _M_aday7;
1ab65677
BK
2713
2714 // Month names, starting with "C"'s January.
ed6814f7
BI
2715 const _CharT* _M_month01;
2716 const _CharT* _M_month02;
2717 const _CharT* _M_month03;
2718 const _CharT* _M_month04;
2719 const _CharT* _M_month05;
2720 const _CharT* _M_month06;
2721 const _CharT* _M_month07;
2722 const _CharT* _M_month08;
2723 const _CharT* _M_month09;
2724 const _CharT* _M_month10;
2725 const _CharT* _M_month11;
2726 const _CharT* _M_month12;
1ab65677
BK
2727
2728 // Abbreviated month names, starting with "C"'s Jan.
ed6814f7
BI
2729 const _CharT* _M_amonth01;
2730 const _CharT* _M_amonth02;
2731 const _CharT* _M_amonth03;
2732 const _CharT* _M_amonth04;
2733 const _CharT* _M_amonth05;
2734 const _CharT* _M_amonth06;
2735 const _CharT* _M_amonth07;
2736 const _CharT* _M_amonth08;
2737 const _CharT* _M_amonth09;
2738 const _CharT* _M_amonth10;
2739 const _CharT* _M_amonth11;
2740 const _CharT* _M_amonth12;
fea4065d
BK
2741
2742 bool _M_allocated;
2743
ed6814f7 2744 __timepunct_cache(size_t __refs = 0) : facet(__refs),
fea4065d 2745 _M_date_format(NULL), _M_date_era_format(NULL), _M_time_format(NULL),
ed6814f7
BI
2746 _M_time_era_format(NULL), _M_date_time_format(NULL),
2747 _M_date_time_era_format(NULL), _M_am(NULL), _M_pm(NULL),
2748 _M_am_pm_format(NULL), _M_day1(NULL), _M_day2(NULL), _M_day3(NULL),
2749 _M_day4(NULL), _M_day5(NULL), _M_day6(NULL), _M_day7(NULL),
2750 _M_aday1(NULL), _M_aday2(NULL), _M_aday3(NULL), _M_aday4(NULL),
fea4065d 2751 _M_aday5(NULL), _M_aday6(NULL), _M_aday7(NULL), _M_month01(NULL),
ed6814f7
BI
2752 _M_month02(NULL), _M_month03(NULL), _M_month04(NULL), _M_month05(NULL),
2753 _M_month06(NULL), _M_month07(NULL), _M_month08(NULL), _M_month09(NULL),
fea4065d 2754 _M_month10(NULL), _M_month11(NULL), _M_month12(NULL), _M_amonth01(NULL),
ed6814f7
BI
2755 _M_amonth02(NULL), _M_amonth03(NULL), _M_amonth04(NULL),
2756 _M_amonth05(NULL), _M_amonth06(NULL), _M_amonth07(NULL),
2757 _M_amonth08(NULL), _M_amonth09(NULL), _M_amonth10(NULL),
fea4065d 2758 _M_amonth11(NULL), _M_amonth12(NULL), _M_allocated(false)
ed6814f7 2759 { }
fea4065d
BK
2760
2761 ~__timepunct_cache();
2762
2763 void
2764 _M_cache(const locale& __loc);
26c691a8
BK
2765
2766 private:
2767 __timepunct_cache&
2768 operator=(const __timepunct_cache&);
2769
2770 explicit
2771 __timepunct_cache(const __timepunct_cache&);
fea4065d
BK
2772 };
2773
2774 template<typename _CharT>
2775 __timepunct_cache<_CharT>::~__timepunct_cache()
2776 {
2777 if (_M_allocated)
2778 {
586b5f20 2779 // Unused.
fea4065d
BK
2780 }
2781 }
2782
2783 // Specializations.
ed6814f7 2784 template<>
fea4065d
BK
2785 const char*
2786 __timepunct_cache<char>::_S_timezones[14];
2787
2788#ifdef _GLIBCXX_USE_WCHAR_T
ed6814f7 2789 template<>
fea4065d
BK
2790 const wchar_t*
2791 __timepunct_cache<wchar_t>::_S_timezones[14];
2792#endif
2793
2794 // Generic.
2795 template<typename _CharT>
2796 const _CharT* __timepunct_cache<_CharT>::_S_timezones[14];
2797
2798 template<typename _CharT>
2799 class __timepunct : public locale::facet
2800 {
2801 public:
2802 // Types:
ed6814f7
BI
2803 typedef _CharT __char_type;
2804 typedef basic_string<_CharT> __string_type;
fea4065d
BK
2805 typedef __timepunct_cache<_CharT> __cache_type;
2806
2807 protected:
2808 __cache_type* _M_data;
2809 __c_locale _M_c_locale_timepunct;
8ae81136 2810 const char* _M_name_timepunct;
e08138aa
BK
2811
2812 public:
9a01c9b0 2813 /// Numpunct facet id.
ed6814f7 2814 static locale::id id;
fea4065d 2815
ed6814f7 2816 explicit
1c26d8fd 2817 __timepunct(size_t __refs = 0);
e08138aa 2818
ed6814f7 2819 explicit
fea4065d
BK
2820 __timepunct(__cache_type* __cache, size_t __refs = 0);
2821
9a01c9b0
JQ
2822 /**
2823 * @brief Internal constructor. Not for general use.
2824 *
2825 * This is a constructor for use by the library itself to set up new
2826 * locales.
2827 *
2828 * @param cloc The "C" locale.
2829 * @param s The name of a locale.
2830 * @param refs Passed to the base facet class.
2831 */
ed6814f7 2832 explicit
1c26d8fd 2833 __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
e08138aa 2834
cb793089
PC
2835 // FIXME: for error checking purposes _M_put should return the return
2836 // value of strftime/wcsftime.
e08138aa 2837 void
ed6814f7 2838 _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
d3a193e3 2839 const tm* __tm) const;
e08138aa 2840
1ab65677 2841 void
da5c0f6e
BK
2842 _M_date_formats(const _CharT** __date) const
2843 {
2844 // Always have default first.
fea4065d 2845 __date[0] = _M_data->_M_date_format;
ed6814f7 2846 __date[1] = _M_data->_M_date_era_format;
da5c0f6e 2847 }
1ab65677 2848
da5c0f6e
BK
2849 void
2850 _M_time_formats(const _CharT** __time) const
2851 {
2852 // Always have default first.
fea4065d 2853 __time[0] = _M_data->_M_time_format;
ed6814f7 2854 __time[1] = _M_data->_M_time_era_format;
da5c0f6e 2855 }
1ab65677 2856
da5c0f6e
BK
2857 void
2858 _M_date_time_formats(const _CharT** __dt) const
2859 {
2860 // Always have default first.
fea4065d 2861 __dt[0] = _M_data->_M_date_time_format;
ed6814f7 2862 __dt[1] = _M_data->_M_date_time_era_format;
da5c0f6e 2863 }
1ab65677 2864
586b5f20
BK
2865 void
2866 _M_am_pm_format(const _CharT* __ampm) const
2867 { __ampm = _M_data->_M_am_pm_format; }
2868
2869 void
2870 _M_am_pm(const _CharT** __ampm) const
2871 {
2872 __ampm[0] = _M_data->_M_am;
2873 __ampm[1] = _M_data->_M_pm;
2874 }
2875
1ab65677
BK
2876 void
2877 _M_days(const _CharT** __days) const
ed6814f7 2878 {
fea4065d
BK
2879 __days[0] = _M_data->_M_day1;
2880 __days[1] = _M_data->_M_day2;
2881 __days[2] = _M_data->_M_day3;
2882 __days[3] = _M_data->_M_day4;
2883 __days[4] = _M_data->_M_day5;
2884 __days[5] = _M_data->_M_day6;
2885 __days[6] = _M_data->_M_day7;
1ab65677
BK
2886 }
2887
2888 void
2889 _M_days_abbreviated(const _CharT** __days) const
ed6814f7 2890 {
fea4065d
BK
2891 __days[0] = _M_data->_M_aday1;
2892 __days[1] = _M_data->_M_aday2;
2893 __days[2] = _M_data->_M_aday3;
2894 __days[3] = _M_data->_M_aday4;
2895 __days[4] = _M_data->_M_aday5;
2896 __days[5] = _M_data->_M_aday6;
2897 __days[6] = _M_data->_M_aday7;
da5c0f6e 2898 }
1ab65677
BK
2899
2900 void
2901 _M_months(const _CharT** __months) const
ed6814f7 2902 {
fea4065d
BK
2903 __months[0] = _M_data->_M_month01;
2904 __months[1] = _M_data->_M_month02;
2905 __months[2] = _M_data->_M_month03;
2906 __months[3] = _M_data->_M_month04;
2907 __months[4] = _M_data->_M_month05;
2908 __months[5] = _M_data->_M_month06;
2909 __months[6] = _M_data->_M_month07;
2910 __months[7] = _M_data->_M_month08;
2911 __months[8] = _M_data->_M_month09;
2912 __months[9] = _M_data->_M_month10;
2913 __months[10] = _M_data->_M_month11;
2914 __months[11] = _M_data->_M_month12;
1ab65677
BK
2915 }
2916
2917 void
2918 _M_months_abbreviated(const _CharT** __months) const
ed6814f7 2919 {
fea4065d
BK
2920 __months[0] = _M_data->_M_amonth01;
2921 __months[1] = _M_data->_M_amonth02;
2922 __months[2] = _M_data->_M_amonth03;
2923 __months[3] = _M_data->_M_amonth04;
2924 __months[4] = _M_data->_M_amonth05;
2925 __months[5] = _M_data->_M_amonth06;
2926 __months[6] = _M_data->_M_amonth07;
2927 __months[7] = _M_data->_M_amonth08;
2928 __months[8] = _M_data->_M_amonth09;
2929 __months[9] = _M_data->_M_amonth10;
2930 __months[10] = _M_data->_M_amonth11;
2931 __months[11] = _M_data->_M_amonth12;
1ab65677
BK
2932 }
2933
e08138aa 2934 protected:
ed6814f7 2935 virtual
1c26d8fd 2936 ~__timepunct();
1ab65677
BK
2937
2938 // For use at construction time only.
ed6814f7 2939 void
aa53f832 2940 _M_initialize_timepunct(__c_locale __cloc = NULL);
e08138aa
BK
2941 };
2942
2943 template<typename _CharT>
2944 locale::id __timepunct<_CharT>::id;
2945
1ab8a33e 2946 // Specializations.
ed6814f7 2947 template<>
1ab8a33e
BK
2948 void
2949 __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc);
2950
2951 template<>
2952 void
d3a193e3 2953 __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const;
1ab8a33e 2954
3d7c150e 2955#ifdef _GLIBCXX_USE_WCHAR_T
ed6814f7 2956 template<>
1ab8a33e
BK
2957 void
2958 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc);
2959
2960 template<>
2961 void
ed6814f7 2962 __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*,
d3a193e3 2963 const tm*) const;
1ab8a33e
BK
2964#endif
2965
1c26d8fd
BK
2966 // Include host and configuration specific timepunct functions.
2967 #include <bits/time_members.h>
da5c0f6e 2968
9a01c9b0
JQ
2969 /**
2970 * @brief Facet for parsing dates and times.
2971 *
2972 * This facet encapsulates the code to parse and return a date or
2973 * time from a string. It is used by the istream numeric
2974 * extraction operators.
2975 *
2976 * The time_get template uses protected virtual functions to provide the
2977 * actual results. The public accessors forward the call to the virtual
2978 * functions. These virtual functions are hooks for developers to
2979 * implement the behavior they require from the time_get facet.
2980 */
725dc051
BK
2981 template<typename _CharT, typename _InIter>
2982 class time_get : public locale::facet, public time_base
2983 {
2984 public:
2985 // Types:
9a01c9b0
JQ
2986 //@{
2987 /// Public typedefs
ed6814f7
BI
2988 typedef _CharT char_type;
2989 typedef _InIter iter_type;
9a01c9b0 2990 //@}
ed6814f7 2991 typedef basic_string<_CharT> __string_type;
725dc051 2992
9a01c9b0 2993 /// Numpunct facet id.
ed6814f7 2994 static locale::id id;
e08138aa 2995
9a01c9b0
JQ
2996 /**
2997 * @brief Constructor performs initialization.
2998 *
2999 * This is the constructor provided by the standard.
3000 *
3001 * @param refs Passed to the base facet class.
3002 */
ed6814f7
BI
3003 explicit
3004 time_get(size_t __refs = 0)
fea4065d 3005 : facet (__refs) { }
725dc051 3006
9a01c9b0
JQ
3007 /**
3008 * @brief Return preferred order of month, day, and year.
3009 *
3010 * This function returns an enum from timebase::dateorder giving the
3011 * preferred ordering if the format "x" given to time_put::put() only
3012 * uses month, day, and year. If the format "x" for the associated
3013 * locale uses other fields, this function returns
ed6814f7 3014 * timebase::dateorder::noorder.
9a01c9b0
JQ
3015 *
3016 * NOTE: The library always returns noorder at the moment.
3017 *
3018 * @return A member of timebase::dateorder.
3019 */
ed6814f7 3020 dateorder
725dc051 3021 date_order() const
1ab65677 3022 { return this->do_date_order(); }
725dc051 3023
9a01c9b0
JQ
3024 /**
3025 * @brief Parse input time string.
3026 *
3027 * This function parses a time according to the format "x" and puts the
3028 * results into a user-supplied struct tm. The result is returned by
3029 * calling time_get::do_get_time().
3030 *
3031 * If there is a valid time string according to format "x", @a tm will
3032 * be filled in accordingly and the returned iterator will point to the
3033 * first character beyond the time string. If an error occurs before
3034 * the end, err |= ios_base::failbit. If parsing reads all the
3035 * characters, err |= ios_base::eofbit.
3036 *
3037 * @param beg Start of string to parse.
3038 * @param end End of string to parse.
3039 * @param io Source of the locale.
3040 * @param err Error flags to set.
3041 * @param tm Pointer to struct tm to fill in.
3042 * @return Iterator to first char beyond time string.
3043 */
ed6814f7
BI
3044 iter_type
3045 get_time(iter_type __beg, iter_type __end, ios_base& __io,
1ab65677
BK
3046 ios_base::iostate& __err, tm* __tm) const
3047 { return this->do_get_time(__beg, __end, __io, __err, __tm); }
725dc051 3048
9a01c9b0
JQ
3049 /**
3050 * @brief Parse input date string.
3051 *
3052 * This function parses a date according to the format "X" and puts the
3053 * results into a user-supplied struct tm. The result is returned by
3054 * calling time_get::do_get_date().
3055 *
3056 * If there is a valid date string according to format "X", @a tm will
3057 * be filled in accordingly and the returned iterator will point to the
3058 * first character beyond the date string. If an error occurs before
3059 * the end, err |= ios_base::failbit. If parsing reads all the
3060 * characters, err |= ios_base::eofbit.
3061 *
3062 * @param beg Start of string to parse.
3063 * @param end End of string to parse.
3064 * @param io Source of the locale.
3065 * @param err Error flags to set.
3066 * @param tm Pointer to struct tm to fill in.
3067 * @return Iterator to first char beyond date string.
3068 */
ed6814f7 3069 iter_type
1ab65677
BK
3070 get_date(iter_type __beg, iter_type __end, ios_base& __io,
3071 ios_base::iostate& __err, tm* __tm) const
3072 { return this->do_get_date(__beg, __end, __io, __err, __tm); }
725dc051 3073
9a01c9b0
JQ
3074 /**
3075 * @brief Parse input weekday string.
3076 *
3077 * This function parses a weekday name and puts the results into a
3078 * user-supplied struct tm. The result is returned by calling
3079 * time_get::do_get_weekday().
3080 *
3081 * Parsing starts by parsing an abbreviated weekday name. If a valid
3082 * abbreviation is followed by a character that would lead to the full
3083 * weekday name, parsing continues until the full name is found or an
3084 * error occurs. Otherwise parsing finishes at the end of the
3085 * abbreviated name.
3086 *
3087 * If an error occurs before the end, err |= ios_base::failbit. If
3088 * parsing reads all the characters, err |= ios_base::eofbit.
3089 *
3090 * @param beg Start of string to parse.
3091 * @param end End of string to parse.
3092 * @param io Source of the locale.
3093 * @param err Error flags to set.
3094 * @param tm Pointer to struct tm to fill in.
3095 * @return Iterator to first char beyond weekday name.
3096 */
ed6814f7 3097 iter_type
1ab65677
BK
3098 get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
3099 ios_base::iostate& __err, tm* __tm) const
3100 { return this->do_get_weekday(__beg, __end, __io, __err, __tm); }
725dc051 3101
9a01c9b0
JQ
3102 /**
3103 * @brief Parse input month string.
3104 *
3105 * This function parses a month name and puts the results into a
3106 * user-supplied struct tm. The result is returned by calling
3107 * time_get::do_get_monthname().
3108 *
3109 * Parsing starts by parsing an abbreviated month name. If a valid
3110 * abbreviation is followed by a character that would lead to the full
3111 * month name, parsing continues until the full name is found or an
3112 * error occurs. Otherwise parsing finishes at the end of the
3113 * abbreviated name.
3114 *
3115 * If an error occurs before the end, err |= ios_base::failbit. If
3116 * parsing reads all the characters, err |=
3117 * ios_base::eofbit.
3118 *
3119 * @param beg Start of string to parse.
3120 * @param end End of string to parse.
3121 * @param io Source of the locale.
3122 * @param err Error flags to set.
3123 * @param tm Pointer to struct tm to fill in.
3124 * @return Iterator to first char beyond month name.
3125 */
ed6814f7
BI
3126 iter_type
3127 get_monthname(iter_type __beg, iter_type __end, ios_base& __io,
1ab65677
BK
3128 ios_base::iostate& __err, tm* __tm) const
3129 { return this->do_get_monthname(__beg, __end, __io, __err, __tm); }
725dc051 3130
9a01c9b0
JQ
3131 /**
3132 * @brief Parse input year string.
3133 *
3134 * This function reads up to 4 characters to parse a year string and
3135 * puts the results into a user-supplied struct tm. The result is
3136 * returned by calling time_get::do_get_year().
3137 *
3138 * 4 consecutive digits are interpreted as a full year. If there are
3139 * exactly 2 consecutive digits, the library interprets this as the
3140 * number of years since 1900.
3141 *
3142 * If an error occurs before the end, err |= ios_base::failbit. If
3143 * parsing reads all the characters, err |= ios_base::eofbit.
3144 *
3145 * @param beg Start of string to parse.
3146 * @param end End of string to parse.
3147 * @param io Source of the locale.
3148 * @param err Error flags to set.
3149 * @param tm Pointer to struct tm to fill in.
3150 * @return Iterator to first char beyond year.
3151 */
ed6814f7 3152 iter_type
1ab65677
BK
3153 get_year(iter_type __beg, iter_type __end, ios_base& __io,
3154 ios_base::iostate& __err, tm* __tm) const
3155 { return this->do_get_year(__beg, __end, __io, __err, __tm); }
725dc051
BK
3156
3157 protected:
9a01c9b0 3158 /// Destructor.
ed6814f7 3159 virtual
1ab65677 3160 ~time_get() { }
725dc051 3161
9a01c9b0
JQ
3162 /**
3163 * @brief Return preferred order of month, day, and year.
3164 *
3165 * This function returns an enum from timebase::dateorder giving the
3166 * preferred ordering if the format "x" given to time_put::put() only
3167 * uses month, day, and year. This function is a hook for derived
3168 * classes to change the value returned.
3169 *
3170 * @return A member of timebase::dateorder.
3171 */
ed6814f7 3172 virtual dateorder
1ab65677 3173 do_date_order() const;
725dc051 3174
9a01c9b0
JQ
3175 /**
3176 * @brief Parse input time string.
3177 *
3178 * This function parses a time according to the format "x" and puts the
3179 * results into a user-supplied struct tm. This function is a hook for
3180 * derived classes to change the value returned. @see get_time() for
3181 * details.
3182 *
3183 * @param beg Start of string to parse.
3184 * @param end End of string to parse.
3185 * @param io Source of the locale.
3186 * @param err Error flags to set.
3187 * @param tm Pointer to struct tm to fill in.
3188 * @return Iterator to first char beyond time string.
3189 */
ed6814f7 3190 virtual iter_type
1ab65677
BK
3191 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
3192 ios_base::iostate& __err, tm* __tm) const;
725dc051 3193
9a01c9b0
JQ
3194 /**
3195 * @brief Parse input date string.
3196 *
3197 * This function parses a date according to the format "X" and puts the
3198 * results into a user-supplied struct tm. This function is a hook for
3199 * derived classes to change the value returned. @see get_date() for
3200 * details.
3201 *
3202 * @param beg Start of string to parse.
3203 * @param end End of string to parse.
3204 * @param io Source of the locale.
3205 * @param err Error flags to set.
3206 * @param tm Pointer to struct tm to fill in.
3207 * @return Iterator to first char beyond date string.
3208 */
ed6814f7 3209 virtual iter_type
1ab65677
BK
3210 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
3211 ios_base::iostate& __err, tm* __tm) const;
725dc051 3212
9a01c9b0
JQ
3213 /**
3214 * @brief Parse input weekday string.
3215 *
3216 * This function parses a weekday name and puts the results into a
3217 * user-supplied struct tm. This function is a hook for derived
3218 * classes to change the value returned. @see get_weekday() for
3219 * details.
3220 *
3221 * @param beg Start of string to parse.
3222 * @param end End of string to parse.
3223 * @param io Source of the locale.
3224 * @param err Error flags to set.
3225 * @param tm Pointer to struct tm to fill in.
3226 * @return Iterator to first char beyond weekday name.
3227 */
ed6814f7 3228 virtual iter_type
1ab65677
BK
3229 do_get_weekday(iter_type __beg, iter_type __end, ios_base&,
3230 ios_base::iostate& __err, tm* __tm) const;
725dc051 3231
9a01c9b0
JQ
3232 /**
3233 * @brief Parse input month string.
3234 *
3235 * This function parses a month name and puts the results into a
3236 * user-supplied struct tm. This function is a hook for derived
3237 * classes to change the value returned. @see get_monthname() for
3238 * details.
3239 *
3240 * @param beg Start of string to parse.
3241 * @param end End of string to parse.
3242 * @param io Source of the locale.
3243 * @param err Error flags to set.
3244 * @param tm Pointer to struct tm to fill in.
3245 * @return Iterator to first char beyond month name.
3246 */
ed6814f7
BI
3247 virtual iter_type
3248 do_get_monthname(iter_type __beg, iter_type __end, ios_base&,
1ab65677 3249 ios_base::iostate& __err, tm* __tm) const;
725dc051 3250
9a01c9b0
JQ
3251 /**
3252 * @brief Parse input year string.
3253 *
3254 * This function reads up to 4 characters to parse a year string and
3255 * puts the results into a user-supplied struct tm. This function is a
3256 * hook for derived classes to change the value returned. @see
3257 * get_year() for details.
3258 *
3259 * @param beg Start of string to parse.
3260 * @param end End of string to parse.
3261 * @param io Source of the locale.
3262 * @param err Error flags to set.
3263 * @param tm Pointer to struct tm to fill in.
3264 * @return Iterator to first char beyond year.
3265 */
ed6814f7 3266 virtual iter_type
1ab65677
BK
3267 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
3268 ios_base::iostate& __err, tm* __tm) const;
3269
da5c0f6e 3270 // Extract numeric component of length __len.
586b5f20
BK
3271 iter_type
3272 _M_extract_num(iter_type __beg, iter_type __end, int& __member,
da5c0f6e 3273 int __min, int __max, size_t __len,
586b5f20 3274 ios_base& __io, ios_base::iostate& __err) const;
ed6814f7 3275
1ab65677
BK
3276 // Extract day or month name, or any unique array of string
3277 // literals in a const _CharT* array.
586b5f20
BK
3278 iter_type
3279 _M_extract_name(iter_type __beg, iter_type __end, int& __member,
ed6814f7 3280 const _CharT** __names, size_t __indexlen,
586b5f20 3281 ios_base& __io, ios_base::iostate& __err) const;
da5c0f6e
BK
3282
3283 // Extract on a component-by-component basis, via __format argument.
586b5f20
BK
3284 iter_type
3285 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
ed6814f7 3286 ios_base::iostate& __err, tm* __tm,
da5c0f6e 3287 const _CharT* __format) const;
725dc051
BK
3288 };
3289
0a31609b
BK
3290 template<typename _CharT, typename _InIter>
3291 locale::id time_get<_CharT, _InIter>::id;
3292
00aca6e8 3293 /// @brief class time_get_byname [22.2.5.2].
725dc051
BK
3294 template<typename _CharT, typename _InIter>
3295 class time_get_byname : public time_get<_CharT, _InIter>
3296 {
3297 public:
1ab65677 3298 // Types:
ed6814f7
BI
3299 typedef _CharT char_type;
3300 typedef _InIter iter_type;
725dc051 3301
ed6814f7
BI
3302 explicit
3303 time_get_byname(const char*, size_t __refs = 0)
725dc051 3304 : time_get<_CharT, _InIter>(__refs) { }
1ab65677 3305
725dc051 3306 protected:
ed6814f7 3307 virtual
725dc051
BK
3308 ~time_get_byname() { }
3309 };
3310
9a01c9b0
JQ
3311 /**
3312 * @brief Facet for outputting dates and times.
3313 *
3314 * This facet encapsulates the code to format and output dates and times
3315 * according to formats used by strftime().
3316 *
3317 * The time_put template uses protected virtual functions to provide the
3318 * actual results. The public accessors forward the call to the virtual
3319 * functions. These virtual functions are hooks for developers to
3320 * implement the behavior they require from the time_put facet.
3321 */
725dc051 3322 template<typename _CharT, typename _OutIter>
586b5f20 3323 class time_put : public locale::facet
725dc051
BK
3324 {
3325 public:
e08138aa 3326 // Types:
9a01c9b0
JQ
3327 //@{
3328 /// Public typedefs
ed6814f7
BI
3329 typedef _CharT char_type;
3330 typedef _OutIter iter_type;
9a01c9b0 3331 //@}
725dc051 3332
9a01c9b0 3333 /// Numpunct facet id.
ed6814f7 3334 static locale::id id;
725dc051 3335
9a01c9b0
JQ
3336 /**
3337 * @brief Constructor performs initialization.
3338 *
3339 * This is the constructor provided by the standard.
3340 *
3341 * @param refs Passed to the base facet class.
3342 */
ed6814f7
BI
3343 explicit
3344 time_put(size_t __refs = 0)
fea4065d 3345 : facet(__refs) { }
725dc051 3346
9a01c9b0
JQ
3347 /**
3348 * @brief Format and output a time or date.
3349 *
3350 * This function formats the data in struct tm according to the
3351 * provided format string. The format string is interpreted as by
3352 * strftime().
3353 *
3354 * @param s The stream to write to.
3355 * @param io Source of locale.
3356 * @param fill char_type to use for padding.
3357 * @param tm Struct tm with date and time info to format.
3358 * @param beg Start of format string.
3359 * @param end End of format string.
3360 * @return Iterator after writing.
3361 */
ed6814f7
BI
3362 iter_type
3363 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
e08138aa 3364 const _CharT* __beg, const _CharT* __end) const;
725dc051 3365
9a01c9b0
JQ
3366 /**
3367 * @brief Format and output a time or date.
3368 *
3369 * This function formats the data in struct tm according to the
3370 * provided format char and optional modifier. The format and modifier
3371 * are interpreted as by strftime(). It does so by returning
3372 * time_put::do_put().
3373 *
3374 * @param s The stream to write to.
3375 * @param io Source of locale.
3376 * @param fill char_type to use for padding.
3377 * @param tm Struct tm with date and time info to format.
3378 * @param format Format char.
3379 * @param mod Optional modifier char.
3380 * @return Iterator after writing.
3381 */
ed6814f7 3382 iter_type
e08138aa
BK
3383 put(iter_type __s, ios_base& __io, char_type __fill,
3384 const tm* __tm, char __format, char __mod = 0) const
3385 { return this->do_put(__s, __io, __fill, __tm, __format, __mod); }
725dc051
BK
3386
3387 protected:
9a01c9b0 3388 /// Destructor.
ed6814f7 3389 virtual
e08138aa
BK
3390 ~time_put()
3391 { }
725dc051 3392
9a01c9b0
JQ
3393 /**
3394 * @brief Format and output a time or date.
3395 *
3396 * This function formats the data in struct tm according to the
3397 * provided format char and optional modifier. This function is a hook
3398 * for derived classes to change the value returned. @see put() for
3399 * more details.
3400 *
3401 * @param s The stream to write to.
3402 * @param io Source of locale.
3403 * @param fill char_type to use for padding.
3404 * @param tm Struct tm with date and time info to format.
3405 * @param format Format char.
3406 * @param mod Optional modifier char.
3407 * @return Iterator after writing.
3408 */
ed6814f7
BI
3409 virtual iter_type
3410 do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
e08138aa 3411 char __format, char __mod) const;
725dc051
BK
3412 };
3413
0a31609b
BK
3414 template<typename _CharT, typename _OutIter>
3415 locale::id time_put<_CharT, _OutIter>::id;
3416
00aca6e8 3417 /// @brief class time_put_byname [22.2.5.4].
725dc051
BK
3418 template<typename _CharT, typename _OutIter>
3419 class time_put_byname : public time_put<_CharT, _OutIter>
3420 {
3421 public:
e08138aa 3422 // Types:
ed6814f7
BI
3423 typedef _CharT char_type;
3424 typedef _OutIter iter_type;
725dc051 3425
ed6814f7
BI
3426 explicit
3427 time_put_byname(const char*, size_t __refs = 0)
3428 : time_put<_CharT, _OutIter>(__refs)
e08138aa 3429 { };
725dc051
BK
3430
3431 protected:
ed6814f7 3432 virtual
725dc051
BK
3433 ~time_put_byname() { }
3434 };
3435
3436
9a01c9b0
JQ
3437 /**
3438 * @brief Money format ordering data.
3439 *
3440 * This class contains an ordered array of 4 fields to represent the
3441 * pattern for formatting a money amount. Each field may contain one entry
3442 * from the part enum. symbol, sign, and value must be present and the
3443 * remaining field must contain either none or space. @see
3444 * moneypunct::pos_format() and moneypunct::neg_format() for details of how
3445 * these fields are interpreted.
3446 */
86ade44c 3447 class money_base
725dc051 3448 {
86ade44c 3449 public:
725dc051
BK
3450 enum part { none, space, symbol, sign, value };
3451 struct pattern { char field[4]; };
3452
3453 static const pattern _S_default_pattern;
0214010c 3454
fe932e50
PC
3455 enum
3456 {
3457 _S_minus,
3458 _S_zero,
3459 _S_end = 11
3460 };
3461
3462 // String literal of acceptable (narrow) input/output, for
3463 // money_get/money_put. "-0123456789"
3464 static const char* _S_atoms;
3465
0214010c
BK
3466 // Construct and return valid pattern consisting of some combination of:
3467 // space none symbol sign value
ed6814f7 3468 static pattern
754d9299 3469 _S_construct_pattern(char __precedes, char __space, char __posn);
725dc051
BK
3470 };
3471
fe932e50 3472 template<typename _CharT, bool _Intl>
fea4065d
BK
3473 struct __moneypunct_cache : public locale::facet
3474 {
ed6814f7 3475 const char* _M_grouping;
fe932e50 3476 size_t _M_grouping_size;
fea4065d 3477 bool _M_use_grouping;
ed6814f7
BI
3478 _CharT _M_decimal_point;
3479 _CharT _M_thousands_sep;
3480 const _CharT* _M_curr_symbol;
fe932e50 3481 size_t _M_curr_symbol_size;
fea4065d 3482 const _CharT* _M_positive_sign;
fe932e50 3483 size_t _M_positive_sign_size;
fea4065d 3484 const _CharT* _M_negative_sign;
fe932e50 3485 size_t _M_negative_sign_size;
ed6814f7
BI
3486 int _M_frac_digits;
3487 money_base::pattern _M_pos_format;
3488 money_base::pattern _M_neg_format;
fea4065d 3489
fe932e50
PC
3490 // A list of valid numeric literals for input and output: in the standard
3491 // "C" locale, this is "-0123456789". This array contains the chars after
3492 // having been passed through the current locale's ctype<_CharT>.widen().
3493 _CharT _M_atoms[money_base::_S_end];
3494
fea4065d
BK
3495 bool _M_allocated;
3496
ed6814f7 3497 __moneypunct_cache(size_t __refs = 0) : facet(__refs),
fe932e50
PC
3498 _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false),
3499 _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()),
3500 _M_curr_symbol(NULL), _M_curr_symbol_size(0),
3501 _M_positive_sign(NULL), _M_positive_sign_size(0),
3502 _M_negative_sign(NULL), _M_negative_sign_size(0),
3503 _M_frac_digits(0),
ed6814f7 3504 _M_pos_format(money_base::pattern()),
fea4065d 3505 _M_neg_format(money_base::pattern()), _M_allocated(false)
ed6814f7 3506 { }
fea4065d
BK
3507
3508 ~__moneypunct_cache();
3509
3510 void
3511 _M_cache(const locale& __loc);
26c691a8
BK
3512
3513 private:
3514 __moneypunct_cache&
3515 operator=(const __moneypunct_cache&);
3516
3517 explicit
3518 __moneypunct_cache(const __moneypunct_cache&);
fea4065d
BK
3519 };
3520
fe932e50
PC
3521 template<typename _CharT, bool _Intl>
3522 __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
fea4065d
BK
3523 {
3524 if (_M_allocated)
3525 {
fe932e50
PC
3526 delete [] _M_grouping;
3527 delete [] _M_curr_symbol;
3528 delete [] _M_positive_sign;
3529 delete [] _M_negative_sign;
fea4065d
BK
3530 }
3531 }
3532
9a01c9b0
JQ
3533 /**
3534 * @brief Facet for formatting data for money amounts.
3535 *
3536 * This facet encapsulates the punctuation, grouping and other formatting
3537 * features of money amount string representations.
3538 */
0214010c
BK
3539 template<typename _CharT, bool _Intl>
3540 class moneypunct : public locale::facet, public money_base
725dc051
BK
3541 {
3542 public:
0214010c 3543 // Types:
9a01c9b0
JQ
3544 //@{
3545 /// Public typedefs
ed6814f7
BI
3546 typedef _CharT char_type;
3547 typedef basic_string<_CharT> string_type;
9a01c9b0 3548 //@}
fe932e50 3549 typedef __moneypunct_cache<_CharT, _Intl> __cache_type;
fea4065d
BK
3550
3551 private:
3552 __cache_type* _M_data;
0214010c 3553
fea4065d 3554 public:
9a01c9b0
JQ
3555 /// This value is provided by the standard, but no reason for its
3556 /// existence.
ed6814f7 3557 static const bool intl = _Intl;
9a01c9b0 3558 /// Numpunct facet id.
ed6814f7 3559 static locale::id id;
0214010c 3560
9a01c9b0
JQ
3561 /**
3562 * @brief Constructor performs initialization.
3563 *
3564 * This is the constructor provided by the standard.
3565 *
3566 * @param refs Passed to the base facet class.
3567 */
ed6814f7 3568 explicit
fea4065d
BK
3569 moneypunct(size_t __refs = 0) : facet(__refs), _M_data(NULL)
3570 { _M_initialize_moneypunct(); }
0214010c 3571
9a01c9b0
JQ
3572 /**
3573 * @brief Constructor performs initialization.
3574 *
3575 * This is an internal constructor.
3576 *
3577 * @param cache Cache for optimization.
3578 * @param refs Passed to the base facet class.
3579 */
ed6814f7
BI
3580 explicit
3581 moneypunct(__cache_type* __cache, size_t __refs = 0)
fea4065d 3582 : facet(__refs), _M_data(__cache)
0214010c
BK
3583 { _M_initialize_moneypunct(); }
3584
9a01c9b0
JQ
3585 /**
3586 * @brief Internal constructor. Not for general use.
3587 *
3588 * This is a constructor for use by the library itself to set up new
3589 * locales.
3590 *
3591 * @param cloc The "C" locale.
3592 * @param s The name of a locale.
3593 * @param refs Passed to the base facet class.
3594 */
ed6814f7
BI
3595 explicit
3596 moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0)
fea4065d 3597 : facet(__refs), _M_data(NULL)
fdf7e809 3598 { _M_initialize_moneypunct(__cloc, __s); }
0214010c 3599
9a01c9b0
JQ
3600 /**
3601 * @brief Return decimal point character.
3602 *
3603 * This function returns a char_type to use as a decimal point. It
3604 * does so by returning returning
3605 * moneypunct<char_type>::do_decimal_point().
3606 *
3607 * @return @a char_type representing a decimal point.
3608 */
0214010c
BK
3609 char_type
3610 decimal_point() const
0a1cceea 3611 { return this->do_decimal_point(); }
ed6814f7 3612
9a01c9b0
JQ
3613 /**
3614 * @brief Return thousands separator character.
3615 *
586b5f20
BK
3616 * This function returns a char_type to use as a thousands
3617 * separator. It does so by returning returning
9a01c9b0
JQ
3618 * moneypunct<char_type>::do_thousands_sep().
3619 *
3620 * @return char_type representing a thousands separator.
3621 */
0214010c
BK
3622 char_type
3623 thousands_sep() const
0a1cceea 3624 { return this->do_thousands_sep(); }
ed6814f7 3625
9a01c9b0
JQ
3626 /**
3627 * @brief Return grouping specification.
3628 *
3629 * This function returns a string representing groupings for the
3630 * integer part of an amount. Groupings indicate where thousands
3631 * separators should be inserted.
3632 *
3633 * Each char in the return string is interpret as an integer rather
3634 * than a character. These numbers represent the number of digits in a
3635 * group. The first char in the string represents the number of digits
3636 * in the least significant group. If a char is negative, it indicates
3637 * an unlimited number of digits for the group. If more chars from the
3638 * string are required to group a number, the last char is used
3639 * repeatedly.
3640 *
3641 * For example, if the grouping() returns "\003\002" and is applied to
3642 * the number 123456789, this corresponds to 12,34,56,789. Note that
3643 * if the string was "32", this would put more than 50 digits into the
3644 * least significant group if the character set is ASCII.
3645 *
3646 * The string is returned by calling
3647 * moneypunct<char_type>::do_grouping().
3648 *
3649 * @return string representing grouping specification.
3650 */
ed6814f7 3651 string
0214010c 3652 grouping() const
0a1cceea 3653 { return this->do_grouping(); }
725dc051 3654
9a01c9b0
JQ
3655 /**
3656 * @brief Return currency symbol string.
3657 *
3658 * This function returns a string_type to use as a currency symbol. It
3659 * does so by returning returning
3660 * moneypunct<char_type>::do_curr_symbol().
3661 *
3662 * @return @a string_type representing a currency symbol.
3663 */
ed6814f7 3664 string_type
0214010c 3665 curr_symbol() const
0a1cceea 3666 { return this->do_curr_symbol(); }
725dc051 3667
9a01c9b0
JQ
3668 /**
3669 * @brief Return positive sign string.
3670 *
3671 * This function returns a string_type to use as a sign for positive
3672 * amounts. It does so by returning returning
3673 * moneypunct<char_type>::do_positive_sign().
3674 *
3675 * If the return value contains more than one character, the first
3676 * character appears in the position indicated by pos_format() and the
3677 * remainder appear at the end of the formatted string.
3678 *
3679 * @return @a string_type representing a positive sign.
3680 */
ed6814f7 3681 string_type
725dc051 3682 positive_sign() const
0a1cceea 3683 { return this->do_positive_sign(); }
725dc051 3684
9a01c9b0
JQ
3685 /**
3686 * @brief Return negative sign string.
3687 *
3688 * This function returns a string_type to use as a sign for negative
3689 * amounts. It does so by returning returning
3690 * moneypunct<char_type>::do_negative_sign().
3691 *
3692 * If the return value contains more than one character, the first
3693 * character appears in the position indicated by neg_format() and the
3694 * remainder appear at the end of the formatted string.
3695 *
3696 * @return @a string_type representing a negative sign.
3697 */
ed6814f7 3698 string_type
725dc051 3699 negative_sign() const
0a1cceea 3700 { return this->do_negative_sign(); }
725dc051 3701
9a01c9b0
JQ
3702 /**
3703 * @brief Return number of digits in fraction.
3704 *
3705 * This function returns the exact number of digits that make up the
3706 * fractional part of a money amount. It does so by returning
3707 * returning moneypunct<char_type>::do_frac_digits().
3708 *
3709 * The fractional part of a money amount is optional. But if it is
3710 * present, there must be frac_digits() digits.
3711 *
3712 * @return Number of digits in amount fraction.
3713 */
3714 int
0214010c 3715 frac_digits() const
0a1cceea 3716 { return this->do_frac_digits(); }
725dc051 3717
9a01c9b0
JQ
3718 //@{
3719 /**
3720 * @brief Return pattern for money values.
3721 *
3722 * This function returns a pattern describing the formatting of a
3723 * positive or negative valued money amount. It does so by returning
3724 * returning moneypunct<char_type>::do_pos_format() or
3725 * moneypunct<char_type>::do_neg_format().
3726 *
3727 * The pattern has 4 fields describing the ordering of symbol, sign,
3728 * value, and none or space. There must be one of each in the pattern.
3729 * The none and space enums may not appear in the first field and space
3730 * may not appear in the final field.
3731 *
3732 * The parts of a money string must appear in the order indicated by
3733 * the fields of the pattern. The symbol field indicates that the
3734 * value of curr_symbol() may be present. The sign field indicates
3735 * that the value of positive_sign() or negative_sign() must be
3736 * present. The value field indicates that the absolute value of the
3737 * money amount is present. none indicates 0 or more whitespace
3738 * characters, except at the end, where it permits no whitespace.
3739 * space indicates that 1 or more whitespace characters must be
3740 * present.
3741 *
3742 * For example, for the US locale and pos_format() pattern
3743 * {symbol,sign,value,none}, curr_symbol() == '$' positive_sign() ==
3744 * '+', and value 10.01, and options set to force the symbol, the
3745 * corresponding string is "$+10.01".
3746 *
3747 * @return Pattern for money values.
3748 */
3749 pattern
0214010c 3750 pos_format() const
0a1cceea 3751 { return this->do_pos_format(); }
725dc051 3752
ed6814f7 3753 pattern
0214010c 3754 neg_format() const
0a1cceea 3755 { return this->do_neg_format(); }
9a01c9b0 3756 //@}
725dc051
BK
3757
3758 protected:
9a01c9b0 3759 /// Destructor.
ed6814f7 3760 virtual
d3a193e3 3761 ~moneypunct();
0214010c 3762
9a01c9b0
JQ
3763 /**
3764 * @brief Return decimal point character.
3765 *
3766 * Returns a char_type to use as a decimal point. This function is a
3767 * hook for derived classes to change the value returned.
3768 *
3769 * @return @a char_type representing a decimal point.
3770 */
0214010c
BK
3771 virtual char_type
3772 do_decimal_point() const
fea4065d 3773 { return _M_data->_M_decimal_point; }
ed6814f7 3774
9a01c9b0
JQ
3775 /**
3776 * @brief Return thousands separator character.
3777 *
3778 * Returns a char_type to use as a thousands separator. This function
3779 * is a hook for derived classes to change the value returned.
3780 *
3781 * @return @a char_type representing a thousands separator.
3782 */
0214010c
BK
3783 virtual char_type
3784 do_thousands_sep() const
fea4065d 3785 { return _M_data->_M_thousands_sep; }
ed6814f7 3786
9a01c9b0
JQ
3787 /**
3788 * @brief Return grouping specification.
3789 *
3790 * Returns a string representing groupings for the integer part of a
3791 * number. This function is a hook for derived classes to change the
3792 * value returned. @see grouping() for details.
3793 *
3794 * @return String representing grouping specification.
3795 */
ed6814f7 3796 virtual string
0214010c 3797 do_grouping() const
fea4065d 3798 { return _M_data->_M_grouping; }
725dc051 3799
9a01c9b0
JQ
3800 /**
3801 * @brief Return currency symbol string.
3802 *
3803 * This function returns a string_type to use as a currency symbol.
3804 * This function is a hook for derived classes to change the value
3805 * returned. @see curr_symbol() for details.
3806 *
3807 * @return @a string_type representing a currency symbol.
3808 */
ed6814f7 3809 virtual string_type
725dc051 3810 do_curr_symbol() const
fea4065d 3811 { return _M_data->_M_curr_symbol; }
725dc051 3812
9a01c9b0
JQ
3813 /**
3814 * @brief Return positive sign string.
3815 *
3816 * This function returns a string_type to use as a sign for positive
3817 * amounts. This function is a hook for derived classes to change the
3818 * value returned. @see positive_sign() for details.
3819 *
3820 * @return @a string_type representing a positive sign.
3821 */
ed6814f7 3822 virtual string_type
725dc051 3823 do_positive_sign() const
fea4065d 3824 { return _M_data->_M_positive_sign; }
725dc051 3825
9a01c9b0
JQ
3826 /**
3827 * @brief Return negative sign string.
3828 *
3829 * This function returns a string_type to use as a sign for negative
3830 * amounts. This function is a hook for derived classes to change the
3831 * value returned. @see negative_sign() for details.
3832 *
3833 * @return @a string_type representing a negative sign.
3834 */
ed6814f7 3835 virtual string_type
725dc051 3836 do_negative_sign() const
fea4065d 3837 { return _M_data->_M_negative_sign; }
725dc051 3838
9a01c9b0
JQ
3839 /**
3840 * @brief Return number of digits in fraction.
3841 *
3842 * This function returns the exact number of digits that make up the
3843 * fractional part of a money amount. This function is a hook for
3844 * derived classes to change the value returned. @see frac_digits()
3845 * for details.
3846 *
3847 * @return Number of digits in amount fraction.
3848 */
ed6814f7 3849 virtual int
725dc051 3850 do_frac_digits() const
fea4065d 3851 { return _M_data->_M_frac_digits; }
725dc051 3852
9a01c9b0
JQ
3853 /**
3854 * @brief Return pattern for money values.
3855 *
3856 * This function returns a pattern describing the formatting of a
3857 * positive valued money amount. This function is a hook for derived
3858 * classes to change the value returned. @see pos_format() for
3859 * details.
3860 *
3861 * @return Pattern for money values.
3862 */
ed6814f7 3863 virtual pattern
725dc051 3864 do_pos_format() const
fea4065d 3865 { return _M_data->_M_pos_format; }
725dc051 3866
9a01c9b0
JQ
3867 /**
3868 * @brief Return pattern for money values.
3869 *
3870 * This function returns a pattern describing the formatting of a
3871 * negative valued money amount. This function is a hook for derived
3872 * classes to change the value returned. @see neg_format() for
3873 * details.
3874 *
3875 * @return Pattern for money values.
3876 */
ed6814f7 3877 virtual pattern
725dc051 3878 do_neg_format() const
fea4065d 3879 { return _M_data->_M_neg_format; }
725dc051 3880
0214010c 3881 // For use at construction time only.
ed6814f7
BI
3882 void
3883 _M_initialize_moneypunct(__c_locale __cloc = NULL,
fdf7e809 3884 const char* __name = NULL);
725dc051
BK
3885 };
3886
0a31609b
BK
3887 template<typename _CharT, bool _Intl>
3888 locale::id moneypunct<_CharT, _Intl>::id;
3889
3890 template<typename _CharT, bool _Intl>
3891 const bool moneypunct<_CharT, _Intl>::intl;
3892
d3a193e3
BK
3893 template<>
3894 moneypunct<char, true>::~moneypunct();
3895
3896 template<>
3897 moneypunct<char, false>::~moneypunct();
3898
ed6814f7 3899 template<>
69971cd8 3900 void
fdf7e809 3901 moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
0214010c 3902
ed6814f7 3903 template<>
0214010c 3904 void
fdf7e809 3905 moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
ea0c0b6e 3906
3d7c150e 3907#ifdef _GLIBCXX_USE_WCHAR_T
d3a193e3
BK
3908 template<>
3909 moneypunct<wchar_t, true>::~moneypunct();
3910
3911 template<>
3912 moneypunct<wchar_t, false>::~moneypunct();
3913
ed6814f7 3914 template<>
0214010c 3915 void
ed6814f7 3916 moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
fdf7e809 3917 const char*);
69971cd8 3918
ed6814f7 3919 template<>
69971cd8 3920 void
ed6814f7 3921 moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
fdf7e809 3922 const char*);
0214010c
BK
3923#endif
3924
00aca6e8 3925 /// @brief class moneypunct_byname [22.2.6.4].
0214010c
BK
3926 template<typename _CharT, bool _Intl>
3927 class moneypunct_byname : public moneypunct<_CharT, _Intl>
725dc051
BK
3928 {
3929 public:
ed6814f7
BI
3930 typedef _CharT char_type;
3931 typedef basic_string<_CharT> string_type;
0214010c 3932
725dc051
BK
3933 static const bool intl = _Intl;
3934
ed6814f7 3935 explicit
0214010c
BK
3936 moneypunct_byname(const char* __s, size_t __refs = 0)
3937 : moneypunct<_CharT, _Intl>(__refs)
3938 {
bf5fe473
BK
3939 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
3940 {
3941 __c_locale __tmp;
3942 this->_S_create_c_locale(__tmp, __s);
ed6814f7
BI
3943 this->_M_initialize_moneypunct(__tmp);
3944 this->_S_destroy_c_locale(__tmp);
bf5fe473 3945 }
0214010c 3946 }
725dc051
BK
3947
3948 protected:
ed6814f7 3949 virtual
bf5fe473 3950 ~moneypunct_byname() { }
725dc051
BK
3951 };
3952
0a31609b
BK
3953 template<typename _CharT, bool _Intl>
3954 const bool moneypunct_byname<_CharT, _Intl>::intl;
3955
9a01c9b0
JQ
3956 /**
3957 * @brief Facet for parsing monetary amounts.
3958 *
3959 * This facet encapsulates the code to parse and return a monetary
3960 * amount from a string.
3961 *
3962 * The money_get template uses protected virtual functions to
3963 * provide the actual results. The public accessors forward the
3964 * call to the virtual functions. These virtual functions are
3965 * hooks for developers to implement the behavior they require from
3966 * the money_get facet.
3967 */
fb678854 3968 template<typename _CharT, typename _InIter>
586b5f20 3969 class money_get : public locale::facet
fb678854
BK
3970 {
3971 public:
1ab65677 3972 // Types:
9a01c9b0
JQ
3973 //@{
3974 /// Public typedefs
ed6814f7
BI
3975 typedef _CharT char_type;
3976 typedef _InIter iter_type;
3977 typedef basic_string<_CharT> string_type;
9a01c9b0 3978 //@}
fb678854 3979
9a01c9b0 3980 /// Numpunct facet id.
ed6814f7 3981 static locale::id id;
fb678854 3982
9a01c9b0
JQ
3983 /**
3984 * @brief Constructor performs initialization.
3985 *
3986 * This is the constructor provided by the standard.
3987 *
3988 * @param refs Passed to the base facet class.
3989 */
ed6814f7 3990 explicit
fea4065d 3991 money_get(size_t __refs = 0) : facet(__refs) { }
fb678854 3992
9a01c9b0
JQ
3993 /**
3994 * @brief Read and parse a monetary value.
3995 *
3996 * This function reads characters from @a s, interprets them as a
3997 * monetary value according to moneypunct and ctype facets retrieved
3998 * from io.getloc(), and returns the result in @a units as an integral
3999 * value moneypunct::frac_digits() * the actual amount. For example,
4000 * the string $10.01 in a US locale would store 1001 in @a units.
4001 *
4002 * Any characters not part of a valid money amount are not consumed.
4003 *
4004 * If a money value cannot be parsed from the input stream, sets
4005 * err=(err|io.failbit). If the stream is consumed before finishing
4006 * parsing, sets err=(err|io.failbit|io.eofbit). @a units is
4007 * unchanged if parsing fails.
4008 *
4009 * This function works by returning the result of do_get().
4010 *
4011 * @param s Start of characters to parse.
4012 * @param end End of characters to parse.
4013 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4014 * @param io Source of facets and io state.
4015 * @param err Error field to set if parsing fails.
4016 * @param units Place to store result of parsing.
4017 * @return Iterator referencing first character beyond valid money
ed6814f7 4018 * amount.
9a01c9b0
JQ
4019 */
4020 iter_type
ed6814f7 4021 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
e08138aa
BK
4022 ios_base::iostate& __err, long double& __units) const
4023 { return this->do_get(__s, __end, __intl, __io, __err, __units); }
fb678854 4024
9a01c9b0
JQ
4025 /**
4026 * @brief Read and parse a monetary value.
4027 *
4028 * This function reads characters from @a s, interprets them as a
4029 * monetary value according to moneypunct and ctype facets retrieved
4030 * from io.getloc(), and returns the result in @a digits. For example,
4031 * the string $10.01 in a US locale would store "1001" in @a digits.
4032 *
4033 * Any characters not part of a valid money amount are not consumed.
4034 *
4035 * If a money value cannot be parsed from the input stream, sets
4036 * err=(err|io.failbit). If the stream is consumed before finishing
4037 * parsing, sets err=(err|io.failbit|io.eofbit).
4038 *
4039 * This function works by returning the result of do_get().
4040 *
4041 * @param s Start of characters to parse.
4042 * @param end End of characters to parse.
4043 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4044 * @param io Source of facets and io state.
4045 * @param err Error field to set if parsing fails.
4046 * @param digits Place to store result of parsing.
4047 * @return Iterator referencing first character beyond valid money
ed6814f7 4048 * amount.
9a01c9b0 4049 */
ed6814f7
BI
4050 iter_type
4051 get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
fb678854 4052 ios_base::iostate& __err, string_type& __digits) const
e08138aa 4053 { return this->do_get(__s, __end, __intl, __io, __err, __digits); }
fb678854
BK
4054
4055 protected:
9a01c9b0 4056 /// Destructor.
ed6814f7 4057 virtual
fb678854
BK
4058 ~money_get() { }
4059
9a01c9b0
JQ
4060 /**
4061 * @brief Read and parse a monetary value.
4062 *
4063 * This function reads and parses characters representing a monetary
4064 * value. This function is a hook for derived classes to change the
4065 * value returned. @see get() for details.
4066 */
ed6814f7
BI
4067 virtual iter_type
4068 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
e08138aa 4069 ios_base::iostate& __err, long double& __units) const;
fb678854 4070
9a01c9b0
JQ
4071 /**
4072 * @brief Read and parse a monetary value.
4073 *
4074 * This function reads and parses characters representing a monetary
4075 * value. This function is a hook for derived classes to change the
4076 * value returned. @see get() for details.
4077 */
ed6814f7
BI
4078 virtual iter_type
4079 do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
e08138aa 4080 ios_base::iostate& __err, string_type& __digits) const;
2ddf25f2 4081
20da06ef
PC
4082 template<bool _Intl>
4083 iter_type
4084 _M_extract(iter_type __s, iter_type __end, ios_base& __io,
f4bdbead 4085 ios_base::iostate& __err, string& __digits) const;
fb678854
BK
4086 };
4087
4088 template<typename _CharT, typename _InIter>
4089 locale::id money_get<_CharT, _InIter>::id;
4090
9a01c9b0
JQ
4091 /**
4092 * @brief Facet for outputting monetary amounts.
4093 *
4094 * This facet encapsulates the code to format and output a monetary
4095 * amount.
4096 *
4097 * The money_put template uses protected virtual functions to
4098 * provide the actual results. The public accessors forward the
4099 * call to the virtual functions. These virtual functions are
4100 * hooks for developers to implement the behavior they require from
4101 * the money_put facet.
4102 */
fb678854 4103 template<typename _CharT, typename _OutIter>
586b5f20 4104 class money_put : public locale::facet
fb678854
BK
4105 {
4106 public:
9a01c9b0
JQ
4107 //@{
4108 /// Public typedefs
ed6814f7
BI
4109 typedef _CharT char_type;
4110 typedef _OutIter iter_type;
fb678854 4111 typedef basic_string<_CharT> string_type;
9a01c9b0 4112 //@}
fb678854 4113
9a01c9b0 4114 /// Numpunct facet id.
ed6814f7 4115 static locale::id id;
fb678854 4116
9a01c9b0
JQ
4117 /**
4118 * @brief Constructor performs initialization.
4119 *
4120 * This is the constructor provided by the standard.
4121 *
4122 * @param refs Passed to the base facet class.
4123 */
ed6814f7 4124 explicit
fea4065d 4125 money_put(size_t __refs = 0) : facet(__refs) { }
fb678854 4126
9a01c9b0
JQ
4127 /**
4128 * @brief Format and output a monetary value.
4129 *
4130 * This function formats @a units as a monetary value according to
4131 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4132 * the resulting characters to @a s. For example, the value 1001 in a
4133 * US locale would write "$10.01" to @a s.
4134 *
4135 * This function works by returning the result of do_put().
4136 *
4137 * @param s The stream to write to.
4138 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4139 * @param io Source of facets and io state.
4140 * @param fill char_type to use for padding.
4141 * @param units Place to store result of parsing.
4142 * @return Iterator after writing.
4143 */
ed6814f7 4144 iter_type
e08138aa 4145 put(iter_type __s, bool __intl, ios_base& __io,
fb678854 4146 char_type __fill, long double __units) const
e08138aa 4147 { return this->do_put(__s, __intl, __io, __fill, __units); }
fb678854 4148
9a01c9b0
JQ
4149 /**
4150 * @brief Format and output a monetary value.
4151 *
4152 * This function formats @a digits as a monetary value according to
4153 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4154 * the resulting characters to @a s. For example, the string "1001" in
4155 * a US locale would write "$10.01" to @a s.
4156 *
4157 * This function works by returning the result of do_put().
4158 *
4159 * @param s The stream to write to.
4160 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4161 * @param io Source of facets and io state.
4162 * @param fill char_type to use for padding.
4163 * @param units Place to store result of parsing.
4164 * @return Iterator after writing.
4165 */
ed6814f7 4166 iter_type
e08138aa 4167 put(iter_type __s, bool __intl, ios_base& __io,
fb678854 4168 char_type __fill, const string_type& __digits) const
e08138aa 4169 { return this->do_put(__s, __intl, __io, __fill, __digits); }
fb678854
BK
4170
4171 protected:
9a01c9b0 4172 /// Destructor.
ed6814f7 4173 virtual
fb678854
BK
4174 ~money_put() { }
4175
9a01c9b0
JQ
4176 /**
4177 * @brief Format and output a monetary value.
4178 *
4179 * This function formats @a units as a monetary value according to
4180 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4181 * the resulting characters to @a s. For example, the value 1001 in a
4182 * US locale would write "$10.01" to @a s.
4183 *
4184 * This function is a hook for derived classes to change the value
4185 * returned. @see put().
4186 *
4187 * @param s The stream to write to.
4188 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4189 * @param io Source of facets and io state.
4190 * @param fill char_type to use for padding.
4191 * @param units Place to store result of parsing.
4192 * @return Iterator after writing.
4193 */
fb678854
BK
4194 virtual iter_type
4195 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4196 long double __units) const;
4197
9a01c9b0
JQ
4198 /**
4199 * @brief Format and output a monetary value.
4200 *
4201 * This function formats @a digits as a monetary value according to
4202 * moneypunct and ctype facets retrieved from io.getloc(), and writes
4203 * the resulting characters to @a s. For example, the string "1001" in
4204 * a US locale would write "$10.01" to @a s.
4205 *
4206 * This function is a hook for derived classes to change the value
4207 * returned. @see put().
4208 *
4209 * @param s The stream to write to.
4210 * @param intl Parameter to use_facet<moneypunct<CharT,intl> >.
4211 * @param io Source of facets and io state.
4212 * @param fill char_type to use for padding.
4213 * @param units Place to store result of parsing.
4214 * @return Iterator after writing.
4215 */
fb678854
BK
4216 virtual iter_type
4217 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
4218 const string_type& __digits) const;
2ddf25f2 4219
fe932e50
PC
4220 template<bool _Intl>
4221 iter_type
4222 _M_insert(iter_type __s, ios_base& __io, char_type __fill,
4223 const string_type& __digits) const;
fb678854
BK
4224 };
4225
4226 template<typename _CharT, typename _OutIter>
4227 locale::id money_put<_CharT, _OutIter>::id;
4228
9a01c9b0
JQ
4229 /**
4230 * @brief Messages facet base class providing catalog typedef.
4231 */
725dc051
BK
4232 struct messages_base
4233 {
4234 typedef int catalog;
4235 };
4236
9a01c9b0
JQ
4237 /**
4238 * @brief Facet for handling message catalogs
4239 *
4240 * This facet encapsulates the code to retrieve messages from
4241 * message catalogs. The only thing defined by the standard for this facet
4242 * is the interface. All underlying functionality is
4243 * implementation-defined.
4244 *
4245 * This library currently implements 3 versions of the message facet. The
4246 * first version (gnu) is a wrapper around gettext, provided by libintl.
4247 * The second version (ieee) is a wrapper around catgets. The final
4248 * version (default) does no actual translation. These implementations are
4249 * only provided for char and wchar_t instantiations.
4250 *
4251 * The messages template uses protected virtual functions to
4252 * provide the actual results. The public accessors forward the
4253 * call to the virtual functions. These virtual functions are
4254 * hooks for developers to implement the behavior they require from
4255 * the messages facet.
4256 */
725dc051 4257 template<typename _CharT>
0214010c 4258 class messages : public locale::facet, public messages_base
725dc051
BK
4259 {
4260 public:
33590f13 4261 // Types:
9a01c9b0
JQ
4262 //@{
4263 /// Public typedefs
ed6814f7
BI
4264 typedef _CharT char_type;
4265 typedef basic_string<_CharT> string_type;
9a01c9b0 4266 //@}
0214010c 4267
33590f13
BK
4268 protected:
4269 // Underlying "C" library locale information saved from
4270 // initialization, needed by messages_byname as well.
ea0c0b6e 4271 __c_locale _M_c_locale_messages;
8ae81136 4272 const char* _M_name_messages;
33590f13
BK
4273
4274 public:
9a01c9b0 4275 /// Numpunct facet id.
ed6814f7 4276 static locale::id id;
0214010c 4277
9a01c9b0
JQ
4278 /**
4279 * @brief Constructor performs initialization.
4280 *
4281 * This is the constructor provided by the standard.
4282 *
4283 * @param refs Passed to the base facet class.
4284 */
ed6814f7 4285 explicit
1c26d8fd 4286 messages(size_t __refs = 0);
33590f13 4287
ea0c0b6e 4288 // Non-standard.
9a01c9b0
JQ
4289 /**
4290 * @brief Internal constructor. Not for general use.
4291 *
4292 * This is a constructor for use by the library itself to set up new
4293 * locales.
4294 *
4295 * @param cloc The "C" locale.
4296 * @param s The name of a locale.
4297 * @param refs Refcount to pass to the base class.
4298 */
ed6814f7 4299 explicit
1c26d8fd 4300 messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
725dc051 4301
9a01c9b0
JQ
4302 /*
4303 * @brief Open a message catalog.
4304 *
4305 * This function opens and returns a handle to a message catalog by
4306 * returning do_open(s, loc).
4307 *
4308 * @param s The catalog to open.
4309 * @param loc Locale to use for character set conversions.
4310 * @return Handle to the catalog or value < 0 if open fails.
4311 */
ed6814f7 4312 catalog
725dc051 4313 open(const basic_string<char>& __s, const locale& __loc) const
33590f13
BK
4314 { return this->do_open(__s, __loc); }
4315
4316 // Non-standard and unorthodox, yet effective.
9a01c9b0
JQ
4317 /*
4318 * @brief Open a message catalog.
4319 *
4320 * This non-standard function opens and returns a handle to a message
4321 * catalog by returning do_open(s, loc). The third argument provides a
4322 * message catalog root directory for gnu gettext and is ignored
4323 * otherwise.
4324 *
4325 * @param s The catalog to open.
4326 * @param loc Locale to use for character set conversions.
4327 * @param dir Message catalog root directory.
4328 * @return Handle to the catalog or value < 0 if open fails.
4329 */
ed6814f7 4330 catalog
33590f13 4331 open(const basic_string<char>&, const locale&, const char*) const;
725dc051 4332
9a01c9b0
JQ
4333 /*
4334 * @brief Look up a string in a message catalog.
4335 *
4336 * This function retrieves and returns a message from a catalog by
4337 * returning do_get(c, set, msgid, s).
4338 *
4339 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4340 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4341 *
4342 * @param c The catalog to access.
4343 * @param set Implementation-defined.
4344 * @param msgid Implementation-defined.
4345 * @param s Default return value if retrieval fails.
4346 * @return Retrieved message or @a s if get fails.
4347 */
ed6814f7 4348 string_type
725dc051 4349 get(catalog __c, int __set, int __msgid, const string_type& __s) const
33590f13 4350 { return this->do_get(__c, __set, __msgid, __s); }
725dc051 4351
9a01c9b0
JQ
4352 /*
4353 * @brief Close a message catalog.
4354 *
4355 * Closes catalog @a c by calling do_close(c).
4356 *
4357 * @param c The catalog to close.
4358 */
ed6814f7 4359 void
725dc051 4360 close(catalog __c) const
33590f13 4361 { return this->do_close(__c); }
725dc051
BK
4362
4363 protected:
9a01c9b0 4364 /// Destructor.
ed6814f7 4365 virtual
1c26d8fd 4366 ~messages();
725dc051 4367
9a01c9b0
JQ
4368 /*
4369 * @brief Open a message catalog.
4370 *
4371 * This function opens and returns a handle to a message catalog in an
4372 * implementation-defined manner. This function is a hook for derived
4373 * classes to change the value returned.
4374 *
4375 * @param s The catalog to open.
4376 * @param loc Locale to use for character set conversions.
4377 * @return Handle to the opened catalog, value < 0 if open failed.
4378 */
ed6814f7 4379 virtual catalog
33590f13 4380 do_open(const basic_string<char>&, const locale&) const;
725dc051 4381
9a01c9b0
JQ
4382 /*
4383 * @brief Look up a string in a message catalog.
4384 *
4385 * This function retrieves and returns a message from a catalog in an
4386 * implementation-defined manner. This function is a hook for derived
4387 * classes to change the value returned.
4388 *
4389 * For gnu, @a set and @a msgid are ignored. Returns gettext(s).
4390 * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
4391 *
4392 * @param c The catalog to access.
4393 * @param set Implementation-defined.
4394 * @param msgid Implementation-defined.
4395 * @param s Default return value if retrieval fails.
4396 * @return Retrieved message or @a s if get fails.
4397 */
ed6814f7 4398 virtual string_type
33590f13 4399 do_get(catalog, int, int, const string_type& __dfault) const;
725dc051 4400
9a01c9b0
JQ
4401 /*
4402 * @brief Close a message catalog.
4403 *
4404 * @param c The catalog to close.
4405 */
ed6814f7 4406 virtual void
33590f13
BK
4407 do_close(catalog) const;
4408
4409 // Returns a locale and codeset-converted string, given a char* message.
4410 char*
4411 _M_convert_to_char(const string_type& __msg) const
4412 {
4413 // XXX
4414 return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
4415 }
4416
4417 // Returns a locale and codeset-converted string, given a char* message.
4418 string_type
22352844 4419 _M_convert_from_char(char*) const
33590f13 4420 {
22352844 4421#if 0
33590f13
BK
4422 // Length of message string without terminating null.
4423 size_t __len = char_traits<char>::length(__msg) - 1;
4424
4425 // "everybody can easily convert the string using
4426 // mbsrtowcs/wcsrtombs or with iconv()"
22352844 4427
33590f13
BK
4428 // Convert char* to _CharT in locale used to open catalog.
4429 // XXX need additional template parameter on messages class for this..
4430 // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type;
ed6814f7 4431 typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type;
33590f13
BK
4432
4433 __codecvt_type::state_type __state;
4434 // XXX may need to initialize state.
4435 //initialize_state(__state._M_init());
ed6814f7 4436
33590f13
BK
4437 char* __from_next;
4438 // XXX what size for this string?
4439 _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1));
4440 const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv);
4441 __cvt.out(__state, __msg, __msg + __len, __from_next,
4442 __to, __to + __len + 1, __to_next);
4443 return string_type(__to);
4444#endif
4445#if 0
4446 typedef ctype<_CharT> __ctype_type;
4447 // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg);
4448 const __ctype_type& __cvt = use_facet<__ctype_type>(locale());
4449 // XXX Again, proper length of converted string an issue here.
4450 // For now, assume the converted length is not larger.
4451 _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1));
4452 __cvt.widen(__msg, __msg + __len, __dest);
4453 return basic_string<_CharT>(__dest);
4454#endif
4455 return string_type();
4456 }
4457 };
725dc051 4458
0a31609b
BK
4459 template<typename _CharT>
4460 locale::id messages<_CharT>::id;
4461
33590f13
BK
4462 // Specializations for required instantiations.
4463 template<>
4464 string
4465 messages<char>::do_get(catalog, int, int, const string&) const;
4466
3d7c150e 4467#ifdef _GLIBCXX_USE_WCHAR_T
89671b70
JJ
4468 template<>
4469 wstring
4470 messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
4471#endif
4472
00aca6e8
BK
4473 /// @brief class messages_byname [22.2.7.2].
4474 template<typename _CharT>
725dc051
BK
4475 class messages_byname : public messages<_CharT>
4476 {
4477 public:
ed6814f7
BI
4478 typedef _CharT char_type;
4479 typedef basic_string<_CharT> string_type;
725dc051 4480
ed6814f7 4481 explicit
1c26d8fd 4482 messages_byname(const char* __s, size_t __refs = 0);
725dc051
BK
4483
4484 protected:
ed6814f7
BI
4485 virtual
4486 ~messages_byname()
33590f13 4487 { }
725dc051
BK
4488 };
4489
1c26d8fd
BK
4490 // Include host and configuration specific messages functions.
4491 #include <bits/messages_members.h>
4492
725dc051 4493
69971cd8
BK
4494 // Subclause convenience interfaces, inlines.
4495 // NB: These are inline because, when used in a loop, some compilers
4496 // can hoist the body out of the loop; then it's just as fast as the
4497 // C is*() function.
00aca6e8
BK
4498
4499 /// Convenience interface to ctype.is(ctype_base::space, __c).
725dc051 4500 template<typename _CharT>
ed6814f7 4501 inline bool
725dc051
BK
4502 isspace(_CharT __c, const locale& __loc)
4503 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
4504
00aca6e8 4505 /// Convenience interface to ctype.is(ctype_base::print, __c).
725dc051 4506 template<typename _CharT>
ed6814f7 4507 inline bool
725dc051
BK
4508 isprint(_CharT __c, const locale& __loc)
4509 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); }
4510
00aca6e8 4511 /// Convenience interface to ctype.is(ctype_base::cntrl, __c).
725dc051 4512 template<typename _CharT>
ed6814f7 4513 inline bool
725dc051
BK
4514 iscntrl(_CharT __c, const locale& __loc)
4515 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); }
4516
00aca6e8 4517 /// Convenience interface to ctype.is(ctype_base::upper, __c).
725dc051 4518 template<typename _CharT>
ed6814f7 4519 inline bool
725dc051
BK
4520 isupper(_CharT __c, const locale& __loc)
4521 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); }
4522
00aca6e8 4523 /// Convenience interface to ctype.is(ctype_base::lower, __c).
725dc051 4524 template<typename _CharT>
00aca6e8
BK
4525 inline bool
4526 islower(_CharT __c, const locale& __loc)
725dc051
BK
4527 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); }
4528
00aca6e8 4529 /// Convenience interface to ctype.is(ctype_base::alpha, __c).
725dc051 4530 template<typename _CharT>
ed6814f7 4531 inline bool
725dc051
BK
4532 isalpha(_CharT __c, const locale& __loc)
4533 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }
4534
00aca6e8 4535 /// Convenience interface to ctype.is(ctype_base::digit, __c).
725dc051 4536 template<typename _CharT>
ed6814f7 4537 inline bool
725dc051
BK
4538 isdigit(_CharT __c, const locale& __loc)
4539 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); }
4540
00aca6e8 4541 /// Convenience interface to ctype.is(ctype_base::punct, __c).
725dc051 4542 template<typename _CharT>
ed6814f7 4543 inline bool
725dc051
BK
4544 ispunct(_CharT __c, const locale& __loc)
4545 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); }
4546
00aca6e8 4547 /// Convenience interface to ctype.is(ctype_base::xdigit, __c).
725dc051 4548 template<typename _CharT>
ed6814f7 4549 inline bool
725dc051
BK
4550 isxdigit(_CharT __c, const locale& __loc)
4551 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); }
4552
00aca6e8 4553 /// Convenience interface to ctype.is(ctype_base::alnum, __c).
725dc051 4554 template<typename _CharT>
ed6814f7 4555 inline bool
725dc051
BK
4556 isalnum(_CharT __c, const locale& __loc)
4557 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); }
4558
00aca6e8 4559 /// Convenience interface to ctype.is(ctype_base::graph, __c).
725dc051 4560 template<typename _CharT>
ed6814f7 4561 inline bool
725dc051
BK
4562 isgraph(_CharT __c, const locale& __loc)
4563 { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); }
4564
00aca6e8 4565 /// Convenience interface to ctype.toupper(__c).
725dc051 4566 template<typename _CharT>
ed6814f7 4567 inline _CharT
725dc051
BK
4568 toupper(_CharT __c, const locale& __loc)
4569 { return use_facet<ctype<_CharT> >(__loc).toupper(__c); }
4570
00aca6e8 4571 /// Convenience interface to ctype.tolower(__c).
725dc051 4572 template<typename _CharT>
ed6814f7 4573 inline _CharT
725dc051
BK
4574 tolower(_CharT __c, const locale& __loc)
4575 { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
3cbc7af0
BK
4576
4577_GLIBCXX_END_NAMESPACE
725dc051 4578
69971cd8 4579#endif