epoc32/include/tools/stlport/stl/_monetary.c
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
/*
williamr@4
     2
 * Copyright (c) 1999
williamr@4
     3
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     4
 *
williamr@4
     5
 * Copyright (c) 1999
williamr@4
     6
 * Boris Fomitchev
williamr@4
     7
 *
williamr@4
     8
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
     9
 * or implied. Any use is at your own risk.
williamr@4
    10
 *
williamr@4
    11
 * Permission to use or copy this software for any purpose is hereby granted
williamr@4
    12
 * without fee, provided the above notices are retained on all copies.
williamr@4
    13
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    14
 * provided the above notices are retained, and a notice that the code was
williamr@4
    15
 * modified is included with the above copyright notice.
williamr@4
    16
 *
williamr@4
    17
 */
williamr@4
    18
#ifndef _STLP_MONETARY_C
williamr@4
    19
#define _STLP_MONETARY_C
williamr@4
    20
williamr@4
    21
# ifndef _STLP_INTERNAL_MONETARY_H
williamr@4
    22
#  include <stl/_monetary.h>
williamr@4
    23
# endif
williamr@4
    24
williamr@4
    25
#ifndef _STLP_INTERNAL_IOS_H
williamr@4
    26
# include <stl/_ios.h>
williamr@4
    27
#endif
williamr@4
    28
williamr@4
    29
#ifndef _STLP_INTERNAL_NUM_PUT_H
williamr@4
    30
# include <stl/_num_put.h>
williamr@4
    31
#endif
williamr@4
    32
williamr@4
    33
#ifndef _STLP_INTERNAL_NUM_GET_H
williamr@4
    34
# include <stl/_num_get.h>
williamr@4
    35
#endif
williamr@4
    36
williamr@4
    37
_STLP_BEGIN_NAMESPACE
williamr@4
    38
williamr@4
    39
#if (_STLP_STATIC_TEMPLATE_DATA > 0)
williamr@4
    40
williamr@4
    41
#  if !defined (__BORLANDC__)
williamr@4
    42
template <class _CharT, class _InputIterator>
williamr@4
    43
locale::id money_get<_CharT, _InputIterator>::id;
williamr@4
    44
williamr@4
    45
template <class _CharT, class _OutputIterator>
williamr@4
    46
locale::id money_put<_CharT, _OutputIterator>::id;
williamr@4
    47
#  endif
williamr@4
    48
williamr@4
    49
#  if (defined (__CYGWIN__) || defined (__MINGW32__)) && \
williamr@4
    50
       defined (_STLP_USE_DYNAMIC_LIB) && !defined (__BUILDING_STLPORT)
williamr@4
    51
/*
williamr@4
    52
 * Under cygwin, when STLport is used as a shared library, the id needs
williamr@4
    53
 * to be specified as imported otherwise they will be duplicated in the
williamr@4
    54
 * calling executable.
williamr@4
    55
 */
williamr@4
    56
template <>
williamr@4
    57
_STLP_DECLSPEC locale::id money_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
williamr@4
    58
/*
williamr@4
    59
template <>
williamr@4
    60
_STLP_DECLSPEC locale::id money_get<char, const char*>::id;
williamr@4
    61
*/
williamr@4
    62
williamr@4
    63
template <>
williamr@4
    64
_STLP_DECLSPEC locale::id money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
williamr@4
    65
template <>
williamr@4
    66
_STLP_DECLSPEC locale::id money_put<char, char*>::id;
williamr@4
    67
williamr@4
    68
#    if !defined (_STLP_NO_WCHAR_T)
williamr@4
    69
template <>
williamr@4
    70
_STLP_DECLSPEC locale::id money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
williamr@4
    71
template <>
williamr@4
    72
_STLP_DECLSPEC locale::id money_get<wchar_t, const wchar_t*>::id;
williamr@4
    73
williamr@4
    74
template <>
williamr@4
    75
_STLP_DECLSPEC locale::id money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
williamr@4
    76
template <>
williamr@4
    77
_STLP_DECLSPEC locale::id money_put<wchar_t, wchar_t*>::id;
williamr@4
    78
#    endif
williamr@4
    79
williamr@4
    80
#  endif
williamr@4
    81
williamr@4
    82
#else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
williamr@4
    83
