00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _CPP_BITS_LOCFACETS_TCC
00034 #define _CPP_BITS_LOCFACETS_TCC 1
00035
00036 #pragma GCC system_header
00037
00038 #include <cerrno>
00039 #include <clocale>
00040 #include <cstdlib>
00041 #include <cmath>
00042 #include <cctype>
00043 #include <limits>
00044 #include <typeinfo>
00045 #include <bits/streambuf_iterator.h>
00046
00047 namespace std
00048 {
00049 template<typename _Facet>
00050 locale
00051 locale::combine(const locale& __other) const
00052 {
00053 _Impl* __tmp = new _Impl(*_M_impl, 1);
00054 try
00055 {
00056 __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
00057 }
00058 catch(...)
00059 {
00060 __tmp->_M_remove_reference();
00061 __throw_exception_again;
00062 }
00063 return locale(__tmp);
00064 }
00065
00066 template<typename _CharT, typename _Traits, typename _Alloc>
00067 bool
00068 locale::operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1,
00069 const basic_string<_CharT, _Traits, _Alloc>& __s2) const
00070 {
00071 typedef std::collate<_CharT> __collate_type;
00072 const __collate_type& __collate = use_facet<__collate_type>(*this);
00073 return (__collate.compare(__s1.data(), __s1.data() + __s1.length(),
00074 __s2.data(), __s2.data() + __s2.length()) < 0);
00075 }
00076
00077 template<typename _Facet>
00078 const _Facet&
00079 use_facet(const locale& __loc)
00080 {
00081 size_t __i = _Facet::id._M_id();
00082 locale::facet** __facets = __loc._M_impl->_M_facets;
00083 if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
00084 __throw_bad_cast();
00085 return static_cast<const _Facet&>(*__facets[__i]);
00086 }
00087
00088 template<typename _Facet>
00089 bool
00090 has_facet(const locale& __loc) throw()
00091 {
00092 size_t __i = _Facet::id._M_id();
00093 locale::facet** __facets = __loc._M_impl->_M_facets;
00094 return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
00095 }
00096
00097
00098
00099 template<typename _Facet>
00100 inline const __locale_cache<_Facet>&
00101 __use_cache(const locale& __loc)
00102 {
00103 size_t __i = _Facet::id._M_id();
00104 if (__builtin_expect(__i >= __loc._M_impl->_M_facets_size,false))
00105 __throw_bad_cast();
00106 __locale_cache_base* __cache = __loc._M_impl->_M_get_cache(__i);
00107 if (__builtin_expect(!__cache, false))
00108 {
00109 __cache = new __locale_cache<_Facet>(__loc);
00110 __loc._M_impl->_M_install_cache(__cache, __i);
00111 }
00112 return static_cast<const __locale_cache<_Facet>&>(*__cache);
00113 }
00114
00115
00116 template<typename _CharT, typename _InIter>
00117 _InIter
00118 num_get<_CharT, _InIter>::
00119 _M_extract_float(_InIter __beg, _InIter __end, ios_base& __io,
00120 ios_base::iostate& __err, string& __xtrc) const
00121 {
00122 typedef char_traits<_CharT> __traits_type;
00123 const locale __loc = __io.getloc();
00124 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
00125 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
00126
00127
00128 const char_type __plus = __ctype.widen('+');
00129 const char_type __minus = __ctype.widen('-');
00130 int __pos = 0;
00131 char_type __c = *__beg;
00132 if ((__traits_type::eq(__c, __plus) || __traits_type::eq(__c, __minus))
00133 && __beg != __end)
00134 {
00135 __xtrc += __ctype.narrow(__c, char());
00136 ++__pos;
00137 __c = *(++__beg);
00138 }
00139
00140
00141 const char_type __zero = __ctype.widen(_S_atoms_in[_M_zero]);
00142 bool __found_zero = false;
00143 while (__traits_type::eq(__c, __zero) && __beg != __end)
00144 {
00145 __c = *(++__beg);
00146 __found_zero = true;
00147 }
00148 if (__found_zero)
00149 {
00150 __xtrc += _S_atoms_in[_M_zero];
00151 ++__pos;
00152 }
00153
00154
00155 const size_t __len = _M_E - _M_zero + 1;
00156 char_type __watoms[__len];
00157 __ctype.widen(_S_atoms_in, _S_atoms_in + __len, __watoms);
00158 bool __found_dec = false;
00159 bool __found_sci = false;
00160 const char_type __dec = __np.decimal_point();
00161
00162 string __found_grouping;
00163 const string __grouping = __np.grouping();
00164 bool __check_grouping = __grouping.size();
00165 int __sep_pos = 0;
00166 const char_type __sep = __np.thousands_sep();
00167
00168 while (__beg != __end)
00169 {
00170
00171 const char_type* __p = __traits_type::find(__watoms, 10, __c);
00172 if (__p)
00173 {
00174
00175 ++__pos;
00176 __xtrc += _S_atoms_in[__p - __watoms];
00177 ++__sep_pos;
00178 __c = *(++__beg);
00179 }
00180 else if (__traits_type::eq(__c, __sep)
00181 && __check_grouping && !__found_dec)
00182 {
00183
00184
00185 if (__sep_pos)
00186 {
00187 __found_grouping += static_cast<char>(__sep_pos);
00188 __sep_pos = 0;
00189 __c = *(++__beg);
00190 }
00191 else
00192 {
00193 __err |= ios_base::failbit;
00194 break;
00195 }
00196 }
00197 else if (__traits_type::eq(__c, __dec) && !__found_dec)
00198 {
00199
00200
00201
00202 if (__found_grouping.size())
00203 __found_grouping += static_cast<char>(__sep_pos);
00204 ++__pos;
00205 __xtrc += '.';
00206 __c = *(++__beg);
00207 __found_dec = true;
00208 }
00209 else if ((__traits_type::eq(__c, __watoms[_M_e])
00210 || __traits_type::eq(__c, __watoms[_M_E]))
00211 && !__found_sci && __pos)
00212 {
00213
00214 ++__pos;
00215 __xtrc += __ctype.narrow(__c, char());
00216 __c = *(++__beg);
00217
00218
00219 if (__traits_type::eq(__c, __plus)
00220 || __traits_type::eq(__c, __minus))
00221 {
00222 ++__pos;
00223 __xtrc += __ctype.narrow(__c, char());
00224 __c = *(++__beg);
00225 }
00226 __found_sci = true;
00227 }
00228 else
00229
00230 break;
00231 }
00232
00233
00234
00235 if (__check_grouping && __found_grouping.size())
00236 {
00237
00238 if (!__found_dec)
00239 __found_grouping += static_cast<char>(__sep_pos);
00240 if (!__verify_grouping(__grouping, __found_grouping))
00241 __err |= ios_base::failbit;
00242 }
00243
00244
00245 __xtrc += char();
00246 if (__beg == __end)
00247 __err |= ios_base::eofbit;
00248 return __beg;
00249 }
00250
00251
00252 template<typename _CharT, typename _InIter>
00253 _InIter
00254 num_get<_CharT, _InIter>::
00255 _M_extract_int(_InIter __beg, _InIter __end, ios_base& __io,
00256 ios_base::iostate& __err, string& __xtrc, int& __base) const
00257 {
00258 typedef char_traits<_CharT> __traits_type;
00259 const locale __loc = __io.getloc();
00260 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
00261 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
00262
00263
00264 ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
00265 if (__basefield == ios_base::oct)
00266 __base = 8;
00267 else if (__basefield == ios_base::hex)
00268 __base = 16;
00269 else
00270 __base = 10;
00271
00272
00273 int __pos = 0;
00274 char_type __c = *__beg;
00275 const char_type __plus = __ctype.widen('+');
00276 const char_type __minus = __ctype.widen('-');
00277
00278 if ((__traits_type::eq(__c, __plus) || __traits_type::eq(__c, __minus))
00279 && __beg != __end)
00280 {
00281 __xtrc += __ctype.narrow(__c, char());
00282 ++__pos;
00283 __c = *(++__beg);
00284 }
00285
00286
00287 const char_type __zero = __ctype.widen(_S_atoms_in[_M_zero]);
00288 const char_type __x = __ctype.widen('x');
00289 const char_type __X = __ctype.widen('X');
00290 if (__base == 10)
00291 {
00292 bool __found_zero = false;
00293 while (__traits_type::eq(__c, __zero) && __beg != __end)
00294 {
00295 __c = *(++__beg);
00296 __found_zero = true;
00297 }
00298 if (__found_zero)
00299 {
00300 __xtrc += _S_atoms_in[_M_zero];
00301 ++__pos;
00302 if (__basefield == 0)
00303 {
00304 if ((__traits_type::eq(__c, __x)
00305 || __traits_type::eq(__c, __X))
00306 && __beg != __end)
00307 {
00308 __xtrc += __ctype.narrow(__c, char());
00309 ++__pos;
00310 __c = *(++__beg);
00311 __base = 16;
00312 }
00313 else
00314 __base = 8;
00315 }
00316 }
00317 }
00318 else if (__base == 16)
00319 {
00320 if (__traits_type::eq(__c, __zero) && __beg != __end)
00321 {
00322 __xtrc += _S_atoms_in[_M_zero];
00323 ++__pos;
00324 __c = *(++__beg);
00325 if ((__traits_type::eq(__c, __x) || __traits_type::eq(__c, __X))
00326 && __beg != __end)
00327 {
00328 __xtrc += __ctype.narrow(__c, char());
00329 ++__pos;
00330 __c = *(++__beg);
00331 }
00332 }
00333 }
00334
00335
00336
00337 size_t __len;
00338 if (__base == 16)
00339 __len = _M_size;
00340 else
00341 __len = __base;
00342
00343
00344 char_type __watoms[_M_size];
00345 __ctype.widen(_S_atoms_in, _S_atoms_in + __len, __watoms);
00346 string __found_grouping;
00347 const string __grouping = __np.grouping();
00348 bool __check_grouping = __grouping.size();
00349 int __sep_pos = 0;
00350 const char_type __sep = __np.thousands_sep();
00351 while (__beg != __end)
00352 {
00353 const char_type* __p = __traits_type::find(__watoms, __len, __c);
00354 if (__p)
00355 {
00356
00357 __xtrc += _S_atoms_in[__p - __watoms];
00358 ++__pos;
00359 ++__sep_pos;
00360 __c = *(++__beg);
00361 }
00362 else if (__traits_type::eq(__c, __sep) && __check_grouping)
00363 {
00364
00365
00366 if (__sep_pos)
00367 {
00368 __found_grouping += static_cast<char>(__sep_pos);
00369 __sep_pos = 0;
00370 __c = *(++__beg);
00371 }
00372 else
00373 {
00374 __err |= ios_base::failbit;
00375 break;
00376 }
00377 }
00378 else
00379
00380 break;
00381 }
00382
00383
00384
00385 if (__check_grouping && __found_grouping.size())
00386 {
00387
00388 __found_grouping += static_cast<char>(__sep_pos);
00389 if (!__verify_grouping(__grouping, __found_grouping))
00390 __err |= ios_base::failbit;
00391 }
00392
00393
00394 __xtrc += char();
00395 if (__beg == __end)
00396 __err |= ios_base::eofbit;
00397 return __beg;
00398 }
00399
00400 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00401
00402 template<typename _CharT, typename _InIter>
00403 _InIter
00404 num_get<_CharT, _InIter>::
00405 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00406 ios_base::iostate& __err, bool& __v) const
00407 {
00408
00409 if (!(__io.flags() & ios_base::boolalpha))
00410 {
00411
00412
00413 string __xtrc;
00414 int __base;
00415 __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
00416
00417 unsigned long __ul;
00418 __convert_to_v(__xtrc.c_str(), __ul, __err, _S_c_locale, __base);
00419 if (!(__err & ios_base::failbit) && __ul <= 1)
00420 __v = __ul;
00421 else
00422 __err |= ios_base::failbit;
00423 }
00424
00425
00426 else
00427 {
00428 typedef char_traits<_CharT> __traits_type;
00429 typedef basic_string<_CharT> __string_type;
00430
00431 locale __loc = __io.getloc();
00432 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
00433 const __string_type __true = __np.truename();
00434 const __string_type __false = __np.falsename();
00435 const char_type* __trues = __true.c_str();
00436 const char_type* __falses = __false.c_str();
00437 const size_t __truen = __true.size() - 1;
00438 const size_t __falsen = __false.size() - 1;
00439
00440 for (size_t __n = 0; __beg != __end; ++__n)
00441 {
00442 char_type __c = *__beg++;
00443 bool __testf = __n <= __falsen
00444 ? __traits_type::eq(__c, __falses[__n]) : false;
00445 bool __testt = __n <= __truen
00446 ? __traits_type::eq(__c, __trues[__n]) : false;
00447 if (!(__testf || __testt))
00448 {
00449 __err |= ios_base::failbit;
00450 break;
00451 }
00452 else if (__testf && __n == __falsen)
00453 {
00454 __v = 0;
00455 break;
00456 }
00457 else if (__testt && __n == __truen)
00458 {
00459 __v = 1;
00460 break;
00461 }
00462 }
00463 if (__beg == __end)
00464 __err |= ios_base::eofbit;
00465 }
00466 return __beg;
00467 }
00468 #endif
00469
00470 template<typename _CharT, typename _InIter>
00471 _InIter
00472 num_get<_CharT, _InIter>::
00473 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00474 ios_base::iostate& __err, long& __v) const
00475 {
00476 string __xtrc;
00477 __xtrc.reserve(32);
00478 int __base;
00479 __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
00480 __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale, __base);
00481 return __beg;
00482 }
00483
00484 template<typename _CharT, typename _InIter>
00485 _InIter
00486 num_get<_CharT, _InIter>::
00487 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00488 ios_base::iostate& __err, unsigned short& __v) const
00489 {
00490 string __xtrc;
00491 __xtrc.reserve(32);
00492 int __base;
00493 __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
00494 unsigned long __ul;
00495 __convert_to_v(__xtrc.c_str(), __ul, __err, _S_c_locale, __base);
00496 if (!(__err & ios_base::failbit)
00497 && __ul <= numeric_limits<unsigned short>::max())
00498 __v = static_cast<unsigned short>(__ul);
00499 else
00500 __err |= ios_base::failbit;
00501 return __beg;
00502 }
00503
00504 template<typename _CharT, typename _InIter>
00505 _InIter
00506 num_get<_CharT, _InIter>::
00507 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00508 ios_base::iostate& __err, unsigned int& __v) const
00509 {
00510 string __xtrc;
00511 __xtrc.reserve(32);
00512 int __base;
00513 __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
00514 unsigned long __ul;
00515 __convert_to_v(__xtrc.c_str(), __ul, __err, _S_c_locale, __base);
00516 if (!(__err & ios_base::failbit)
00517 && __ul <= numeric_limits<unsigned int>::max())
00518 __v = static_cast<unsigned int>(__ul);
00519 else
00520 __err |= ios_base::failbit;
00521 return __beg;
00522 }
00523
00524 template<typename _CharT, typename _InIter>
00525 _InIter
00526 num_get<_CharT, _InIter>::
00527 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00528 ios_base::iostate& __err, unsigned long& __v) const
00529 {
00530 string __xtrc;
00531 __xtrc.reserve(32);
00532 int __base;
00533 __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
00534 __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale, __base);
00535 return __beg;
00536 }
00537
00538 #ifdef _GLIBCPP_USE_LONG_LONG
00539 template<typename _CharT, typename _InIter>
00540 _InIter
00541 num_get<_CharT, _InIter>::
00542 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00543 ios_base::iostate& __err, long long& __v) const
00544 {
00545 string __xtrc;
00546 __xtrc.reserve(32);
00547 int __base;
00548 __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
00549 __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale, __base);
00550 return __beg;
00551 }
00552
00553 template<typename _CharT, typename _InIter>
00554 _InIter
00555 num_get<_CharT, _InIter>::
00556 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00557 ios_base::iostate& __err, unsigned long long& __v) const
00558 {
00559 string __xtrc;
00560 __xtrc.reserve(32);
00561 int __base;
00562 __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
00563 __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale, __base);
00564 return __beg;
00565 }
00566 #endif
00567
00568 template<typename _CharT, typename _InIter>
00569 _InIter
00570 num_get<_CharT, _InIter>::
00571 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00572 ios_base::iostate& __err, float& __v) const
00573 {
00574 string __xtrc;
00575 __xtrc.reserve(32);
00576 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
00577 __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale);
00578 return __beg;
00579 }
00580
00581 template<typename _CharT, typename _InIter>
00582 _InIter
00583 num_get<_CharT, _InIter>::
00584 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00585 ios_base::iostate& __err, double& __v) const
00586 {
00587 string __xtrc;
00588 __xtrc.reserve(32);
00589 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
00590 __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale);
00591 return __beg;
00592 }
00593
00594 template<typename _CharT, typename _InIter>
00595 _InIter
00596 num_get<_CharT, _InIter>::
00597 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00598 ios_base::iostate& __err, long double& __v) const
00599 {
00600 string __xtrc;
00601 __xtrc.reserve(32);
00602 __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
00603 __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale);
00604 return __beg;
00605 }
00606
00607 template<typename _CharT, typename _InIter>
00608 _InIter
00609 num_get<_CharT, _InIter>::
00610 do_get(iter_type __beg, iter_type __end, ios_base& __io,
00611 ios_base::iostate& __err, void*& __v) const
00612 {
00613
00614 typedef ios_base::fmtflags fmtflags;
00615 fmtflags __fmt = __io.flags();
00616 __io.flags(__fmt & ~ios_base::basefield | ios_base::hex);
00617
00618 string __xtrc;
00619 __xtrc.reserve(32);
00620 int __base;
00621 __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
00622
00623
00624 __io.flags(__fmt);
00625
00626 unsigned long __ul;
00627 __convert_to_v(__xtrc.c_str(), __ul, __err, _S_c_locale, __base);
00628 if (!(__err & ios_base::failbit))
00629 __v = reinterpret_cast<void*>(__ul);
00630 else
00631 __err |= ios_base::failbit;
00632 return __beg;
00633 }
00634
00635
00636
00637 template<typename _CharT, typename _OutIter>
00638 void
00639 num_put<_CharT, _OutIter>::
00640 _M_pad(_CharT __fill, streamsize __w, ios_base& __io,
00641 _CharT* __new, const _CharT* __cs, int& __len) const
00642 {
00643
00644
00645 __pad<_CharT, char_traits<_CharT> >::_S_pad(__io, __fill, __new, __cs,
00646 __w, __len, true);
00647 __len = static_cast<int>(__w);
00648 }
00649
00650
00651 template<typename _CharT>
00652 inline int
00653 __int_to_char(_CharT* __out, const int __size, long __v,
00654 const _CharT* __lit, ios_base::fmtflags __flags)
00655 {
00656 unsigned long __ul = static_cast<unsigned long>(__v);
00657 bool __neg = false;
00658 if (__v < 0)
00659 {
00660 __ul = -__ul;
00661 __neg = true;
00662 }
00663 return __int_to_char(__out, __size, __ul, __lit, __flags, __neg);
00664 }
00665
00666 template<typename _CharT>
00667 inline int
00668 __int_to_char(_CharT* __out, const int __size, unsigned long __v,
00669 const _CharT* __lit, ios_base::fmtflags __flags)
00670 { return __int_to_char(__out, __size, __v, __lit, __flags, false); }
00671
00672 #ifdef _GLIBCPP_USE_LONG_LONG
00673 template<typename _CharT>
00674 inline int
00675 __int_to_char(_CharT* __out, const int __size, long long __v,
00676 const _CharT* __lit, ios_base::fmtflags __flags)
00677 {
00678 unsigned long long __ull = static_cast<unsigned long long>(__v);
00679 bool __neg = false;
00680 if (__v < 0)
00681 {
00682 __ull = -__ull;
00683 __neg = true;
00684 }
00685 return __int_to_char(__out, __size, __ull, __lit, __flags, __neg);
00686 }
00687
00688 template<typename _CharT>
00689 inline int
00690 __int_to_char(_CharT* __out, const int __size, unsigned long long __v,
00691 const _CharT* __lit, ios_base::fmtflags __flags)
00692 { return __int_to_char(__out, __size, __v, __lit, __flags, false); }
00693 #endif
00694
00695 template<typename _CharT, typename _ValueT>
00696 int
00697 __int_to_char(_CharT* __out, const int __size, _ValueT __v,
00698 const _CharT* __lit, ios_base::fmtflags __flags, bool __neg)
00699 {
00700
00701 const bool __showbase = (__flags & ios_base::showbase) && __v;
00702 const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
00703 _CharT* __buf = __out + __size - 1;
00704 _CharT* __bufend = __out + __size;
00705
00706 if (__builtin_expect(__basefield != ios_base::oct &&
00707 __basefield != ios_base::hex, true))
00708 {
00709
00710 do
00711 {
00712 *__buf-- = __lit[(__v % 10) + __num_base::_S_digits];
00713 __v /= 10;
00714 }
00715 while (__v != 0);
00716 if (__neg)
00717 *__buf-- = __lit[__num_base::_S_minus];
00718 else if (__flags & ios_base::showpos)
00719 *__buf-- = __lit[__num_base::_S_plus];
00720 }
00721 else if (__basefield == ios_base::oct)
00722 {
00723
00724 do
00725 {
00726 *__buf-- = __lit[(__v & 0x7) + __num_base::_S_digits];
00727 __v >>= 3;
00728 }
00729 while (__v != 0);
00730 if (__showbase)
00731 *__buf-- = __lit[__num_base::_S_digits];
00732 }
00733 else
00734 {
00735
00736 const bool __uppercase = __flags & ios_base::uppercase;
00737 int __case_offset = __uppercase
00738 ? __num_base::_S_udigits : __num_base::_S_digits;
00739 do
00740 {
00741 *__buf-- = __lit[(__v & 0xf) + __case_offset];
00742 __v >>= 4;
00743 }
00744 while (__v != 0);
00745 if (__showbase)
00746 {
00747
00748 *__buf-- = __lit[__num_base::_S_x + __uppercase];
00749
00750 *__buf-- = __lit[__num_base::_S_digits];
00751 }
00752 }
00753 int __ret = __bufend - __buf - 1;
00754 return __ret;
00755 }
00756
00757 template<typename _CharT, typename _OutIter>
00758 void
00759 num_put<_CharT, _OutIter>::
00760 _M_group_int(const string& __grouping, _CharT __sep, ios_base& __io,
00761 _CharT* __new, _CharT* __cs, int& __len) const
00762 {
00763
00764
00765
00766
00767
00768 streamsize __off = 0;
00769 const ios_base::fmtflags __basefield = __io.flags()
00770 & ios_base::basefield;
00771 if ((__io.flags() & ios_base::showbase) && __len > 1)
00772 if (__basefield == ios_base::oct)
00773 {
00774 __off = 1;
00775 *__new = *__cs;
00776 }
00777 else if (__basefield == ios_base::hex)
00778 {
00779 __off = 2;
00780 *__new = *__cs;
00781 *(__new + 1) = *(__cs + 1);
00782 }
00783 _CharT* __p;
00784 __p = __add_grouping(__new + __off, __sep,
00785 __grouping.c_str(),
00786 __grouping.c_str() + __grouping.size(),
00787 __cs + __off, __cs + __len);
00788 __len = __p - __new;
00789 }
00790
00791 template<typename _CharT, typename _OutIter>
00792 template<typename _ValueT>
00793 _OutIter
00794 num_put<_CharT, _OutIter>::
00795 _M_convert_int(_OutIter __s, ios_base& __io, _CharT __fill,
00796 _ValueT __v) const
00797 {
00798 typedef numpunct<_CharT> __facet_type;
00799 typedef __locale_cache<numpunct<_CharT> > __cache_type;
00800 const locale& __loc = __io._M_getloc();
00801 const __cache_type& __lc = __use_cache<__facet_type>(__loc);
00802 const _CharT* __lit = __lc._M_atoms_out;
00803
00804
00805 int __ilen = 4 * sizeof(_ValueT);
00806 _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
00807 * __ilen));
00808
00809
00810 int __len;
00811 __len = __int_to_char(&__cs[0], __ilen, __v, __lit, __io.flags());
00812 __cs = __cs + __ilen - __len;
00813
00814
00815 _CharT* __cs2;
00816 if (__lc._M_use_grouping)
00817 {
00818
00819
00820 __cs2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
00821 * __len * 2));
00822 _M_group_int(__lc._M_grouping, __lc._M_thousands_sep, __io,
00823 __cs2, __cs, __len);
00824 __cs = __cs2;
00825 }
00826
00827
00828 _CharT* __cs3;
00829 streamsize __w = __io.width();
00830 if (__w > static_cast<streamsize>(__len))
00831 {
00832 __cs3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
00833 * __w));
00834 _M_pad(__fill, __w, __io, __cs3, __cs, __len);
00835 __cs = __cs3;
00836 }
00837 __io.width(0);
00838
00839
00840
00841 return __write(__s, __cs, __len);
00842 }
00843
00844 template<typename _CharT, typename _OutIter>
00845 void
00846 num_put<_CharT, _OutIter>::
00847 _M_group_float(const string& __grouping, _CharT __sep, const _CharT* __p,
00848 _CharT* __new, _CharT* __cs, int& __len) const
00849 {
00850 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00851
00852
00853 _CharT* __p2;
00854 int __declen = __p ? __p - __cs : __len;
00855 __p2 = __add_grouping(__new, __sep,
00856 __grouping.c_str(),
00857 __grouping.c_str() + __grouping.size(),
00858 __cs, __cs + __declen);
00859
00860
00861 int __newlen = __p2 - __new;
00862 if (__p)
00863 {
00864 char_traits<_CharT>::copy(__p2, __p, __len - __declen);
00865 __newlen += __len - __declen;
00866 }
00867 __len = __newlen;
00868 #endif
00869 }
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881 template<typename _CharT, typename _OutIter>
00882 template<typename _ValueT>
00883 _OutIter
00884 num_put<_CharT, _OutIter>::
00885 _M_convert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
00886 _ValueT __v) const
00887 {
00888
00889 streamsize __prec = __io.precision();
00890 if (__prec < static_cast<streamsize>(0))
00891 __prec = static_cast<streamsize>(6);
00892
00893 const int __max_digits = numeric_limits<_ValueT>::digits10;
00894
00895 typedef numpunct<_CharT> __facet_type;
00896 typedef __locale_cache<numpunct<_CharT> > __cache_type;
00897 const locale __loc = __io._M_getloc();
00898 const __cache_type& __lc = __use_cache<__facet_type>(__loc);
00899
00900
00901 int __len;
00902
00903 char __fbuf[16];
00904
00905 #ifdef _GLIBCPP_USE_C99
00906
00907
00908 int __cs_size = __max_digits * 3;
00909 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
00910
00911 _S_format_float(__io, __fbuf, __mod, __prec);
00912 __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
00913 _S_c_locale, __prec);
00914
00915
00916 if (__len >= __cs_size)
00917 {
00918 __cs_size = __len + 1;
00919 __cs = static_cast<char*>(__builtin_alloca(__cs_size));
00920 __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
00921 _S_c_locale, __prec);
00922 }
00923 #else
00924
00925 const bool __fixed = __io.flags() & ios_base::fixed;
00926 const int __max_exp = numeric_limits<_ValueT>::max_exponent10;
00927
00928
00929
00930
00931
00932
00933 const int __cs_size = __fixed ? __max_exp + __prec + 4
00934 : __max_digits * 2 + __prec;
00935 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
00936
00937 _S_format_float(__io, __fbuf, __mod, __prec);
00938 __len = __convert_from_v(__cs, 0, __fbuf, __v, _S_c_locale, __prec);
00939 #endif
00940
00941
00942
00943 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
00944
00945 _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
00946 * __len));
00947 __ctype.widen(__cs, __cs + __len, __ws);
00948
00949
00950 const _CharT __cdec = __ctype.widen('.');
00951 const _CharT __dec = __lc._M_decimal_point;
00952 const _CharT* __p;
00953 if (__p = char_traits<_CharT>::find(__ws, __len, __cdec))
00954 __ws[__p - __ws] = __dec;
00955
00956
00957 _CharT* __ws2;
00958 if (__lc._M_use_grouping)
00959 {
00960
00961
00962 __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
00963 * __len * 2));
00964 _M_group_float(__lc._M_grouping, __lc._M_thousands_sep, __p,
00965 __ws2, __ws, __len);
00966 __ws = __ws2;
00967 }
00968
00969
00970 _CharT* __ws3;
00971 streamsize __w = __io.width();
00972 if (__w > static_cast<streamsize>(__len))
00973 {
00974 __ws3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
00975 _M_pad(__fill, __w, __io, __ws3, __ws, __len);
00976 __ws = __ws3;
00977 }
00978 __io.width(0);
00979
00980
00981
00982 return __write(__s, __ws, __len);
00983 }
00984
00985 template<typename _CharT, typename _OutIter>
00986 _OutIter
00987 num_put<_CharT, _OutIter>::
00988 do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const
00989 {
00990 ios_base::fmtflags __flags = __io.flags();
00991 if ((__flags & ios_base::boolalpha) == 0)
00992 {
00993 unsigned long __uv = __v;
00994 __s = _M_convert_int(__s, __io, __fill, __uv);
00995 }
00996 else
00997 {
00998 typedef numpunct<_CharT> __facet_type;
00999 typedef __locale_cache<numpunct<_CharT> > __cache_type;
01000 const locale __loc = __io._M_getloc();
01001 const __cache_type& __lc = __use_cache<__facet_type>(__loc);
01002
01003 typedef basic_string<_CharT> __string_type;
01004 __string_type __name;
01005 if (__v)
01006 __name = __lc._M_truename;
01007 else
01008 __name = __lc._M_falsename;
01009
01010 const _CharT* __cs = __name.c_str();
01011 int __len = __name.size();
01012 _CharT* __cs3;
01013 streamsize __w = __io.width();
01014 if (__w > static_cast<streamsize>(__len))
01015 {
01016 __cs3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
01017 * __w));
01018 _M_pad(__fill, __w, __io, __cs3, __cs, __len);
01019 __cs = __cs3;
01020 }
01021 __io.width(0);
01022 __s = __write(__s, __cs, __len);
01023 }
01024 return __s;
01025 }
01026
01027 template<typename _CharT, typename _OutIter>
01028 _OutIter
01029 num_put<_CharT, _OutIter>::
01030 do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
01031 { return _M_convert_int(__s, __io, __fill, __v); }
01032
01033 template<typename _CharT, typename _OutIter>
01034 _OutIter
01035 num_put<_CharT, _OutIter>::
01036 do_put(iter_type __s, ios_base& __io, char_type __fill,
01037 unsigned long __v) const
01038 { return _M_convert_int(__s, __io, __fill, __v); }
01039
01040 #ifdef _GLIBCPP_USE_LONG_LONG
01041 template<typename _CharT, typename _OutIter>
01042 _OutIter
01043 num_put<_CharT, _OutIter>::
01044 do_put(iter_type __s, ios_base& __b, char_type __fill, long long __v) const
01045 { return _M_convert_int(__s, __b, __fill, __v); }
01046
01047 template<typename _CharT, typename _OutIter>
01048 _OutIter
01049 num_put<_CharT, _OutIter>::
01050 do_put(iter_type __s, ios_base& __io, char_type __fill,
01051 unsigned long long __v) const
01052 { return _M_convert_int(__s, __io, __fill, __v); }
01053 #endif
01054
01055 template<typename _CharT, typename _OutIter>
01056 _OutIter
01057 num_put<_CharT, _OutIter>::
01058 do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const
01059 { return _M_convert_float(__s, __io, __fill, char(), __v); }
01060
01061 template<typename _CharT, typename _OutIter>
01062 _OutIter
01063 num_put<_CharT, _OutIter>::
01064 do_put(iter_type __s, ios_base& __io, char_type __fill,
01065 long double __v) const
01066 { return _M_convert_float(__s, __io, __fill, 'L', __v); }
01067
01068 template<typename _CharT, typename _OutIter>
01069 _OutIter
01070 num_put<_CharT, _OutIter>::
01071 do_put(iter_type __s, ios_base& __io, char_type __fill,
01072 const void* __v) const
01073 {
01074 ios_base::fmtflags __flags = __io.flags();
01075 ios_base::fmtflags __fmt = ~(ios_base::showpos | ios_base::basefield
01076 | ios_base::uppercase | ios_base::internal);
01077 __io.flags(__flags & __fmt | (ios_base::hex | ios_base::showbase));
01078 try
01079 {
01080 __s = _M_convert_int(__s, __io, __fill,
01081 reinterpret_cast<unsigned long>(__v));
01082 __io.flags(__flags);
01083 }
01084 catch (...)
01085 {
01086 __io.flags(__flags);
01087 __throw_exception_again;
01088 }
01089 return __s;
01090 }
01091
01092
01093 template<typename _CharT, typename _InIter>
01094 _InIter
01095 money_get<_CharT, _InIter>::
01096 do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
01097 ios_base::iostate& __err, long double& __units) const
01098 {
01099 string_type __str;
01100 __beg = this->do_get(__beg, __end, __intl, __io, __err, __str);
01101
01102 const int __cs_size = __str.size() + 1;
01103 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
01104 const locale __loc = __io.getloc();
01105 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
01106 const _CharT* __wcs = __str.c_str();
01107 __ctype.narrow(__wcs, __wcs + __cs_size, char(), __cs);
01108 __convert_to_v(__cs, __units, __err, _S_c_locale);
01109 return __beg;
01110 }
01111
01112 template<typename _CharT, typename _InIter>
01113 _InIter
01114 money_get<_CharT, _InIter>::
01115 do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
01116 ios_base::iostate& __err, string_type& __units) const
01117 {
01118
01119 typedef moneypunct<_CharT, true> __money_true;
01120 typedef moneypunct<_CharT, false> __money_false;
01121 typedef money_base::part part;
01122 typedef typename string_type::size_type size_type;
01123
01124 const locale __loc = __io.getloc();
01125 const __money_true& __mpt = use_facet<__money_true>(__loc);
01126 const __money_false& __mpf = use_facet<__money_false>(__loc);
01127 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
01128
01129 const money_base::pattern __p = __intl ? __mpt.neg_format()
01130 : __mpf.neg_format();
01131
01132 const string_type __pos_sign =__intl ? __mpt.positive_sign()
01133 : __mpf.positive_sign();
01134 const string_type __neg_sign =__intl ? __mpt.negative_sign()
01135 : __mpf.negative_sign();
01136 const char_type __d = __intl ? __mpt.decimal_point()
01137 : __mpf.decimal_point();
01138 const char_type __sep = __intl ? __mpt.thousands_sep()
01139 : __mpf.thousands_sep();
01140
01141 const string __grouping = __intl ? __mpt.grouping() : __mpf.grouping();
01142
01143
01144 string_type __sign;
01145
01146 string __grouping_tmp;
01147
01148 int __sep_pos = 0;
01149
01150 bool __testvalid = true;
01151
01152 bool __testdecfound = false;
01153
01154
01155 string_type __temp_units;
01156 __temp_units.reserve(20);
01157
01158 char_type __c = *__beg;
01159 char_type __eof = static_cast<char_type>(char_traits<char_type>::eof());
01160 for (int __i = 0; __beg != __end && __i < 4 && __testvalid; ++__i)
01161 {
01162 part __which = static_cast<part>(__p.field[__i]);
01163 switch (__which)
01164 {
01165 case money_base::symbol:
01166 if (__io.flags() & ios_base::showbase
01167 || __i < 2 || __sign.size() > 1
01168 || ((static_cast<part>(__p.field[3]) != money_base::none)
01169 && __i == 2))
01170 {
01171
01172
01173
01174
01175
01176 const string_type __symbol = __intl ? __mpt.curr_symbol()
01177 : __mpf.curr_symbol();
01178 size_type __len = __symbol.size();
01179 size_type __j = 0;
01180 while (__beg != __end
01181 && __j < __len && __symbol[__j] == __c)
01182 {
01183 __c = *(++__beg);
01184 ++__j;
01185 }
01186
01187
01188 if (__j != __len && (__io.flags() & ios_base::showbase))
01189 __testvalid = false;
01190 }
01191 break;
01192 case money_base::sign:
01193
01194 if (__pos_sign.size() && __c == __pos_sign[0])
01195 {
01196 __sign = __pos_sign;
01197 __c = *(++__beg);
01198 }
01199 else if (__neg_sign.size() && __c == __neg_sign[0])
01200 {
01201 __sign = __neg_sign;
01202 __c = *(++__beg);
01203 }
01204 else if (__pos_sign.size() && __neg_sign.size())
01205 {
01206
01207 __testvalid = false;
01208 }
01209 break;
01210 case money_base::value:
01211
01212
01213 while (__beg != __end
01214 && (__ctype.is(ctype_base::digit, __c)
01215 || (__c == __d && !__testdecfound)
01216 || __c == __sep))
01217 {
01218 if (__c == __d)
01219 {
01220 __grouping_tmp += static_cast<char>(__sep_pos);
01221 __sep_pos = 0;
01222 __testdecfound = true;
01223 }
01224 else if (__c == __sep)
01225 {
01226 if (__grouping.size())
01227 {
01228
01229 __grouping_tmp += static_cast<char>(__sep_pos);
01230 __sep_pos = 0;
01231 }
01232 else
01233 {
01234 __testvalid = false;
01235 break;
01236 }
01237 }
01238 else
01239 {
01240 __temp_units += __c;
01241 ++__sep_pos;
01242 }
01243 __c = *(++__beg);
01244 }
01245 break;
01246 case money_base::space:
01247 case money_base::none:
01248
01249 if (__i != 3)
01250 while (__beg != __end
01251 && __ctype.is(ctype_base::space, __c))
01252 __c = *(++__beg);
01253 break;
01254 }
01255 }
01256
01257
01258 if (__sign.size() > 1)
01259 {
01260 size_type __len = __sign.size();
01261 size_type __i = 1;
01262 for (; __c != __eof && __i < __len; ++__i)
01263 while (__beg != __end && __c != __sign[__i])
01264 __c = *(++__beg);
01265
01266 if (__i != __len)
01267 __testvalid = false;
01268 }
01269
01270
01271 while (__temp_units.size() > 1 && __temp_units[0] == __ctype.widen('0'))
01272 __temp_units.erase(__temp_units.begin());
01273
01274 if (__sign.size() && __sign == __neg_sign)
01275 __temp_units.insert(__temp_units.begin(), __ctype.widen('-'));
01276
01277
01278 if (__grouping.size() && __grouping_tmp.size())
01279 {
01280 if (!__verify_grouping(__grouping, __grouping_tmp))
01281 __testvalid = false;
01282 }
01283
01284
01285 if (__c == __eof)
01286 __err |= ios_base::eofbit;
01287
01288
01289 if (!__testvalid || !__temp_units.size())
01290 __err |= ios_base::failbit;
01291 else
01292
01293 __temp_units.swap(__units);
01294
01295 return __beg;
01296 }
01297
01298 template<typename _CharT, typename _OutIter>
01299 _OutIter
01300 money_put<_CharT, _OutIter>::
01301 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
01302 long double __units) const
01303 {
01304 const locale __loc = __io.getloc();
01305 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
01306 #ifdef _GLIBCPP_USE_C99
01307
01308 int __cs_size = 64;
01309 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
01310
01311
01312 int __len = __convert_from_v(__cs, __cs_size, "%.0Lf", __units,
01313 _S_c_locale);
01314
01315 if (__len >= __cs_size)
01316 {
01317 __cs_size = __len + 1;
01318 __cs = static_cast<char*>(__builtin_alloca(__cs_size));
01319 __len = __convert_from_v(__cs, __cs_size, "%.0Lf", __units,
01320 _S_c_locale);
01321 }
01322 #else
01323
01324 const int __cs_size = numeric_limits<long double>::max_exponent10 + 3;
01325 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
01326 int __len = __convert_from_v(__cs, 0, "%.0Lf", __units, _S_c_locale);
01327 #endif
01328 _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
01329 * __cs_size));
01330 __ctype.widen(__cs, __cs + __len, __ws);
01331 const string_type __digits(__ws, __len);
01332 return this->do_put(__s, __intl, __io, __fill, __digits);
01333 }
01334
01335 template<typename _CharT, typename _OutIter>
01336 _OutIter
01337 money_put<_CharT, _OutIter>::
01338 do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
01339 const string_type& __digits) const
01340 {
01341 typedef typename string_type::size_type size_type;
01342 typedef money_base::part part;
01343
01344 const locale __loc = __io.getloc();
01345 const size_type __width = static_cast<size_type>(__io.width());
01346
01347
01348 typedef moneypunct<_CharT, true> __money_true;
01349 typedef moneypunct<_CharT, false> __money_false;
01350 const __money_true& __mpt = use_facet<__money_true>(__loc);
01351 const __money_false& __mpf = use_facet<__money_false>(__loc);
01352 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
01353
01354
01355
01356 const char_type* __beg = __digits.data();
01357 const char_type* __end = __beg + __digits.size();
01358 money_base::pattern __p;
01359 string_type __sign;
01360 if (*__beg != __ctype.widen('-'))
01361 {
01362 __p = __intl ? __mpt.pos_format() : __mpf.pos_format();
01363 __sign =__intl ? __mpt.positive_sign() : __mpf.positive_sign();
01364 }
01365 else
01366 {
01367 __p = __intl ? __mpt.neg_format() : __mpf.neg_format();
01368 __sign =__intl ? __mpt.negative_sign() : __mpf.negative_sign();
01369 ++__beg;
01370 }
01371
01372
01373 __end = __ctype.scan_not(ctype_base::digit, __beg, __end);
01374 if (__beg != __end)
01375 {
01376
01377
01378
01379 string_type __value;
01380 __value.reserve(20);
01381
01382 const int __frac = __intl ? __mpt.frac_digits()
01383 : __mpf.frac_digits();
01384
01385
01386
01387 const int __paddec = __frac - (__end - __beg);
01388 if (__paddec < 0)
01389 {
01390 const string __grouping = __intl ? __mpt.grouping()
01391 : __mpf.grouping();
01392 if (__grouping.size())
01393 {
01394 const char_type __sep = __intl ? __mpt.thousands_sep()
01395 : __mpf.thousands_sep();
01396 const char* __gbeg = __grouping.data();
01397 const char* __gend = __gbeg + __grouping.size();
01398 const int __n = (__end - __beg) * 2;
01399 _CharT* __ws2 =
01400 static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __n));
01401 _CharT* __ws_end = __add_grouping(__ws2, __sep, __gbeg,
01402 __gend, __beg,
01403 __end - __frac);
01404 __value.assign(__ws2, __ws_end - __ws2);
01405 }
01406 else
01407 __value.assign(__beg, -__paddec);
01408 }
01409
01410
01411 if (__frac > 0)
01412 {
01413 const char_type __d = __intl ? __mpt.decimal_point()
01414 : __mpf.decimal_point();
01415 __value += __d;
01416 if (__paddec <= 0)
01417 __value.append(__end - __frac, __frac);
01418 else
01419 {
01420
01421 const char_type __zero = __ctype.widen('0');
01422 __value.append(__paddec, __zero);
01423 __value.append(__beg, __end - __beg);
01424 }
01425 }
01426
01427 const string_type __symbol = __intl ? __mpt.curr_symbol()
01428 : __mpf.curr_symbol();
01429
01430
01431 ios_base::fmtflags __f = __io.flags() & ios_base::adjustfield;
01432 size_type __len = __value.size() + __sign.size();
01433 __len += (__io.flags() & ios_base::showbase) ? __symbol.size() : 0;
01434
01435 string_type __res;
01436 __res.reserve(__len);
01437
01438 bool __testipad = __f == ios_base::internal && __len < __width;
01439
01440
01441 for (int __i = 0; __i < 4; ++__i)
01442 {
01443 part __which = static_cast<part>(__p.field[__i]);
01444 switch (__which)
01445 {
01446 case money_base::symbol:
01447 if (__io.flags() & ios_base::showbase)
01448 __res += __symbol;
01449 break;
01450 case money_base::sign:
01451
01452
01453
01454 if (__sign.size())
01455 __res += __sign[0];
01456 break;
01457 case money_base::value:
01458 __res += __value;
01459 break;
01460 case money_base::space:
01461
01462
01463
01464 if (__testipad)
01465 __res += string_type(__width - __len, __fill);
01466 else
01467 __res += __ctype.widen(__fill);
01468 break;
01469 case money_base::none:
01470 if (__testipad)
01471 __res += string_type(__width - __len, __fill);
01472 break;
01473 }
01474 }
01475
01476
01477 if (__sign.size() > 1)
01478 __res += string_type(__sign.begin() + 1, __sign.end());
01479
01480
01481 __len = __res.size();
01482 if (__width > __len)
01483 {
01484 if (__f == ios_base::left)
01485
01486 __res.append(__width - __len, __fill);
01487 else
01488
01489 __res.insert(0, string_type(__width - __len, __fill));
01490 __len = __width;
01491 }
01492
01493
01494 __s = __write(__s, __res.data(), __len);
01495 }
01496 __io.width(0);
01497 return __s;
01498 }
01499
01500
01501
01502
01503
01504 template<typename _CharT, typename _InIter>
01505 time_base::dateorder
01506 time_get<_CharT, _InIter>::do_date_order() const
01507 { return time_base::no_order; }
01508
01509 template<typename _CharT, typename _InIter>
01510 void
01511 time_get<_CharT, _InIter>::
01512 _M_extract_via_format(iter_type& __beg, iter_type& __end, ios_base& __io,
01513 ios_base::iostate& __err, tm* __tm,
01514 const _CharT* __format) const
01515 {
01516 locale __loc = __io.getloc();
01517 __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
01518 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
01519 size_t __len = char_traits<_CharT>::length(__format);
01520
01521 for (size_t __i = 0; __beg != __end && __i < __len && !__err; ++__i)
01522 {
01523 if (__ctype.narrow(__format[__i], 0) == '%')
01524 {
01525
01526 char __c = __ctype.narrow(__format[++__i], 0);
01527 int __mem = 0;
01528 if (__c == 'E' || __c == 'O')
01529 __c = __ctype.narrow(__format[++__i], 0);
01530 switch (__c)
01531 {
01532 const char* __cs;
01533 _CharT __wcs[10];
01534 case 'a':
01535
01536 const char_type* __days1[7];
01537 __tp._M_days_abbreviated(__days1);
01538 _M_extract_name(__beg, __end, __tm->tm_wday, __days1, 7,
01539 __err);
01540 break;
01541 case 'A':
01542
01543 const char_type* __days2[7];
01544 __tp._M_days(__days2);
01545 _M_extract_name(__beg, __end, __tm->tm_wday, __days2, 7,
01546 __err);
01547 break;
01548 case 'h':
01549 case 'b':
01550
01551 const char_type* __months1[12];
01552 __tp._M_months_abbreviated(__months1);
01553 _M_extract_name(__beg, __end, __tm->tm_mon, __months1, 12,
01554 __err);
01555 break;
01556 case 'B':
01557
01558 const char_type* __months2[12];
01559 __tp._M_months(__months2);
01560 _M_extract_name(__beg, __end, __tm->tm_mon, __months2, 12,
01561 __err);
01562 break;
01563 case 'c':
01564
01565 const char_type* __dt[2];
01566 __tp._M_date_time_formats(__dt);
01567 _M_extract_via_format(__beg, __end, __io, __err, __tm,
01568 __dt[0]);
01569 break;
01570 case 'd':
01571
01572 _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2,
01573 __ctype, __err);
01574 break;
01575 case 'D':
01576
01577 __cs = "%m/%d/%y";
01578 __ctype.widen(__cs, __cs + 9, __wcs);
01579 _M_extract_via_format(__beg, __end, __io, __err, __tm,
01580 __wcs);
01581 break;
01582 case 'H':
01583
01584 _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2,
01585 __ctype, __err);
01586 break;
01587 case 'I':
01588
01589 _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2,
01590 __ctype, __err);
01591 break;
01592 case 'm':
01593
01594 _M_extract_num(__beg, __end, __mem, 1, 12, 2, __ctype,
01595 __err);
01596 if (!__err)
01597 __tm->tm_mon = __mem - 1;
01598 break;
01599 case 'M':
01600
01601 _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2,
01602 __ctype, __err);
01603 break;
01604 case 'n':
01605 if (__ctype.narrow(*__beg, 0) == '\n')
01606 ++__beg;
01607 else
01608 __err |= ios_base::failbit;
01609 break;
01610 case 'R':
01611
01612 __cs = "%H:%M";
01613 __ctype.widen(__cs, __cs + 6, __wcs);
01614 _M_extract_via_format(__beg, __end, __io, __err, __tm,
01615 __wcs);
01616 break;
01617 case 'S':
01618
01619 _M_extract_num(__beg, __end, __tm->tm_sec, 0, 59, 2,
01620 __ctype, __err);
01621 break;
01622 case 't':
01623 if (__ctype.narrow(*__beg, 0) == '\t')
01624 ++__beg;
01625 else
01626 __err |= ios_base::failbit;
01627 break;
01628 case 'T':
01629
01630 __cs = "%H:%M:%S";
01631 __ctype.widen(__cs, __cs + 9, __wcs);
01632 _M_extract_via_format(__beg, __end, __io, __err, __tm,
01633 __wcs);
01634 break;
01635 case 'x':
01636
01637 const char_type* __dates[2];
01638 __tp._M_date_formats(__dates);
01639 _M_extract_via_format(__beg, __end, __io, __err, __tm,
01640 __dates[0]);
01641 break;
01642 case 'X':
01643
01644 const char_type* __times[2];
01645 __tp._M_time_formats(__times);
01646 _M_extract_via_format(__beg, __end, __io, __err, __tm,
01647 __times[0]);
01648 break;
01649 case 'y':
01650
01651 _M_extract_num(__beg, __end, __tm->tm_year, 0, 99, 2,
01652 __ctype, __err);
01653 break;
01654 case 'Y':
01655
01656 _M_extract_num(__beg, __end, __mem, 0,
01657 numeric_limits<int>::max(), 4,
01658 __ctype, __err);
01659 if (!__err)
01660 __tm->tm_year = __mem - 1900;
01661 break;
01662 case 'Z':
01663
01664 if (__ctype.is(ctype_base::upper, *__beg))
01665 {
01666 int __tmp;
01667 _M_extract_name(__beg, __end, __tmp,
01668 __timepunct<_CharT>::_S_timezones,
01669 14, __err);
01670
01671
01672 char_type __c = *__beg;
01673 if (!__err && __tmp == 0
01674 && (__c == __ctype.widen('-')
01675 || __c == __ctype.widen('+')))
01676 {
01677 _M_extract_num(__beg, __end, __tmp, 0, 23, 2,
01678 __ctype, __err);
01679 _M_extract_num(__beg, __end, __tmp, 0, 59, 2,
01680 __ctype, __err);
01681 }
01682 }
01683 else
01684 __err |= ios_base::failbit;
01685 break;
01686 default:
01687
01688 __err |= ios_base::failbit;
01689 }
01690 }
01691 else
01692 {
01693
01694 if (__format[__i] == *__beg)
01695 ++__beg;
01696 else
01697 __err |= ios_base::failbit;
01698 }
01699 }
01700 }
01701
01702 template<typename _CharT, typename _InIter>
01703 void
01704 time_get<_CharT, _InIter>::
01705 _M_extract_num(iter_type& __beg, iter_type& __end, int& __member,
01706 int __min, int __max, size_t __len,
01707 const ctype<_CharT>& __ctype,
01708 ios_base::iostate& __err) const
01709 {
01710 size_t __i = 0;
01711 string __digits;
01712 bool __testvalid = true;
01713 char_type __c = *__beg;
01714 while (__beg != __end && __i < __len
01715 && __ctype.is(ctype_base::digit, __c))
01716 {
01717 __digits += __ctype.narrow(__c, 0);
01718 __c = *(++__beg);
01719 ++__i;
01720 }
01721 if (__i == __len)
01722 {
01723 int __value = atoi(__digits.c_str());
01724 if (__min <= __value && __value <= __max)
01725 __member = __value;
01726 else
01727 __testvalid = false;
01728 }
01729 else
01730 __testvalid = false;
01731 if (!__testvalid)
01732 __err |= ios_base::failbit;
01733 }
01734
01735
01736
01737 template<typename _CharT, typename _InIter>
01738 void
01739 time_get<_CharT, _InIter>::
01740 _M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
01741 const _CharT** __names, size_t __indexlen,
01742 ios_base::iostate& __err) const
01743 {
01744 typedef char_traits<_CharT> __traits_type;
01745 int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int)
01746 * __indexlen));
01747 size_t __nmatches = 0;
01748 size_t __pos = 0;
01749 bool __testvalid = true;
01750 const char_type* __name;
01751
01752 char_type __c = *__beg;
01753
01754 for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
01755 if (__c == __names[__i1][0])
01756 __matches[__nmatches++] = __i1;
01757
01758 while (__nmatches > 1)
01759 {
01760
01761 size_t __minlen = 10;
01762 for (size_t __i2 = 0; __i2 < __nmatches; ++__i2)
01763 __minlen = min(__minlen,
01764 __traits_type::length(__names[__matches[__i2]]));
01765
01766 if (__pos < __minlen && __beg != __end)
01767 {
01768 ++__pos;
01769 __c = *(++__beg);
01770 for (size_t __i3 = 0; __i3 < __nmatches; ++__i3)
01771 {
01772 __name = __names[__matches[__i3]];
01773 if (__name[__pos] != __c)
01774 __matches[__i3] = __matches[--__nmatches];
01775 }
01776 }
01777 else
01778 break;
01779 }
01780
01781 if (__nmatches == 1)
01782 {
01783
01784 __name = __names[__matches[0]];
01785 const size_t __len = __traits_type::length(__name);
01786 while (__pos < __len && __beg != __end && __name[__pos] == *__beg)
01787 ++__beg, ++__pos;
01788
01789 if (__len == __pos)
01790 __member = __matches[0];
01791 else
01792 __testvalid = false;
01793 }
01794 else
01795 __testvalid = false;
01796 if (!__testvalid)
01797 __err |= ios_base::failbit;
01798 }
01799
01800 template<typename _CharT, typename _InIter>
01801 _InIter
01802 time_get<_CharT, _InIter>::
01803 do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
01804 ios_base::iostate& __err, tm* __tm) const
01805 {
01806 _CharT __wcs[3];
01807 const char* __cs = "%X";
01808 locale __loc = __io.getloc();
01809 ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
01810 __ctype.widen(__cs, __cs + 3, __wcs);
01811 _M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs);
01812 if (__beg == __end)
01813 __err |= ios_base::eofbit;
01814 return __beg;
01815 }
01816
01817 template<typename _CharT, typename _InIter>
01818 _InIter
01819 time_get<_CharT, _InIter>::
01820 do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
01821 ios_base::iostate& __err, tm* __tm) const
01822 {
01823 _CharT __wcs[3];
01824 const char* __cs = "%x";
01825 locale __loc = __io.getloc();
01826 ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
01827 __ctype.widen(__cs, __cs + 3, __wcs);
01828 _M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs);
01829 if (__beg == __end)
01830 __err |= ios_base::eofbit;
01831 return __beg;
01832 }
01833
01834 template<typename _CharT, typename _InIter>
01835 _InIter
01836 time_get<_CharT, _InIter>::
01837 do_get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
01838 ios_base::iostate& __err, tm* __tm) const
01839 {
01840 typedef char_traits<_CharT> __traits_type;
01841 locale __loc = __io.getloc();
01842 __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
01843 const char_type* __days[7];
01844 __tp._M_days_abbreviated(__days);
01845 int __tmpwday;
01846 _M_extract_name(__beg, __end, __tmpwday, __days, 7, __err);
01847
01848
01849
01850
01851
01852
01853
01854 if (!__err)
01855 {
01856 size_t __pos = __traits_type::length(__days[__tmpwday]);
01857 __tp._M_days(__days);
01858 const char_type* __name = __days[__tmpwday];
01859 if (__name[__pos] == *__beg)
01860 {
01861
01862 const size_t __len = __traits_type::length(__name);
01863 while (__pos < __len && __beg != __end
01864 && __name[__pos] == *__beg)
01865 ++__beg, ++__pos;
01866 if (__len != __pos)
01867 __err |= ios_base::failbit;
01868 }
01869 if (!__err)
01870 __tm->tm_wday = __tmpwday;
01871 }
01872 if (__beg == __end)
01873 __err |= ios_base::eofbit;
01874 return __beg;
01875 }
01876
01877 template<typename _CharT, typename _InIter>
01878 _InIter
01879 time_get<_CharT, _InIter>::
01880 do_get_monthname(iter_type __beg, iter_type __end,
01881 ios_base& __io, ios_base::iostate& __err, tm* __tm) const
01882 {
01883 typedef char_traits<_CharT> __traits_type;
01884 locale __loc = __io.getloc();
01885 __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
01886 const char_type* __months[12];
01887 __tp._M_months_abbreviated(__months);
01888 int __tmpmon;
01889 _M_extract_name(__beg, __end, __tmpmon, __months, 12, __err);
01890
01891
01892
01893
01894
01895
01896
01897 if (!__err)
01898 {
01899 size_t __pos = __traits_type::length(__months[__tmpmon]);
01900 __tp._M_months(__months);
01901 const char_type* __name = __months[__tmpmon];
01902 if (__name[__pos] == *__beg)
01903 {
01904
01905 const size_t __len = __traits_type::length(__name);
01906 while (__pos < __len && __beg != __end
01907 && __name[__pos] == *__beg)
01908 ++__beg, ++__pos;
01909 if (__len != __pos)
01910 __err |= ios_base::failbit;
01911 }
01912 if (!__err)
01913 __tm->tm_mon = __tmpmon;
01914 }
01915
01916 if (__beg == __end)
01917 __err |= ios_base::eofbit;
01918 return __beg;
01919 }
01920
01921 template<typename _CharT, typename _InIter>
01922 _InIter
01923 time_get<_CharT, _InIter>::
01924 do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
01925 ios_base::iostate& __err, tm* __tm) const
01926 {
01927 locale __loc = __io.getloc();
01928 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
01929
01930 char_type __c = *__beg;
01931 size_t __i = 0;
01932 string __digits;
01933 while (__i < 4 && __beg != __end && __ctype.is(ctype_base::digit, __c))
01934 {
01935 __digits += __ctype.narrow(__c, 0);
01936 __c = *(++__beg);
01937 ++__i;
01938 }
01939 if (__i == 2 || __i == 4)
01940 {
01941 long __l;
01942 __convert_to_v(__digits.c_str(), __l, __err, _S_c_locale);
01943 if (!(__err & ios_base::failbit) && __l <= INT_MAX)
01944 {
01945 __l = __i == 2 ? __l : __l - 1900;
01946 __tm->tm_year = static_cast<int>(__l);
01947 }
01948 }
01949 else
01950 __err |= ios_base::failbit;
01951 if (__beg == __end)
01952 __err |= ios_base::eofbit;
01953 return __beg;
01954 }
01955
01956 template<typename _CharT, typename _OutIter>
01957 _OutIter
01958 time_put<_CharT, _OutIter>::
01959 put(iter_type __s, ios_base& __io, char_type, const tm* __tm,
01960 const _CharT* __beg, const _CharT* __end) const
01961 {
01962 locale __loc = __io.getloc();
01963 ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
01964 while (__beg != __end)
01965 {
01966 char __c = __ctype.narrow(*__beg, 0);
01967 ++__beg;
01968 if (__c == '%')
01969 {
01970 char __format;
01971 char __mod = 0;
01972 size_t __len = 1;
01973 __c = __ctype.narrow(*__beg, 0);
01974 ++__beg;
01975 if (__c == 'E' || __c == 'O')
01976 {
01977 __mod = __c;
01978 __format = __ctype.narrow(*__beg, 0);
01979 ++__beg;
01980 }
01981 else
01982 __format = __c;
01983 __s = this->do_put(__s, __io, _CharT(), __tm, __format, __mod);
01984 }
01985 else
01986 {
01987 *__s = __c;
01988 ++__s;
01989 }
01990 }
01991 return __s;
01992 }
01993
01994 template<typename _CharT, typename _OutIter>
01995 _OutIter
01996 time_put<_CharT, _OutIter>::
01997 do_put(iter_type __s, ios_base& __io, char_type, const tm* __tm,
01998 char __format, char __mod) const
01999 {
02000 locale __loc = __io.getloc();
02001 ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
02002 __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
02003
02004
02005
02006 const size_t __maxlen = 64;
02007 char_type* __res = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen));
02008
02009
02010
02011
02012
02013
02014 char_type __fmt[4];
02015 __fmt[0] = __ctype.widen('%');
02016 if (!__mod)
02017 {
02018 __fmt[1] = __format;
02019 __fmt[2] = char_type();
02020 }
02021 else
02022 {
02023 __fmt[1] = __mod;
02024 __fmt[2] = __format;
02025 __fmt[3] = char_type();
02026 }
02027
02028 __tp._M_put(__res, __maxlen, __fmt, __tm);
02029
02030
02031 return __write(__s, __res, char_traits<char_type>::length(__res));
02032 }
02033
02034
02035
02036 template<typename _CharT>
02037 int
02038 collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const
02039 { return 0; }
02040
02041
02042 template<typename _CharT>
02043 size_t
02044 collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const
02045 { return 0; }
02046
02047 template<typename _CharT>
02048 int
02049 collate<_CharT>::
02050 do_compare(const _CharT* __lo1, const _CharT* __hi1,
02051 const _CharT* __lo2, const _CharT* __hi2) const
02052 {
02053
02054
02055 const string_type __one(__lo1, __hi1);
02056 const string_type __two(__lo2, __hi2);
02057
02058 const _CharT* __p = __one.c_str();
02059 const _CharT* __pend = __one.c_str() + __one.length();
02060 const _CharT* __q = __two.c_str();
02061 const _CharT* __qend = __two.c_str() + __two.length();
02062
02063
02064
02065
02066 for (;;)
02067 {
02068 int __res = _M_compare(__p, __q);
02069 if (__res)
02070 return __res;
02071
02072 __p += char_traits<_CharT>::length(__p);
02073 __q += char_traits<_CharT>::length(__q);
02074 if (__p == __pend && __q == __qend)
02075 return 0;
02076 else if (__p == __pend)
02077 return -1;
02078 else if (__q == __qend)
02079 return 1;
02080
02081 __p++;
02082 __q++;
02083 }
02084 }
02085
02086 template<typename _CharT>
02087 typename collate<_CharT>::string_type
02088 collate<_CharT>::
02089 do_transform(const _CharT* __lo, const _CharT* __hi) const
02090 {
02091
02092 string_type __str(__lo, __hi);
02093
02094 const _CharT* __p = __str.c_str();
02095 const _CharT* __pend = __str.c_str() + __str.length();
02096
02097 size_t __len = (__hi - __lo) * 2;
02098
02099 string_type __ret;
02100
02101
02102
02103
02104 for (;;)
02105 {
02106
02107 _CharT* __c =
02108 static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len));
02109 size_t __res = _M_transform(__c, __p, __len);
02110
02111
02112 if (__res >= __len)
02113 {
02114 __len = __res + 1;
02115 __c = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
02116 * __len));
02117 __res = _M_transform(__c, __p, __res + 1);
02118 }
02119
02120 __ret.append(__c, __res);
02121 __p += char_traits<_CharT>::length(__p);
02122 if (__p == __pend)
02123 return __ret;
02124
02125 __p++;
02126 __ret.push_back(_CharT());
02127 }
02128 }
02129
02130 template<typename _CharT>
02131 long
02132 collate<_CharT>::
02133 do_hash(const _CharT* __lo, const _CharT* __hi) const
02134 {
02135 unsigned long __val = 0;
02136 for (; __lo < __hi; ++__lo)
02137 __val = *__lo + ((__val << 7) |
02138 (__val >> (numeric_limits<unsigned long>::digits - 7)));
02139 return static_cast<long>(__val);
02140 }
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153 template<typename _CharT, typename _Traits>
02154 void
02155 __pad<_CharT, _Traits>::_S_pad(ios_base& __io, _CharT __fill,
02156 _CharT* __news, const _CharT* __olds,
02157 const streamsize __newlen,
02158 const streamsize __oldlen, const bool __num)
02159 {
02160 const size_t __plen = static_cast<size_t>(__newlen - __oldlen);
02161 const ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield;
02162
02163
02164 if (__adjust == ios_base::left)
02165 {
02166 _Traits::copy(__news, const_cast<_CharT*>(__olds), __oldlen);
02167 _Traits::assign(__news + __oldlen, __plen, __fill);
02168 return;
02169 }
02170
02171 size_t __mod = 0;
02172 if (__adjust == ios_base::internal && __num)
02173 {
02174
02175
02176
02177 const locale& __loc = __io.getloc();
02178 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
02179 const _CharT __minus = __ctype.widen('-');
02180 const _CharT __plus = __ctype.widen('+');
02181 const bool __testsign = _Traits::eq(__olds[0], __minus)
02182 || _Traits::eq(__olds[0], __plus);
02183
02184 const bool __testhex = (_Traits::eq(__ctype.widen('0'), __olds[0])
02185 && __oldlen > 1
02186 && (_Traits::eq(__ctype.widen('x'), __olds[1])
02187 || _Traits::eq(__ctype.widen('X'),
02188 __olds[1])));
02189 if (__testhex)
02190 {
02191 __news[0] = __olds[0];
02192 __news[1] = __olds[1];
02193 __mod = 2;
02194 __news += 2;
02195 }
02196 else if (__testsign)
02197 {
02198 __news[0] = __olds[0];
02199 __mod = 1;
02200 ++__news;
02201 }
02202
02203 }
02204 _Traits::assign(__news, __plen, __fill);
02205 _Traits::copy(__news + __plen, const_cast<_CharT*>(__olds + __mod),
02206 __oldlen - __mod);
02207 }
02208
02209 template<typename _CharT>
02210 bool
02211 __verify_grouping(const basic_string<_CharT>& __grouping,
02212 basic_string<_CharT>& __grouping_tmp)
02213 {
02214 const size_t __n = __grouping_tmp.size() - 1;
02215 const size_t __min = std::min(__n, __grouping.size() - 1);
02216 size_t __i = __n;
02217 bool __test = true;
02218
02219
02220
02221
02222 for (size_t __j = 0; __j < __min && __test; --__i, ++__j)
02223 __test = __grouping_tmp[__i] == __grouping[__j];
02224 for (; __i && __test; --__i)
02225 __test = __grouping_tmp[__i] == __grouping[__min];
02226
02227
02228 __test &= __grouping_tmp[0] <= __grouping[__min];
02229 return __test;
02230 }
02231
02232 template<typename _CharT>
02233 _CharT*
02234 __add_grouping(_CharT* __s, _CharT __sep,
02235 const char* __gbeg, const char* __gend,
02236 const _CharT* __first, const _CharT* __last)
02237 {
02238 if (__last - __first > *__gbeg)
02239 {
02240 __s = __add_grouping(__s, __sep,
02241 (__gbeg + 1 == __gend ? __gbeg : __gbeg + 1),
02242 __gend, __first, __last - *__gbeg);
02243 __first = __last - *__gbeg;
02244 *__s++ = __sep;
02245 }
02246 do
02247 *__s++ = *__first++;
02248 while (__first != __last);
02249 return __s;
02250 }
02251
02252 #if 1
02253
02254 template<typename _CharT, typename _OutIter>
02255 template<typename _ValueT>
02256 _OutIter
02257 num_put<_CharT, _OutIter>::
02258 _M_convert_int(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
02259 char __modl, _ValueT __v) const
02260 {
02261
02262
02263
02264 char __fbuf[16];
02265 _S_format_int(__io, __fbuf, __mod, __modl);
02266 #ifdef _GLIBCPP_USE_C99
02267
02268 int __cs_size = 64;
02269 char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
02270 int __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
02271 _S_c_locale);
02272
02273 if (__len >= __cs_size)
02274 {
02275 __cs_size = __len + 1;
02276 __cs = static_cast<char*>(__builtin_alloca(__cs_size));
02277 __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
02278 _S_c_locale);
02279 }
02280 #else
02281
02282
02283 char __cs[128];
02284 int __len = __convert_from_v(__cs, 0, __fbuf, __v, _S_c_locale);
02285 #endif
02286 return _M_widen_int(__s, __io, __fill, __cs, __len);
02287 }
02288
02289 template<typename _CharT, typename _OutIter>
02290 _OutIter
02291 num_put<_CharT, _OutIter>::
02292 _M_widen_float(_OutIter __s, ios_base& __io, _CharT __fill, char* __cs,
02293 int __len) const
02294 {
02295 typedef char_traits<_CharT> __traits_type;
02296
02297
02298 const locale __loc = __io.getloc();
02299 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
02300 _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
02301 * __len));
02302
02303
02304 _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
02305 * __len * 2));
02306 __ctype.widen(__cs, __cs + __len, __ws);
02307
02308
02309 const _CharT* __p;
02310 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
02311 if (__p = __traits_type::find(__ws, __len, __ctype.widen('.')))
02312 __ws[__p - __ws] = __np.decimal_point();
02313
02314 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
02315
02316
02317 const string __grouping = __np.grouping();
02318 if (__grouping.size())
02319 {
02320 _CharT* __p2;
02321 int __declen = __p ? __p - __ws : __len;
02322 __p2 = __add_grouping(__ws2, __np.thousands_sep(),
02323 __grouping.c_str(),
02324 __grouping.c_str() + __grouping.size(),
02325 __ws, __ws + __declen);
02326 int __newlen = __p2 - __ws2;
02327
02328
02329 if (__p)
02330 {
02331 __traits_type::copy(__p2, __p, __len - __declen);
02332 __newlen += __len - __declen;
02333 }
02334
02335
02336 __ws = __ws2;
02337 __len = __newlen;
02338 }
02339 #endif
02340 return _M_insert(__s, __io, __fill, __ws, __len);
02341 }
02342
02343 template<typename _CharT, typename _OutIter>
02344 _OutIter
02345 num_put<_CharT, _OutIter>::
02346 _M_widen_int(_OutIter __s, ios_base& __io, _CharT __fill, char* __cs,
02347 int __len) const
02348 {
02349
02350
02351 const locale __loc = __io.getloc();
02352 const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
02353 _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
02354 * __len));
02355
02356
02357 _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
02358 * __len * 2));
02359 __ctype.widen(__cs, __cs + __len, __ws);
02360
02361
02362 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
02363 const string __grouping = __np.grouping();
02364 if (__grouping.size())
02365 {
02366
02367
02368
02369
02370
02371 streamsize __off = 0;
02372 const ios_base::fmtflags __basefield = __io.flags()
02373 & ios_base::basefield;
02374 if ((__io.flags() & ios_base::showbase) && __len > 1)
02375 if (__basefield == ios_base::oct)
02376 {
02377 __off = 1;
02378 *__ws2 = *__ws;
02379 }
02380 else if (__basefield == ios_base::hex)
02381 {
02382 __off = 2;
02383 *__ws2 = *__ws;
02384 *(__ws2 + 1) = *(__ws + 1);
02385 }
02386 _CharT* __p;
02387 __p = __add_grouping(__ws2 + __off, __np.thousands_sep(),
02388 __grouping.c_str(),
02389 __grouping.c_str() + __grouping.size(),
02390 __ws + __off, __ws + __len);
02391 __len = __p - __ws2;
02392
02393 __ws = __ws2;
02394 }
02395 return _M_insert(__s, __io, __fill, __ws, __len);
02396 }
02397
02398
02399
02400 template<typename _CharT, typename _OutIter>
02401 _OutIter
02402 num_put<_CharT, _OutIter>::
02403 _M_insert(_OutIter __s, ios_base& __io, _CharT __fill, const _CharT* __ws,
02404 int __len) const
02405 {
02406 typedef char_traits<_CharT> __traits_type;
02407
02408
02409 streamsize __w = __io.width();
02410 _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
02411 * __w));
02412 if (__w > static_cast<streamsize>(__len))
02413 {
02414 __pad<_CharT, __traits_type>::_S_pad(__io, __fill, __ws2, __ws,
02415 __w, __len, true);
02416 __len = static_cast<int>(__w);
02417
02418 __ws = __ws2;
02419 }
02420 __io.width(0);
02421
02422
02423
02424 return __write(__s, __ws, __len);
02425 }
02426 #endif
02427
02428 template<typename _CharT>
02429 __locale_cache<numpunct<_CharT> >::__locale_cache(const locale& __loc)
02430 : _M_truename(0), _M_falsename(0), _M_use_grouping(false),
02431 _M_grouping(0)
02432 {
02433 if (has_facet<numpunct<_CharT> >(__loc))
02434 {
02435 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
02436 _M_decimal_point = __np.decimal_point();
02437 _M_thousands_sep = __np.thousands_sep();
02438
02439 string_type __false = __np.falsename();
02440 _CharT* __falsename = new _CharT[__false.length() + 1];
02441 __false.copy(__falsename, __false.length());
02442 __falsename[__false.length()] = _CharT();
02443 _M_falsename = __falsename;
02444
02445 string_type __true = __np.truename();
02446 _CharT* __truename = new _CharT[__true.length() + 1];
02447 __true.copy(__truename, __true.length());
02448 __truename[__true.length()] = _CharT();
02449 _M_truename = __truename;
02450
02451 string __grouping = __np.grouping();
02452 char* __group = new char[__grouping.length() + 1];
02453 __grouping.copy(__group, __grouping.length());
02454 __group[__grouping.length()] = 0;
02455 _M_grouping = __group;
02456
02457 _M_use_grouping = __grouping.length() != 0
02458 && __grouping.data()[0] != 0;
02459 }
02460
02461 if (has_facet<ctype<_CharT> >(__loc))
02462 {
02463 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
02464 __ct.widen(__num_base::_S_atoms_out,
02465 __num_base::_S_atoms_out + __num_base::_S_end,
02466 _M_atoms_out);
02467 }
02468 }
02469
02470
02471
02472 template<typename _CharT>
02473 __locale_cache<numpunct<_CharT> >::
02474 __locale_cache(const locale& __loc, bool)
02475 {
02476
02477 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
02478 _M_thousands_sep = __np._M_thousands_sep;
02479 _M_decimal_point = __np._M_decimal_point;
02480 _M_falsename = __np._M_falsename;
02481 _M_truename = __np._M_truename;
02482 _M_grouping = __np._M_grouping;
02483 _M_use_grouping = false;
02484
02485 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
02486 __ct.widen(__num_base::_S_atoms_out,
02487 __num_base::_S_atoms_out + __num_base::_S_end,
02488 _M_atoms_out);
02489 }
02490
02491
02492
02493
02494 #if _GLIBCPP_EXTERN_TEMPLATE
02495 extern template class moneypunct<char, false>;
02496 extern template class moneypunct<char, true>;
02497 extern template class moneypunct_byname<char, false>;
02498 extern template class moneypunct_byname<char, true>;
02499 extern template class money_get<char>;
02500 extern template class money_put<char>;
02501 extern template class numpunct<char>;
02502 extern template class numpunct_byname<char>;
02503 extern template class num_get<char>;
02504 extern template class num_put<char>;
02505 extern template class __timepunct<char>;
02506 extern template class time_put<char>;
02507 extern template class time_put_byname<char>;
02508 extern template class time_get<char>;
02509 extern template class time_get_byname<char>;
02510 extern template class messages<char>;
02511 extern template class messages_byname<char>;
02512 extern template class ctype_byname<char>;
02513 extern template class codecvt_byname<char, char, mbstate_t>;
02514 extern template class collate<char>;
02515 extern template class collate_byname<char>;
02516
02517 extern template
02518 const codecvt<char, char, mbstate_t>&
02519 use_facet<codecvt<char, char, mbstate_t> >(const locale&);
02520
02521 extern template
02522 const collate<char>&
02523 use_facet<collate<char> >(const locale&);
02524
02525 extern template
02526 const numpunct<char>&
02527 use_facet<numpunct<char> >(const locale&);
02528
02529 extern template
02530 const num_put<char>&
02531 use_facet<num_put<char> >(const locale&);
02532
02533 extern template
02534 const num_get<char>&
02535 use_facet<num_get<char> >(const locale&);
02536
02537 extern template
02538 const moneypunct<char, true>&
02539 use_facet<moneypunct<char, true> >(const locale&);
02540
02541 extern template
02542 const moneypunct<char, false>&
02543 use_facet<moneypunct<char, false> >(const locale&);
02544
02545 extern template
02546 const money_put<char>&
02547 use_facet<money_put<char> >(const locale&);
02548
02549 extern template
02550 const money_get<char>&
02551 use_facet<money_get<char> >(const locale&);
02552
02553 extern template
02554 const __timepunct<char>&
02555 use_facet<__timepunct<char> >(const locale&);
02556
02557 extern template
02558 const time_put<char>&
02559 use_facet<time_put<char> >(const locale&);
02560
02561 extern template
02562 const time_get<char>&
02563 use_facet<time_get<char> >(const locale&);
02564
02565 extern template
02566 const messages<char>&
02567 use_facet<messages<char> >(const locale&);
02568
02569 extern template
02570 bool
02571 has_facet<ctype<char> >(const locale&);
02572
02573 extern template
02574 bool
02575 has_facet<codecvt<char, char, mbstate_t> >(const locale&);
02576
02577 extern template
02578 bool
02579 has_facet<collate<char> >(const locale&);
02580
02581 extern template
02582 bool
02583 has_facet<numpunct<char> >(const locale&);
02584
02585 extern template
02586 bool
02587 has_facet<num_put<char> >(const locale&);
02588
02589 extern template
02590 bool
02591 has_facet<num_get<char> >(const locale&);
02592
02593 extern template
02594 bool
02595 has_facet<moneypunct<char> >(const locale&);
02596
02597 extern template
02598 bool
02599 has_facet<money_put<char> >(const locale&);
02600
02601 extern template
02602 bool
02603 has_facet<money_get<char> >(const locale&);
02604
02605 extern template
02606 bool
02607 has_facet<__timepunct<char> >(const locale&);
02608
02609 extern template
02610 bool
02611 has_facet<time_put<char> >(const locale&);
02612
02613 extern template
02614 bool
02615 has_facet<time_get<char> >(const locale&);
02616
02617 extern template
02618 bool
02619 has_facet<messages<char> >(const locale&);
02620
02621 #ifdef _GLIBCPP_USE_WCHAR_T
02622 extern template class moneypunct<wchar_t, false>;
02623 extern template class moneypunct<wchar_t, true>;
02624 extern template class moneypunct_byname<wchar_t, false>;
02625 extern template class moneypunct_byname<wchar_t, true>;
02626 extern template class money_get<wchar_t>;
02627 extern template class money_put<wchar_t>;
02628 extern template class numpunct<wchar_t>;
02629 extern template class numpunct_byname<wchar_t>;
02630 extern template class num_get<wchar_t>;
02631 extern template class num_put<wchar_t>;
02632 extern template class __timepunct<wchar_t>;
02633 extern template class time_put<wchar_t>;
02634 extern template class time_put_byname<wchar_t>;
02635 extern template class time_get<wchar_t>;
02636 extern template class time_get_byname<wchar_t>;
02637 extern template class messages<wchar_t>;
02638 extern template class messages_byname<wchar_t>;
02639 extern template class ctype_byname<wchar_t>;
02640 extern template class codecvt_byname<wchar_t, char, mbstate_t>;
02641 extern template class collate<wchar_t>;
02642 extern template class collate_byname<wchar_t>;
02643
02644 extern template
02645 const codecvt<wchar_t, char, mbstate_t>&
02646 use_facet<codecvt<wchar_t, char, mbstate_t> >(locale const&);
02647
02648 extern template
02649 const collate<wchar_t>&
02650 use_facet<collate<wchar_t> >(const locale&);
02651
02652 extern template
02653 const numpunct<wchar_t>&
02654 use_facet<numpunct<wchar_t> >(const locale&);
02655
02656 extern template
02657 const num_put<wchar_t>&
02658 use_facet<num_put<wchar_t> >(const locale&);
02659
02660 extern template
02661 const num_get<wchar_t>&
02662 use_facet<num_get<wchar_t> >(const locale&);
02663
02664 extern template
02665 const moneypunct<wchar_t, true>&
02666 use_facet<moneypunct<wchar_t, true> >(const locale&);
02667
02668 extern template
02669 const moneypunct<wchar_t, false>&
02670 use_facet<moneypunct<wchar_t, false> >(const locale&);
02671
02672 extern template
02673 const money_put<wchar_t>&
02674 use_facet<money_put<wchar_t> >(const locale&);
02675
02676 extern template
02677 const money_get<wchar_t>&
02678 use_facet<money_get<wchar_t> >(const locale&);
02679
02680 extern template
02681 const __timepunct<wchar_t>&
02682 use_facet<__timepunct<wchar_t> >(const locale&);
02683
02684 extern template
02685 const time_put<wchar_t>&
02686 use_facet<time_put<wchar_t> >(const locale&);
02687
02688 extern template
02689 const time_get<wchar_t>&
02690 use_facet<time_get<wchar_t> >(const locale&);
02691
02692 extern template
02693 const messages<wchar_t>&
02694 use_facet<messages<wchar_t> >(const locale&);
02695
02696 extern template
02697 bool
02698 has_facet<ctype<wchar_t> >(const locale&);
02699
02700 extern template
02701 bool
02702 has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
02703
02704 extern template
02705 bool
02706 has_facet<collate<wchar_t> >(const locale&);
02707
02708 extern template
02709 bool
02710 has_facet<numpunct<wchar_t> >(const locale&);
02711
02712 extern template
02713 bool
02714 has_facet<num_put<wchar_t> >(const locale&);
02715
02716 extern template
02717 bool
02718 has_facet<num_get<wchar_t> >(const locale&);
02719
02720 extern template
02721 bool
02722 has_facet<moneypunct<wchar_t> >(const locale&);
02723
02724 extern template
02725 bool
02726 has_facet<money_put<wchar_t> >(const locale&);
02727
02728 extern template
02729 bool
02730 has_facet<money_get<wchar_t> >(const locale&);
02731
02732 extern template
02733 bool
02734 has_facet<__timepunct<wchar_t> >(const locale&);
02735
02736 extern template
02737 bool
02738 has_facet<time_put<wchar_t> >(const locale&);
02739
02740 extern template
02741 bool
02742 has_facet<time_get<wchar_t> >(const locale&);
02743
02744 extern template
02745 bool
02746 has_facet<messages<wchar_t> >(const locale&);
02747 #endif
02748 #endif
02749 }
02750
02751 #endif