Beispiel #1
0
_OutputIter  _STLP_CALL
__put_float(__iostring &__str, _OutputIter __oi,
            ios_base& __f, char __fill,
            char __decimal_point, char __sep, 
            size_t __group_pos, const string& __grouping) {
  if ((__group_pos < __str.size()) && (__str[__group_pos] == '.')) {
    __str[__group_pos] = __decimal_point;
  }

  if (!__grouping.empty()) {
    __insert_grouping(__str, __group_pos,
                      __grouping, __sep, '+', '-', 0);
  }

  return __copy_float_and_fill(__CONST_CAST(char*, __str.data()), 
                               __CONST_CAST(char*, __str.data()) + __str.size(), __oi,
                               __f.flags(), __f.width(0), __fill, '+', '-');
}
Beispiel #2
0
size_t __format_float_fixed(__iostring &buf, const char * bp,
                            int decpt, int sign, bool /* x */,
                            ios_base::fmtflags flags,
                            int precision, bool islong ) {
  size_t __group_pos;
  char static_buf[128];
  int const BUF_SIZE = sizeof(static_buf) - 1;
  char *sbuf = static_buf;

  if (sign && decpt > -precision && *bp != 0)
    *sbuf++ = '-';
  else if (flags & ios_base::showpos)
    *sbuf++ = '+';
  
  int rzero   = 0;
  int nn      = decpt;
  int k       = 0;
  int maxfsig = islong ? 2*MAXFSIG : MAXFSIG;

  do {
    int nnn = (min) (nn, BUF_SIZE);
    nn -= nnn;
    do {
      *sbuf++ = ((nnn <= 0 || *bp == 0 || k >= maxfsig) ?
               '0' : (++k, *bp++));
    } while (--nnn > 0);
    buf.append(static_buf, sbuf);
    sbuf = static_buf;
  } while (nn != 0);

  // decimal point if needed
  __group_pos = buf.size() - 1;
  if (flags & ios_base::showpoint || precision > 0) {
    *sbuf++ = '.';
    ++__group_pos;
  } 

  // digits after decimal point if any
  nn = (min) (precision, MAXFCVT);
  if (precision > nn)
    rzero = precision - nn;
  while (nn != 0) {
    int nnn = (min) (nn, BUF_SIZE);
    nn -= nnn;
    while (--nnn >= 0) {
     *sbuf++ = (++decpt <= 0 || *bp == 0 || k >= maxfsig) ?
               '0' : (++k, *bp++);
    }
    buf.append(static_buf, sbuf);
    sbuf = static_buf;
  }

  // trailing zeros if needed
  while (rzero != 0) {
    int nnn = (min) (rzero, BUF_SIZE);
    rzero -= nnn;
    while (nnn-- > 0) {
      *sbuf++ = '0';
    }
    buf.append(static_buf, sbuf);
    sbuf = static_buf;
  }
  return __group_pos;
}