williamr@4
    84
//typedef money_get<char, const char*> money_get_char;
williamr@4
    85
//typedef money_put<char, char*> money_put_char;
williamr@4
    86
typedef money_get<char, istreambuf_iterator<char, char_traits<char> > > money_get_char_2;
williamr@4
    87
typedef money_put<char, ostreambuf_iterator<char, char_traits<char> > > money_put_char_2;
williamr@4
    88
williamr@4
    89
//__DECLARE_INSTANCE(locale::id, money_get_char::id, );
williamr@4
    90
//__DECLARE_INSTANCE(locale::id, money_put_char::id, );
williamr@4
    91
__DECLARE_INSTANCE(locale::id, money_get_char_2::id, );
williamr@4
    92
__DECLARE_INSTANCE(locale::id, money_put_char_2::id, );
williamr@4
    93
williamr@4
    94
#  ifndef _STLP_NO_WCHAR_T
williamr@4
    95
williamr@4
    96
//typedef money_get<wchar_t, const wchar_t*> money_get_wchar_t;
williamr@4
    97
//typedef money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > money_get_wchar_t_2;
williamr@4
    98
typedef money_put<wchar_t, wchar_t*> money_put_wchar_t;
williamr@4
    99
typedef money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > money_put_wchar_t_2;
williamr@4
   100
williamr@4
   101
//__DECLARE_INSTANCE(locale::id, money_get_wchar_t::id, );
williamr@4
   102
//__DECLARE_INSTANCE(locale::id, money_put_wchar_t::id, );
williamr@4
   103
__DECLARE_INSTANCE(locale::id, money_get_wchar_t_2::id, );
williamr@4
   104
__DECLARE_INSTANCE(locale::id, money_put_wchar_t_2::id, );
williamr@4
   105
williamr@4
   106
#  endif
williamr@4
   107
#endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
williamr@4
   108
williamr@4
   109
// money_get facets
williamr@4
   110
williamr@4
   111
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   112
williamr@4
   113
// helper functions for do_get
williamr@4
   114
template <class _InIt1, class _InIt2>
williamr@4
   115
pair<_InIt1, bool> __get_string( _InIt1 __first, _InIt1 __last,
williamr@4
   116
                                 _InIt2 __str_first, _InIt2 __str_last) {
williamr@4
   117
  while ( __first != __last && __str_first != __str_last && *__first == *__str_first ) {
williamr@4
   118
    ++__first;
williamr@4
   119
    ++__str_first;
williamr@4
   120
  }
williamr@4
   121
  return make_pair(__first, __str_first == __str_last);
williamr@4
   122
}
williamr@4
   123
williamr@4
   124
template <class _InIt, class _OuIt, class _CharT>
williamr@4
   125
bool
williamr@4
   126
__get_monetary_value(_InIt& __first, _InIt __last, _OuIt __out_ite,
williamr@4
   127
                     const ctype<_CharT>& _c_type,
williamr@4
   128
                     _CharT __point, int __frac_digits, _CharT __sep,
williamr@4
   129
                     const string& __grouping, bool &__syntax_ok) {
williamr@4
   130
  if (__first == __last || !_c_type.is(ctype_base::digit, *__first))
williamr@4
   131
    return false;
williamr@4
   132
williamr@4
   133
  char __group_sizes[128];
williamr@4
   134
  char* __group_sizes_end = __grouping.empty()? 0 : __group_sizes;
williamr@4
   135
  char   __current_group_size = 0;
williamr@4
   136
williamr@4
   137
  while (__first != __last) {
williamr@4
   138
    if (_c_type.is(ctype_base::digit, *__first)) {
williamr@4
   139
      ++__current_group_size;
williamr@4
   140
      *__out_ite++ = *__first++;
williamr@4
   141
    }
williamr@4
   142
    else if (__group_sizes_end) {
williamr@4
   143
      if (*__first == __sep) {
williamr@4
   144
        *__group_sizes_end++ = __current_group_size;
williamr@4
   145
        __current_group_size = 0;
williamr@4
   146
        ++__first;
williamr@4
   147
      }
williamr@4
   148
      else break;
williamr@4
   149
    }
williamr@4
   150
    else
williamr@4
   151
      break;
williamr@4
   152
  }
williamr@4
   153
williamr@4
   154
  if (__grouping.empty())
williamr@4
   155
    __syntax_ok = true;
williamr@4
   156
  else {
williamr@4
   157
    if (__group_sizes_end != __group_sizes)
williamr@4
   158
      *__group_sizes_end++ = __current_group_size;
williamr@4
   159
williamr@4
   160
    __syntax_ok = __valid_grouping(__group_sizes, __group_sizes_end,
williamr@4
   161
                                   __grouping.data(), __grouping.data()+ __grouping.size());
williamr@4
   162
williamr@4
   163
    if (__first == __last || *__first != __point) {
williamr@4
   164
      for (int __digits = 0; __digits != __frac_digits; ++__digits)
williamr@4
   165
        *__out_ite++ = _CharT('0');
williamr@4
   166
      return true; // OK not to have decimal point
williamr@4
   167
    }
williamr@4
   168
  }
williamr@4
   169
williamr@4
   170
  ++__first;
williamr@4
   171
williamr@4
   172
  int __digits = 0;
williamr@4
   173
williamr@4
   174
  while (__first != __last && _c_type.is(ctype_base::digit, *__first)) {
williamr@4
   175
      *__out_ite++ = *__first++;
williamr@4
   176
     ++__digits;
williamr@4
   177
  }
williamr@4
   178
williamr@4
   179
  __syntax_ok = __syntax_ok && (__digits == __frac_digits);
williamr@4
   180
williamr@4
   181
  return true;
williamr@4
   182
}
williamr@4
   183
