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