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