williamr@4
   184
williamr@4
   185
template <class _CharT, class _InputIter, class _StrType>
williamr@4
   186
_InputIter __money_do_get(_InputIter __s, _InputIter __end, bool  __intl,
williamr@4
   187
                     ios_base&  __str, ios_base::iostate&  __err,
williamr@4
   188
                     _StrType& __digits, bool &__is_positive, _CharT* /*__dummy*/) {
williamr@4
   189
  if (__s == __end) {
williamr@4
   190
    __err |= ios_base::eofbit;
williamr@4
   191
    return __s;
williamr@4
   192
  }
williamr@4
   193
williamr@4
   194
  typedef _CharT char_type;
williamr@4
   195
  typedef _StrType string_type;
williamr@4
   196
  typedef _InputIter iter_type;
williamr@4
   197
  typedef moneypunct<char_type, false> _Punct;
williamr@4
   198
  typedef moneypunct<char_type, true>  _Punct_intl;
williamr@4
   199
  typedef ctype<char_type>             _Ctype;
williamr@4
   200
williamr@4
   201
  locale __loc = __str.getloc();
williamr@4
   202
  const _Punct&      __punct      = use_facet<_Punct>(__loc) ;
williamr@4
   203
  const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ;
williamr@4
   204
  const _Ctype&      __c_type     = use_facet<_Ctype>(__loc) ;
williamr@4
   205
williamr@4
   206
  money_base::pattern __format = __intl ? __punct_intl.neg_format()
williamr@4
   207
                                        : __punct.neg_format();
williamr@4
   208
  string_type __ns = __intl ? __punct_intl.negative_sign()
williamr@4
   209
                            : __punct.negative_sign();
williamr@4
   210
  string_type __ps = __intl ? __punct_intl.positive_sign()
williamr@4
   211
                            : __punct.positive_sign();
williamr@4
   212
  int __i;
williamr@4
   213
  bool __symbol_required = (__str.flags() & ios_base::showbase) != 0;
williamr@4
   214
  string_type __buf;
williamr@4
   215
  back_insert_iterator<string_type> __out_ite(__buf);
williamr@4
   216
williamr@4
   217
  for (__i = 0; __i < 4; ++__i) {
williamr@4
   218
    switch (__format.field[__i]) {
williamr@4
   219
    case money_base::none:
williamr@4
   220
      if (__i == 3) {
williamr@4
   221
        if (__c_type.is(ctype_base::space, *__s)) {
williamr@4
   222
          __err = ios_base::failbit;
williamr@4
   223
          return __s;
williamr@4
   224
        }
williamr@4
   225
        break;
williamr@4
   226
      }
williamr@4
   227
      while (__s != __end && __c_type.is(ctype_base::space, *__s))
williamr@4
   228
        ++__s;
williamr@4
   229
      break;
williamr@4
   230
    case money_base::space:
williamr@4
   231
      if (!__c_type.is(ctype_base::space, *__s)) {
williamr@4
   232
        __err = ios_base::failbit;
williamr@4
   233
        return __s;
williamr@4
   234
      }
williamr@4
   235
      ++__s;
williamr@4
   236
      while (__s != __end && __c_type.is(ctype_base::space, *__s))
williamr@4
   237
        ++__s;
williamr@4
   238
      break;
williamr@4
   239
    case money_base::symbol: {
williamr@4
   240
      string_type __curs = __intl ? __punct_intl.curr_symbol()
williamr@4
   241
                                  : __punct.curr_symbol();
williamr@4
   242
      pair<iter_type, bool>
williamr@4
   243
      __result  = __get_string(__s, __end, __curs.begin(), __curs.end());
williamr@4
   244
      if (!__result.second && __symbol_required)
williamr@4
   245
        __err = ios_base::failbit;
williamr@4
   246
      __s = __result.first;
williamr@4
   247
      break;
williamr@4
   248
    }
williamr@4
   249
    case money_base::sign: {
williamr@4
   250
      if (__s == __end) {
williamr@4
   251
        if (__ps.empty())
williamr@4
   252
          break;
williamr@4
   253
        if (__ns.empty()) {
williamr@4
   254
          __is_positive = false;
williamr@4
   255
          break;
williamr@4
   256
        }
williamr@4
   257
        __err = ios_base::failbit;
williamr@4
   258
        return __s;
williamr@4
   259
      }
williamr@4
   260
      else {
williamr@4
   261
        if (__ps.empty()) {
williamr@4
   262
          if (__ns.empty())
williamr@4
   263
            break;
williamr@4
   264
          if (*__s == __ns[0]) {
williamr@4
   265
            ++__s;
williamr@4
   266
            __is_positive = false;
williamr@4
   267
          }
williamr@4
   268
          break;
williamr@4
   269
        }
williamr@4
   270
        else {
williamr@4
   271
          if (*__s == __ps[0]) {
williamr@4
   272
            ++__s;
williamr@4
   273
            break;
williamr@4
   274
          }
williamr@4
   275
          if (__ns.empty())
williamr@4
   276
            break;
williamr@4
   277
          if (*__s == __ns[0]) {
williamr@4
   278
            ++__s;
williamr@4
   279
            __is_positive = false;
williamr@4
   280
            break;
williamr@4
   281
          }
williamr@4
   282
          __err = ios_base::failbit;
williamr@4
   283
        }
williamr@4
   284
      }
williamr@4
   285
      return __s;
williamr@4
   286
    }
williamr@4
   287
    case money_base::value: {
williamr@4
   288
      char_type __point = __intl ? __punct_intl.decimal_point()
williamr@4
   289
                                 : __punct.decimal_point();
williamr@4
   290
      int __frac_digits = __intl ? __punct_intl.frac_digits()
williamr@4
   291
                                 : __punct.frac_digits();
williamr@4
   292
      string __grouping = __intl ? __punct_intl.grouping()
williamr@4
   293
                                 : __punct.grouping();
williamr@4
   294
      bool __syntax_ok = true;
williamr@4
   295
williamr@4
   296
      bool __result;
williamr@4
   297
williamr@4
   298
      char_type __sep = __grouping.empty() ? char_type() :
williamr@4
   299
      __intl ? __punct_intl.thousands_sep() : __punct.thousands_sep();
williamr@4
   300
williamr@4
   301
      __result = __get_monetary_value(__s, __end, __out_ite, __c_type,
williamr@4
   302
                                      __point, __frac_digits,
williamr@4
   303
                                      __sep,
williamr@4
   304
                                      __grouping, __syntax_ok);
williamr@4
   305
williamr@4
   306
      if (!__syntax_ok)
williamr@4
   307
        __err |= ios_base::failbit;
williamr@4
   308
      if (!__result) {
williamr@4
   309
        __err = ios_base::failbit;
williamr@4
   310
        return __s;
williamr@4
   311
      }
williamr@4
   312
      break;
williamr@4
   313
williamr@4
   314
    }                           // Close money_base::value case
williamr@4
   315
    }                           // Close switch statement
williamr@4
   316
  }                             // Close for loop
williamr@4
   317
williamr@4
   318
  if (__is_positive) {
williamr@4
   319
    if (__ps.size() > 1) {
williamr@4
   320
      pair<_InputIter, bool>
williamr@4
   321
        __result = __get_string(__s, __end, __ps.begin() + 1, __ps.end());
williamr@4
   322
      __s = __result.first;
williamr@4
   323
      if (!__result.second)
williamr@4
   324
        __err |= ios::failbit;
williamr@4
   325
    }
williamr@4
   326
    if (!(__err & ios_base::failbit))
williamr@4
   327
      __digits = __buf;
williamr@4
   328
  }
williamr@4
   329
  else {
williamr@4
   330
    if (__ns.size() > 1) {
williamr@4
   331
      pair<_InputIter, bool>
williamr@4
   332
        __result = __get_string(__s, __end, __ns.begin() + 1, __ns.end());
williamr@4
   333
      __s = __result.first;
williamr@4
   334
      if (!__result.second)
williamr@4
   335
        __err |= ios::failbit;
williamr@4
   336
    }
williamr@4
   337
    if (!(__err & ios::failbit)) {
williamr@4
   338
      __digits = __c_type.widen('-');
williamr@4
   339
      __digits += __buf;
williamr@4
   340
    }
williamr@4
   341
  }
williamr@4
   342
  if (__s == __end)
williamr@4
   343
    __err |= ios::eofbit;
williamr@4
   344
williamr@4
   345
  return __s;
williamr@4
   346
}
williamr@4
   347
