numeric_traits.h: Do not include <limits>.
[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 <ext/numeric_traits.h>
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 (__gnu_cxx::__numeric_traits<_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 ? -__gnu_cxx::__numeric_traits<_ValueT>::__min
612 : __gnu_cxx::__numeric_traits<_ValueT>::__max;
613 const __unsigned_type __smax = __max / __base;
614 __unsigned_type __result = 0;
615 int __digit = 0;
616 const char_type* __lit_zero = __lit + __num_base::_S_izero;
617
618 if (!__lc->_M_allocated)
619 // "C" locale
620 while (!__testeof)
621 {
622 __digit = _M_find(__lit_zero, __len, __c);
623 if (__digit == -1)
624 break;
625
626 if (__result > __smax)
627 __testfail = true;
628 else
629 {
630 __result *= __base;
631 __testfail |= __result > __max - __digit;
632 __result += __digit;
633 ++__sep_pos;
634 }
635
636 if (++__beg != __end)
637 __c = *__beg;
638 else
639 __testeof = true;
640 }
641 else
642 while (!__testeof)
643 {
644 // According to 22.2.2.1.2, p8-9, first look for thousands_sep
645 // and decimal_point.
646 if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
647 {
648 // NB: Thousands separator at the beginning of a string
649 // is a no-no, as is two consecutive thousands separators.
650 if (__sep_pos)
651 {
652 __found_grouping += static_cast<char>(__sep_pos);
653 __sep_pos = 0;
654 }
655 else
656 {
657 __testfail = true;
658 break;
659 }
660 }
661 else if (__c == __lc->_M_decimal_point)
662 break;
663 else
664 {
665 const char_type* __q =
666 __traits_type::find(__lit_zero, __len, __c);
667 if (!__q)
668 break;
669
670 __digit = __q - __lit_zero;
671 if (__digit > 15)
672 __digit -= 6;
673 if (__result > __smax)
674 __testfail = true;
675 else
676 {
677 __result *= __base;
678 __testfail |= __result > __max - __digit;
679 __result += __digit;
680 ++__sep_pos;
681 }
682 }
683
684 if (++__beg != __end)
685 __c = *__beg;
686 else
687 __testeof = true;
688 }
689
690 // Digit grouping is checked. If grouping and found_grouping don't
691 // match, then get very very upset, and set failbit.
692 if (__found_grouping.size())
693 {
694 // Add the ending grouping.
695 __found_grouping += static_cast<char>(__sep_pos);
696
697 if (!std::__verify_grouping(__lc->_M_grouping,
698 __lc->_M_grouping_size,
699 __found_grouping))
700 __err |= ios_base::failbit;
701 }
702
703 if (!__testfail && (__sep_pos || __found_zero
704 || __found_grouping.size()))
705 __v = __negative ? -__result : __result;
706 else
707 __err |= ios_base::failbit;
708
709 if (__testeof)
710 __err |= ios_base::eofbit;
711 return __beg;
712 }
713
714 // _GLIBCXX_RESOLVE_LIB_DEFECTS
715 // 17. Bad bool parsing
716 template<typename _CharT, typename _InIter>
717 _InIter
718 num_get<_CharT, _InIter>::
719 do_get(iter_type __beg, iter_type __end, ios_base& __io,
720 ios_base::iostate& __err, bool& __v) const
721 {
722 if (!(__io.flags() & ios_base::boolalpha))
723 {
724 // Parse bool values as long.
725 // NB: We can't just call do_get(long) here, as it might
726 // refer to a derived class.
727 long __l = -1;
728 __beg = _M_extract_int(__beg, __end, __io, __err, __l);
729 if (__l == 0 || __l == 1)
730 __v = bool(__l);
731 else
732 __err |= ios_base::failbit;
733 }
734 else
735 {
736 // Parse bool values as alphanumeric.
737 typedef __numpunct_cache<_CharT> __cache_type;
738 __use_cache<__cache_type> __uc;
739 const locale& __loc = __io._M_getloc();
740 const __cache_type* __lc = __uc(__loc);
741
742 bool __testf = true;
743 bool __testt = true;
744 size_t __n;
745 bool __testeof = __beg == __end;
746 for (__n = 0; !__testeof; ++__n)
747 {
748 const char_type __c = *__beg;
749
750 if (__testf)
751 {
752 if (__n < __lc->_M_falsename_size)
753 __testf = __c == __lc->_M_falsename[__n];
754 else
755 break;
756 }
757
758 if (__testt)
759 {
760 if (__n < __lc->_M_truename_size)
761 __testt = __c == __lc->_M_truename[__n];
762 else
763 break;
764 }
765
766 if (!__testf && !__testt)
767 break;
768
769 if (++__beg == __end)
770 __testeof = true;
771 }
772 if (__testf && __n == __lc->_M_falsename_size)
773 __v = false;
774 else if (__testt && __n == __lc->_M_truename_size)
775 __v = true;
776 else
777 __err |= ios_base::failbit;
778
779 if (__testeof)
780 __err |= ios_base::eofbit;
781 }
782 return __beg;
783 }
784
785 template<typename _CharT, typename _InIter>
786 _InIter
787 num_get<_CharT, _InIter>::
788 do_get(iter_type __beg, iter_type __end, ios_base& __io,
789 ios_base::iostate& __err, long& __v) const
790 { return _M_extract_int(__beg, __end, __io, __err, __v); }
791
792 template<typename _CharT, typename _InIter>
793 _InIter
794 num_get<_CharT, _InIter>::
795 do_get(iter_type __beg, iter_type __end, ios_base& __io,
796 ios_base::iostate& __err, unsigned short& __v) const
797 { return _M_extract_int(__beg, __end, __io, __err, __v); }
798
799 template<typename _CharT, typename _InIter>
800 _InIter
801 num_get<_CharT, _InIter>::
802 do_get(iter_type __beg, iter_type __end, ios_base& __io,
803 ios_base::iostate& __err, unsigned int& __v) const
804 { return _M_extract_int(__beg, __end, __io, __err, __v); }
805
806 template<typename _CharT, typename _InIter>
807 _InIter
808 num_get<_CharT, _InIter>::
809 do_get(iter_type __beg, iter_type __end, ios_base& __io,
810 ios_base::iostate& __err, unsigned long& __v) const
811 { return _M_extract_int(__beg, __end, __io, __err, __v); }
812
813 #ifdef _GLIBCXX_USE_LONG_LONG
814 template<typename _CharT, typename _InIter>
815 _InIter
816 num_get<_CharT, _InIter>::
817 do_get(iter_type __beg, iter_type __end, ios_base& __io,
818 ios_base::iostate& __err, long long& __v) const
819 { return _M_extract_int(__beg, __end, __io, __err, __v); }
820
821 template<typename _CharT, typename _InIter>
822 _InIter
823 num_get<_CharT, _InIter>::
824 do_get(iter_type __beg, iter_type __end, ios_base& __io,
825 ios_base::iostate& __err, unsigned long long& __v) const
826 { return _M_extract_int(__beg, __end, __io, __err, __v); }
827 #endif
828
829 template<typename _CharT, typename _InIter>
830 _InIter
831 num_get<_CharT, _InIter>::
832 do_get(iter_type __beg, iter_type __end, ios_base& __io,
833 ios_base::iostate& __err, float& __v) const
834 {
835 string __xtrc;
836 __xtrc.reserve(32);
837 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
838 std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
839 return __beg;
840 }
841
842 template<typename _CharT, typename _InIter>
843 _InIter
844 num_get<_CharT, _InIter>::
845 do_get(iter_type __beg, iter_type __end, ios_base& __io,
846 ios_base::iostate& __err, double& __v) const
847 {
848 string __xtrc;
849 __xtrc.reserve(32);
850 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
851 std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
852 return __beg;
853 }
854
855 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
856 template<typename _CharT, typename _InIter>
857 _InIter
858 num_get<_CharT, _InIter>::
859 __do_get(iter_type __beg, iter_type __end, ios_base& __io,
860 ios_base::iostate& __err, double& __v) const
861 {
862 string __xtrc;
863 __xtrc.reserve(32);
864 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
865 std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
866 return __beg;
867 }
868 #endif
869
870 template<typename _CharT, typename _InIter>
871 _InIter
872 num_get<_CharT, _InIter>::
873 do_get(iter_type __beg, iter_type __end, ios_base& __io,
874 ios_base::iostate& __err, long double& __v) const
875 {
876 string __xtrc;
877 __xtrc.reserve(32);
878 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
879 std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
880 return __beg;
881 }
882
883 template<typename _CharT, typename _InIter>
884 _InIter
885 num_get<_CharT, _InIter>::
886 do_get(iter_type __beg, iter_type __end, ios_base& __io,
887 ios_base::iostate& __err, void*& __v) const
888 {
889 // Prepare for hex formatted input.
890 typedef ios_base::fmtflags fmtflags;
891 const fmtflags __fmt = __io.flags();
892 __io.flags((__fmt & ~ios_base::basefield) | ios_base::hex);
893
894 typedef __gnu_cxx::__conditional_type<(sizeof(void*)
895 <= sizeof(unsigned long)),
896 unsigned long, unsigned long long>::__type _UIntPtrType;
897
898 _UIntPtrType __ul;
899 __beg = _M_extract_int(__beg, __end, __io, __err, __ul);
900
901 // Reset from hex formatted input.
902 __io.flags(__fmt);
903
904 if (!(__err & ios_base::failbit))
905 __v = reinterpret_cast<void*>(__ul);
906 return __beg;
907 }
908
909 // For use by integer and floating-point types after they have been
910 // converted into a char_type string.
911 template<typename _CharT, typename _OutIter>
912 void
913 num_put<_CharT, _OutIter>::
914 _M_pad(_CharT __fill, streamsize __w, ios_base& __io,
915 _CharT* __new, const _CharT* __cs, int& __len) const
916 {
917 // [22.2.2.2.2] Stage 3.
918 // If necessary, pad.
919 __pad<_CharT, char_traits<_CharT> >::_S_pad(__io, __fill, __new,
920 __cs, __w, __len);
921 __len = static_cast<int>(__w);
922 }
923
924 _GLIBCXX_END_LDBL_NAMESPACE
925
926 template<typename _CharT, typename _ValueT>
927 int
928 __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit,
929 ios_base::fmtflags __flags, bool __dec)
930 {
931 _CharT* __buf = __bufend;
932 if (__builtin_expect(__dec, true))
933 {
934 // Decimal.
935 do
936 {
937 *--__buf = __lit[(__v % 10) + __num_base::_S_odigits];
938 __v /= 10;
939 }
940 while (__v != 0);
941 }
942 else if ((__flags & ios_base::basefield) == ios_base::oct)
943 {
944 // Octal.
945 do
946 {
947 *--__buf = __lit[(__v & 0x7) + __num_base::_S_odigits];
948 __v >>= 3;
949 }
950 while (__v != 0);
951 }
952 else
953 {
954 // Hex.
955 const bool __uppercase = __flags & ios_base::uppercase;
956 const int __case_offset = __uppercase ? __num_base::_S_oudigits
957 : __num_base::_S_odigits;
958 do
959 {
960 *--__buf = __lit[(__v & 0xf) + __case_offset];
961 __v >>= 4;
962 }
963 while (__v != 0);
964 }
965 return __bufend - __buf;
966 }
967
968 _GLIBCXX_BEGIN_LDBL_NAMESPACE
969
970 template<typename _CharT, typename _OutIter>
971 void
972 num_put<_CharT, _OutIter>::
973 _M_group_int(const char* __grouping, size_t __grouping_size, _CharT __sep,
974 ios_base&, _CharT* __new, _CharT* __cs, int& __len) const
975 {
976 _CharT* __p = std::__add_grouping(__new, __sep, __grouping,
977 __grouping_size, __cs, __cs + __len);
978 __len = __p - __new;
979 }
980
981 template<typename _CharT, typename _OutIter>
982 template<typename _ValueT>
983 _OutIter
984 num_put<_CharT, _OutIter>::
985 _M_insert_int(_OutIter __s, ios_base& __io, _CharT __fill,
986 _ValueT __v) const
987 {
988 using __gnu_cxx::__add_unsigned;
989 typedef typename __add_unsigned<_ValueT>::__type __unsigned_type;
990 typedef __numpunct_cache<_CharT> __cache_type;
991 __use_cache<__cache_type> __uc;
992 const locale& __loc = __io._M_getloc();
993 const __cache_type* __lc = __uc(__loc);
994 const _CharT* __lit = __lc->_M_atoms_out;
995 const ios_base::fmtflags __flags = __io.flags();
996
997 // Long enough to hold hex, dec, and octal representations.
998 const int __ilen = 5 * sizeof(_ValueT);
999 _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1000 * __ilen));
1001
1002 // [22.2.2.2.2] Stage 1, numeric conversion to character.
1003 // Result is returned right-justified in the buffer.
1004 const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
1005 const bool __dec = (__basefield != ios_base::oct
1006 && __basefield != ios_base::hex);
1007 const __unsigned_type __u = ((__v > 0 || !__dec)
1008 ? __unsigned_type(__v)
1009 : -__unsigned_type(__v));
1010 int __len = __int_to_char(__cs + __ilen, __u, __lit, __flags, __dec);
1011 __cs += __ilen - __len;
1012
1013 // Add grouping, if necessary.
1014 if (__lc->_M_use_grouping)
1015 {
1016 // Grouping can add (almost) as many separators as the number
1017 // of digits + space is reserved for numeric base or sign.
1018 _CharT* __cs2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1019 * (__len + 1)
1020 * 2));
1021 _M_group_int(__lc->_M_grouping, __lc->_M_grouping_size,
1022 __lc->_M_thousands_sep, __io, __cs2 + 2, __cs, __len);
1023 __cs = __cs2 + 2;
1024 }
1025
1026 // Complete Stage 1, prepend numeric base or sign.
1027 if (__builtin_expect(__dec, true))
1028 {
1029 // Decimal.
1030 if (__v > 0)
1031 {
1032 if (__flags & ios_base::showpos
1033 && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed)
1034 *--__cs = __lit[__num_base::_S_oplus], ++__len;
1035 }
1036 else if (__v)
1037 *--__cs = __lit[__num_base::_S_ominus], ++__len;
1038 }
1039 else if (__flags & ios_base::showbase && __v)
1040 {
1041 if (__basefield == ios_base::oct)
1042 *--__cs = __lit[__num_base::_S_odigits], ++__len;
1043 else
1044 {
1045 // 'x' or 'X'
1046 const bool __uppercase = __flags & ios_base::uppercase;
1047 *--__cs = __lit[__num_base::_S_ox + __uppercase];
1048 // '0'
1049 *--__cs = __lit[__num_base::_S_odigits];
1050 __len += 2;
1051 }
1052 }
1053
1054 // Pad.
1055 const streamsize __w = __io.width();
1056 if (__w > static_cast<streamsize>(__len))
1057 {
1058 _CharT* __cs3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1059 * __w));
1060 _M_pad(__fill, __w, __io, __cs3, __cs, __len);
1061 __cs = __cs3;
1062 }
1063 __io.width(0);
1064
1065 // [22.2.2.2.2] Stage 4.
1066 // Write resulting, fully-formatted string to output iterator.
1067 return std::__write(__s, __cs, __len);
1068 }
1069
1070 template<typename _CharT, typename _OutIter>
1071 void
1072 num_put<_CharT, _OutIter>::
1073 _M_group_float(const char* __grouping, size_t __grouping_size,
1074 _CharT __sep, const _CharT* __p, _CharT* __new,
1075 _CharT* __cs, int& __len) const
1076 {
1077 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1078 // 282. What types does numpunct grouping refer to?
1079 // Add grouping, if necessary.
1080 const int __declen = __p ? __p - __cs : __len;
1081 _CharT* __p2 = std::__add_grouping(__new, __sep, __grouping,
1082 __grouping_size,
1083 __cs, __cs + __declen);
1084
1085 // Tack on decimal part.
1086 int __newlen = __p2 - __new;
1087 if (__p)
1088 {
1089 char_traits<_CharT>::copy(__p2, __p, __len - __declen);
1090 __newlen += __len - __declen;
1091 }
1092 __len = __newlen;
1093 }
1094
1095 // The following code uses vsnprintf (or vsprintf(), when
1096 // _GLIBCXX_USE_C99 is not defined) to convert floating point values
1097 // for insertion into a stream. An optimization would be to replace
1098 // them with code that works directly on a wide buffer and then use
1099 // __pad to do the padding. It would be good to replace them anyway
1100 // to gain back the efficiency that C++ provides by knowing up front
1101 // the type of the values to insert. Also, sprintf is dangerous
1102 // since may lead to accidental buffer overruns. This
1103 // implementation follows the C++ standard fairly directly as
1104 // outlined in 22.2.2.2 [lib.locale.num.put]
1105 template<typename _CharT, typename _OutIter>
1106 template<typename _ValueT>
1107 _OutIter
1108 num_put<_CharT, _OutIter>::
1109 _M_insert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
1110 _ValueT __v) const
1111 {
1112 typedef __numpunct_cache<_CharT> __cache_type;
1113 __use_cache<__cache_type> __uc;
1114 const locale& __loc = __io._M_getloc();
1115 const __cache_type* __lc = __uc(__loc);
1116
1117 // Use default precision if out of range.
1118 const streamsize __prec = __io.precision() < 0 ? 6 : __io.precision();
1119
1120 const int __max_digits =
1121 __gnu_cxx::__numeric_traits<_ValueT>::__digits10;
1122
1123 // [22.2.2.2.2] Stage 1, numeric conversion to character.
1124 int __len;
1125 // Long enough for the max format spec.
1126 char __fbuf[16];
1127 __num_base::_S_format_float(__io, __fbuf, __mod);
1128
1129 #ifdef _GLIBCXX_USE_C99
1130 // First try a buffer perhaps big enough (most probably sufficient
1131 // for non-ios_base::fixed outputs)
1132 int __cs_size = __max_digits * 3;
1133 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1134 __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
1135 __fbuf, __prec, __v);
1136
1137 // If the buffer was not large enough, try again with the correct size.
1138 if (__len >= __cs_size)
1139 {
1140 __cs_size = __len + 1;
1141 __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1142 __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
1143 __fbuf, __prec, __v);
1144 }
1145 #else
1146 // Consider the possibility of long ios_base::fixed outputs
1147 const bool __fixed = __io.flags() & ios_base::fixed;
1148 const int __max_exp =
1149 __gnu_cxx::__numeric_traits<_ValueT>::__max_exponent10;
1150
1151 // The size of the output string is computed as follows.
1152 // ios_base::fixed outputs may need up to __max_exp + 1 chars
1153 // for the integer part + __prec chars for the fractional part
1154 // + 3 chars for sign, decimal point, '\0'. On the other hand,
1155 // for non-fixed outputs __max_digits * 2 + __prec chars are
1156 // largely sufficient.
1157 const int __cs_size = __fixed ? __max_exp + __prec + 4
1158 : __max_digits * 2 + __prec;
1159 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1160 __len = std::__convert_from_v(_S_get_c_locale(), __cs, 0, __fbuf,
1161 __prec, __v);
1162 #endif
1163
1164 // [22.2.2.2.2] Stage 2, convert to char_type, using correct
1165 // numpunct.decimal_point() values for '.' and adding grouping.
1166 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1167
1168 _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1169 * __len));
1170 __ctype.widen(__cs, __cs + __len, __ws);
1171
1172 // Replace decimal point.
1173 _CharT* __wp = 0;
1174 const char* __p = char_traits<char>::find(__cs, __len, '.');
1175 if (__p)
1176 {
1177 __wp = __ws + (__p - __cs);
1178 *__wp = __lc->_M_decimal_point;
1179 }
1180
1181 // Add grouping, if necessary.
1182 // N.B. Make sure to not group things like 2e20, i.e., no decimal
1183 // point, scientific notation.
1184 if (__lc->_M_use_grouping
1185 && (__wp || __len < 3 || (__cs[1] <= '9' && __cs[2] <= '9'
1186 && __cs[1] >= '0' && __cs[2] >= '0')))
1187 {
1188 // Grouping can add (almost) as many separators as the
1189 // number of digits, but no more.
1190 _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1191 * __len * 2));
1192
1193 streamsize __off = 0;
1194 if (__cs[0] == '-' || __cs[0] == '+')
1195 {
1196 __off = 1;
1197 __ws2[0] = __ws[0];
1198 __len -= 1;
1199 }
1200
1201 _M_group_float(__lc->_M_grouping, __lc->_M_grouping_size,
1202 __lc->_M_thousands_sep, __wp, __ws2 + __off,
1203 __ws + __off, __len);
1204 __len += __off;
1205
1206 __ws = __ws2;
1207 }
1208
1209 // Pad.
1210 const streamsize __w = __io.width();
1211 if (__w > static_cast<streamsize>(__len))
1212 {
1213 _CharT* __ws3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1214 * __w));
1215 _M_pad(__fill, __w, __io, __ws3, __ws, __len);
1216 __ws = __ws3;
1217 }
1218 __io.width(0);
1219
1220 // [22.2.2.2.2] Stage 4.
1221 // Write resulting, fully-formatted string to output iterator.
1222 return std::__write(__s, __ws, __len);
1223 }
1224
1225 template<typename _CharT, typename _OutIter>
1226 _OutIter
1227 num_put<_CharT, _OutIter>::
1228 do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const
1229 {
1230 const ios_base::fmtflags __flags = __io.flags();
1231 if ((__flags & ios_base::boolalpha) == 0)
1232 {
1233 const long __l = __v;
1234 __s = _M_insert_int(__s, __io, __fill, __l);
1235 }
1236 else
1237 {
1238 typedef __numpunct_cache<_CharT> __cache_type;
1239 __use_cache<__cache_type> __uc;
1240 const locale& __loc = __io._M_getloc();
1241 const __cache_type* __lc = __uc(__loc);
1242
1243 const _CharT* __name = __v ? __lc->_M_truename
1244 : __lc->_M_falsename;
1245 int __len = __v ? __lc->_M_truename_size
1246 : __lc->_M_falsename_size;
1247
1248 const streamsize __w = __io.width();
1249 if (__w > static_cast<streamsize>(__len))
1250 {
1251 _CharT* __cs
1252 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1253 * __w));
1254 _M_pad(__fill, __w, __io, __cs, __name, __len);
1255 __name = __cs;
1256 }
1257 __io.width(0);
1258 __s = std::__write(__s, __name, __len);
1259 }
1260 return __s;
1261 }
1262
1263 template<typename _CharT, typename _OutIter>
1264 _OutIter
1265 num_put<_CharT, _OutIter>::
1266 do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
1267 { return _M_insert_int(__s, __io, __fill, __v); }
1268
1269 template<typename _CharT, typename _OutIter>
1270 _OutIter
1271 num_put<_CharT, _OutIter>::
1272 do_put(iter_type __s, ios_base& __io, char_type __fill,
1273 unsigned long __v) const
1274 { return _M_insert_int(__s, __io, __fill, __v); }
1275
1276 #ifdef _GLIBCXX_USE_LONG_LONG
1277 template<typename _CharT, typename _OutIter>
1278 _OutIter
1279 num_put<_CharT, _OutIter>::
1280 do_put(iter_type __s, ios_base& __io, char_type __fill, long long __v) const
1281 { return _M_insert_int(__s, __io, __fill, __v); }
1282
1283 template<typename _CharT, typename _OutIter>
1284 _OutIter
1285 num_put<_CharT, _OutIter>::
1286 do_put(iter_type __s, ios_base& __io, char_type __fill,
1287 unsigned long long __v) const
1288 { return _M_insert_int(__s, __io, __fill, __v); }
1289 #endif
1290
1291 template<typename _CharT, typename _OutIter>
1292 _OutIter
1293 num_put<_CharT, _OutIter>::
1294 do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const
1295 { return _M_insert_float(__s, __io, __fill, char(), __v); }
1296
1297 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1298 template<typename _CharT, typename _OutIter>
1299 _OutIter
1300 num_put<_CharT, _OutIter>::
1301 __do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const
1302 { return _M_insert_float(__s, __io, __fill, char(), __v); }
1303 #endif
1304
1305 template<typename _CharT, typename _OutIter>
1306 _OutIter
1307 num_put<_CharT, _OutIter>::
1308 do_put(iter_type __s, ios_base& __io, char_type __fill,
1309 long double __v) const
1310 { return _M_insert_float(__s, __io, __fill, 'L', __v); }
1311
1312 template<typename _CharT, typename _OutIter>
1313 _OutIter
1314 num_put<_CharT, _OutIter>::
1315 do_put(iter_type __s, ios_base& __io, char_type __fill,
1316 const void* __v) const
1317 {
1318 const ios_base::fmtflags __flags = __io.flags();
1319 const ios_base::fmtflags __fmt = ~(ios_base::basefield
1320 | ios_base::uppercase
1321 | ios_base::internal);
1322 __io.flags((__flags & __fmt) | (ios_base::hex | ios_base::showbase));
1323
1324 typedef __gnu_cxx::__conditional_type<(sizeof(const void*)
1325 <= sizeof(unsigned long)),
1326 unsigned long, unsigned long long>::__type _UIntPtrType;
1327
1328 __s = _M_insert_int(__s, __io, __fill,
1329 reinterpret_cast<_UIntPtrType>(__v));
1330 __io.flags(__flags);
1331 return __s;
1332 }
1333
1334 template<typename _CharT, typename _InIter>
1335 template<bool _Intl>
1336 _InIter
1337 money_get<_CharT, _InIter>::
1338 _M_extract(iter_type __beg, iter_type __end, ios_base& __io,
1339 ios_base::iostate& __err, string& __units) const
1340 {
1341 typedef char_traits<_CharT> __traits_type;
1342 typedef typename string_type::size_type size_type;
1343 typedef money_base::part part;
1344 typedef __moneypunct_cache<_CharT, _Intl> __cache_type;
1345
1346 const locale& __loc = __io._M_getloc();
1347 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1348
1349 __use_cache<__cache_type> __uc;
1350 const __cache_type* __lc = __uc(__loc);
1351 const char_type* __lit = __lc->_M_atoms;
1352
1353 // Deduced sign.
1354 bool __negative = false;
1355 // Sign size.
1356 size_type __sign_size = 0;
1357 // True if sign is mandatory.
1358 const bool __mandatory_sign = (__lc->_M_positive_sign_size
1359 && __lc->_M_negative_sign_size);
1360 // String of grouping info from thousands_sep plucked from __units.
1361 string __grouping_tmp;
1362 if (__lc->_M_use_grouping)
1363 __grouping_tmp.reserve(32);
1364 // Last position before the decimal point.
1365 int __last_pos = 0;
1366 // Separator positions, then, possibly, fractional digits.
1367 int __n = 0;
1368 // If input iterator is in a valid state.
1369 bool __testvalid = true;
1370 // Flag marking when a decimal point is found.
1371 bool __testdecfound = false;
1372
1373 // The tentative returned string is stored here.
1374 string __res;
1375 __res.reserve(32);
1376
1377 const char_type* __lit_zero = __lit + money_base::_S_zero;
1378 const money_base::pattern __p = __lc->_M_neg_format;
1379 for (int __i = 0; __i < 4 && __testvalid; ++__i)
1380 {
1381 const part __which = static_cast<part>(__p.field[__i]);
1382 switch (__which)
1383 {
1384 case money_base::symbol:
1385 // According to 22.2.6.1.2, p2, symbol is required
1386 // if (__io.flags() & ios_base::showbase), otherwise
1387 // is optional and consumed only if other characters
1388 // are needed to complete the format.
1389 if (__io.flags() & ios_base::showbase || __sign_size > 1
1390 || __i == 0
1391 || (__i == 1 && (__mandatory_sign
1392 || (static_cast<part>(__p.field[0])
1393 == money_base::sign)
1394 || (static_cast<part>(__p.field[2])
1395 == money_base::space)))
1396 || (__i == 2 && ((static_cast<part>(__p.field[3])
1397 == money_base::value)
1398 || (__mandatory_sign
1399 && (static_cast<part>(__p.field[3])
1400 == money_base::sign)))))
1401 {
1402 const size_type __len = __lc->_M_curr_symbol_size;
1403 size_type __j = 0;
1404 for (; __beg != __end && __j < __len
1405 && *__beg == __lc->_M_curr_symbol[__j];
1406 ++__beg, ++__j);
1407 if (__j != __len
1408 && (__j || __io.flags() & ios_base::showbase))
1409 __testvalid = false;
1410 }
1411 break;
1412 case money_base::sign:
1413 // Sign might not exist, or be more than one character long.
1414 if (__lc->_M_positive_sign_size && __beg != __end
1415 && *__beg == __lc->_M_positive_sign[0])
1416 {
1417 __sign_size = __lc->_M_positive_sign_size;
1418 ++__beg;
1419 }
1420 else if (__lc->_M_negative_sign_size && __beg != __end
1421 && *__beg == __lc->_M_negative_sign[0])
1422 {
1423 __negative = true;
1424 __sign_size = __lc->_M_negative_sign_size;
1425 ++__beg;
1426 }
1427 else if (__lc->_M_positive_sign_size
1428 && !__lc->_M_negative_sign_size)
1429 // "... if no sign is detected, the result is given the sign
1430 // that corresponds to the source of the empty string"
1431 __negative = true;
1432 else if (__mandatory_sign)
1433 __testvalid = false;
1434 break;
1435 case money_base::value:
1436 // Extract digits, remove and stash away the
1437 // grouping of found thousands separators.
1438 for (; __beg != __end; ++__beg)
1439 {
1440 const char_type __c = *__beg;
1441 const char_type* __q = __traits_type::find(__lit_zero,
1442 10, __c);
1443 if (__q != 0)
1444 {
1445 __res += money_base::_S_atoms[__q - __lit];
1446 ++__n;
1447 }
1448 else if (__c == __lc->_M_decimal_point
1449 && !__testdecfound)
1450 {
1451 __last_pos = __n;
1452 __n = 0;
1453 __testdecfound = true;
1454 }
1455 else if (__lc->_M_use_grouping
1456 && __c == __lc->_M_thousands_sep
1457 && !__testdecfound)
1458 {
1459 if (__n)
1460 {
1461 // Mark position for later analysis.
1462 __grouping_tmp += static_cast<char>(__n);
1463 __n = 0;
1464 }
1465 else
1466 {
1467 __testvalid = false;
1468 break;
1469 }
1470 }
1471 else
1472 break;
1473 }
1474 if (__res.empty())
1475 __testvalid = false;
1476 break;
1477 case money_base::space:
1478 // At least one space is required.
1479 if (__beg != __end && __ctype.is(ctype_base::space, *__beg))
1480 ++__beg;
1481 else
1482 __testvalid = false;
1483 case money_base::none:
1484 // Only if not at the end of the pattern.
1485 if (__i != 3)
1486 for (; __beg != __end
1487 && __ctype.is(ctype_base::space, *__beg); ++__beg);
1488 break;
1489 }
1490 }
1491
1492 // Need to get the rest of the sign characters, if they exist.
1493 if (__sign_size > 1 && __testvalid)
1494 {
1495 const char_type* __sign = __negative ? __lc->_M_negative_sign
1496 : __lc->_M_positive_sign;
1497 size_type __i = 1;
1498 for (; __beg != __end && __i < __sign_size
1499 && *__beg == __sign[__i]; ++__beg, ++__i);
1500
1501 if (__i != __sign_size)
1502 __testvalid = false;
1503 }
1504
1505 if (__testvalid)
1506 {
1507 // Strip leading zeros.
1508 if (__res.size() > 1)
1509 {
1510 const size_type __first = __res.find_first_not_of('0');
1511 const bool __only_zeros = __first == string::npos;
1512 if (__first)
1513 __res.erase(0, __only_zeros ? __res.size() - 1 : __first);
1514 }
1515
1516 // 22.2.6.1.2, p4
1517 if (__negative && __res[0] != '0')
1518 __res.insert(__res.begin(), '-');
1519
1520 // Test for grouping fidelity.
1521 if (__grouping_tmp.size())
1522 {
1523 // Add the ending grouping.
1524 __grouping_tmp += static_cast<char>(__testdecfound ? __last_pos
1525 : __n);
1526 if (!std::__verify_grouping(__lc->_M_grouping,
1527 __lc->_M_grouping_size,
1528 __grouping_tmp))
1529 __err |= ios_base::failbit;
1530 }
1531
1532 // Iff not enough digits were supplied after the decimal-point.
1533 if (__testdecfound && __lc->_M_frac_digits > 0
1534 && __n != __lc->_M_frac_digits)
1535 __testvalid = false;
1536 }
1537
1538 // Iff valid sequence is not recognized.
1539 if (!__testvalid)
1540 __err |= ios_base::failbit;
1541 else
1542 __units.swap(__res);
1543
1544 // Iff no more characters are available.
1545 if (__beg == __end)
1546 __err |= ios_base::eofbit;
1547 return __beg;
1548 }
1549
1550 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1551 template<typename _CharT, typename _InIter>
1552 _InIter
1553 money_get<_CharT, _InIter>::
1554 __do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
1555 ios_base::iostate& __err, double& __units) const
1556 {
1557 string __str;
1558 __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str)
1559 : _M_extract<false>(__beg, __end, __io, __err, __str);
1560 std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale());
1561 return __beg;
1562 }
1563 #endif
1564
1565 template<typename _CharT, typename _InIter>
1566 _InIter
1567 money_get<_CharT, _InIter>::
1568 do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
1569 ios_base::iostate& __err, long double& __units) const
1570 {
1571 string __str;
1572 __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str)
1573 : _M_extract<false>(__beg, __end, __io, __err, __str);
1574 std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale());
1575 return __beg;
1576 }
1577
1578 template<typename _CharT, typename _InIter>
1579 _InIter
1580 money_get<_CharT, _InIter>::
1581 do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
1582 ios_base::iostate& __err, string_type& __digits) const
1583 {
1584 typedef typename string::size_type size_type;
1585
1586 const locale& __loc = __io._M_getloc();
1587 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1588
1589 string __str;
1590 __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str)
1591 : _M_extract<false>(__beg, __end, __io, __err, __str);
1592 const size_type __len = __str.size();
1593 if (__len)
1594 {
1595 __digits.resize(__len);
1596 __ctype.widen(__str.data(), __str.data() + __len, &__digits[0]);
1597 }
1598 return __beg;
1599 }
1600
1601 template<typename _CharT, typename _OutIter>
1602 template<bool _Intl>
1603 _OutIter
1604 money_put<_CharT, _OutIter>::
1605 _M_insert(iter_type __s, ios_base& __io, char_type __fill,
1606 const string_type& __digits) const
1607 {
1608 typedef typename string_type::size_type size_type;
1609 typedef money_base::part part;
1610 typedef __moneypunct_cache<_CharT, _Intl> __cache_type;
1611
1612 const locale& __loc = __io._M_getloc();
1613 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1614
1615 __use_cache<__cache_type> __uc;
1616 const __cache_type* __lc = __uc(__loc);
1617 const char_type* __lit = __lc->_M_atoms;
1618
1619 // Determine if negative or positive formats are to be used, and
1620 // discard leading negative_sign if it is present.
1621 const char_type* __beg = __digits.data();
1622
1623 money_base::pattern __p;
1624 const char_type* __sign;
1625 size_type __sign_size;
1626 if (!(*__beg == __lit[money_base::_S_minus]))
1627 {
1628 __p = __lc->_M_pos_format;
1629 __sign = __lc->_M_positive_sign;
1630 __sign_size = __lc->_M_positive_sign_size;
1631 }
1632 else
1633 {
1634 __p = __lc->_M_neg_format;
1635 __sign = __lc->_M_negative_sign;
1636 __sign_size = __lc->_M_negative_sign_size;
1637 if (__digits.size())
1638 ++__beg;
1639 }
1640
1641 // Look for valid numbers in the ctype facet within input digits.
1642 size_type __len = __ctype.scan_not(ctype_base::digit, __beg,
1643 __beg + __digits.size()) - __beg;
1644 if (__len)
1645 {
1646 // Assume valid input, and attempt to format.
1647 // Break down input numbers into base components, as follows:
1648 // final_value = grouped units + (decimal point) + (digits)
1649 string_type __value;
1650 __value.reserve(2 * __len);
1651
1652 // Add thousands separators to non-decimal digits, per
1653 // grouping rules.
1654 long __paddec = __len - __lc->_M_frac_digits;
1655 if (__paddec > 0)
1656 {
1657 if (__lc->_M_frac_digits < 0)
1658 __paddec = __len;
1659 if (__lc->_M_grouping_size)
1660 {
1661 __value.assign(2 * __paddec, char_type());
1662 _CharT* __vend =
1663 std::__add_grouping(&__value[0], __lc->_M_thousands_sep,
1664 __lc->_M_grouping,
1665 __lc->_M_grouping_size,
1666 __beg, __beg + __paddec);
1667 __value.erase(__vend - &__value[0]);
1668 }
1669 else
1670 __value.assign(__beg, __paddec);
1671 }
1672
1673 // Deal with decimal point, decimal digits.
1674 if (__lc->_M_frac_digits > 0)
1675 {
1676 __value += __lc->_M_decimal_point;
1677 if (__paddec >= 0)
1678 __value.append(__beg + __paddec, __lc->_M_frac_digits);
1679 else
1680 {
1681 // Have to pad zeros in the decimal position.
1682 __value.append(-__paddec, __lit[money_base::_S_zero]);
1683 __value.append(__beg, __len);
1684 }
1685 }
1686
1687 // Calculate length of resulting string.
1688 const ios_base::fmtflags __f = __io.flags()
1689 & ios_base::adjustfield;
1690 __len = __value.size() + __sign_size;
1691 __len += ((__io.flags() & ios_base::showbase)
1692 ? __lc->_M_curr_symbol_size : 0);
1693
1694 string_type __res;
1695 __res.reserve(2 * __len);
1696
1697 const size_type __width = static_cast<size_type>(__io.width());
1698 const bool __testipad = (__f == ios_base::internal
1699 && __len < __width);
1700 // Fit formatted digits into the required pattern.
1701 for (int __i = 0; __i < 4; ++__i)
1702 {
1703 const part __which = static_cast<part>(__p.field[__i]);
1704 switch (__which)
1705 {
1706 case money_base::symbol:
1707 if (__io.flags() & ios_base::showbase)
1708 __res.append(__lc->_M_curr_symbol,
1709 __lc->_M_curr_symbol_size);
1710 break;
1711 case money_base::sign:
1712 // Sign might not exist, or be more than one
1713 // charater long. In that case, add in the rest
1714 // below.
1715 if (__sign_size)
1716 __res += __sign[0];
1717 break;
1718 case money_base::value:
1719 __res += __value;
1720 break;
1721 case money_base::space:
1722 // At least one space is required, but if internal
1723 // formatting is required, an arbitrary number of
1724 // fill spaces will be necessary.
1725 if (__testipad)
1726 __res.append(__width - __len, __fill);
1727 else
1728 __res += __fill;
1729 break;
1730 case money_base::none:
1731 if (__testipad)
1732 __res.append(__width - __len, __fill);
1733 break;
1734 }
1735 }
1736
1737 // Special case of multi-part sign parts.
1738 if (__sign_size > 1)
1739 __res.append(__sign + 1, __sign_size - 1);
1740
1741 // Pad, if still necessary.
1742 __len = __res.size();
1743 if (__width > __len)
1744 {
1745 if (__f == ios_base::left)
1746 // After.
1747 __res.append(__width - __len, __fill);
1748 else
1749 // Before.
1750 __res.insert(0, __width - __len, __fill);
1751 __len = __width;
1752 }
1753
1754 // Write resulting, fully-formatted string to output iterator.
1755 __s = std::__write(__s, __res.data(), __len);
1756 }
1757 __io.width(0);
1758 return __s;
1759 }
1760
1761 #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__
1762 template<typename _CharT, typename _OutIter>
1763 _OutIter
1764 money_put<_CharT, _OutIter>::
1765 __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1766 double __units) const
1767 { return this->do_put(__s, __intl, __io, __fill, (long double) __units); }
1768 #endif
1769
1770 template<typename _CharT, typename _OutIter>
1771 _OutIter
1772 money_put<_CharT, _OutIter>::
1773 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1774 long double __units) const
1775 {
1776 const locale __loc = __io.getloc();
1777 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1778 #ifdef _GLIBCXX_USE_C99
1779 // First try a buffer perhaps big enough.
1780 int __cs_size = 64;
1781 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1782 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1783 // 328. Bad sprintf format modifier in money_put<>::do_put()
1784 int __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
1785 "%.*Lf", 0, __units);
1786 // If the buffer was not large enough, try again with the correct size.
1787 if (__len >= __cs_size)
1788 {
1789 __cs_size = __len + 1;
1790 __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1791 __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
1792 "%.*Lf", 0, __units);
1793 }
1794 #else
1795 // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'.
1796 const int __cs_size =
1797 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 3;
1798 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1799 int __len = std::__convert_from_v(_S_get_c_locale(), __cs, 0, "%.*Lf",
1800 0, __units);
1801 #endif
1802 string_type __digits(__len, char_type());
1803 __ctype.widen(__cs, __cs + __len, &__digits[0]);
1804 return __intl ? _M_insert<true>(__s, __io, __fill, __digits)
1805 : _M_insert<false>(__s, __io, __fill, __digits);
1806 }
1807
1808 template<typename _CharT, typename _OutIter>
1809 _OutIter
1810 money_put<_CharT, _OutIter>::
1811 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1812 const string_type& __digits) const
1813 { return __intl ? _M_insert<true>(__s, __io, __fill, __digits)
1814 : _M_insert<false>(__s, __io, __fill, __digits); }
1815
1816 _GLIBCXX_END_LDBL_NAMESPACE
1817
1818 // NB: Not especially useful. Without an ios_base object or some
1819 // kind of locale reference, we are left clawing at the air where
1820 // the side of the mountain used to be...
1821 template<typename _CharT, typename _InIter>
1822 time_base::dateorder
1823 time_get<_CharT, _InIter>::do_date_order() const
1824 { return time_base::no_order; }
1825
1826 // Expand a strftime format string and parse it. E.g., do_get_date() may
1827 // pass %m/%d/%Y => extracted characters.
1828 template<typename _CharT, typename _InIter>
1829 _InIter
1830 time_get<_CharT, _InIter>::
1831 _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io,
1832 ios_base::iostate& __err, tm* __tm,
1833 const _CharT* __format) const
1834 {
1835 const locale& __loc = __io._M_getloc();
1836 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
1837 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1838 const size_t __len = char_traits<_CharT>::length(__format);
1839
1840 ios_base::iostate __tmperr = ios_base::goodbit;
1841 for (size_t __i = 0; __beg != __end && __i < __len && !__tmperr; ++__i)
1842 {
1843 if (__ctype.narrow(__format[__i], 0) == '%')
1844 {
1845 // Verify valid formatting code, attempt to extract.
1846 char __c = __ctype.narrow(__format[++__i], 0);
1847 int __mem = 0;
1848 if (__c == 'E' || __c == 'O')
1849 __c = __ctype.narrow(__format[++__i], 0);
1850 switch (__c)
1851 {
1852 const char* __cs;
1853 _CharT __wcs[10];
1854 case 'a':
1855 // Abbreviated weekday name [tm_wday]
1856 const char_type* __days1[7];
1857 __tp._M_days_abbreviated(__days1);
1858 __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days1,
1859 7, __io, __tmperr);
1860 break;
1861 case 'A':
1862 // Weekday name [tm_wday].
1863 const char_type* __days2[7];
1864 __tp._M_days(__days2);
1865 __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days2,
1866 7, __io, __tmperr);
1867 break;
1868 case 'h':
1869 case 'b':
1870 // Abbreviated month name [tm_mon]
1871 const char_type* __months1[12];
1872 __tp._M_months_abbreviated(__months1);
1873 __beg = _M_extract_name(__beg, __end, __tm->tm_mon,
1874 __months1, 12, __io, __tmperr);
1875 break;
1876 case 'B':
1877 // Month name [tm_mon].
1878 const char_type* __months2[12];
1879 __tp._M_months(__months2);
1880 __beg = _M_extract_name(__beg, __end, __tm->tm_mon,
1881 __months2, 12, __io, __tmperr);
1882 break;
1883 case 'c':
1884 // Default time and date representation.
1885 const char_type* __dt[2];
1886 __tp._M_date_time_formats(__dt);
1887 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1888 __tm, __dt[0]);
1889 break;
1890 case 'd':
1891 // Day [01, 31]. [tm_mday]
1892 __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2,
1893 __io, __tmperr);
1894 break;
1895 case 'e':
1896 // Day [1, 31], with single digits preceded by
1897 // space. [tm_mday]
1898 if (__ctype.is(ctype_base::space, *__beg))
1899 __beg = _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9,
1900 1, __io, __tmperr);
1901 else
1902 __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31,
1903 2, __io, __tmperr);
1904 break;
1905 case 'D':
1906 // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year]
1907 __cs = "%m/%d/%y";
1908 __ctype.widen(__cs, __cs + 9, __wcs);
1909 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1910 __tm, __wcs);
1911 break;
1912 case 'H':
1913 // Hour [00, 23]. [tm_hour]
1914 __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2,
1915 __io, __tmperr);
1916 break;
1917 case 'I':
1918 // Hour [01, 12]. [tm_hour]
1919 __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2,
1920 __io, __tmperr);
1921 break;
1922 case 'm':
1923 // Month [01, 12]. [tm_mon]
1924 __beg = _M_extract_num(__beg, __end, __mem, 1, 12, 2,
1925 __io, __tmperr);
1926 if (!__tmperr)
1927 __tm->tm_mon = __mem - 1;
1928 break;
1929 case 'M':
1930 // Minute [00, 59]. [tm_min]
1931 __beg = _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2,
1932 __io, __tmperr);
1933 break;
1934 case 'n':
1935 if (__ctype.narrow(*__beg, 0) == '\n')
1936 ++__beg;
1937 else
1938 __tmperr |= ios_base::failbit;
1939 break;
1940 case 'R':
1941 // Equivalent to (%H:%M).
1942 __cs = "%H:%M";
1943 __ctype.widen(__cs, __cs + 6, __wcs);
1944 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1945 __tm, __wcs);
1946 break;
1947 case 'S':
1948 // Seconds. [tm_sec]
1949 // [00, 60] in C99 (one leap-second), [00, 61] in C89.
1950 #ifdef _GLIBCXX_USE_C99
1951 __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 60, 2,
1952 #else
1953 __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 61, 2,
1954 #endif
1955 __io, __tmperr);
1956 break;
1957 case 't':
1958 if (__ctype.narrow(*__beg, 0) == '\t')
1959 ++__beg;
1960 else
1961 __tmperr |= ios_base::failbit;
1962 break;
1963 case 'T':
1964 // Equivalent to (%H:%M:%S).
1965 __cs = "%H:%M:%S";
1966 __ctype.widen(__cs, __cs + 9, __wcs);
1967 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1968 __tm, __wcs);
1969 break;
1970 case 'x':
1971 // Locale's date.
1972 const char_type* __dates[2];
1973 __tp._M_date_formats(__dates);
1974 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1975 __tm, __dates[0]);
1976 break;
1977 case 'X':
1978 // Locale's time.
1979 const char_type* __times[2];
1980 __tp._M_time_formats(__times);
1981 __beg = _M_extract_via_format(__beg, __end, __io, __tmperr,
1982 __tm, __times[0]);
1983 break;
1984 case 'y':
1985 case 'C': // C99
1986 // Two digit year. [tm_year]
1987 __beg = _M_extract_num(__beg, __end, __tm->tm_year, 0, 99, 2,
1988 __io, __tmperr);
1989 break;
1990 case 'Y':
1991 // Year [1900). [tm_year]
1992 __beg = _M_extract_num(__beg, __end, __mem, 0, 9999, 4,
1993 __io, __tmperr);
1994 if (!__tmperr)
1995 __tm->tm_year = __mem - 1900;
1996 break;
1997 case 'Z':
1998 // Timezone info.
1999 if (__ctype.is(ctype_base::upper, *__beg))
2000 {
2001 int __tmp;
2002 __beg = _M_extract_name(__beg, __end, __tmp,
2003 __timepunct_cache<_CharT>::_S_timezones,
2004 14, __io, __tmperr);
2005
2006 // GMT requires special effort.
2007 if (__beg != __end && !__tmperr && __tmp == 0
2008 && (*__beg == __ctype.widen('-')
2009 || *__beg == __ctype.widen('+')))
2010 {
2011 __beg = _M_extract_num(__beg, __end, __tmp, 0, 23, 2,
2012 __io, __tmperr);
2013 __beg = _M_extract_num(__beg, __end, __tmp, 0, 59, 2,
2014 __io, __tmperr);
2015 }
2016 }
2017 else
2018 __tmperr |= ios_base::failbit;
2019 break;
2020 default:
2021 // Not recognized.
2022 __tmperr |= ios_base::failbit;
2023 }
2024 }
2025 else
2026 {
2027 // Verify format and input match, extract and discard.
2028 if (__format[__i] == *__beg)
2029 ++__beg;
2030 else
2031 __tmperr |= ios_base::failbit;
2032 }
2033 }
2034
2035 if (__tmperr)
2036 __err |= ios_base::failbit;
2037
2038 return __beg;
2039 }
2040
2041 template<typename _CharT, typename _InIter>
2042 _InIter
2043 time_get<_CharT, _InIter>::
2044 _M_extract_num(iter_type __beg, iter_type __end, int& __member,
2045 int __min, int __max, size_t __len,
2046 ios_base& __io, ios_base::iostate& __err) const
2047 {
2048 const locale& __loc = __io._M_getloc();
2049 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2050
2051 // As-is works for __len = 1, 2, 4, the values actually used.
2052 int __mult = __len == 2 ? 10 : (__len == 4 ? 1000 : 1);
2053
2054 ++__min;
2055 size_t __i = 0;
2056 int __value = 0;
2057 for (; __beg != __end && __i < __len; ++__beg, ++__i)
2058 {
2059 const char __c = __ctype.narrow(*__beg, '*');
2060 if (__c >= '0' && __c <= '9')
2061 {
2062 __value = __value * 10 + (__c - '0');
2063 const int __valuec = __value * __mult;
2064 if (__valuec > __max || __valuec + __mult < __min)
2065 break;
2066 __mult /= 10;
2067 }
2068 else
2069 break;
2070 }
2071 if (__i == __len)
2072 __member = __value;
2073 else
2074 __err |= ios_base::failbit;
2075
2076 return __beg;
2077 }
2078
2079 // Assumptions:
2080 // All elements in __names are unique.
2081 template<typename _CharT, typename _InIter>
2082 _InIter
2083 time_get<_CharT, _InIter>::
2084 _M_extract_name(iter_type __beg, iter_type __end, int& __member,
2085 const _CharT** __names, size_t __indexlen,
2086 ios_base& __io, ios_base::iostate& __err) const
2087 {
2088 typedef char_traits<_CharT> __traits_type;
2089 const locale& __loc = __io._M_getloc();
2090 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2091
2092 int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int)
2093 * __indexlen));
2094 size_t __nmatches = 0;
2095 size_t __pos = 0;
2096 bool __testvalid = true;
2097 const char_type* __name;
2098
2099 // Look for initial matches.
2100 // NB: Some of the locale data is in the form of all lowercase
2101 // names, and some is in the form of initially-capitalized
2102 // names. Look for both.
2103 if (__beg != __end)
2104 {
2105 const char_type __c = *__beg;
2106 for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
2107 if (__c == __names[__i1][0]
2108 || __c == __ctype.toupper(__names[__i1][0]))
2109 __matches[__nmatches++] = __i1;
2110 }
2111
2112 while (__nmatches > 1)
2113 {
2114 // Find smallest matching string.
2115 size_t __minlen = __traits_type::length(__names[__matches[0]]);
2116 for (size_t __i2 = 1; __i2 < __nmatches; ++__i2)
2117 __minlen = std::min(__minlen,
2118 __traits_type::length(__names[__matches[__i2]]));
2119 ++__beg, ++__pos;
2120 if (__pos < __minlen && __beg != __end)
2121 for (size_t __i3 = 0; __i3 < __nmatches;)
2122 {
2123 __name = __names[__matches[__i3]];
2124 if (!(__name[__pos] == *__beg))
2125 __matches[__i3] = __matches[--__nmatches];
2126 else
2127 ++__i3;
2128 }
2129 else
2130 break;
2131 }
2132
2133 if (__nmatches == 1)
2134 {
2135 // Make sure found name is completely extracted.
2136 ++__beg, ++__pos;
2137 __name = __names[__matches[0]];
2138 const size_t __len = __traits_type::length(__name);
2139 while (__pos < __len && __beg != __end && __name[__pos] == *__beg)
2140 ++__beg, ++__pos;
2141
2142 if (__len == __pos)
2143 __member = __matches[0];
2144 else
2145 __testvalid = false;
2146 }
2147 else
2148 __testvalid = false;
2149 if (!__testvalid)
2150 __err |= ios_base::failbit;
2151
2152 return __beg;
2153 }
2154
2155 template<typename _CharT, typename _InIter>
2156 _InIter
2157 time_get<_CharT, _InIter>::
2158 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
2159 ios_base::iostate& __err, tm* __tm) const
2160 {
2161 const locale& __loc = __io._M_getloc();
2162 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2163 const char_type* __times[2];
2164 __tp._M_time_formats(__times);
2165 __beg = _M_extract_via_format(__beg, __end, __io, __err,
2166 __tm, __times[0]);
2167 if (__beg == __end)
2168 __err |= ios_base::eofbit;
2169 return __beg;
2170 }
2171
2172 template<typename _CharT, typename _InIter>
2173 _InIter
2174 time_get<_CharT, _InIter>::
2175 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
2176 ios_base::iostate& __err, tm* __tm) const
2177 {
2178 const locale& __loc = __io._M_getloc();
2179 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2180 const char_type* __dates[2];
2181 __tp._M_date_formats(__dates);
2182 __beg = _M_extract_via_format(__beg, __end, __io, __err,
2183 __tm, __dates[0]);
2184 if (__beg == __end)
2185 __err |= ios_base::eofbit;
2186 return __beg;
2187 }
2188
2189 template<typename _CharT, typename _InIter>
2190 _InIter
2191 time_get<_CharT, _InIter>::
2192 do_get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
2193 ios_base::iostate& __err, tm* __tm) const
2194 {
2195 typedef char_traits<_CharT> __traits_type;
2196 const locale& __loc = __io._M_getloc();
2197 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2198 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2199 const char_type* __days[7];
2200 __tp._M_days_abbreviated(__days);
2201 int __tmpwday;
2202 ios_base::iostate __tmperr = ios_base::goodbit;
2203 __beg = _M_extract_name(__beg, __end, __tmpwday, __days, 7,
2204 __io, __tmperr);
2205
2206 // Check to see if non-abbreviated name exists, and extract.
2207 // NB: Assumes both _M_days and _M_days_abbreviated organized in
2208 // exact same order, first to last, such that the resulting
2209 // __days array with the same index points to a day, and that
2210 // day's abbreviated form.
2211 // NB: Also assumes that an abbreviated name is a subset of the name.
2212 if (!__tmperr && __beg != __end)
2213 {
2214 size_t __pos = __traits_type::length(__days[__tmpwday]);
2215 __tp._M_days(__days);
2216 const char_type* __name = __days[__tmpwday];
2217 if (__name[__pos] == *__beg)
2218 {
2219 // Extract the rest of it.
2220 const size_t __len = __traits_type::length(__name);
2221 while (__pos < __len && __beg != __end
2222 && __name[__pos] == *__beg)
2223 ++__beg, ++__pos;
2224 if (__len != __pos)
2225 __tmperr |= ios_base::failbit;
2226 }
2227 }
2228 if (!__tmperr)
2229 __tm->tm_wday = __tmpwday;
2230 else
2231 __err |= ios_base::failbit;
2232
2233 if (__beg == __end)
2234 __err |= ios_base::eofbit;
2235 return __beg;
2236 }
2237
2238 template<typename _CharT, typename _InIter>
2239 _InIter
2240 time_get<_CharT, _InIter>::
2241 do_get_monthname(iter_type __beg, iter_type __end,
2242 ios_base& __io, ios_base::iostate& __err, tm* __tm) const
2243 {
2244 typedef char_traits<_CharT> __traits_type;
2245 const locale& __loc = __io._M_getloc();
2246 const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2247 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2248 const char_type* __months[12];
2249 __tp._M_months_abbreviated(__months);
2250 int __tmpmon;
2251 ios_base::iostate __tmperr = ios_base::goodbit;
2252 __beg = _M_extract_name(__beg, __end, __tmpmon, __months, 12,
2253 __io, __tmperr);
2254
2255 // Check to see if non-abbreviated name exists, and extract.
2256 // NB: Assumes both _M_months and _M_months_abbreviated organized in
2257 // exact same order, first to last, such that the resulting
2258 // __months array with the same index points to a month, and that
2259 // month's abbreviated form.
2260 // NB: Also assumes that an abbreviated name is a subset of the name.
2261 if (!__tmperr && __beg != __end)
2262 {
2263 size_t __pos = __traits_type::length(__months[__tmpmon]);
2264 __tp._M_months(__months);
2265 const char_type* __name = __months[__tmpmon];
2266 if (__name[__pos] == *__beg)
2267 {
2268 // Extract the rest of it.
2269 const size_t __len = __traits_type::length(__name);
2270 while (__pos < __len && __beg != __end
2271 && __name[__pos] == *__beg)
2272 ++__beg, ++__pos;
2273 if (__len != __pos)
2274 __tmperr |= ios_base::failbit;
2275 }
2276 }
2277 if (!__tmperr)
2278 __tm->tm_mon = __tmpmon;
2279 else
2280 __err |= ios_base::failbit;
2281
2282 if (__beg == __end)
2283 __err |= ios_base::eofbit;
2284 return __beg;
2285 }
2286
2287 template<typename _CharT, typename _InIter>
2288 _InIter
2289 time_get<_CharT, _InIter>::
2290 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
2291 ios_base::iostate& __err, tm* __tm) const
2292 {
2293 const locale& __loc = __io._M_getloc();
2294 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2295
2296 size_t __i = 0;
2297 int __value = 0;
2298 for (; __beg != __end && __i < 4; ++__beg, ++__i)
2299 {
2300 const char __c = __ctype.narrow(*__beg, '*');
2301 if (__c >= '0' && __c <= '9')
2302 __value = __value * 10 + (__c - '0');
2303 else
2304 break;
2305 }
2306 if (__i == 2 || __i == 4)
2307 __tm->tm_year = __i == 2 ? __value : __value - 1900;
2308 else
2309 __err |= ios_base::failbit;
2310
2311 if (__beg == __end)
2312 __err |= ios_base::eofbit;
2313 return __beg;
2314 }
2315
2316 template<typename _CharT, typename _OutIter>
2317 _OutIter
2318 time_put<_CharT, _OutIter>::
2319 put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
2320 const _CharT* __beg, const _CharT* __end) const
2321 {
2322 const locale& __loc = __io._M_getloc();
2323 ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
2324 for (; __beg != __end; ++__beg)
2325 if (__ctype.narrow(*__beg, 0) != '%')
2326 {
2327 *__s = *__beg;
2328 ++__s;
2329 }
2330 else if (++__beg != __end)
2331 {
2332 char __format;
2333 char __mod = 0;
2334 const char __c = __ctype.narrow(*__beg, 0);
2335 if (__c != 'E' && __c != 'O')
2336 __format = __c;
2337 else if (++__beg != __end)
2338 {
2339 __mod = __c;
2340 __format = __ctype.narrow(*__beg, 0);
2341 }
2342 else
2343 break;
2344 __s = this->do_put(__s, __io, __fill, __tm, __format, __mod);
2345 }
2346 else
2347 break;
2348 return __s;
2349 }
2350
2351 template<typename _CharT, typename _OutIter>
2352 _OutIter
2353 time_put<_CharT, _OutIter>::
2354 do_put(iter_type __s, ios_base& __io, char_type, const tm* __tm,
2355 char __format, char __mod) const
2356 {
2357 const locale& __loc = __io._M_getloc();
2358 ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
2359 __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
2360
2361 // NB: This size is arbitrary. Should this be a data member,
2362 // initialized at construction?
2363 const size_t __maxlen = 128;
2364 char_type* __res =
2365 static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen));
2366
2367 // NB: In IEE 1003.1-200x, and perhaps other locale models, it
2368 // is possible that the format character will be longer than one
2369 // character. Possibilities include 'E' or 'O' followed by a
2370 // format character: if __mod is not the default argument, assume
2371 // it's a valid modifier.
2372 char_type __fmt[4];
2373 __fmt[0] = __ctype.widen('%');
2374 if (!__mod)
2375 {
2376 __fmt[1] = __format;
2377 __fmt[2] = char_type();
2378 }
2379 else
2380 {
2381 __fmt[1] = __mod;
2382 __fmt[2] = __format;
2383 __fmt[3] = char_type();
2384 }
2385
2386 __tp._M_put(__res, __maxlen, __fmt, __tm);
2387
2388 // Write resulting, fully-formatted string to output iterator.
2389 return std::__write(__s, __res, char_traits<char_type>::length(__res));
2390 }
2391
2392 // Generic version does nothing.
2393 template<typename _CharT>
2394 int
2395 collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const
2396 { return 0; }
2397
2398 // Generic version does nothing.
2399 template<typename _CharT>
2400 size_t
2401 collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const
2402 { return 0; }
2403
2404 template<typename _CharT>
2405 int
2406 collate<_CharT>::
2407 do_compare(const _CharT* __lo1, const _CharT* __hi1,
2408 const _CharT* __lo2, const _CharT* __hi2) const
2409 {
2410 // strcoll assumes zero-terminated strings so we make a copy
2411 // and then put a zero at the end.
2412 const string_type __one(__lo1, __hi1);
2413 const string_type __two(__lo2, __hi2);
2414
2415 const _CharT* __p = __one.c_str();
2416 const _CharT* __pend = __one.data() + __one.length();
2417 const _CharT* __q = __two.c_str();
2418 const _CharT* __qend = __two.data() + __two.length();
2419
2420 // strcoll stops when it sees a nul character so we break
2421 // the strings into zero-terminated substrings and pass those
2422 // to strcoll.
2423 for (;;)
2424 {
2425 const int __res = _M_compare(__p, __q);
2426 if (__res)
2427 return __res;
2428
2429 __p += char_traits<_CharT>::length(__p);
2430 __q += char_traits<_CharT>::length(__q);
2431 if (__p == __pend && __q == __qend)
2432 return 0;
2433 else if (__p == __pend)
2434 return -1;
2435 else if (__q == __qend)
2436 return 1;
2437
2438 __p++;
2439 __q++;
2440 }
2441 }
2442
2443 template<typename _CharT>
2444 typename collate<_CharT>::string_type
2445 collate<_CharT>::
2446 do_transform(const _CharT* __lo, const _CharT* __hi) const
2447 {
2448 string_type __ret;
2449
2450 // strxfrm assumes zero-terminated strings so we make a copy
2451 const string_type __str(__lo, __hi);
2452
2453 const _CharT* __p = __str.c_str();
2454 const _CharT* __pend = __str.data() + __str.length();
2455
2456 size_t __len = (__hi - __lo) * 2;
2457
2458 _CharT* __c = new _CharT[__len];
2459
2460 try
2461 {
2462 // strxfrm stops when it sees a nul character so we break
2463 // the string into zero-terminated substrings and pass those
2464 // to strxfrm.
2465 for (;;)
2466 {
2467 // First try a buffer perhaps big enough.
2468 size_t __res = _M_transform(__c, __p, __len);
2469 // If the buffer was not large enough, try again with the
2470 // correct size.
2471 if (__res >= __len)
2472 {
2473 __len = __res + 1;
2474 delete [] __c, __c = 0;
2475 __c = new _CharT[__len];
2476 __res = _M_transform(__c, __p, __len);
2477 }
2478
2479 __ret.append(__c, __res);
2480 __p += char_traits<_CharT>::length(__p);
2481 if (__p == __pend)
2482 break;
2483
2484 __p++;
2485 __ret.push_back(_CharT());
2486 }
2487 }
2488 catch(...)
2489 {
2490 delete [] __c;
2491 __throw_exception_again;
2492 }
2493
2494 delete [] __c;
2495
2496 return __ret;
2497 }
2498
2499 template<typename _CharT>
2500 long
2501 collate<_CharT>::
2502 do_hash(const _CharT* __lo, const _CharT* __hi) const
2503 {
2504 unsigned long __val = 0;
2505 for (; __lo < __hi; ++__lo)
2506 __val =
2507 *__lo + ((__val << 7)
2508 | (__val >> (__gnu_cxx::__numeric_traits<unsigned long>::
2509 __digits - 7)));
2510 return static_cast<long>(__val);
2511 }
2512
2513 // Construct correctly padded string, as per 22.2.2.2.2
2514 // Assumes
2515 // __newlen > __oldlen
2516 // __news is allocated for __newlen size
2517
2518 // NB: Of the two parameters, _CharT can be deduced from the
2519 // function arguments. The other (_Traits) has to be explicitly specified.
2520 template<typename _CharT, typename _Traits>
2521 void
2522 __pad<_CharT, _Traits>::_S_pad(ios_base& __io, _CharT __fill,
2523 _CharT* __news, const _CharT* __olds,
2524 const streamsize __newlen,
2525 const streamsize __oldlen)
2526 {
2527 const size_t __plen = static_cast<size_t>(__newlen - __oldlen);
2528 const ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield;
2529
2530 // Padding last.
2531 if (__adjust == ios_base::left)
2532 {
2533 _Traits::copy(__news, const_cast<_CharT*>(__olds), __oldlen);
2534 _Traits::assign(__news + __oldlen, __plen, __fill);
2535 return;
2536 }
2537
2538 size_t __mod = 0;
2539 if (__adjust == ios_base::internal)
2540 {
2541 // Pad after the sign, if there is one.
2542 // Pad after 0[xX], if there is one.
2543 // Who came up with these rules, anyway? Jeeze.
2544 const locale& __loc = __io._M_getloc();
2545 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2546
2547 const bool __testsign = (__ctype.widen('-') == __olds[0]
2548 || __ctype.widen('+') == __olds[0]);
2549 const bool __testhex = (__ctype.widen('0') == __olds[0]
2550 && __oldlen > 1
2551 && (__ctype.widen('x') == __olds[1]
2552 || __ctype.widen('X') == __olds[1]));
2553 if (__testhex)
2554 {
2555 __news[0] = __olds[0];
2556 __news[1] = __olds[1];
2557 __mod = 2;
2558 __news += 2;
2559 }
2560 else if (__testsign)
2561 {
2562 __news[0] = __olds[0];
2563 __mod = 1;
2564 ++__news;
2565 }
2566 // else Padding first.
2567 }
2568 _Traits::assign(__news, __plen, __fill);
2569 _Traits::copy(__news + __plen, const_cast<_CharT*>(__olds + __mod),
2570 __oldlen - __mod);
2571 }
2572
2573 bool
2574 __verify_grouping(const char* __grouping, size_t __grouping_size,
2575 const string& __grouping_tmp)
2576 {
2577 const size_t __n = __grouping_tmp.size() - 1;
2578 const size_t __min = std::min(__n, size_t(__grouping_size - 1));
2579 size_t __i = __n;
2580 bool __test = true;
2581
2582 // Parsed number groupings have to match the
2583 // numpunct::grouping string exactly, starting at the
2584 // right-most point of the parsed sequence of elements ...
2585 for (size_t __j = 0; __j < __min && __test; --__i, ++__j)
2586 __test = __grouping_tmp[__i] == __grouping[__j];
2587 for (; __i && __test; --__i)
2588 __test = __grouping_tmp[__i] == __grouping[__min];
2589 // ... but the first parsed grouping can be <= numpunct
2590 // grouping (only do the check if the numpunct char is > 0
2591 // because <= 0 means any size is ok).
2592 if (static_cast<signed char>(__grouping[__min]) > 0)
2593 __test &= __grouping_tmp[0] <= __grouping[__min];
2594 return __test;
2595 }
2596
2597 template<typename _CharT>
2598 _CharT*
2599 __add_grouping(_CharT* __s, _CharT __sep,
2600 const char* __gbeg, size_t __gsize,
2601 const _CharT* __first, const _CharT* __last)
2602 {
2603 size_t __idx = 0;
2604 size_t __ctr = 0;
2605
2606 while (__last - __first > __gbeg[__idx]
2607 && static_cast<signed char>(__gbeg[__idx]) > 0)
2608 {
2609 __last -= __gbeg[__idx];
2610 __idx < __gsize - 1 ? ++__idx : ++__ctr;
2611 }
2612
2613 while (__first != __last)
2614 *__s++ = *__first++;
2615
2616 while (__ctr--)
2617 {
2618 *__s++ = __sep;
2619 for (char __i = __gbeg[__idx]; __i > 0; --__i)
2620 *__s++ = *__first++;
2621 }
2622
2623 while (__idx--)
2624 {
2625 *__s++ = __sep;
2626 for (char __i = __gbeg[__idx]; __i > 0; --__i)
2627 *__s++ = *__first++;
2628 }
2629
2630 return __s;
2631 }
2632
2633 // Inhibit implicit instantiations for required instantiations,
2634 // which are defined via explicit instantiations elsewhere.
2635 // NB: This syntax is a GNU extension.
2636 #if _GLIBCXX_EXTERN_TEMPLATE
2637 extern template class moneypunct<char, false>;
2638 extern template class moneypunct<char, true>;
2639 extern template class moneypunct_byname<char, false>;
2640 extern template class moneypunct_byname<char, true>;
2641 extern template class _GLIBCXX_LDBL_NAMESPACE money_get<char>;
2642 extern template class _GLIBCXX_LDBL_NAMESPACE money_put<char>;
2643 extern template class numpunct<char>;
2644 extern template class numpunct_byname<char>;
2645 extern template class _GLIBCXX_LDBL_NAMESPACE num_get<char>;
2646 extern template class _GLIBCXX_LDBL_NAMESPACE num_put<char>;
2647 extern template class __timepunct<char>;
2648 extern template class time_put<char>;
2649 extern template class time_put_byname<char>;
2650 extern template class time_get<char>;
2651 extern template class time_get_byname<char>;
2652 extern template class messages<char>;
2653 extern template class messages_byname<char>;
2654 extern template class ctype_byname<char>;
2655 extern template class codecvt_byname<char, char, mbstate_t>;
2656 extern template class collate<char>;
2657 extern template class collate_byname<char>;
2658
2659 extern template
2660 const codecvt<char, char, mbstate_t>&
2661 use_facet<codecvt<char, char, mbstate_t> >(const locale&);
2662
2663 extern template
2664 const collate<char>&
2665 use_facet<collate<char> >(const locale&);
2666
2667 extern template
2668 const numpunct<char>&
2669 use_facet<numpunct<char> >(const locale&);
2670
2671 extern template
2672 const num_put<char>&
2673 use_facet<num_put<char> >(const locale&);
2674
2675 extern template
2676 const num_get<char>&
2677 use_facet<num_get<char> >(const locale&);
2678
2679 extern template
2680 const moneypunct<char, true>&
2681 use_facet<moneypunct<char, true> >(const locale&);
2682
2683 extern template
2684 const moneypunct<char, false>&
2685 use_facet<moneypunct<char, false> >(const locale&);
2686
2687 extern template
2688 const money_put<char>&
2689 use_facet<money_put<char> >(const locale&);
2690
2691 extern template
2692 const money_get<char>&
2693 use_facet<money_get<char> >(const locale&);
2694
2695 extern template
2696 const __timepunct<char>&
2697 use_facet<__timepunct<char> >(const locale&);
2698
2699 extern template
2700 const time_put<char>&
2701 use_facet<time_put<char> >(const locale&);
2702
2703 extern template
2704 const time_get<char>&
2705 use_facet<time_get<char> >(const locale&);
2706
2707 extern template
2708 const messages<char>&
2709 use_facet<messages<char> >(const locale&);
2710
2711 extern template
2712 bool
2713 has_facet<ctype<char> >(const locale&);
2714
2715 extern template
2716 bool
2717 has_facet<codecvt<char, char, mbstate_t> >(const locale&);
2718
2719 extern template
2720 bool
2721 has_facet<collate<char> >(const locale&);
2722
2723 extern template
2724 bool
2725 has_facet<numpunct<char> >(const locale&);
2726
2727 extern template
2728 bool
2729 has_facet<num_put<char> >(const locale&);
2730
2731 extern template
2732 bool
2733 has_facet<num_get<char> >(const locale&);
2734
2735 extern template
2736 bool
2737 has_facet<moneypunct<char> >(const locale&);
2738
2739 extern template
2740 bool
2741 has_facet<money_put<char> >(const locale&);
2742
2743 extern template
2744 bool
2745 has_facet<money_get<char> >(const locale&);
2746
2747 extern template
2748 bool
2749 has_facet<__timepunct<char> >(const locale&);
2750
2751 extern template
2752 bool
2753 has_facet<time_put<char> >(const locale&);
2754
2755 extern template
2756 bool
2757 has_facet<time_get<char> >(const locale&);
2758
2759 extern template
2760 bool
2761 has_facet<messages<char> >(const locale&);
2762
2763 #ifdef _GLIBCXX_USE_WCHAR_T
2764 extern template class moneypunct<wchar_t, false>;
2765 extern template class moneypunct<wchar_t, true>;
2766 extern template class moneypunct_byname<wchar_t, false>;
2767 extern template class moneypunct_byname<wchar_t, true>;
2768 extern template class _GLIBCXX_LDBL_NAMESPACE money_get<wchar_t>;
2769 extern template class _GLIBCXX_LDBL_NAMESPACE money_put<wchar_t>;
2770 extern template class numpunct<wchar_t>;
2771 extern template class numpunct_byname<wchar_t>;
2772 extern template class _GLIBCXX_LDBL_NAMESPACE num_get<wchar_t>;
2773 extern template class _GLIBCXX_LDBL_NAMESPACE num_put<wchar_t>;
2774 extern template class __timepunct<wchar_t>;
2775 extern template class time_put<wchar_t>;
2776 extern template class time_put_byname<wchar_t>;
2777 extern template class time_get<wchar_t>;
2778 extern template class time_get_byname<wchar_t>;
2779 extern template class messages<wchar_t>;
2780 extern template class messages_byname<wchar_t>;
2781 extern template class ctype_byname<wchar_t>;
2782 extern template class codecvt_byname<wchar_t, char, mbstate_t>;
2783 extern template class collate<wchar_t>;
2784 extern template class collate_byname<wchar_t>;
2785
2786 extern template
2787 const codecvt<wchar_t, char, mbstate_t>&
2788 use_facet<codecvt<wchar_t, char, mbstate_t> >(locale const&);
2789
2790 extern template
2791 const collate<wchar_t>&
2792 use_facet<collate<wchar_t> >(const locale&);
2793
2794 extern template
2795 const numpunct<wchar_t>&
2796 use_facet<numpunct<wchar_t> >(const locale&);
2797
2798 extern template
2799 const num_put<wchar_t>&
2800 use_facet<num_put<wchar_t> >(const locale&);
2801
2802 extern template
2803 const num_get<wchar_t>&
2804 use_facet<num_get<wchar_t> >(const locale&);
2805
2806 extern template
2807 const moneypunct<wchar_t, true>&
2808 use_facet<moneypunct<wchar_t, true> >(const locale&);
2809
2810 extern template
2811 const moneypunct<wchar_t, false>&
2812 use_facet<moneypunct<wchar_t, false> >(const locale&);
2813
2814 extern template
2815 const money_put<wchar_t>&
2816 use_facet<money_put<wchar_t> >(const locale&);
2817
2818 extern template
2819 const money_get<wchar_t>&
2820 use_facet<money_get<wchar_t> >(const locale&);
2821
2822 extern template
2823 const __timepunct<wchar_t>&
2824 use_facet<__timepunct<wchar_t> >(const locale&);
2825
2826 extern template
2827 const time_put<wchar_t>&
2828 use_facet<time_put<wchar_t> >(const locale&);
2829
2830 extern template
2831 const time_get<wchar_t>&
2832 use_facet<time_get<wchar_t> >(const locale&);
2833
2834 extern template
2835 const messages<wchar_t>&
2836 use_facet<messages<wchar_t> >(const locale&);
2837
2838 extern template
2839 bool
2840 has_facet<ctype<wchar_t> >(const locale&);
2841
2842 extern template
2843 bool
2844 has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
2845
2846 extern template
2847 bool
2848 has_facet<collate<wchar_t> >(const locale&);
2849
2850 extern template
2851 bool
2852 has_facet<numpunct<wchar_t> >(const locale&);
2853
2854 extern template
2855 bool
2856 has_facet<num_put<wchar_t> >(const locale&);
2857
2858 extern template
2859 bool
2860 has_facet<num_get<wchar_t> >(const locale&);
2861
2862 extern template
2863 bool
2864 has_facet<moneypunct<wchar_t> >(const locale&);
2865
2866 extern template
2867 bool
2868 has_facet<money_put<wchar_t> >(const locale&);
2869
2870 extern template
2871 bool
2872 has_facet<money_get<wchar_t> >(const locale&);
2873
2874 extern template
2875 bool
2876 has_facet<__timepunct<wchar_t> >(const locale&);
2877
2878 extern template
2879 bool
2880 has_facet<time_put<wchar_t> >(const locale&);
2881
2882 extern template
2883 bool
2884 has_facet<time_get<wchar_t> >(const locale&);
2885
2886 extern template
2887 bool
2888 has_facet<messages<wchar_t> >(const locale&);
2889 #endif
2890 #endif
2891
2892 _GLIBCXX_END_NAMESPACE
2893
2894 #endif