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