williamr@4
   348
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   349
williamr@4
   350
//===== methods ======
williamr@4
   351
template <class _CharT, class _InputIter>
williamr@4
   352
_InputIter
williamr@4
   353
money_get<_CharT, _InputIter>::do_get(_InputIter __s, _InputIter  __end, bool  __intl,
williamr@4
   354
                                      ios_base&  __str, ios_base::iostate& __err,
williamr@4
   355
                                      _STLP_LONGEST_FLOAT_TYPE& __units) const {
williamr@4
   356
  string_type __buf;
williamr@4
   357
  bool __is_positive = true;
williamr@4
   358
  __s = _STLP_PRIV __money_do_get(__s, __end, __intl, __str, __err, __buf, __is_positive, (_CharT*)0);
williamr@4
   359
williamr@4
   360
  if (__err == ios_base::goodbit || __err == ios_base::eofbit) {
williamr@4
   361
    typename string_type::iterator __b = __buf.begin(), __e = __buf.end();
williamr@4
   362
williamr@4
   363
    if (!__is_positive) ++__b;
williamr@4
   364
    // Can't use atold, since it might be wchar_t. Don't get confused by name below :
williamr@4
   365
    // it's perfectly capable of reading long double.
williamr@4
   366
    _STLP_PRIV __get_decimal_integer(__b, __e, __units, (_CharT*)0);
williamr@4
   367
williamr@4
   368
    if (!__is_positive) {
williamr@4
   369
      __units = -__units;
williamr@4
   370
    }
williamr@4
   371
  }
williamr@4
   372
williamr@4
   373
  return __s;
williamr@4
   374
}
williamr@4
   375
