_OutputIter
money_put<_CharT, _OutputIter>
 ::do_put(_OutputIter __s, bool __intl, ios_base& __str,
          char_type __fill, _STLP_LONG_DOUBLE __units) const {
  _STLP_BASIC_IOSTRING(char_type) __digits;
  __get_money_digits(__digits, __str, __units);
  return _S_do_put(__s, __intl, __str, __fill, __digits, false, __STATIC_CAST(string_type*, 0));
}
Beispiel #2
0
inline void __get_money_digits_aux (__iostring &__buf, ios_base &, _STLP_LONG_DOUBLE __x) {
  __get_floor_digits(__buf, __x);
}

#if !defined (_STLP_NO_WCHAR_T)
inline void __get_money_digits_aux (__iowstring &__wbuf, ios_base &__f, _STLP_LONG_DOUBLE __x) {
  __iostring __buf;
  __get_floor_digits(__buf, __x);

  const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet());
  __convert_float_buffer(__buf, __wbuf, __ct, wchar_t(0), false);
}
#endif

template <class _CharT>
void _STLP_CALL __get_money_digits(_STLP_BASIC_IOSTRING(_CharT) &__buf, ios_base& __f, _STLP_LONG_DOUBLE __x) {
  __get_money_digits_aux(__buf, __f, __x);
}

// _M_do_put_integer and its helper functions.

