locale_facets.tcc (num_get<>::do_get(iter_type, ios_base&, ios_base::iostate&, void...
[gcc.git] / libstdc++-v3 / include / bits / locale_facets.tcc
1 // Locale support -*- C++ -*-
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007
5 // Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 2, or (at your option)
11 // any later version.
12
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING. If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // USA.
22
23 // As a special exception, you may use this file as part of a free software
24 // library without restriction. Specifically, if other files instantiate
25 // templates or use macros or inline functions from this file, or you compile
26 // this file and link it with other files to produce an executable, this
27 // file does not by itself cause the resulting executable to be covered by
28 // the GNU General Public License. This exception does not however
29 // invalidate any other reasons why the executable file might be covered by
30 // the GNU General Public License.
31
32 /** @file locale_facets.tcc
33 * This is an internal header file, included by other library headers.
34 * You should not attempt to use it directly.
35 */
36
37 #ifndef _LOCALE_FACETS_TCC
38 #define _LOCALE_FACETS_TCC 1
39
40 #pragma GCC system_header
41
42 #include <limits> // For numeric_limits
43 #include <typeinfo> // For bad_cast.
44 #include <bits/streambuf_iterator.h>
45 #include <ext/type_traits.h>
46
47 _GLIBCXX_BEGIN_NAMESPACE(std)
48
49 template<typename _Facet>
50 locale
51 locale::combine(const locale& __other) const
52 {
53 _Impl* __tmp = new _Impl(*_M_impl, 1);
54 try
55 {
56 __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
57 }
58 catch(...)
59 {
60 __tmp->_M_remove_reference();
61 __throw_exception_again;
62 }
63 return locale(__tmp);
64 }
65
66 template<typename _CharT, typename _Traits, typename _Alloc>
67 bool
68 locale::operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1,
69 const basic_string<_CharT, _Traits, _Alloc>& __s2) const
70 {
71 typedef std::collate<_CharT> __collate_type;
72 const __collate_type& __collate = use_facet<__collate_type>(*this);
73 return (__collate.compare(__s1.data(), __s1.data() + __s1.length(),
74 __s2.data(), __s2.data() + __s2.length()) < 0);
75 }
76
77 /**
78 * @brief Test for the presence of a facet.
79 *
80 * has_facet tests the locale argument for the presence of the facet type
81 * provided as the template parameter. Facets derived from the facet
82 * parameter will also return true.
83 *
84 * @param Facet The facet type to test the presence of.
85 * @param locale The locale to test.
86 * @return true if locale contains a facet of type Facet, else false.
87 */
88 template<typename _Facet>
89 inline bool
90 has_facet(const locale& __loc) throw()
91 {
92 const size_t __i = _Facet::id._M_id();
93 const locale::facet** __facets = __loc._M_impl->_M_facets;
94 return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
95 }
96
97 /**
98 * @brief Return a facet.
99 *
100 * use_facet looks for and returns a reference to a facet of type Facet
101 * where Facet is the template parameter. If has_facet(locale) is true,
102 * there is a suitable facet to return. It throws std::bad_cast if the
103 * locale doesn't contain a facet of type Facet.
104 *
105 * @param Facet The facet type to access.
106 * @param locale The locale to use.
107 * @return Reference to facet of type Facet.
108 * @throw std::bad_cast if locale doesn't contain a facet of type Facet.
109 */
110 template<typename _Facet>
111 inline const _Facet&
112 use_facet(const locale& __loc)
113 {
114 const size_t __i = _Facet::id._M_id();
115 const locale::facet** __facets = __loc._M_impl->_M_facets;
116 if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
117 __throw_bad_cast();
118 return static_cast<const _Facet&>(*__facets[__i]);
119 }
120
121 // Routine to access a cache for the facet. If the cache didn't
122 // exist before, it gets constructed on the fly.
123 template<typename _Facet>
124 struct __use_cache
125 {
126 const _Facet*
127 operator() (const locale& __loc) const;
128 };
129
130 // Specializations.
131 template<typename _CharT>
132 struct __use_cache<__numpunct_cache<_CharT> >
133 {
134 const __numpunct_cache<_CharT>*
135 operator() (const locale& __loc) const
136 {
137 const size_t __i = numpunct<_CharT>::id._M_id();
138 const locale::facet** __caches = __loc._M_impl->_M_caches;
139 if (!__caches[__i])
140 {
141 __numpunct_cache<_CharT>* __tmp = NULL;
142 try
143 {
144 __tmp = new __numpunct_cache<_CharT>;
145 __tmp->_M_cache(__loc);
146 }
147 catch(...)
148 {
149 delete __tmp;
150 __throw_exception_again;
151 }
152 __loc._M_impl->_M_install_cache(__tmp, __i);
153 }
154 return static_cast<const __numpunct_cache<_CharT>*>(__caches[__i]);
155 }
156 };
157
158 template<typename _CharT, bool _Intl>
159 struct __use_cache<__moneypunct_cache<_CharT, _Intl> >
160 {
161 const __moneypunct_cache<_CharT, _Intl>*
162 operator() (const locale& __loc) const
163 {
164 const size_t __i = moneypunct<_CharT, _Intl>::id._M_id();
165 const locale::facet** __caches = __loc._M_impl->_M_caches;
166 if (!__caches[__i])
167 {
168 __moneypunct_cache<_CharT, _Intl>* __tmp = NULL;
169 try
170 {
171 __tmp = new __moneypunct_cache<_CharT, _Intl>;
172 __tmp->_M_cache(__loc);
173 }
174 catch(...)
175 {
176 delete __tmp;
177 __throw_exception_again;
178 }
179 __loc._M_impl->_M_install_cache(__tmp, __i);
180 }
181 return static_cast<
182 const __moneypunct_cache<_CharT, _Intl>*>(__caches[__i]);
183 }
184 };
185
186 template<typename _CharT>
187 void
188 __numpunct_cache<_CharT>::_M_cache(const locale& __loc)
189 {
190 _M_allocated = true;
191
192 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
193
194 _M_grouping_size = __np.grouping().size();
195 char* __grouping = new char[_M_grouping_size];
196 __np.grouping().copy(__grouping, _M_grouping_size);
197 _M_grouping = __grouping;
198 _M_use_grouping = (_M_grouping_size
199 && static_cast<signed char>(__np.grouping()[0]) > 0);
200
201 _M_truename_size = __np.truename().size();
202 _CharT* __truename = new _CharT[_M_truename_size];
203 __np.truename().copy(__truename, _M_truename_size);
204 _M_truename = __truename;
205
206 _M_falsename_size = __np.falsename().size();
207 _CharT* __falsename = new _CharT[_M_falsename_size];
208 __np.falsename().copy(__falsename, _M_falsename_size);
209 _M_falsename = __falsename;
210
211 _M_decimal_point = __np.decimal_point();
212 _M_thousands_sep = __np.thousands_sep();
213
214 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
215 __ct.widen(__num_base::_S_atoms_out,
216 __num_base::_S_atoms_out + __num_base::_S_oend, _M_atoms_out);
217 __ct.widen(__num_base::_S_atoms_in,
218 __num_base::_S_atoms_in + __num_base::_S_iend, _M_atoms_in);
219 }
220
221 template<typename _CharT, bool _Intl>
222 void
223 __moneypunct_cache<_CharT, _Intl>::_M_cache(const locale& __loc)
224 {
225 _M_allocated = true;
226
227 const moneypunct<_CharT, _Intl>& __mp =
228 use_facet<moneypunct<_CharT, _Intl> >(__loc);
229
230 _M_grouping_size = __mp.grouping().size();
231 char* __grouping = new char[_M_grouping_size];
232 __mp.grouping().copy(__grouping, _M_grouping_size);
233 _M_grouping = __grouping;
234 _M_use_grouping = (_M_grouping_size
235 && static_cast<signed char>(__mp.grouping()[0]) > 0);
236
237 _M_decimal_point = __mp.decimal_point();
238 _M_thousands_sep = __mp.thousands_sep();
239 _M_frac_digits = __mp.frac_digits();
240
241 _M_curr_symbol_size = __mp.curr_symbol().size();
242 _CharT* __curr_symbol = new _CharT[_M_curr_symbol_size];
243 __mp.curr_symbol().copy(__curr_symbol, _M_curr_symbol_size);
244 _M_curr_symbol = __curr_symbol;
245
246 _M_positive_sign_size = __mp.positive_sign().size();
247 _CharT* __positive_sign = new _CharT[_M_positive_sign_size];
248 __mp.positive_sign().copy(__positive_sign, _M_positive_sign_size);
249 _M_positive_sign = __positive_sign;
250
251 _M_negative_sign_size = __mp.negative_sign().size();
252 _CharT* __negative_sign = new _CharT[_M_negative_sign_size];
253 __mp.negative_sign().copy(__negative_sign, _M_negative_sign_size);
254 _M_negative_sign = __negative_sign;
255
256 _M_pos_format = __mp.pos_format();
257 _M_neg_format = __mp.neg_format();
258
259 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
260 __ct.widen(money_base::_S_atoms,
261 money_base::_S_atoms + money_base::_S_end, _M_atoms);
262 }
263
264
265 // Used by both numeric and monetary facets.
266 // Check to make sure that the __grouping_tmp string constructed in
267 // money_get or num_get matches the canonical grouping for a given
268 // locale.
269 // __grouping_tmp is parsed L to R
270 // 1,222,444 == __grouping_tmp of "\1\3\3"
271 // __grouping is parsed R to L
272 // 1,222,444 == __grouping of "\3" == "\3\3\3"
273 static bool
274 __verify_grouping(const char* __grouping, size_t __grouping_size,
275 const string& __grouping_tmp);
276
277 _GLIBCXX_BEGIN_LDBL_NAMESPACE
278
279 template<typename _CharT, typename _InIter>
280 _InIter
281 num_get<_CharT, _InIter>::
282 _M_extract_float(_InIter __beg, _InIter __end, ios_base& __io,
283 ios_base::iostate& __err, string& __xtrc) const
284 {
285 typedef char_traits<_CharT> __traits_type;
286 typedef __numpunct_cache<_CharT> __cache_type;
287 __use_cache<__cache_type> __uc;
288 const locale& __loc = __io._M_getloc();
289 const __cache_type* __lc = __uc(__loc);
290 const _CharT* __lit = __lc->_M_atoms_in;
291 char_type __c = char_type();
292
293 // True if __beg becomes equal to __end.
294 bool __testeof = __beg == __end;
295
296 // First check for sign.
297 if (!__testeof)
298 {
299 __c = *__beg;
300 const bool __plus = __c == __lit[__num_base::_S_iplus];
301 if ((__plus || __c == __lit[__num_base::_S_iminus])
302 && !(__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
303 && !(__c == __lc->_M_decimal_point))
304 {
305 __xtrc += __plus ? '+' : '-';
306 if (++__beg != __end)
307 __c = *__beg;
308 else
309 __testeof = true;
310 }
311 }
312
313 // Next, look for leading zeros.
314 bool __found_mantissa = false;
315 int __sep_pos = 0;
316 while (!__testeof)
317 {
318 if ((__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
319 || __c == __lc->_M_decimal_point)
320 break;
321 else if (__c == __lit[__num_base::_S_izero])
322 {
323 if (!__found_mantissa)
324 {
325 __xtrc += '0';
326 __found_mantissa = true;
327 }
328 ++__sep_pos;
329
330 if (++__beg != __end)
331 __c = *__beg;
332 else
333 __testeof = true;
334 }
335 else
336 break;
337 }
338
339 // Only need acceptable digits for floating point numbers.
340 bool __found_dec = false;
341 bool __found_sci = false;
342 string __found_grouping;
343 if (__lc->_M_use_grouping)
344 __found_grouping.reserve(32);
345 const char_type* __lit_zero = __lit + __num_base::_S_izero;
346
347 if (!__lc->_M_allocated)
348 // "C" locale
349 while (!__testeof)
350 {
351 const int __digit = _M_find(__lit_zero, 10, __c);
352 if (__digit != -1)
353 {
354 __xtrc += '0' + __digit;
355 __found_mantissa = true;
356 }
357 else if (__c == __lc->_M_decimal_point
358 && !__found_dec && !__found_sci)
359 {
360 __xtrc += '.';
361 __found_dec = true;
362 }
363 else if ((__c == __lit[__num_base::_S_ie]
364 || __c == __lit[__num_base::_S_iE])
365 && !__found_sci && __found_mantissa)
366 {
367 // Scientific notation.
368 __xtrc += 'e';
369 __found_sci = true;
370
371 // Remove optional plus or minus sign, if they exist.
372 if (++__beg != __end)
373 {
374 __c = *__beg;
375 const bool __plus = __c == __lit[__num_base::_S_iplus];
376 if (__plus || __c == __lit[__num_base::_S_iminus])
377 __xtrc += __plus ? '+' : '-';
378 else
379 continue;
380 }
381 else
382 {
383 __testeof = true;
384 break;
385 }
386 }
387 else
388 break;
389
390 if (++__beg != __end)
391 __c = *__beg;
392 else
393 __testeof = true;
394 }
395 else
396 while (!__testeof)
397 {
398 // According to 22.2.2.1.2, p8-9, first look for thousands_sep
399 // and decimal_point.
400 if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
401 {
402 if (!__found_dec && !__found_sci)
403 {
404 // NB: Thousands separator at the beginning of a string
405 // is a no-no, as is two consecutive thousands separators.
406 if (__sep_pos)
407 {
408 __found_grouping += static_cast<char>(__sep_pos);
409 __sep_pos = 0;
410 }
411 else
412 {
413 // NB: __convert_to_v will not assign __v and will
414 // set the failbit.
415 __xtrc.clear();
416 break;
417 }
418 }
419 else
420 break;
421 }
422 else if (__c == __lc->_M_decimal_point)
423 {
424 if (!__found_dec && !__found_sci)
425 {
426 // If no grouping chars are seen, no grouping check
427 // is applied. Therefore __found_grouping is adjusted
428 // only if decimal_point comes after some thousands_sep.
429 if (__found_grouping.size())
430 __found_grouping += static_cast<char>(__sep_pos);
431 __xtrc += '.';
432 __found_dec = true;
433 }
434 else
435 break;
436 }
437 else
438 {
439 const char_type* __q =
440 __traits_type::find(__lit_zero, 10, __c);
441 if (__q)
442 {
443 __xtrc += '0' + (__q - __lit_zero);
444 __found_mantissa = true;
445 ++__sep_pos;
446 }
447 else if ((__c == __lit[__num_base::_S_ie]
448 || __c == __lit[__num_base::_S_iE])
449 && !__found_sci && __found_mantissa)
450 {
451 // Scientific notation.
452 if (__found_grouping.size() && !__found_dec)
453 __found_grouping += static_cast<char>(__sep_pos);
454 __xtrc += 'e';
455 __found_sci = true;
456
457 // Remove optional plus or minus sign, if they exist.
458 if (++__beg != __end)
459 {
460 __c = *__beg;
461 const bool __plus = __c == __lit[__num_base::_S_iplus];
462 if ((__plus || __c == __lit[__num_base::_S_iminus])
463 && !(__lc->_M_use_grouping
464 && __c == __lc->_M_thousands_sep)
465 && !(__c == __lc->_M_decimal_point))
466 __xtrc += __plus ? '+' : '-';
467 else
468 continue;
469 }
470 else
471 {
472 __testeof = true;
473 break;
474 }
475 }
476 else
477 break;
478 }
479
480 if (++__beg != __end)
481 __c = *__beg;
482 else
483 __testeof = true;
484 }
485
486 // Digit grouping is checked. If grouping and found_grouping don't
487 // match, then get very very upset, and set failbit.
488 if (__found_grouping.size())
489 {
490 // Add the ending grouping if a decimal or 'e'/'E' wasn't found.
491 if (!__found_dec && !__found_sci)
492 __found_grouping += static_cast<char>(__sep_pos);
493
494 if (!std::__verify_grouping(__lc->_M_grouping,
495 __lc->_M_grouping_size,
496 __found_grouping))
497 __err |= ios_base::failbit;
498 }
499
500 // Finish up.
501 if (__testeof)
502 __err |= ios_base::eofbit;
503 return __beg;
504 }
505
506 _GLIBCXX_END_LDBL_NAMESPACE
507
508 _GLIBCXX_BEGIN_LDBL_NAMESPACE
509
510 template<typename _CharT, typename _InIter>
511 template<typename _ValueT>
512 _InIter
513 num_get<_CharT, _InIter>::
514 _M_extract_int(_InIter __beg, _InIter __end, ios_base& __io,
515 ios_base::iostate& __err, _ValueT& __v) const
516 {
517 typedef char_traits<_CharT> __traits_type;
518 using __gnu_cxx::__add_unsigned;
519 typedef typename __add_unsigned<_ValueT>::__type __unsigned_type;
520 typedef __numpunct_cache<_CharT> __cache_type;
521 __use_cache<__cache_type> __uc;
522 const locale& __loc = __io._M_getloc();
523 const __cache_type* __lc = __uc(__loc);
524 const _CharT* __lit = __lc->_M_atoms_in;
525 char_type __c = char_type();
526
527 // NB: Iff __basefield == 0, __base can change based on contents.
528 const ios_base::fmtflags __basefield = __io.flags()
529 & ios_base::basefield;
530 const bool __oct = __basefield == ios_base::oct;
531 int __base = __oct ? 8 : (__basefield == ios_base::hex ? 16 : 10);
532
533 // True if __beg becomes equal to __end.
534 bool __testeof = __beg == __end;
535
536 // First check for sign.
537 bool __negative = false;
538 if (!__testeof)
539 {
540 __c = *__beg;
541 if (numeric_limits<_ValueT>::is_signed)
542 __negative = __c == __lit[__num_base::_S_iminus];
543 if ((__negative || __c == __lit[__num_base::_S_iplus])
544 && !(__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
545 && !(__c == __lc->_M_decimal_point))
546 {
547 if (++__beg != __end)
548 __c = *__beg;
549 else
550 __testeof = true;
551 }
552 }
553
554 // Next, look for leading zeros and check required digits
555 // for base formats.
556 bool __found_zero = false;
557 int __sep_pos = 0;
558 while (!__testeof)
559 {
560 if ((__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
561 || __c == __lc->_M_decimal_point)
562 break;
563 else if (__c == __lit[__num_base::_S_izero]
564 && (!__found_zero || __base == 10))
565 {
566 __found_zero = true;
567 ++__sep_pos;
568 if (__basefield == 0)
569 __base = 8;
570 if (__base == 8)
571 __sep_pos = 0;
572 }
573 else if (__found_zero
574 && (__c == __lit[__num_base::_S_ix]
575 || __c == __lit[__num_base::_S_iX]))
576 {
577 if (__basefield == 0)
578 __base = 16;
579 if (__base == 16)
580 {
581 __found_zero = false;
582 __sep_pos = 0;
583 }
584 else
585 break;
586 }
587 else
588 break;
589
590 if (++__beg != __end)
591 {
592 __c = *__beg;
593 if (!__found_zero)
594 break;
595 }
596 else
597 __testeof = true;
598 }
599
600 // At this point, base is determined. If not hex, only allow
601 // base digits as valid input.
602 const size_t __len = (__base == 16 ? __num_base::_S_iend
603 - __num_base::_S_izero : __base);
604
605 // Extract.
606 string __found_grouping;
607 if (__lc->_M_use_grouping)
608 __found_grouping.reserve(32);
609 bool __testfail = false;
610 const __unsigned_type __max = __negative ?
611 -numeric_limits<_ValueT>::min() : numeric_limits<_ValueT>::max();
612 const __unsigned_type __smax = __max / __base;
613 __unsigned_type __result = 0;
614 int __digit = 0;
615 const char_type* __lit_zero = __lit + __num_base::_S_izero;
616
617 if (!__lc->_M_allocated)
618 // "C" locale
619 while (!__testeof)
620 {
621 __digit = _M_find(__lit_zero, __len, __c);
622 if (__digit == -1)
623 break;
624
625 if (__result > __smax)
626 __testfail = true;
627 else
628 {
629 __result *= __base;
630 __testfail |= __result > __max - __digit;
631 __result += __digit;
632 ++__sep_pos;
633 }
634
635 if (++__beg != __end)
636 __c = *__beg;
637 else
638 __testeof = true;
639 }
640 else
641 while (!__testeof)
642 {
643 // According to 22.2.2.1.2, p8-9, first look for thousands_sep
644 // and decimal_point.
645 if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
646 {
647 // NB: Thousands separator at the beginning of a string
648 // is a no-no, as is two consecutive thousands separators.
649 if (__sep_pos)
650 {
651 __found_grouping += static_cast<char>(__sep_pos);
652 __sep_pos = 0;
653 }
654 else
655 {
656 __testfail = true;
657 break;
658 }
659 }
660 else if (__c == __lc->_M_decimal_point)
661 break;
662 else
663 {
664 const char_type* __q =
665 __traits_type::find(__lit_zero, __len, __c);
666 if (!__q)
667 break;
668
669 __digit = __q - __lit_zero;
670 if (__digit > 15)
671 __digit -= 6;
672 if (__result > __smax)
673 __testfail = true;
674 else
675 {
676 __result *= __base;
677 __testfail |= __result > __max - __digit;
678 __result += __digit;
679 ++__sep_pos;
680 }
681 }
682
683 if (++__beg != __end)
684 __c = *__beg;
685 else
686 __testeof = true;
687 }
688
689 // Digit grouping is checked. If grouping and found_grouping don't
690 // match, then get very very upset, and set failbit.
691 if (__found_grouping.size())
692 {
693 // Add the ending grouping.
694 __found_grouping += static_cast<char>(__sep_pos);
695
696 if (!std::__verify_grouping(__lc->_M_grouping,
697 __lc->_M_grouping_size,
698 __found_grouping))
699 __err |= ios_base::failbit;
700 }
701
702 if (!__testfail && (__sep_pos || __found_zero
703 || __found_grouping.size()))
704 __v = __negative ? -__result : __result;
705 else
706 __err |= ios_base::failbit;
707
708 if (__testeof)
709 __err |= ios_base::eofbit;
710 return __beg;
711 }
712
713 // _GLIBCXX_RESOLVE_LIB_DEFECTS
714 // 17. Bad bool parsing
715 template<typename _CharT, typename _InIter>
716 _InIter
717 num_get<_CharT, _InIter>::
718 do_get(iter_type __beg, iter_type __end, ios_base& __io,
719 ios_base::iostate& __err, bool& __v) const
720 {
721 if (!(__io.flags() & ios_base::boolalpha))
722 {
723 // Parse bool values as long.
724 // NB: We can't just call do_get(long) here, as it might
725 // refer to a derived class.
726 long __l = -1;
727 __beg = _M_extract_int(__beg, __end, __io, __err, __l);
728 if (__l == 0 || __l == 1)
729 __v = bool(__l);
730 else
731 __err |= ios_base::failbit;
732 }
733 else
734 {
735 // Parse bool values as alphanumeric.
736 typedef __numpunct_cache<_CharT> __cache_type;
737 __use_cache<__cache_type> __uc;
738 const locale& __loc = __io._M_getloc();
739 const __cache_type* __lc = __uc(__loc);
740
741 bool __testf = true;
742 bool __testt = true;
743 size_t __n;
744 bool __testeof = __beg == __end;
745 for (__n = 0; !__testeof; ++__n)
746 {
747 const char_type __c = *__beg;
748
749 if (__testf)
750 {
751 if (__n < __lc->_M_falsename_size)
752 __testf = __c == __lc->_M_falsename[__n];
753 else
754 break;
755 }
756
757 if (__testt)
758 {
759 if (__n < __lc->_M_truename_size)
760 __testt = __c == __lc->_M_truename[__n];
761 else
762 break;
763 }
764
765 if (!__testf && !__testt)
766 break;
767
768 if (++__beg == __end)
769 __testeof = true;
770 }
771 if (__testf && __n == __lc->_M_falsename_size)
772 __v = false;
773 else if (__testt && __n == __lc->_M_truename_size)
774 __v = true;
775 else
776 __err |= ios_base::failbit;
777
778 if (__testeof)
779 __err |= ios_base::eofbit;
780 }
781 return __beg;
782 }
783
784 template<typename _CharT, typename _InIter>
785 _InIter
786 num_get<_CharT, _InIter>::
787 do_get(iter_type __beg, iter_type __end, ios_base& __io,
788 ios_base::iostate& __err, long& __v) const
789 { return _M_extract_int(__beg, __end, __io, __err, __v); }
790
791 template<typename _CharT, typename _InIter>
792 _InIter
793 num_get<_CharT, _InIter>::
794 do_get(iter_type __beg, iter_type __end, ios_base& __io,
795 ios_base::iostate& __err, unsigned short& __v) const
796 { return _M_extract_int(__beg, __end, __io, __err, __v); }
797
798 template<typename _CharT, typename _InIter>
799 _InIter
800 num_get<_CharT, _InIter>::
801 do_get(iter_type __beg, iter_type __end, ios_base& __io,
802 ios_base::iostate& __err, unsigned int& __v) const
803 { return _M_extract_int(__beg, __end, __io, __err, __v); }
804
805 template<typename _CharT, typename _InIter>
806 _InIter
807 num_get<_CharT, _InIter>::
808 do_get(iter_type __beg, iter_type __end, ios_base& __io,
809 ios_base::iostate& __err, unsigned long& __v) const
810 { return _M_extract_int(__beg, __end, __io, __err, __v); }
811
812 #ifdef _GLIBCXX_USE_LONG_LONG
813 template<typename _CharT, typename _InIter>
814 _InIter
815 num_get<_CharT, _InIter>::
816 do_get(iter_type __beg, iter_type __end, ios_base& __io,
817 ios_base::iostate& __err, long long& __v) const
818 { return _M_extract_int(__beg, __end, __io, __err, __v); }
819
820 template<typename _CharT, typename _InIter>
821 _InIter
822 num_get<_CharT, _InIter>::
823 do_get(iter_type __beg, iter_type __end, ios_base& __io,
824 ios_base::iostate& __err, unsigned long long& __v) const
825 { return _M_extract_int(__beg, __end, __io, __err, __v); }
826 #endif
827
828 template<typename _CharT, typename _InIter>
829 _InIter
830 num_get<_CharT, _InIter>::
831 do_get(iter_type __beg, iter_type __end, ios_base& __io,
832 ios_base::iostate& __err, float& __v) const
833 {
834 string __xtrc;
835 __xtrc.reserve(32);
836 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
837 std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
838 return __beg;
839 }
840
841 template<typename _CharT, typename _InIter>
842 _InIter
843 num_get<_CharT, _InIter>::
844 do_get(iter_type __beg, iter_type __end, ios_base& __io,
845 ios_base::iostate& __err, double& __v) const
846 {
847 string __xtrc;
848 __xtrc.reserve(32);
849 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
850 std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
851 return __beg;
852 }
853
854 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
855 template<typename _CharT, typename _InIter>
856 _InIter
857 num_get<_CharT, _InIter>::
858 __do_get(iter_type __beg, iter_type __end, ios_base& __io,
859 ios_base::iostate& __err, double& __v) const
860 {
861 string __xtrc;
862 __xtrc.reserve(32);
863 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
864 std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
865 return __beg;
866 }
867 #endif
868
869 template<typename _CharT, typename _InIter>
870 _InIter
871 num_get<_CharT, _InIter>::
872 do_get(iter_type __beg, iter_type __end, ios_base& __io,
873 ios_base::iostate& __err, long double& __v) const
874 {
875 string __xtrc;
876 __xtrc.reserve(32);
877 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
878 std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
879 return __beg;
880 }
881
882 template<typename _CharT, typename _InIter>
883 _InIter
884 num_get<_CharT, _InIter>::
885 do_get(iter_type __beg, iter_type __end, ios_base& __io,
886 ios_base::iostate& __err, void*& __v) const
887 {
888 // Prepare for hex formatted input.
889 typedef ios_base::fmtflags fmtflags;
890 const fmtflags __fmt = __io.flags();
891 __io.flags((__fmt & ~ios_base::basefield) | ios_base::hex);
892
893 typedef __gnu_cxx::__conditional_type<(sizeof(void*)
894 <= sizeof(unsigned long)),
895 unsigned long, unsigned long long>::__type _UIntPtrType;
896
897 _UIntPtrType __ul;
898 __beg = _M_extract_int(__beg, __end, __io, __err, __ul);
899
900 // Reset from hex formatted input.
901 __io.flags(__fmt);
902
903 if (!(__err & ios_base::failbit))
904 __v = reinterpret_cast<void*>(__ul);
905 return __beg;
906 }
907
908 // For use by integer and floating-point types after they have been
909 // converted into a char_type string.
910 template<typename _CharT, typename _OutIter>
911 void
912 num_put<_CharT, _OutIter>::
913 _M_pad(_CharT __fill, streamsize __w, ios_base& __io,
914 _CharT* __new, const _CharT* __cs, int& __len) const
915 {
916 // [22.2.2.2.2] Stage 3.
917 // If necessary, pad.
918 __pad<_CharT, char_traits<_CharT> >::_S_pad(__io, __fill, __new,
919 __cs, __w, __len);
920 __len = static_cast<int>(__w);
921 }
922
923 _GLIBCXX_END_LDBL_NAMESPACE
924
925 template<typename _CharT, typename _ValueT>
926 int
927 __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit,
928 ios_base::fmtflags __flags, bool __dec)
929 {
930 _CharT* __buf = __bufend;
931 if (__builtin_expect(__dec, true))
932 {
933 // Decimal.
934 do
935 {
936 *--__buf = __lit[(__v % 10) + __num_base::_S_odigits];
937 __v /= 10;
938 }
939 while (__v != 0);
940 }
941 else if ((__flags & ios_base::basefield) == ios_base::oct)
942 {
943 // Octal.
944 do
945 {
946 *--__buf = __lit[(__v & 0x7) + __num_base::_S_odigits];
947 __v >>= 3;
948 }
949 while (__v != 0);
950 }
951 else
952 {
953 // Hex.
954 const bool __uppercase = __flags & ios_base::uppercase;
955 const int __case_offset = __uppercase ? __num_base::_S_oudigits
956 : __num_base::_S_odigits;
957 do
958 {
959 *--__buf = __lit[(__v & 0xf) + __case_offset];
960 __v >>= 4;
961 }
962 while (__v != 0);
963 }
964 return __bufend - __buf;
965 }
966
967 _GLIBCXX_BEGIN_LDBL_NAMESPACE
968
969 template<typename _CharT, typename _OutIter>
970 void
971 num_put<_CharT, _OutIter>::
972 _M_group_int(const char* __grouping, size_t __grouping_size, _CharT __sep,
973 ios_base&, _CharT* __new, _CharT* __cs, int& __len) const
974 {
975 _CharT* __p = std::__add_grouping(__new, __sep, __grouping,
976 __grouping_size, __cs, __cs + __len);
977 __len = __p - __new;
978 }
979
980 template<typename _CharT, typename _OutIter>
981 template<typename _ValueT>
982 _OutIter
983 num_put<_CharT, _OutIter>::
984 _M_insert_int(_OutIter __s, ios_base& __io, _CharT __fill,
985 _ValueT __v) const
986 {
987 using __gnu_cxx::__add_unsigned;
988 typedef typename __add_unsigned<_ValueT>::__type __unsigned_type;
989 typedef __numpunct_cache<_CharT> __cache_type;
990 __use_cache<__cache_type> __uc;
991 const locale& __loc = __io._M_getloc();
992 const __cache_type* __lc = __uc(__loc);
993 const _CharT* __lit = __lc->_M_atoms_out;
994 const ios_base::fmtflags __flags = __io.flags();
995
996 // Long enough to hold hex, dec, and octal representations.
997 const int __ilen = 5 * sizeof(_ValueT);
998 _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
999 * __ilen));
1000
1001 // [22.2.2.2.2] Stage 1, numeric conversion to character.
1002 // Result is returned right-justified in the buffer.
1003 const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
1004 const bool __dec = (__basefield != ios_base::oct
1005 && __basefield != ios_base::hex);
1006 const __unsigned_type __u = ((__v > 0 || !__dec)
1007 ? __unsigned_type(__v)
1008 : -__unsigned_type(__v));
1009 int __len = __int_to_char(__cs + __ilen, __u, __lit, __flags, __dec);
1010 __cs += __ilen - __len;
1011
1012 // Add grouping, if necessary.
1013 if (__lc->_M_use_grouping)
1014 {
1015 // Grouping can add (almost) as many separators as the number
1016 // of digits + space is reserved for numeric base or sign.
1017 _CharT* __cs2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1018 * (__len + 1)
1019 * 2));
1020 _M_group_int(__lc->_M_grouping, __lc->_M_grouping_size,
1021 __lc->_M_thousands_sep, __io, __cs2 + 2, __cs, __len);
1022 __cs = __cs2 + 2;
1023 }
1024
1025 // Complete Stage 1, prepend numeric base or sign.
1026 if (__builtin_expect(__dec, true))
1027 {
1028 // Decimal.
1029 if (__v > 0)
1030 {
1031 if (__flags & ios_base::showpos
1032 && numeric_limits<_ValueT>::is_signed)
1033 *--__cs = __lit[__num_base::_S_oplus], ++__len;
1034 }
1035 else if (__v)
1036 *--__cs = __lit[__num_base::_S_ominus], ++__len;
1037 }
1038 else if (__flags & ios_base::showbase && __v)
1039 {
1040 if (__basefield == ios_base::oct)
1041 *--__cs = __lit[__num_base::_S_odigits], ++__len;
1042 else
1043 {
1044 // 'x' or 'X'
1045 const bool __uppercase = __flags & ios_base::uppercase;
1046 *--__cs = __lit[__num_base::_S_ox + __uppercase];
1047 // '0'
1048 *--__cs = __lit[__num_base::_S_odigits];
1049 __len += 2;
1050 }
1051 }
1052
1053 // Pad.
1054 const streamsize __w = __io.width();
1055 if (__w > static_cast<streamsize>(__len))
1056 {
1057 _CharT* __cs3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1058 * __w));
1059 _M_pad(__fill, __w, __io, __cs3, __cs, __len);
1060 __cs = __cs3;
1061 }
1062 __io.width(0);
1063
1064 // [22.2.2.2.2] Stage 4.
1065 // Write resulting, fully-formatted string to output iterator.
1066 return std::__write(__s, __cs, __len);
1067 }
1068
1069 template<typename _CharT, typename _OutIter>
1070 void
1071 num_put<_CharT, _OutIter>::
1072 _M_group_float(const char* __grouping, size_t __grouping_size,
1073 _CharT __sep, const _CharT* __p, _CharT* __new,
1074 _CharT* __cs, int& __len) const
1075 {
1076 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1077 // 282. What types does numpunct grouping refer to?
1078 // Add grouping, if necessary.
1079 const int __declen = __p ? __p - __cs : __len;
1080 _CharT* __p2 = std::__add_grouping(__new, __sep, __grouping,
1081 __grouping_size,
1082 __cs, __cs + __declen);
1083
1084 // Tack on decimal part.
1085 int __newlen = __p2 - __new;
1086 if (__p)
1087 {
1088 char_traits<_CharT>::copy(__p2, __p, __len - __declen);
1089 __newlen += __len - __declen;
1090 }
1091 __len = __newlen;
1092 }
1093
1094 // The following code uses vsnprintf (or vsprintf(), when
1095 // _GLIBCXX_USE_C99 is not defined) to convert floating point values
1096 // for insertion into a stream. An optimization would be to replace
1097 // them with code that works directly on a wide buffer and then use
1098 // __pad to do the padding. It would be good to replace them anyway
1099 // to gain back the efficiency that C++ provides by knowing up front
1100 // the type of the values to insert. Also, sprintf is dangerous
1101 // since may lead to accidental buffer overruns. This
1102 // implementation follows the C++ standard fairly directly as
1103 // outlined in 22.2.2.2 [lib.locale.num.put]
1104 template<typename _CharT, typename _OutIter>
1105 template<typename _ValueT>
1106 _OutIter
1107 num_put<_CharT, _OutIter>::
1108 _M_insert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
1109 _ValueT __v) const
1110 {
1111 typedef __numpunct_cache<_CharT> __cache_type;
1112 __use_cache<__cache_type> __uc;
1113 const locale& __loc = __io._M_getloc();
1114 const __cache_type* __lc = __uc(__loc);
1115
1116 // Use default precision if out of range.
1117 const streamsize __prec = __io.precision() < 0 ? 6 : __io.precision();
1118
1119 const int __max_digits = numeric_limits<_ValueT>::digits10;
1120
1121 // [22.2.2.2.2] Stage 1, numeric conversion to character.
1122 int __len;
1123 // Long enough for the max format spec.
1124 char __fbuf[16];
1125 __num_base::_S_format_float(__io, __fbuf, __mod);
1126
1127 #ifdef _GLIBCXX_USE_C99
1128 // First try a buffer perhaps big enough (most probably sufficient
1129 // for non-ios_base::fixed outputs)
1130 int __cs_size = __max_digits * 3;
1131 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1132 __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
1133 __fbuf, __prec, __v);
1134
1135 // If the buffer was not large enough, try again with the correct size.
1136 if (__len >= __cs_size)
1137 {
1138 __cs_size = __len + 1;
1139 __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1140 __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
1141 __fbuf, __prec, __v);
1142 }
1143 #else
1144 // Consider the possibility of long ios_base::fixed outputs
1145 const bool __fixed = __io.flags() & ios_base::fixed;
1146 const int __max_exp = numeric_limits<_ValueT>::max_exponent10;
1147
1148 // The size of the output string is computed as follows.
1149 // ios_base::fixed outputs may need up to __max_exp + 1 chars
1150 // for the integer part + __prec chars for the fractional part
1151 // + 3 chars for sign, decimal point, '\0'. On the other hand,
1152 // for non-fixed outputs __max_digits * 2 + __prec chars are
1153 // largely sufficient.
1154 const int __cs_size = __fixed ? __max_exp + __prec + 4
1155 : __max_digits * 2 + __prec;
1156 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1157 __len = std::__convert_from_v(_S_get_c_locale(), __cs, 0, __fbuf,
1158 __prec, __v);
1159 #endif
1160
1161 // [22.2.2.2.2] Stage 2, convert to char_type, using correct
1162 // numpunct.decimal_point() values for '.' and adding grouping.
1163 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1164
1165 _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1166 * __len));
1167 __ctype.widen(__cs, __cs + __len, __ws);
1168
1169 // Replace decimal point.
1170 _CharT* __wp = 0;
1171 const char* __p = char_traits<char>::find(__cs, __len, '.');
1172 if (__p)
1173 {
1174 __wp = __ws + (__p - __cs);
1175 *__wp = __lc->_M_decimal_point;
1176 }
1177
1178 // Add grouping, if necessary.
1179 // N.B. Make sure to not group things like 2e20, i.e., no decimal
1180 // point, scientific notation.
1181 if (__lc->_M_use_grouping
1182 && (__wp || __len < 3 || (__cs[1] <= '9' && __cs[2] <= '9'
1183 && __cs[1] >= '0' && __cs[2] >= '0')))
1184 {
1185 // Grouping can add (almost) as many separators as the
1186 // number of digits, but no more.
1187 _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1188 * __len * 2));
1189
1190 streamsize __off = 0;
1191 if (__cs[0] == '-' || __cs[0] == '+')
1192 {
1193 __off = 1;
1194 __ws2[0] = __ws[0];
1195 __len -= 1;
1196 }
1197
1198 _M_group_float(__lc->_M_grouping, __lc->_M_grouping_size,
1199 __lc->_M_thousands_sep, __wp, __ws2 + __off,
1200 __ws + __off, __len);
1201 __len += __off;
1202
1203 __ws = __ws2;
1204 }
1205
1206 // Pad.
1207 const streamsize __w = __io.width();
1208 if (__w > static_cast<streamsize>(__len))
1209 {
1210 _CharT* __ws3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1211 * __w));
1212 _M_pad(__fill, __w, __io, __ws3, __ws, __len);
1213 __ws = __ws3;
1214 }
1215 __io.width(0);
1216
1217 // [22.2.2.2.2] Stage 4.
1218 // Write resulting, fully-formatted string to output iterator.
1219 return std::__write(__s, __ws, __len);
1220 }
1221
1222 template<typename _CharT, typename _OutIter>
1223 _OutIter
1224 num_put<_CharT, _OutIter>::
1225 do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const
1226 {
1227 const ios_base::fmtflags __flags = __io.flags();
1228 if ((__flags & ios_base::boolalpha) == 0)
1229 {
1230 const long __l = __v;
1231 __s = _M_insert_int(__s, __io, __fill, __l);
1232 }
1233 else
1234 {
1235 typedef __numpunct_cache<_CharT> __cache_type;
1236 __use_cache<__cache_type> __uc;
1237 const locale& __loc = __io._M_getloc();
1238 const __cache_type* __lc = __uc(__loc);
1239
1240 const _CharT* __name = __v ? __lc->_M_truename
1241 : __lc->_M_falsename;
1242 int __len = __v ? __lc->_M_truename_size
1243 : __lc->_M_falsename_size;
1244
1245 const streamsize __w = __io.width();
1246 if (__w > static_cast<streamsize>(__len))
1247 {
1248 _CharT* __cs
1249 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1250 * __w));
1251 _M_pad(__fill, __w, __io, __cs, __name, __len);
1252 __name = __cs;
1253 }
1254 __io.width(0);
1255 __s = std::__write(__s, __name, __len);
1256 }
1257 return __s;
1258 }
1259
1260 template<typename _CharT, typename _OutIter>
1261 _OutIter
1262 num_put<_CharT, _OutIter>::
1263 do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
1264 { return _M_insert_int(__s, __io, __fill, __v); }
1265
1266 template<typename _CharT, typename _OutIter>
1267 _OutIter
1268 num_put<_CharT, _OutIter>::
1269 do_put(iter_type __s, ios_base& __io, char_type __fill,
1270 unsigned long __v) const
1271 { return _M_insert_int(__s, __io, __fill, __v); }
1272
1273 #ifdef _GLIBCXX_USE_LONG_LONG
1274 template<typename _CharT, typename _OutIter>
1275 _OutIter
1276 num_put<_CharT, _OutIter>::
1277 do_put(iter_type __s, ios_base& __io, char_type __fill, long long __v) const
1278 { return _M_insert_int(__s, __io, __fill, __v); }
1279
1280 template<typename _CharT, typename _OutIter>
1281 _OutIter
1282 num_put<_CharT, _OutIter>::
1283 do_put(iter_type __s, ios_base& __io, char_type __fill,
1284 unsigned long long __v) const
1285 { return _M_insert_int(__s, __io, __fill, __v); }
1286 #endif
1287
1288 template<typename _CharT, typename _OutIter>
1289 _OutIter
1290 num_put<_CharT, _OutIter>::
1291 do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const
1292 { return _M_insert_float(__s, __io, __fill, char(), __v); }
1293
1294 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1295 template<typename _CharT, typename _OutIter>
1296 _OutIter
1297 num_put<_CharT, _OutIter>::
1298 __do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const
1299 { return _M_insert_float(__s, __io, __fill, char(), __v); }
1300 #endif
1301
1302 template<typename _CharT, typename _OutIter>
1303 _OutIter
1304 num_put<_CharT, _OutIter>::
1305 do_put(iter_type __s, ios_base& __io, char_type __fill,
1306 long double __v) const
1307 { return _M_insert_float(__s, __io, __fill, 'L', __v); }
1308
1309 template<typename _CharT, typename _OutIter>
1310 _OutIter
1311 num_put<_CharT, _OutIter>::
1312 do_put(iter_type __s, ios_base& __io, char_type __fill,
1313 const void* __v) const
1314 {
1315 const ios_base::fmtflags __flags = __io.flags();
1316 const ios_base::fmtflags __fmt = ~(ios_base::basefield
1317 | ios_base::uppercase
1318 | ios_base::internal);
1319 __io.flags((__flags & __fmt) | (ios_base::hex | ios_base::showbase));
1320
1321 typedef __gnu_cxx::__conditional_type<(sizeof(const void*)
1322 <= sizeof(unsigned long)),
1323 unsigned long, unsigned long long>::__type _UIntPtrType;
1324
1325 __s = _M_insert_int(__s, __io, __fill,
1326 reinterpret_cast<_UIntPtrType>(__v));
1327 __io.flags(__flags);
1328 return __s;
1329 }
1330
1331 template<typename _CharT, typename _InIter>
1332 template<bool _Intl>
1333 _InIter
1334 money_get<_CharT, _InIter>::
1335 _M_extract(iter_type __beg, iter_type __end, ios_base& __io,
1336 ios_base::iostate& __err, string& __units) const
1337 {
1338 typedef char_traits<_CharT> __traits_type;
1339 typedef typename string_type::size_type size_type;
1340 typedef money_base::part part;
1341 typedef __moneypunct_cache<_CharT, _Intl> __cache_type;
1342
1343 const locale& __loc = __io._M_getloc();
1344 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1345
1346 __use_cache<__cache_type> __uc;
1347 const __cache_type* __lc = __uc(__loc);
1348 const char_type* __lit = __lc->_M_atoms;
1349
1350 // Deduced sign.
1351 bool __negative = false;
1352 // Sign size.
1353 size_type __sign_size = 0;
1354 // True if sign is mandatory.
1355 const bool __mandatory_sign = (__lc->_M_positive_sign_size
1356 && __lc->_M_negative_sign_size);
1357 // String of grouping info from thousands_sep plucked from __units.
1358 string __grouping_tmp;
1359 if (__lc->_M_use_grouping)
1360 __grouping_tmp.reserve(32);
1361 // Last position before the decimal point.
1362 int __last_pos = 0;
1363 // Separator positions, then, possibly, fractional digits.
1364 int __n = 0;
1365 // If input iterator is in a valid state.
1366 bool __testvalid = true;
1367 // Flag marking when a decimal point is found.
1368 bool __testdecfound = false;
1369
1370 // The tentative returned string is stored here.
1371 string __res;
1372 __res.reserve(32);
1373
1374 const char_type* __lit_zero = __lit + money_base::_S_zero;
1375 const money_base::pattern __p = __lc->_M_neg_format;
1376 for (int __i = 0; __i < 4 && __testvalid; ++__i)
1377 {
1378 const part __which = static_cast<part>(__p.field[__i]);
1379 switch (__which)
1380 {
1381 case money_base::symbol:
1382 // According to 22.2.6.1.2, p2, symbol is required
1383 // if (__io.flags() & ios_base::showbase), otherwise
1384 // is optional and consumed only if other characters
1385 // are needed to complete the format.
1386 if (__io.flags() & ios_base::showbase || __sign_size > 1
1387 || __i == 0
1388 || (__i == 1 && (__mandatory_sign
1389 || (static_cast<part>(__p.field[0])
1390 == money_base::sign)
1391 || (static_cast<part>(__p.field[2])
1392 == money_base::space)))
1393 || (__i == 2 && ((static_cast<part>(__p.field[3])
1394 == money_base::value)
1395 || (__mandatory_sign
1396 && (static_cast<part>(__p.field[3])
1397 == money_base::sign)))))
1398 {
1399 const size_type __len = __lc->_M_curr_symbol_size;
1400 size_type __j = 0;
1401 for (; __beg != __end && __j < __len
1402 && *__beg == __lc->_M_curr_symbol[__j];
1403 ++__beg, ++__j);
1404 if (__j != __len
1405 && (__j || __io.flags() & ios_base::showbase))
1406 __testvalid = false;
1407 }
1408 break;
1409 case money_base::sign:
1410 // Sign might not exist, or be more than one character long.
1411 if (__lc->_M_positive_sign_size && __beg != __end
1412 && *__beg == __lc->_M_positive_sign[0])
1413 {
1414 __sign_size = __lc->_M_positive_sign_size;
1415 ++__beg;
1416 }
1417 else if (__lc->_M_negative_sign_size && __beg != __end
1418 && *__beg == __lc->_M_negative_sign[0])
1419 {
1420 __negative = true;
1421 __sign_size = __lc->_M_negative_sign_size;
1422 ++__beg;
1423 }
1424 else if (__lc->_M_positive_sign_size
1425 && !__lc->_M_negative_sign_size)
1426 // "... if no sign is detected, the result is given the sign
1427 // that corresponds to the source of the empty string"
1428 __negative = true;
1429 else if (__mandatory_sign)
1430 __testvalid = false;
1431 break;
1432 case money_base::value:
1433 // Extract digits, remove and stash away the
1434 // grouping of found thousands separators.
1435 for (; __beg != __end; ++__beg)
1436 {
1437 const char_type __c = *__beg;
1438 const char_type* __q = __traits_type::find(__lit_zero,
1439 10, __c);
1440 if (__q != 0)
1441 {
1442 __res += money_base::_S_atoms[__q - __lit];
1443 ++__n;
1444 }
1445 else if (__c == __lc->_M_decimal_point
1446 && !__testdecfound)
1447 {
1448 __last_pos = __n;
1449 __n = 0;
1450 __testdecfound = true;
1451 }
1452 else if (__lc->_M_use_grouping
1453 && __c == __lc->_M_thousands_sep
1454 && !__testdecfound)
1455 {
1456 if (__n)
1457 {
1458 // Mark position for later analysis.
1459 __grouping_tmp += static_cast<char>(__n);
1460 __n = 0;
1461 }
1462 else
1463 {
1464 __testvalid = false;
1465 break;
1466 }
1467 }
1468 else
1469 break;
1470 }
1471 if (__res.empty())
1472 __testvalid = false;
1473 break;
1474 case money_base::space:
1475 // At least one space is required.
1476 if (__beg != __end && __ctype.is(ctype_base::space, *__beg))
1477 ++__beg;
1478 else
1479 __testvalid = false;
1480 case money_base::none:
1481 // Only if not at the end of the pattern.
1482 if (__i != 3)
1483 for (; __beg != __end
1484 && __ctype.is(ctype_base::space, *__beg); ++__beg);
1485 break;
1486 }
1487 }
1488
1489 // Need to get the rest of the sign characters, if they exist.
1490 if (__sign_size > 1 && __testvalid)
1491 {
1492 const char_type* __sign = __negative ? __lc->_M_negative_sign
1493 : __lc->_M_positive_sign;
1494 size_type __i = 1;
1495 for (; __beg != __end && __i < __sign_size
1496 && *__beg == __sign[__i]; ++__beg, ++__i);
1497
1498 if (__i != __sign_size)
1499 __testvalid = false;
1500 }
1501
1502 if (__testvalid)
1503 {
1504 // Strip leading zeros.
1505 if (__res.size() > 1)
1506 {
1507 const size_type __first = __res.find_first_not_of('0');
1508 const bool __only_zeros = __first == string::npos;
1509 if (__first)
1510 __res.erase(0, __only_zeros ? __res.size() - 1 : __first);
1511 }
1512
1513 // 22.2.6.1.2, p4
1514 if (__negative && __res[0] != '0')
1515 __res.insert(__res.begin(), '-');
1516
1517 // Test for grouping fidelity.
1518 if (__grouping_tmp.size())
1519 {
1520 // Add the ending grouping.
1521 __grouping_tmp += static_cast<char>(__testdecfound ? __last_pos
1522 : __n);
1523 if (!std::__verify_grouping(__lc->_M_grouping,
1524 __lc->_M_grouping_size,
1525 __grouping_tmp))
1526 __err |= ios_base::failbit;
1527 }
1528
1529 // Iff not enough digits were supplied after the decimal-point.
1530 if (__testdecfound && __lc->_M_frac_digits > 0
1531 && __n != __lc->_M_frac_digits)
1532 __testvalid = false;
1533 }
1534
1535 // Iff valid sequence is not recognized.
1536 if (!__testvalid)
1537 __err |= ios_base::failbit;
1538 else
1539 __units.swap(__res);
1540
1541 // Iff no more characters are available.
1542 if (__beg == __end)
1543 __err |= ios_base::eofbit;
1544 return __beg;
1545 }
1546
1547 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1548 template<typename _CharT, typename _InIter>
1549 _InIter
1550 money_get<_CharT, _InIter>::
1551 __do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
1552 ios_base::iostate& __err, double& __units) const
1553 {
1554 string __str;
1555 __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str)
1556 : _M_extract<false>(__beg, __end, __io, __err, __str);
1557 std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale());
1558 return __beg;
1559 }
1560 #endif
1561
1562 template<typename _CharT, typename _InIter>
1563 _InIter
1564 money_get<_CharT, _InIter>::
1565 do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
1566 ios_base::iostate& __err, long double& __units) const
1567 {
1568 string __str;
1569 __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str)
1570 : _M_extract<false>(__beg, __end, __io, __err, __str);
1571 std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale());
1572 return __beg;
1573 }
1574
1575 template<typename _CharT, typename _InIter>
1576 _InIter
1577 money_get<_CharT, _InIter>::
1578 do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
1579 ios_base::iostate& __err, string_type& __digits) const
1580 {
1581 typedef typename string::size_type size_type;
1582
1583 const locale& __loc = __io._M_getloc();
1584 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1585
1586 string __str;
1587 __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str)
1588 : _M_extract<false>(__beg, __end, __io, __err, __str);
1589 const size_type __len = __str.size();
1590 if (__len)
1591 {
1592 __digits.resize(__len);
1593 __ctype.widen(__str.data(), __str.data() + __len, &__digits[0]);
1594 }
1595 return __beg;
1596 }
1597
1598 template<typename _CharT, typename _OutIter>
1599 template<bool _Intl>
1600 _OutIter
1601 money_put<_CharT, _OutIter>::
1602 _M_insert(iter_type __s, ios_base& __io, char_type __fill,
1603 const string_type& __digits) const
1604 {
1605 typedef typename string_type::size_type size_type;
1606 typedef money_base::part part;
1607 typedef __moneypunct_cache<_CharT, _Intl> __cache_type;
1608
1609 const locale& __loc = __io._M_getloc();
1610 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1611
1612 __use_cache<__cache_type> __uc;
1613 const __cache_type* __lc = __uc(__loc);
1614 const char_type* __lit = __lc->_M_atoms;
1615
1616 // Determine if negative or positive formats are to be used, and
1617 // discard leading negative_sign if it is present.
1618 const char_type* __beg = __digits.data();
1619
1620 money_base::pattern __p;
1621 const char_type* __sign;
1622 size_type __sign_size;
1623 if (!(*__beg == __lit[money_base::_S_minus]))
1624 {
1625 __p = __lc->_M_pos_format;
1626 __sign = __lc->_M_positive_sign;
1627 __sign_size = __lc->_M_positive_sign_size;
1628 }
1629 else
1630 {
1631 __p = __lc->_M_neg_format;
1632 __sign = __lc->_M_negative_sign;
1633 __sign_size = __lc->_M_negative_sign_size;
1634 if (__digits.size())
1635 ++__beg;
1636 }
1637
1638 // Look for valid numbers in the ctype facet within input digits.
1639 size_type __len = __ctype.scan_not(ctype_base::digit, __beg,
1640 __beg + __digits.size()) - __beg;
1641 if (__len)
1642 {
1643 // Assume valid input, and attempt to format.
1644 // Break down input numbers into base components, as follows:
1645 // final_value = grouped units + (decimal point) + (digits)
1646 string_type __value;
1647 __value.reserve(2 * __len);
1648
1649 // Add thousands separators to non-decimal digits, per
1650 // grouping rules.
1651 long __paddec = __len - __lc->_M_frac_digits;
1652 if (__paddec > 0)
1653 {
1654 if (__lc->_M_frac_digits < 0)
1655 __paddec = __len;
1656 if (__lc->_M_grouping_size)
1657 {
1658 __value.assign(2 * __paddec, char_type());
1659 _CharT* __vend =
1660 std::__add_grouping(&__value[0], __lc->_M_thousands_sep,
1661 __lc->_M_grouping,
1662 __lc->_M_grouping_size,
1663 __beg, __beg + __paddec);
1664 __value.erase(__vend - &__value[0]);
1665 }
1666 else
1667 __value.assign(__beg, __paddec);
1668 }
1669
1670 // Deal with decimal point, decimal digits.
1671 if (__lc->_M_frac_digits > 0)
1672 {
1673 __value += __lc->_M_decimal_point;
1674 if (__paddec >= 0)
1675 __value.append(__beg + __paddec, __lc->_M_frac_digits);
1676 else
1677 {
1678 // Have to pad zeros in the decimal position.
1679 __value.append(-__paddec, __lit[money_base::_S_zero]);
1680 __value.append(__beg, __len);
1681 }
1682 }
1683
1684 // Calculate length of resulting string.
1685 const ios_base::fmtflags __f = __io.flags()
1686 & ios_base::adjustfield;
1687 __len = __value.size() + __sign_size;
1688 __len += ((__io.flags() & ios_base::showbase)
1689 ? __lc->_M_curr_symbol_size : 0);
1690
1691 string_type __res;
1692 __res.reserve(2 * __len);
1693
1694 const size_type __width = static_cast<size_type>(__io.width());
1695 const bool __testipad = (__f == ios_base::internal
1696 && __len < __width);
1697 // Fit formatted digits into the required pattern.
1698 for (int __i = 0; __i < 4; ++__i)
1699 {
1700 const part __which = static_cast<part>(__p.field[__i]);
1701 switch (__which)
1702 {
1703 case money_base::symbol:
1704 if (__io.flags() & ios_base::showbase)
1705 __res.append(__lc->_M_curr_symbol,
1706 __lc->_M_curr_symbol_size);
1707 break;
1708 case money_base::sign:
1709 // Sign might not exist, or be more than one
1710 // charater long. In that case, add in the rest
1711 // below.
1712 if (__sign_size)
1713 __res += __sign[0];
1714 break;
1715 case money_base::value:
1716 __res += __value;
1717 break;
1718 case money_base::space:
1719 // At least one space is required, but if internal
1720 // formatting is required, an arbitrary number of
1721 // fill spaces will be necessary.
1722 if (__testipad)
1723 __res.append(__width - __len, __fill);
1724 else
1725 __res += __fill;
1726 break;
1727 case money_base::none:
1728 if (__testipad)
1729 __res.append(__width - __len, __fill);
1730 break;
1731 }
1732 }
1733
1734 // Special case of multi-part sign parts.
1735 if (__sign_size > 1)
1736 __res.append(__sign + 1, __sign_size - 1);
1737
1738 // Pad, if still necessary.
1739 __len = __res.size();
1740 if (__width > __len)
1741 {
1742 if (__f == ios_base::left)
1743 // After.
1744 __res.append(__width - __len, __fill);
1745 else
1746 // Before.
1747 __res.insert(0, __width - __len, __fill);
1748 __len = __width;
1749 }
1750
1751 // Write resulting, fully-formatted string to output iterator.
1752 __s = std::__write(__s, __res.data(), __len);
1753 }
1754 __io.width(0);
1755 return __s;
1756 }
1757
1758 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1759 template<typename _CharT, typename _OutIter>
1760 _OutIter
1761 money_put<_CharT, _OutIter>::
1762 __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1763 double __units) const
1764 { return this->do_put(__s, __intl, __io, __fill, (long double) __units); }
1765 #endif
1766
1767 template<typename _CharT, typename _OutIter>
1768 _OutIter
1769 money_put<_CharT, _OutIter>::
1770 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1771 long double __units) const
1772 {
1773 const locale __loc = __io.getloc();
1774 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1775 #ifdef _GLIBCXX_USE_C99
1776 // First try a buffer perhaps big enough.
1777 int __cs_size = 64;
1778 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1779 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1780 // 328. Bad sprintf format modifier in money_put<>::do_put()
1781 int __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
1782 "%.*Lf", 0, __units);
1783 // If the buffer was not large enough, try again with the correct size.
1784 if (__len >= __cs_size)
1785 {
1786 __cs_size = __len + 1;
1787 __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1788 __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
1789 "%.*Lf", 0, __units);
1790 }
1791 #else
1792 // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'.
1793 const int __cs_size = numeric_limits<long double>::max_exponent10 + 3;
1794 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1795 int __len = std::__convert_from_v(_S_get_c_locale(), __cs, 0, "%.*Lf",
1796 0, __units);
1797 #endif
1798 string_type __digits(__len, char_type());
1799 __ctype.widen(__cs, __cs + __len, &__digits[0]);
1800 return __intl ? _M_insert<true>(__s, __io, __fill, __digits)
1801 : _M_insert<false>(__s, __io, __fill, __digits);
1802 }
1803
1804 template<typename _CharT, typename _OutIter>
1805 _OutIter
1806 money_put<_CharT, _OutIter>::
1807 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1808 const string_type& __digits) const
1809 { return __intl ? _M_insert<true>(__s, __io, __fill, __digits)
1810 : _M_insert<false>(__s, __io, __fill, __digits); }
1811
1812 _GLIBCXX_END_LDBL_NAMESPACE
1813
1814 // NB: Not especially useful. Without an ios_base object or some
1815 // kind of locale reference, we are left clawing at the air where
1816 // the side of the mountain used to be...
1817 template<typename _CharT, typename _InIter>
1818 time_base::dateorder
1819 time_get<_CharT, _InIter>::do_date_order() const
1820 { return time_base::no_order; }
1821
1822 // Expand a strftime format string and parse it. E.g., do_get_date() may
1823 // pass %m/%d/%Y => extracted characters.
1824 template<typename _CharT, typename _InIter>
1825 _InIter
1826 time_get<_CharT, _InIter>::
1827 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
1828 ios_base::iostate& __err, tm* __tm,
1829 const _CharT* __format) const
1830 {
1831 const locale& __loc = __io._M_getloc();
1832 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
1833 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1834 const size_t __len = char_traits<_CharT>::length(__format);
1835
1836 ios_base::iostate __tmperr = ios_base::goodbit;
1837 for (size_t __i = 0; __beg != __end && __i < __len && !__tmperr; ++__i)
1838 {
1839 if (__ctype.narrow(__format[__i], 0) == '%')
1840 {
1841 // Verify valid formatting code, attempt to extract.
1842 char __c = __ctype.narrow(__format[++__i], 0);
1843 int __mem = 0;
1844 if (__c == 'E' || __c == 'O')
1845 __c = __ctype.narrow(__format[++__i], 0);
1846 switch (__c)
1847 {
1848 const char* __cs;
1849 _CharT __wcs[10];
1850 case 'a':
1851 // Abbreviated weekday name [tm_wday]
1852 const char_type* __days1[7];
1853 __tp._M_days_abbreviated(__days1);
1854 __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days1,
1855 7, __io, __tmperr);
1856 break;
1857 case 'A':
1858 // Weekday name [tm_wday].
1859 const char_type* __days2[7];
1860 __tp._M_days(__days2);
1861 __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days2,
1862 7, __io, __tmperr);
1863 break;
1864 case 'h':
1865 case 'b':
1866 // Abbreviated month name [tm_mon]
1867 const char_type* __months1[12];
1868 __tp._M_months_abbreviated(__months1);
1869 __beg = _M_extract_name(__beg, __end, __tm->tm_mon,
1870 __months1, 12, __io, __tmperr);
1871 break;
1872 case 'B':
1873 // Month name [tm_mon].
1874 const char_type* __months2[12];
1875 __tp._M_months(__months2);
1876 __beg = _M_extract_name(__beg, __end, __tm->tm_mon,
1877 __months2, 12, __io, __tmperr);
1878 break;
1879 case 'c':
1880 // Default time and date representation.
1881 const char_type* __dt[2];
1882 __tp._M_date_time_formats(__dt);
1883 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1884 __tm, __dt[0]);
1885 break;
1886 case 'd':
1887 // Day [01, 31]. [tm_mday]
1888 __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2,
1889 __io, __tmperr);
1890 break;
1891 case 'e':
1892 // Day [1, 31], with single digits preceded by
1893 // space. [tm_mday]
1894 if (__ctype.is(ctype_base::space, *__beg))
1895 __beg = _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9,
1896 1, __io, __tmperr);
1897 else
1898 __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31,
1899 2, __io, __tmperr);
1900 break;
1901 case 'D':
1902 // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year]
1903 __cs = "%m/%d/%y";
1904 __ctype.widen(__cs, __cs + 9, __wcs);
1905 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1906 __tm, __wcs);
1907 break;
1908 case 'H':
1909 // Hour [00, 23]. [tm_hour]
1910 __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2,
1911 __io, __tmperr);
1912 break;
1913 case 'I':
1914 // Hour [01, 12]. [tm_hour]
1915 __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2,
1916 __io, __tmperr);
1917 break;
1918 case 'm':
1919 // Month [01, 12]. [tm_mon]
1920 __beg = _M_extract_num(__beg, __end, __mem, 1, 12, 2,
1921 __io, __tmperr);
1922 if (!__tmperr)
1923 __tm->tm_mon = __mem - 1;
1924 break;
1925 case 'M':
1926 // Minute [00, 59]. [tm_min]
1927 __beg = _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2,
1928 __io, __tmperr);
1929 break;
1930 case 'n':
1931 if (__ctype.narrow(*__beg, 0) == '\n')
1932 ++__beg;
1933 else
1934 __tmperr |= ios_base::failbit;
1935 break;
1936 case 'R':
1937 // Equivalent to (%H:%M).
1938 __cs = "%H:%M";
1939 __ctype.widen(__cs, __cs + 6, __wcs);
1940 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1941 __tm, __wcs);
1942 break;
1943 case 'S':
1944 // Seconds. [tm_sec]
1945 // [00, 60] in C99 (one leap-second), [00, 61] in C89.
1946 #ifdef _GLIBCXX_USE_C99
1947 __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 60, 2,
1948 #else
1949 __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 61, 2,
1950 #endif
1951 __io, __tmperr);
1952 break;
1953 case 't':
1954 if (__ctype.narrow(*__beg, 0) == '\t')
1955 ++__beg;
1956 else
1957 __tmperr |= ios_base::failbit;
1958 break;
1959 case 'T':
1960 // Equivalent to (%H:%M:%S).
1961 __cs = "%H:%M:%S";
1962 __ctype.widen(__cs, __cs + 9, __wcs);
1963 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1964 __tm, __wcs);
1965 break;
1966 case 'x':
1967 // Locale's date.
1968 const char_type* __dates[2];
1969 __tp._M_date_formats(__dates);
1970 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1971 __tm, __dates[0]);
1972 break;
1973 case 'X':
1974 // Locale's time.
1975 const char_type* __times[2];
1976 __tp._M_time_formats(__times);
1977 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1978 __tm, __times[0]);
1979 break;
1980 case 'y':
1981 case 'C': // C99
1982 // Two digit year. [tm_year]
1983 __beg = _M_extract_num(__beg, __end, __tm->tm_year, 0, 99, 2,
1984 __io, __tmperr);
1985 break;
1986 case 'Y':
1987 // Year [1900). [tm_year]
1988 __beg = _M_extract_num(__beg, __end, __mem, 0, 9999, 4,
1989 __io, __tmperr);
1990 if (!__tmperr)
1991 __tm->tm_year = __mem - 1900;
1992 break;
1993 case 'Z':
1994 // Timezone info.
1995 if (__ctype.is(ctype_base::upper, *__beg))
1996 {
1997 int __tmp;
1998 __beg = _M_extract_name(__beg, __end, __tmp,
1999 __timepunct_cache<_CharT>::_S_timezones,
2000 14, __io, __tmperr);
2001
2002 // GMT requires special effort.
2003 if (__beg != __end && !__tmperr && __tmp == 0
2004 && (*__beg == __ctype.widen('-')
2005 || *__beg == __ctype.widen('+')))
2006 {
2007 __beg = _M_extract_num(__beg, __end, __tmp, 0, 23, 2,
2008 __io, __tmperr);
2009 __beg = _M_extract_num(__beg, __end, __tmp, 0, 59, 2,
2010 __io, __tmperr);
2011 }
2012 }
2013 else
2014 __tmperr |= ios_base::failbit;
2015 break;
2016 default:
2017 // Not recognized.
2018 __tmperr |= ios_base::failbit;
2019 }
2020 }
2021 else
2022 {
2023 // Verify format and input match, extract and discard.
2024 if (__format[__i] == *__beg)
2025 ++__beg;
2026 else
2027 __tmperr |= ios_base::failbit;
2028 }
2029 }
2030
2031 if (__tmperr)
2032 __err |= ios_base::failbit;
2033
2034 return __beg;
2035 }
2036
2037 template<typename _CharT, typename _InIter>
2038 _InIter
2039 time_get<_CharT, _InIter>::
2040 _M_extract_num(iter_type __beg, iter_type __end, int& __member,
2041 int __min, int __max, size_t __len,
2042 ios_base& __io, ios_base::iostate& __err) const
2043 {
2044 const locale& __loc = __io._M_getloc();
2045 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2046
2047 // As-is works for __len = 1, 2, 4, the values actually used.
2048 int __mult = __len == 2 ? 10 : (__len == 4 ? 1000 : 1);
2049
2050 ++__min;
2051 size_t __i = 0;
2052 int __value = 0;
2053 for (; __beg != __end && __i < __len; ++__beg, ++__i)
2054 {
2055 const char __c = __ctype.narrow(*__beg, '*');
2056 if (__c >= '0' && __c <= '9')
2057 {
2058 __value = __value * 10 + (__c - '0');
2059 const int __valuec = __value * __mult;
2060 if (__valuec > __max || __valuec + __mult < __min)
2061 break;
2062 __mult /= 10;
2063 }
2064 else
2065 break;
2066 }
2067 if (__i == __len)
2068 __member = __value;
2069 else
2070 __err |= ios_base::failbit;
2071
2072 return __beg;
2073 }
2074
2075 // Assumptions:
2076 // All elements in __names are unique.
2077 template<typename _CharT, typename _InIter>
2078 _InIter
2079 time_get<_CharT, _InIter>::
2080 _M_extract_name(iter_type __beg, iter_type __end, int& __member,
2081 const _CharT** __names, size_t __indexlen,
2082 ios_base& __io, ios_base::iostate& __err) const
2083 {
2084 typedef char_traits<_CharT> __traits_type;
2085 const locale& __loc = __io._M_getloc();
2086 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2087
2088 int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int)
2089 * __indexlen));
2090 size_t __nmatches = 0;
2091 size_t __pos = 0;
2092 bool __testvalid = true;
2093 const char_type* __name;
2094
2095 // Look for initial matches.
2096 // NB: Some of the locale data is in the form of all lowercase
2097 // names, and some is in the form of initially-capitalized
2098 // names. Look for both.
2099 if (__beg != __end)
2100 {
2101 const char_type __c = *__beg;
2102 for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
2103 if (__c == __names[__i1][0]
2104 || __c == __ctype.toupper(__names[__i1][0]))
2105 __matches[__nmatches++] = __i1;
2106 }
2107
2108 while (__nmatches > 1)
2109 {
2110 // Find smallest matching string.
2111 size_t __minlen = __traits_type::length(__names[__matches[0]]);
2112 for (size_t __i2 = 1; __i2 < __nmatches; ++__i2)
2113 __minlen = std::min(__minlen,
2114 __traits_type::length(__names[__matches[__i2]]));
2115 ++__beg, ++__pos;
2116 if (__pos < __minlen && __beg != __end)
2117 for (size_t __i3 = 0; __i3 < __nmatches;)
2118 {
2119 __name = __names[__matches[__i3]];
2120 if (!(__name[__pos] == *__beg))
2121 __matches[__i3] = __matches[--__nmatches];
2122 else
2123 ++__i3;
2124 }
2125 else
2126 break;
2127 }
2128
2129 if (__nmatches == 1)
2130 {
2131 // Make sure found name is completely extracted.
2132 ++__beg, ++__pos;
2133 __name = __names[__matches[0]];
2134 const size_t __len = __traits_type::length(__name);
2135 while (__pos < __len && __beg != __end && __name[__pos] == *__beg)
2136 ++__beg, ++__pos;
2137
2138 if (__len == __pos)
2139 __member = __matches[0];
2140 else
2141 __testvalid = false;
2142 }
2143 else
2144 __testvalid = false;
2145 if (!__testvalid)
2146 __err |= ios_base::failbit;
2147
2148 return __beg;
2149 }
2150
2151 template<typename _CharT, typename _InIter>
2152 _InIter
2153 time_get<_CharT, _InIter>::
2154 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
2155 ios_base::iostate& __err, tm* __tm) const
2156 {
2157 const locale& __loc = __io._M_getloc();
2158 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2159 const char_type* __times[2];
2160 __tp._M_time_formats(__times);
2161 __beg = _M_extract_via_format(__beg, __end, __io, __err,
2162 __tm, __times[0]);
2163 if (__beg == __end)
2164 __err |= ios_base::eofbit;
2165 return __beg;
2166 }
2167
2168 template<typename _CharT, typename _InIter>
2169 _InIter
2170 time_get<_CharT, _InIter>::
2171 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
2172 ios_base::iostate& __err, tm* __tm) const
2173 {
2174 const locale& __loc = __io._M_getloc();
2175 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2176 const char_type* __dates[2];
2177 __tp._M_date_formats(__dates);
2178 __beg = _M_extract_via_format(__beg, __end, __io, __err,
2179 __tm, __dates[0]);
2180 if (__beg == __end)
2181 __err |= ios_base::eofbit;
2182 return __beg;
2183 }
2184
2185 template<typename _CharT, typename _InIter>
2186 _InIter
2187 time_get<_CharT, _InIter>::
2188 do_get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
2189 ios_base::iostate& __err, tm* __tm) const
2190 {
2191 typedef char_traits<_CharT> __traits_type;
2192 const locale& __loc = __io._M_getloc();
2193 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2194 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2195 const char_type* __days[7];
2196 __tp._M_days_abbreviated(__days);
2197 int __tmpwday;
2198 ios_base::iostate __tmperr = ios_base::goodbit;
2199 __beg = _M_extract_name(__beg, __end, __tmpwday, __days, 7,
2200 __io, __tmperr);
2201
2202 // Check to see if non-abbreviated name exists, and extract.
2203 // NB: Assumes both _M_days and _M_days_abbreviated organized in
2204 // exact same order, first to last, such that the resulting
2205 // __days array with the same index points to a day, and that
2206 // day's abbreviated form.
2207 // NB: Also assumes that an abbreviated name is a subset of the name.
2208 if (!__tmperr && __beg != __end)
2209 {
2210 size_t __pos = __traits_type::length(__days[__tmpwday]);
2211 __tp._M_days(__days);
2212 const char_type* __name = __days[__tmpwday];
2213 if (__name[__pos] == *__beg)
2214 {
2215 // Extract the rest of it.
2216 const size_t __len = __traits_type::length(__name);
2217 while (__pos < __len && __beg != __end
2218 && __name[__pos] == *__beg)
2219 ++__beg, ++__pos;
2220 if (__len != __pos)
2221 __tmperr |= ios_base::failbit;
2222 }
2223 }
2224 if (!__tmperr)
2225 __tm->tm_wday = __tmpwday;
2226 else
2227 __err |= ios_base::failbit;
2228
2229 if (__beg == __end)
2230 __err |= ios_base::eofbit;
2231 return __beg;
2232 }
2233
2234 template<typename _CharT, typename _InIter>
2235 _InIter
2236 time_get<_CharT, _InIter>::
2237 do_get_monthname(iter_type __beg, iter_type __end,
2238 ios_base& __io, ios_base::iostate& __err, tm* __tm) const
2239 {
2240 typedef char_traits<_CharT> __traits_type;
2241 const locale& __loc = __io._M_getloc();
2242 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2243 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2244 const char_type* __months[12];
2245 __tp._M_months_abbreviated(__months);
2246 int __tmpmon;
2247 ios_base::iostate __tmperr = ios_base::goodbit;
2248 __beg = _M_extract_name(__beg, __end, __tmpmon, __months, 12,
2249 __io, __tmperr);
2250
2251 // Check to see if non-abbreviated name exists, and extract.
2252 // NB: Assumes both _M_months and _M_months_abbreviated organized in
2253 // exact same order, first to last, such that the resulting
2254 // __months array with the same index points to a month, and that
2255 // month's abbreviated form.
2256 // NB: Also assumes that an abbreviated name is a subset of the name.
2257 if (!__tmperr && __beg != __end)
2258 {
2259 size_t __pos = __traits_type::length(__months[__tmpmon]);
2260 __tp._M_months(__months);
2261 const char_type* __name = __months[__tmpmon];
2262 if (__name[__pos] == *__beg)
2263 {
2264 // Extract the rest of it.
2265 const size_t __len = __traits_type::length(__name);
2266 while (__pos < __len && __beg != __end
2267 && __name[__pos] == *__beg)
2268 ++__beg, ++__pos;
2269 if (__len != __pos)
2270 __tmperr |= ios_base::failbit;
2271 }
2272 }
2273 if (!__tmperr)
2274 __tm->tm_mon = __tmpmon;
2275 else
2276 __err |= ios_base::failbit;
2277
2278 if (__beg == __end)
2279 __err |= ios_base::eofbit;
2280 return __beg;
2281 }
2282
2283 template<typename _CharT, typename _InIter>
2284 _InIter
2285 time_get<_CharT, _InIter>::
2286 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
2287 ios_base::iostate& __err, tm* __tm) const
2288 {
2289 const locale& __loc = __io._M_getloc();
2290 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2291
2292 size_t __i = 0;
2293 int __value = 0;
2294 for (; __beg != __end && __i < 4; ++__beg, ++__i)
2295 {
2296 const char __c = __ctype.narrow(*__beg, '*');
2297 if (__c >= '0' && __c <= '9')
2298 __value = __value * 10 + (__c - '0');
2299 else
2300 break;
2301 }
2302 if (__i == 2 || __i == 4)
2303 __tm->tm_year = __i == 2 ? __value : __value - 1900;
2304 else
2305 __err |= ios_base::failbit;
2306
2307 if (__beg == __end)
2308 __err |= ios_base::eofbit;
2309 return __beg;
2310 }
2311
2312 template<typename _CharT, typename _OutIter>
2313 _OutIter
2314 time_put<_CharT, _OutIter>::
2315 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
2316 const _CharT* __beg, const _CharT* __end) const
2317 {
2318 const locale& __loc = __io._M_getloc();
2319 ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
2320 for (; __beg != __end; ++__beg)
2321 if (__ctype.narrow(*__beg, 0) != '%')
2322 {
2323 *__s = *__beg;
2324 ++__s;
2325 }
2326 else if (++__beg != __end)
2327 {
2328 char __format;
2329 char __mod = 0;
2330 const char __c = __ctype.narrow(*__beg, 0);
2331 if (__c != 'E' && __c != 'O')
2332 __format = __c;
2333 else if (++__beg != __end)
2334 {
2335 __mod = __c;
2336 __format = __ctype.narrow(*__beg, 0);
2337 }
2338 else
2339 break;
2340 __s = this->do_put(__s, __io, __fill, __tm, __format, __mod);
2341 }
2342 else
2343 break;
2344 return __s;
2345 }
2346
2347 template<typename _CharT, typename _OutIter>
2348 _OutIter
2349 time_put<_CharT, _OutIter>::
2350 do_put(iter_type __s, ios_base& __io, char_type, const tm* __tm,
2351 char __format, char __mod) const
2352 {
2353 const locale& __loc = __io._M_getloc();
2354 ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
2355 __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
2356
2357 // NB: This size is arbitrary. Should this be a data member,
2358 // initialized at construction?
2359 const size_t __maxlen = 128;
2360 char_type* __res =
2361 static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen));
2362
2363 // NB: In IEE 1003.1-200x, and perhaps other locale models, it
2364 // is possible that the format character will be longer than one
2365 // character. Possibilities include 'E' or 'O' followed by a
2366 // format character: if __mod is not the default argument, assume
2367 // it's a valid modifier.
2368 char_type __fmt[4];
2369 __fmt[0] = __ctype.widen('%');
2370 if (!__mod)
2371 {
2372 __fmt[1] = __format;
2373 __fmt[2] = char_type();
2374 }
2375 else
2376 {
2377 __fmt[1] = __mod;
2378 __fmt[2] = __format;
2379 __fmt[3] = char_type();
2380 }
2381
2382 __tp._M_put(__res, __maxlen, __fmt, __tm);
2383
2384 // Write resulting, fully-formatted string to output iterator.
2385 return std::__write(__s, __res, char_traits<char_type>::length(__res));
2386 }
2387
2388 // Generic version does nothing.
2389 template<typename _CharT>
2390 int
2391 collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const
2392 { return 0; }
2393
2394 // Generic version does nothing.
2395 template<typename _CharT>
2396 size_t
2397 collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const
2398 { return 0; }
2399
2400 template<typename _CharT>
2401 int
2402 collate<_CharT>::
2403 do_compare(const _CharT* __lo1, const _CharT* __hi1,
2404 const _CharT* __lo2, const _CharT* __hi2) const
2405 {
2406 // strcoll assumes zero-terminated strings so we make a copy
2407 // and then put a zero at the end.
2408 const string_type __one(__lo1, __hi1);
2409 const string_type __two(__lo2, __hi2);
2410
2411 const _CharT* __p = __one.c_str();
2412 const _CharT* __pend = __one.data() + __one.length();
2413 const _CharT* __q = __two.c_str();
2414 const _CharT* __qend = __two.data() + __two.length();
2415
2416 // strcoll stops when it sees a nul character so we break
2417 // the strings into zero-terminated substrings and pass those
2418 // to strcoll.
2419 for (;;)
2420 {
2421 const int __res = _M_compare(__p, __q);
2422 if (__res)
2423 return __res;
2424
2425 __p += char_traits<_CharT>::length(__p);
2426 __q += char_traits<_CharT>::length(__q);
2427 if (__p == __pend && __q == __qend)
2428 return 0;
2429 else if (__p == __pend)
2430 return -1;
2431 else if (__q == __qend)
2432 return 1;
2433
2434 __p++;
2435 __q++;
2436 }
2437 }
2438
2439 template<typename _CharT>
2440 typename collate<_CharT>::string_type
2441 collate<_CharT>::
2442 do_transform(const _CharT* __lo, const _CharT* __hi) const
2443 {
2444 string_type __ret;
2445
2446 // strxfrm assumes zero-terminated strings so we make a copy
2447 const string_type __str(__lo, __hi);
2448
2449 const _CharT* __p = __str.c_str();
2450 const _CharT* __pend = __str.data() + __str.length();
2451
2452 size_t __len = (__hi - __lo) * 2;
2453
2454 _CharT* __c = new _CharT[__len];
2455
2456 try
2457 {
2458 // strxfrm stops when it sees a nul character so we break
2459 // the string into zero-terminated substrings and pass those
2460 // to strxfrm.
2461 for (;;)
2462 {
2463 // First try a buffer perhaps big enough.
2464 size_t __res = _M_transform(__c, __p, __len);
2465 // If the buffer was not large enough, try again with the
2466 // correct size.
2467 if (__res >= __len)
2468 {
2469 __len = __res + 1;
2470 delete [] __c, __c = 0;
2471 __c = new _CharT[__len];
2472 __res = _M_transform(__c, __p, __len);
2473 }
2474
2475 __ret.append(__c, __res);
2476 __p += char_traits<_CharT>::length(__p);
2477 if (__p == __pend)
2478 break;
2479
2480 __p++;
2481 __ret.push_back(_CharT());
2482 }
2483 }
2484 catch(...)
2485 {
2486 delete [] __c;
2487 __throw_exception_again;
2488 }
2489
2490 delete [] __c;
2491
2492 return __ret;
2493 }
2494
2495 template<typename _CharT>
2496 long
2497 collate<_CharT>::
2498 do_hash(const _CharT* __lo, const _CharT* __hi) const
2499 {
2500 unsigned long __val = 0;
2501 for (; __lo < __hi; ++__lo)
2502 __val = *__lo + ((__val << 7) |
2503 (__val >> (numeric_limits<unsigned long>::digits - 7)));
2504 return static_cast<long>(__val);
2505 }
2506
2507 // Construct correctly padded string, as per 22.2.2.2.2
2508 // Assumes
2509 // __newlen > __oldlen
2510 // __news is allocated for __newlen size
2511
2512 // NB: Of the two parameters, _CharT can be deduced from the
2513 // function arguments. The other (_Traits) has to be explicitly specified.
2514 template<typename _CharT, typename _Traits>
2515 void
2516 __pad<_CharT, _Traits>::_S_pad(ios_base& __io, _CharT __fill,
2517 _CharT* __news, const _CharT* __olds,
2518 const streamsize __newlen,
2519 const streamsize __oldlen)
2520 {
2521 const size_t __plen = static_cast<size_t>(__newlen - __oldlen);
2522 const ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield;
2523
2524 // Padding last.
2525 if (__adjust == ios_base::left)
2526 {
2527 _Traits::copy(__news, const_cast<_CharT*>(__olds), __oldlen);
2528 _Traits::assign(__news + __oldlen, __plen, __fill);
2529 return;
2530 }
2531
2532 size_t __mod = 0;
2533 if (__adjust == ios_base::internal)
2534 {
2535 // Pad after the sign, if there is one.
2536 // Pad after 0[xX], if there is one.
2537 // Who came up with these rules, anyway? Jeeze.
2538 const locale& __loc = __io._M_getloc();
2539 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2540
2541 const bool __testsign = (__ctype.widen('-') == __olds[0]
2542 || __ctype.widen('+') == __olds[0]);
2543 const bool __testhex = (__ctype.widen('0') == __olds[0]
2544 && __oldlen > 1
2545 && (__ctype.widen('x') == __olds[1]
2546 || __ctype.widen('X') == __olds[1]));
2547 if (__testhex)
2548 {
2549 __news[0] = __olds[0];
2550 __news[1] = __olds[1];
2551 __mod = 2;
2552 __news += 2;
2553 }
2554 else if (__testsign)
2555 {
2556 __news[0] = __olds[0];
2557 __mod = 1;
2558 ++__news;
2559 }
2560 // else Padding first.
2561 }
2562 _Traits::assign(__news, __plen, __fill);
2563 _Traits::copy(__news + __plen, const_cast<_CharT*>(__olds + __mod),
2564 __oldlen - __mod);
2565 }
2566
2567 bool
2568 __verify_grouping(const char* __grouping, size_t __grouping_size,
2569 const string& __grouping_tmp)
2570 {
2571 const size_t __n = __grouping_tmp.size() - 1;
2572 const size_t __min = std::min(__n, size_t(__grouping_size - 1));
2573 size_t __i = __n;
2574 bool __test = true;
2575
2576 // Parsed number groupings have to match the
2577 // numpunct::grouping string exactly, starting at the
2578 // right-most point of the parsed sequence of elements ...
2579 for (size_t __j = 0; __j < __min && __test; --__i, ++__j)
2580 __test = __grouping_tmp[__i] == __grouping[__j];
2581 for (; __i && __test; --__i)
2582 __test = __grouping_tmp[__i] == __grouping[__min];
2583 // ... but the first parsed grouping can be <= numpunct
2584 // grouping (only do the check if the numpunct char is > 0
2585 // because <= 0 means any size is ok).
2586 if (static_cast<signed char>(__grouping[__min]) > 0)
2587 __test &= __grouping_tmp[0] <= __grouping[__min];
2588 return __test;
2589 }
2590
2591 template<typename _CharT>
2592 _CharT*
2593 __add_grouping(_CharT* __s, _CharT __sep,
2594 const char* __gbeg, size_t __gsize,
2595 const _CharT* __first, const _CharT* __last)
2596 {
2597 size_t __idx = 0;
2598 size_t __ctr = 0;
2599
2600 while (__last - __first > __gbeg[__idx]
2601 && static_cast<signed char>(__gbeg[__idx]) > 0)
2602 {
2603 __last -= __gbeg[__idx];
2604 __idx < __gsize - 1 ? ++__idx : ++__ctr;
2605 }
2606
2607 while (__first != __last)
2608 *__s++ = *__first++;
2609
2610 while (__ctr--)
2611 {
2612 *__s++ = __sep;
2613 for (char __i = __gbeg[__idx]; __i > 0; --__i)
2614 *__s++ = *__first++;
2615 }
2616
2617 while (__idx--)
2618 {
2619 *__s++ = __sep;
2620 for (char __i = __gbeg[__idx]; __i > 0; --__i)
2621 *__s++ = *__first++;
2622 }
2623
2624 return __s;
2625 }
2626
2627 // Inhibit implicit instantiations for required instantiations,
2628 // which are defined via explicit instantiations elsewhere.
2629 // NB: This syntax is a GNU extension.
2630 #if _GLIBCXX_EXTERN_TEMPLATE
2631 extern template class moneypunct<char, false>;
2632 extern template class moneypunct<char, true>;
2633 extern template class moneypunct_byname<char, false>;
2634 extern template class moneypunct_byname<char, true>;
2635 extern template class _GLIBCXX_LDBL_NAMESPACE money_get<char>;
2636 extern template class _GLIBCXX_LDBL_NAMESPACE money_put<char>;
2637 extern template class numpunct<char>;
2638 extern template class numpunct_byname<char>;
2639 extern template class _GLIBCXX_LDBL_NAMESPACE num_get<char>;
2640 extern template class _GLIBCXX_LDBL_NAMESPACE num_put<char>;
2641 extern template class __timepunct<char>;
2642 extern template class time_put<char>;
2643 extern template class time_put_byname<char>;
2644 extern template class time_get<char>;
2645 extern template class time_get_byname<char>;
2646 extern template class messages<char>;
2647 extern template class messages_byname<char>;
2648 extern template class ctype_byname<char>;
2649 extern template class codecvt_byname<char, char, mbstate_t>;
2650 extern template class collate<char>;
2651 extern template class collate_byname<char>;
2652
2653 extern template
2654 const codecvt<char, char, mbstate_t>&
2655 use_facet<codecvt<char, char, mbstate_t> >(const locale&);
2656
2657 extern template
2658 const collate<char>&
2659 use_facet<collate<char> >(const locale&);
2660
2661 extern template
2662 const numpunct<char>&
2663 use_facet<numpunct<char> >(const locale&);
2664
2665 extern template
2666 const num_put<char>&
2667 use_facet<num_put<char> >(const locale&);
2668
2669 extern template
2670 const num_get<char>&
2671 use_facet<num_get<char> >(const locale&);
2672
2673 extern template
2674 const moneypunct<char, true>&
2675 use_facet<moneypunct<char, true> >(const locale&);
2676
2677 extern template
2678 const moneypunct<char, false>&
2679 use_facet<moneypunct<char, false> >(const locale&);
2680
2681 extern template
2682 const money_put<char>&
2683 use_facet<money_put<char> >(const locale&);
2684
2685 extern template
2686 const money_get<char>&
2687 use_facet<money_get<char> >(const locale&);
2688
2689 extern template
2690 const __timepunct<char>&
2691 use_facet<__timepunct<char> >(const locale&);
2692
2693 extern template
2694 const time_put<char>&
2695 use_facet<time_put<char> >(const locale&);
2696
2697 extern template
2698 const time_get<char>&
2699 use_facet<time_get<char> >(const locale&);
2700
2701 extern template
2702 const messages<char>&
2703 use_facet<messages<char> >(const locale&);
2704
2705 extern template
2706 bool
2707 has_facet<ctype<char> >(const locale&);
2708
2709 extern template
2710 bool
2711 has_facet<codecvt<char, char, mbstate_t> >(const locale&);
2712
2713 extern template
2714 bool
2715 has_facet<collate<char> >(const locale&);
2716
2717 extern template
2718 bool
2719 has_facet<numpunct<char> >(const locale&);
2720
2721 extern template
2722 bool
2723 has_facet<num_put<char> >(const locale&);
2724
2725 extern template
2726 bool
2727 has_facet<num_get<char> >(const locale&);
2728
2729 extern template
2730 bool
2731 has_facet<moneypunct<char> >(const locale&);
2732
2733 extern template
2734 bool
2735 has_facet<money_put<char> >(const locale&);
2736
2737 extern template
2738 bool
2739 has_facet<money_get<char> >(const locale&);
2740
2741 extern template
2742 bool
2743 has_facet<__timepunct<char> >(const locale&);
2744
2745 extern template
2746 bool
2747 has_facet<time_put<char> >(const locale&);
2748
2749 extern template
2750 bool
2751 has_facet<time_get<char> >(const locale&);
2752
2753 extern template
2754 bool
2755 has_facet<messages<char> >(const locale&);
2756
2757 #ifdef _GLIBCXX_USE_WCHAR_T
2758 extern template class moneypunct<wchar_t, false>;
2759 extern template class moneypunct<wchar_t, true>;
2760 extern template class moneypunct_byname<wchar_t, false>;
2761 extern template class moneypunct_byname<wchar_t, true>;
2762 extern template class _GLIBCXX_LDBL_NAMESPACE money_get<wchar_t>;
2763 extern template class _GLIBCXX_LDBL_NAMESPACE money_put<wchar_t>;
2764 extern template class numpunct<wchar_t>;
2765 extern template class numpunct_byname<wchar_t>;
2766 extern template class _GLIBCXX_LDBL_NAMESPACE num_get<wchar_t>;
2767 extern template class _GLIBCXX_LDBL_NAMESPACE num_put<wchar_t>;
2768 extern template class __timepunct<wchar_t>;
2769 extern template class time_put<wchar_t>;
2770 extern template class time_put_byname<wchar_t>;
2771 extern template class time_get<wchar_t>;
2772 extern template class time_get_byname<wchar_t>;
2773 extern template class messages<wchar_t>;
2774 extern template class messages_byname<wchar_t>;
2775 extern template class ctype_byname<wchar_t>;
2776 extern template class codecvt_byname<wchar_t, char, mbstate_t>;
2777 extern template class collate<wchar_t>;
2778 extern template class collate_byname<wchar_t>;
2779
2780 extern template
2781 const codecvt<wchar_t, char, mbstate_t>&
2782 use_facet<codecvt<wchar_t, char, mbstate_t> >(locale const&);
2783
2784 extern template
2785 const collate<wchar_t>&
2786 use_facet<collate<wchar_t> >(const locale&);
2787
2788 extern template
2789 const numpunct<wchar_t>&
2790 use_facet<numpunct<wchar_t> >(const locale&);
2791
2792 extern template
2793 const num_put<wchar_t>&
2794 use_facet<num_put<wchar_t> >(const locale&);
2795
2796 extern template
2797 const num_get<wchar_t>&
2798 use_facet<num_get<wchar_t> >(const locale&);
2799
2800 extern template
2801 const moneypunct<wchar_t, true>&
2802 use_facet<moneypunct<wchar_t, true> >(const locale&);
2803
2804 extern template
2805 const moneypunct<wchar_t, false>&
2806 use_facet<moneypunct<wchar_t, false> >(const locale&);
2807
2808 extern template
2809 const money_put<wchar_t>&
2810 use_facet<money_put<wchar_t> >(const locale&);
2811
2812 extern template
2813 const money_get<wchar_t>&
2814 use_facet<money_get<wchar_t> >(const locale&);
2815
2816 extern template
2817 const __timepunct<wchar_t>&
2818 use_facet<__timepunct<wchar_t> >(const locale&);
2819
2820 extern template
2821 const time_put<wchar_t>&
2822 use_facet<time_put<wchar_t> >(const locale&);
2823
2824 extern template
2825 const time_get<wchar_t>&
2826 use_facet<time_get<wchar_t> >(const locale&);
2827
2828 extern template
2829 const messages<wchar_t>&
2830 use_facet<messages<wchar_t> >(const locale&);
2831
2832 extern template
2833 bool
2834 has_facet<ctype<wchar_t> >(const locale&);
2835
2836 extern template
2837 bool
2838 has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
2839
2840 extern template
2841 bool
2842 has_facet<collate<wchar_t> >(const locale&);
2843
2844 extern template
2845 bool
2846 has_facet<numpunct<wchar_t> >(const locale&);
2847
2848 extern template
2849 bool
2850 has_facet<num_put<wchar_t> >(const locale&);
2851
2852 extern template
2853 bool
2854 has_facet<num_get<wchar_t> >(const locale&);
2855
2856 extern template
2857 bool
2858 has_facet<moneypunct<wchar_t> >(const locale&);
2859
2860 extern template
2861 bool
2862 has_facet<money_put<wchar_t> >(const locale&);
2863
2864 extern template
2865 bool
2866 has_facet<money_get<wchar_t> >(const locale&);
2867
2868 extern template
2869 bool
2870 has_facet<__timepunct<wchar_t> >(const locale&);
2871
2872 extern template
2873 bool
2874 has_facet<time_put<wchar_t> >(const locale&);
2875
2876 extern template
2877 bool
2878 has_facet<time_get<wchar_t> >(const locale&);
2879
2880 extern template
2881 bool
2882 has_facet<messages<wchar_t> >(const locale&);
2883 #endif
2884 #endif
2885
2886 _GLIBCXX_END_NAMESPACE
2887
2888 #endif