williamr@4
   376
template <class _CharT, class _InputIter>
williamr@4
   377
_InputIter
williamr@4
   378
money_get<_CharT, _InputIter>::do_get(iter_type __s, iter_type  __end, bool  __intl,
williamr@4
   379
                                      ios_base&  __str, ios_base::iostate&  __err,
williamr@4
   380
                                      string_type& __digits) const {
williamr@4
   381
  bool __is_positive = true;
williamr@4
   382
  return _STLP_PRIV __money_do_get(__s, __end, __intl, __str, __err, __digits, __is_positive, (_CharT*)0);
williamr@4
   383
}
williamr@4
   384
williamr@4
   385
// money_put facets
williamr@4
   386
williamr@4
   387
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   388
williamr@4
   389
template <class _CharT, class _OutputIter, class _Str_Type, class _Str>
williamr@4
   390
_OutputIter __money_do_put(_OutputIter __s, bool  __intl, ios_base&  __str,
williamr@4
   391
                           _CharT __fill, const _Str& __digits, bool __check_digits,
williamr@4
   392
                           _Str_Type * /*__dummy*/) {
williamr@4
   393
  typedef _CharT char_type;
williamr@4
   394
  typedef _Str_Type string_type;
williamr@4
   395
  typedef ctype<char_type>             _Ctype;
williamr@4
   396
  typedef moneypunct<char_type, false> _Punct;
williamr@4
   397
  typedef moneypunct<char_type, true>  _Punct_intl;
williamr@4
   398
williamr@4
   399
  locale __loc = __str.getloc();
williamr@4
   400
  const _Ctype&      __c_type     = use_facet<_Ctype>(__loc) ;
williamr@4
   401
  const _Punct&      __punct      = use_facet<_Punct>(__loc) ;
williamr@4
   402
  const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ;
williamr@4
   403
williamr@4
   404
  // some special characters
williamr@4
   405
  char_type __minus = __c_type.widen('-');
williamr@4
   406
  char_type __plus  = __c_type.widen('+');
williamr@4
   407
  char_type __space = __c_type.widen(' ');
williamr@4
   408
  char_type __zero  = __c_type.widen('0');
williamr@4
   409
  char_type __point = __intl ? __punct_intl.decimal_point()
williamr@4
   410
                             : __punct.decimal_point();
williamr@4
   411
williamr@4
   412
  char_type __sep = __intl ? __punct_intl.thousands_sep()
williamr@4
   413
                           : __punct.thousands_sep();
williamr@4
   414
williamr@4
   415
  string __grouping = __intl ? __punct_intl.grouping()
williamr@4
   416
                             : __punct.grouping();
williamr@4
   417
williamr@4
   418
  int __frac_digits      = __intl ? __punct_intl.frac_digits()
williamr@4
   419
                                  : __punct.frac_digits();
williamr@4
   420
williamr@4
   421
  string_type __curr_sym = __intl ? __punct_intl.curr_symbol()
williamr@4
   422
                                  : __punct.curr_symbol();
williamr@4
   423
williamr@4
   424
  // if there are no digits we are going to return __s.  If there
williamr@4
   425
  // are digits, but not enough to fill the frac_digits, we are
williamr@4
   426
  // going to add zeros.  I don't know whether this is right or
williamr@4
   427
  // not.
williamr@4
   428
  if (__digits.empty())
williamr@4
   429
    return __s;
williamr@4
   430
williamr@4
   431
  typename string_type::const_iterator __digits_first = __digits.begin();
williamr@4
   432
  typename string_type::const_iterator __digits_last  = __digits.end();
williamr@4
   433
williamr@4
   434
  bool __is_negative = *__digits_first == __minus;
williamr@4
   435
  if (__is_negative)
williamr@4
   436
    ++__digits_first;
williamr@4
   437
williamr@4
   438
#if !defined (__BORLANDC__)
williamr@4
   439
  string_type __sign = __intl ? __is_negative ? __punct_intl.negative_sign()
williamr@4
   440
                                              : __punct_intl.positive_sign()
williamr@4
   441
                              : __is_negative ? __punct.negative_sign()
williamr@4
   442
                                              : __punct.positive_sign();
williamr@4
   443
#else
williamr@4
   444
  string_type __sign;
williamr@4
   445
  if (__intl) {
williamr@4
   446
    if (__is_negative)
williamr@4
   447
      __sign = __punct_intl.negative_sign();
williamr@4
   448
    else
williamr@4
   449
      __sign = __punct_intl.positive_sign();
williamr@4
   450
  }
williamr@4
   451
  else {
williamr@4
   452
    if (__is_negative)
williamr@4
   453
      __sign = __punct.negative_sign();
williamr@4
   454
    else
williamr@4
   455
      __sign = __punct.positive_sign();
williamr@4
   456
  }
williamr@4
   457
#endif
williamr@4
   458
williamr@4
   459
  if (__check_digits) {
williamr@4
   460
    typename string_type::const_iterator __cp = __digits_first;
williamr@4
   461
    while (__cp != __digits_last && __c_type.is(ctype_base::digit, *__cp))
williamr@4
   462
      ++__cp;
williamr@4
   463
    if (__cp == __digits_first)
williamr@4
   464
      return __s;
williamr@4
   465
    __digits_last = __cp;
williamr@4
   466
  }
williamr@4
   467
williamr@4
   468
  // If grouping is required, we make a copy of __digits and
williamr@4
   469
  // insert the grouping.
williamr@4
   470
  _STLP_BASIC_IOSTRING(char_type) __new_digits;
williamr@4
   471
  if (!__grouping.empty()) {
williamr@4
   472
    __new_digits.assign(__digits_first, __digits_last);
williamr@4
   473
    __insert_grouping(__new_digits,
williamr@4
   474
                      __new_digits.size() - __frac_digits,
williamr@4
   475
                      __grouping,
williamr@4
   476
                      __sep, __plus, __minus, 0);
williamr@4
   477
    __digits_first = __new_digits.begin(); // <<--
williamr@4
   478
    __digits_last  = __new_digits.end();   // <<--
williamr@4
   479
  }
williamr@4
   480
williamr@4
   481
  // Determine the amount of padding required, if any.
williamr@4
   482
  streamsize __width = __str.width();
williamr@4
   483
williamr@4
   484
#if defined (_STLP_DEBUG) && (defined(__HP_aCC) && (__HP_aCC <= 1))
williamr@4
   485
  size_t __value_length = operator -(__digits_last, __digits_first);
williamr@4
   486
#else
williamr@4
   487
  size_t __value_length = __digits_last - __digits_first;
williamr@4
   488
#endif
williamr@4
   489
williamr@4
   490
  size_t __length = __value_length + __sign.size();
williamr@4
   491
williamr@4
   492
  if (__frac_digits != 0)
williamr@4
   493
    ++__length;
williamr@4
   494
williamr@4
   495
  bool __generate_curr = (__str.flags() & ios_base::showbase) !=0;
williamr@4
   496
  if (__generate_curr)
williamr@4
   497
    __length += __curr_sym.size();
williamr@4
   498
  money_base::pattern __format = __intl ? (__is_negative ? __punct_intl.neg_format()
williamr@4
   499
                                                         : __punct_intl.pos_format())
williamr@4
   500
                                        : (__is_negative ? __punct.neg_format()
williamr@4
   501
                                                         : __punct.pos_format());
williamr@4
   502
  {
williamr@4
   503
    //For the moment the following is commented for decoding reason.
williamr@4
   504
    //No reason to add a space last if the money symbol do not have to be display
williamr@4
   505
    //if (__format.field[3] == (char) money_base::symbol && !__generate_curr) {
williamr@4
   506
    //  if (__format.field[2] == (char) money_base::space) {
williamr@4
   507
    //    __format.field[2] = (char) money_base::none;
williamr@4
   508
    //  }
williamr@4
   509
    //}
williamr@4
   510
    //space can only be second or third and only once (22.2.6.3-1):
williamr@4
   511
    if ((__format.field[1] == (char) money_base::space) ||
williamr@4
   512
        (__format.field[2] == (char) money_base::space))
williamr@4
   513
      ++__length;
williamr@4
   514
  }
williamr@4
   515
williamr@4
   516
  const bool __need_fill = (((sizeof(streamsize) > sizeof(size_t)) && (__STATIC_CAST(streamsize, __length) < __width)) ||
williamr@4
   517
                            ((sizeof(streamsize) <= sizeof(size_t)) && (__length < __STATIC_CAST(size_t, __width))));
williamr@4
   518
  streamsize __fill_amt = __need_fill ? __width - __length : 0;
williamr@4
   519
williamr@4
   520
  ios_base::fmtflags __fill_pos = __str.flags() & ios_base::adjustfield;
williamr@4
   521
williamr@4
   522
  if (__fill_amt != 0 &&
williamr@4
   523
      !(__fill_pos & (ios_base::left | ios_base::internal)))
williamr@4
   524
    __s = __fill_n(__s, __fill_amt, __fill);
williamr@4
   525
williamr@4
   526
  for (int __i = 0; __i < 4; ++__i) {
williamr@4
   527
    char __ffield = __format.field[__i];
williamr@4
   528
    switch (__ffield) {
williamr@4
   529
      case money_base::none:
williamr@4
   530
        if (__fill_amt != 0 && __fill_pos == ios_base::internal)
williamr@4
   531
          __s = __fill_n(__s, __fill_amt, __fill);
williamr@4
   532
        break;
williamr@4
   533
      case money_base::space:
williamr@4
   534
        *__s++ = __space;
williamr@4
   535
        if (__fill_amt != 0 && __fill_pos == ios_base::internal)
williamr@4
   536
          __s = __fill_n(__s, __fill_amt, __fill);
williamr@4
   537
        break;
williamr@4
   538
      case money_base::symbol:
williamr@4
   539
        if (__generate_curr)
williamr@4
   540
          __s = copy(__curr_sym.begin(), __curr_sym.end(), __s);
williamr@4
   541
        break;
williamr@4
   542
      case money_base::sign:
williamr@4
   543
        if (!__sign.empty())
williamr@4
   544
          *__s++ = __sign[0];
williamr@4
   545
        break;
williamr@4
   546
      case money_base::value:
williamr@4
   547
        if (__frac_digits == 0) {
williamr@4
   548
          __s = copy(__digits_first, __digits_last, __s);
williamr@4
   549
        } else {
williamr@4
   550
          if ((int)__value_length <= __frac_digits) {
williamr@4
   551
            // if we see '9' here, we should out 0.09
williamr@4
   552
            *__s++ = __zero;  // integer part is zero
williamr@4
   553
            *__s++ = __point; // decimal point
williamr@4
   554
            __s =  __fill_n(__s, __frac_digits - __value_length, __zero); // zeros
williamr@4
   555
            __s = copy(__digits_first, __digits_last, __s); // digits
williamr@4
   556
          } else {
williamr@4
   557
            __s = copy(__digits_first, __digits_last - __frac_digits, __s);
williamr@4
   558
            if (__frac_digits != 0) {
williamr@4
   559
              *__s++ = __point;
williamr@4
   560
              __s = copy(__digits_last - __frac_digits, __digits_last, __s);
williamr@4
   561
            }
williamr@4
   562
          }
williamr@4
   563
        }
williamr@4
   564
        break;
williamr@4
   565
    } //Close for switch
williamr@4
   566
  } // Close for loop
williamr@4
   567
williamr@4
   568
  // Ouput rest of sign if necessary.
williamr@4
   569
  if (__sign.size() > 1)
williamr@4
   570
    __s = copy(__sign.begin() + 1, __sign.end(), __s);
williamr@4
   571
  if (__fill_amt != 0 &&
williamr@4
   572
      !(__fill_pos & (ios_base::right | ios_base::internal)))
williamr@4
   573
    __s = __fill_n(__s, __fill_amt, __fill);
williamr@4
   574
williamr@4
   575
  return __s;
williamr@4
   576
}
williamr@4
   577