template <class _CharT, class _OutputIter>
_OutputIter _STLP_CALL
__copy_integer_and_fill(const _CharT* __buf, ptrdiff_t __len,
                        _OutputIter __oi,
                        ios_base::fmtflags __flg, streamsize __wid, _CharT __fill,
                        _CharT __xplus, _CharT __xminus) {
  if (__len >= __wid)
    return copy(__buf, __buf + __len, __oi);
  else {
    //casting numeric_limits<ptrdiff_t>::max to streamsize only works is ptrdiff_t is signed or streamsize representation
Beispiel #3
0
  for (i = 0; i < 7; ++i)
    table._M_dayname[i] = _WLocale_abbrev_dayofweek(time, i, _STLP_ARRAY_AND_SIZE(buf));
  for (i = 0; i < 7; ++i)
    table._M_dayname[i+7] = _WLocale_full_dayofweek(time, i, _STLP_ARRAY_AND_SIZE(buf));
  for (i = 0; i < 12; ++i)
    table._M_monthname[i] = _WLocale_abbrev_monthname(time, i, _STLP_ARRAY_AND_SIZE(buf));
  for (i = 0; i < 12; ++i)
    table._M_monthname[i+12] = _WLocale_full_monthname(time, i, _STLP_ARRAY_AND_SIZE(buf));
  table._M_am_pm[0] = _WLocale_am_str(time, _STLP_ARRAY_AND_SIZE(buf));
  table._M_am_pm[1] = _WLocale_pm_str(time, _STLP_ARRAY_AND_SIZE(buf));
  _Init_timeinfo_base(table, time);
}
#endif

template <class _Ch, class _TimeInfo>
void __subformat(_STLP_BASIC_IOSTRING(_Ch) &buf, const ctype<_Ch>& ct,
                 const string& format, const _TimeInfo& table, const tm* t) {
  const char * cp = format.data();
  const char * cp_end = cp + format.size();
  while (cp != cp_end) {
    if (*cp == '%') {
      char mod = 0;
      ++cp;
      if (*cp == '#') {
        mod = *cp; ++cp;
      }
      __write_formatted_timeT(buf, ct, *cp++, mod, table, t);
    } else
      buf.append(1, *cp++);
  }
}
_OutputIter _S_do_put(_OutputIter __s, bool  __intl, ios_base&  __str,
                      _CharT __fill, const _Str& __digits, bool __check_digits,
                      _Str_Type * /*__dummy*/) {
  typedef _CharT char_type;
  typedef _Str_Type string_type;
  typedef ctype<char_type>             _Ctype;
  typedef moneypunct<char_type, false> _Punct;
  typedef moneypunct<char_type, true>  _Punct_intl;

  locale __loc = __str.getloc();
  const _Ctype&      __c_type     = use_facet<_Ctype>(__loc) ;
  const _Punct&      __punct      = use_facet<_Punct>(__loc) ;
  const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ;

  // some special characters
  char_type __minus = __c_type.widen('-');
  char_type __plus  = __c_type.widen('+');
  char_type __space = __c_type.widen(' ');
  char_type __zero  = __c_type.widen('0');
  char_type __point = __intl ? __punct_intl.decimal_point()
                             : __punct.decimal_point();

  char_type __sep = __intl ? __punct_intl.thousands_sep()
                           : __punct.thousands_sep();

  string __grouping = __intl ? __punct_intl.grouping()
                             : __punct.grouping();

  int __frac_digits      = __intl ? __punct_intl.frac_digits() 
                                  : __punct.frac_digits();

  string_type __curr_sym = __intl ? __punct_intl.curr_symbol() 
                                  : __punct.curr_symbol();

  // if there are no digits we are going to return __s.  If there
  // are digits, but not enough to fill the frac_digits, we are
  // going to add zeros.  I don't know whether this is right or
  // not.
  if (__digits.empty()) 
    return __s;

  typename string_type::const_iterator __digits_first = __digits.begin();
  typename string_type::const_iterator __digits_last  = __digits.end();

  bool __is_negative = *__digits_first == __minus;
  if (__is_negative)
    ++__digits_first;

  string_type __sign = __intl ? __is_negative ? __punct_intl.negative_sign()
                                              : __punct_intl.positive_sign()
                              : __is_negative ? __punct.negative_sign()
                                              : __punct.positive_sign();
  if (__check_digits) {
    typename string_type::const_iterator __cp = __digits_first;
    while (__cp != __digits_last && __c_type.is(ctype_base::digit, *__cp))
      ++__cp;
    if (__cp == __digits_first)
      return __s;
    __digits_last = __cp;
  }

  // If grouping is required, we make a copy of __digits and
  // insert the grouping.

  _STLP_BASIC_IOSTRING(char_type) __new_digits;
  if (!__grouping.empty()) {
    __new_digits.assign(__digits_first, __digits_last);
    __insert_grouping(__new_digits,
                      __new_digits.size() - __frac_digits,
                      __grouping,
                      __sep, __plus, __minus, 0);
    __digits_first = __new_digits.begin(); // <<--
    __digits_last  = __new_digits.end();   // <<--
  }

  // Determine the amount of padding required, if any.  
  streamsize __width = __str.width();

#if defined(_STLP_DEBUG) && (defined(__HP_aCC) && (__HP_aCC <= 1))
  size_t __value_length = operator -(__digits_last, __digits_first);
#else
  size_t __value_length = __digits_last - __digits_first;
#endif

  size_t __length = __value_length + __sign.size();

  if (__frac_digits != 0)
    ++__length;

  bool __generate_curr = (__str.flags() & ios_base::showbase) !=0;
  if (__generate_curr)
    __length += __curr_sym.size();
  money_base::pattern __format = __intl ? (__is_negative ? __punct_intl.neg_format()
                                                         : __punct_intl.pos_format())
                                        : (__is_negative ? __punct.neg_format()
                                                         : __punct.pos_format());
  {
    //For the moment the following is commented for decoding reason.
    //No reason to add a space last if the money symbol do not have to be display
    //if (__format.field[3] == (char) money_base::symbol && !__generate_curr) {
    //  if (__format.field[2] == (char) money_base::space) {
    //    __format.field[2] = (char) money_base::none;
    //  }
    //}
    //space can only be second or third and only once (22.2.6.3-1):
    if ((__format.field[1] == (char) money_base::space) ||
        (__format.field[2] == (char) money_base::space))
      ++__length;
  }

  const bool __need_fill = (((sizeof(streamsize) > sizeof(size_t)) && (__STATIC_CAST(streamsize, __length) < __width)) ||
                            ((sizeof(streamsize) <= sizeof(size_t)) && (__length < __STATIC_CAST(size_t, __width))));
  streamsize __fill_amt = __need_fill ? __width - __length : 0;

  ios_base::fmtflags __fill_pos = __str.flags() & ios_base::adjustfield;

  if (__fill_amt != 0 &&
      !(__fill_pos & (ios_base::left | ios_base::internal)))
    __s = __fill_n(__s, __fill_amt, __fill);
    
  for (int __i = 0; __i < 4; ++__i) {
    char __ffield = __format.field[__i];
    switch (__ffield) {
    case money_base::none:
      if (__fill_amt != 0 && __fill_pos == ios_base::internal)
        __s = __fill_n(__s, __fill_amt, __fill);
      break;
    case money_base::space:
      *__s++ = __space;
      if (__fill_amt != 0 && __fill_pos == ios_base::internal)
        __s = __fill_n(__s, __fill_amt, __fill);
      break;
    case money_base::symbol:
      if (__generate_curr)
        __s = copy(__curr_sym.begin(), __curr_sym.end(), __s);
      break;
    case money_base::sign:
      if (!__sign.empty())
        *__s++ = __sign[0];
      break;
    case money_base::value:
      if (__frac_digits == 0)
        __s = copy(__digits_first, __digits_last, __s);
      else {
        if ((int)__value_length <= __frac_digits) {
          *__s++ = __point;
          __s = copy(__digits_first, __digits_last, __s);
          __s =  __fill_n(__s, __frac_digits - __value_length, __zero);
        }
        else {
          __s = copy(__digits_first, __digits_last - __frac_digits, __s);
          if (__frac_digits != 0) {
            *__s++ = __point;
            __s = copy(__digits_last - __frac_digits, __digits_last, __s);
          }
        }
      }
    } //Close for switch
  } // Close for loop

  // Ouput rest of sign if necessary.
  if (__sign.size() > 1)
    __s = copy(__sign.begin() + 1, __sign.end(), __s);
  if (__fill_amt != 0 &&
      !(__fill_pos & (ios_base::right | ios_base::internal)))
    __s = __fill_n(__s, __fill_amt, __fill);
  
  return __s;
}
Beispiel #5
0
inline void __get_money_digits_aux (__iostring &__buf, ios_base &, _STLP_LONGEST_FLOAT_TYPE __x)
{ __get_floor_digits(__buf, __x); }

#if !defined (_STLP_NO_WCHAR_T)
inline void __get_money_digits_aux (__iowstring &__wbuf, ios_base &__f, _STLP_LONGEST_FLOAT_TYPE __x) {
  __iostring __buf;
  __get_floor_digits(__buf, __x);

  const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet());
  __convert_float_buffer(__buf, __wbuf, __ct, wchar_t(0), false);
}
#endif

template <class _CharT>
void _STLP_CALL __get_money_digits(_STLP_BASIC_IOSTRING(_CharT) &__buf, ios_base& __f, _STLP_LONGEST_FLOAT_TYPE __x)
{ __get_money_digits_aux(__buf, __f, __x); }

// _M_do_put_integer and its helper functions.

template <class _CharT, class _OutputIter>
_OutputIter _STLP_CALL
__copy_integer_and_fill(const _CharT* __buf, ptrdiff_t __len,
                        _OutputIter __oi,
                        ios_base::fmtflags __flg, streamsize __wid, _CharT __fill,
                        _CharT __xplus, _CharT __xminus) {
  if (__len >= __wid)
    return copy(__buf, __buf + __len, __oi);
  else {
    //casting numeric_limits<ptrdiff_t>::max to streamsize only works is ptrdiff_t is signed or streamsize representation
    //is larger than ptrdiff_t one.