williamr@4
   578
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   579
williamr@4
   580
template <class _CharT, class _OutputIter>
williamr@4
   581
_OutputIter
williamr@4
   582
money_put<_CharT, _OutputIter>
williamr@4
   583
 ::do_put(_OutputIter __s, bool __intl, ios_base& __str,
williamr@4
   584
          char_type __fill, _STLP_LONGEST_FLOAT_TYPE __units) const {
williamr@4
   585
  _STLP_BASIC_IOSTRING(char_type) __digits;
williamr@4
   586
  _STLP_PRIV __get_money_digits(__digits, __str, __units);
williamr@4
   587
  return _STLP_PRIV __money_do_put(__s, __intl, __str, __fill, __digits, false, __STATIC_CAST(string_type*, 0));
williamr@4
   588
}
williamr@4
   589
williamr@4
   590
template <class _CharT, class _OutputIter>
williamr@4
   591
_OutputIter
williamr@4
   592
money_put<_CharT, _OutputIter>
williamr@4
   593
 ::do_put(_OutputIter __s, bool __intl, ios_base& __str,
williamr@4
   594
          char_type __fill, const string_type& __digits) const {
williamr@4
   595
  return _STLP_PRIV __money_do_put(__s, __intl, __str, __fill, __digits, true, __STATIC_CAST(string_type*, 0));
williamr@4
   596
}
williamr@4
   597
williamr@4
   598
_STLP_END_NAMESPACE
williamr@4
   599
williamr@4
   600
#endif /* _STLP_MONETARY_C */
williamr@4
   601
williamr@4
   602
// Local Variables:
williamr@4
   603
// mode:C++
williamr@4
   604
// End: