Esempio n. 1
0
void _STLP_CALL
__convert_float_buffer(__iostring const& str, __iowstring &out,
                       const ctype<wchar_t>& ct, wchar_t dot, bool __check_dot) {
    wchar_t __static_buf[128];
    wchar_t *__beg = __static_buf;
    wchar_t *__end = __static_buf + (sizeof(__static_buf) / sizeof(wchar_t));
    string::const_iterator str_ite(str.begin()), str_end(str.end());

    wchar_t *__cur = __beg;
    //First loop, check the dot char
    if (__check_dot) {
        while (str_ite != str_end) {
            if (*str_ite != '.') {
                *__cur = ct.widen(*str_ite);
            } else {
                *__cur = dot;
                break;
            }
            ++__cur;
            if (__cur == __end) {
                out.append(__beg, __cur);
                __cur = __beg;
            }
            ++str_ite;
        }
    } else {
        if (str_ite != str_end) {
            *__cur = ct.widen(*str_ite);
        }
    }

    if (str_ite != str_end) {
        ++__cur;
        ++str_ite;
        if (__cur == __end) {
            out.append(__beg, __cur);
            __cur = __beg;
        }

        //Second loop, dot has been found, no check anymore
        while (str_ite != str_end) {
            *__cur = ct.widen(*str_ite);
            ++__cur;
            if (__cur == __end) {
                out.append(__beg, __cur);
                __cur = __beg;
            }
            ++str_ite;
        }
    }

    out.append(__beg, __cur);
}
Esempio n. 2
0
size_t _STLP_CALL
__write_float(__iostring &buf, ios_base::fmtflags flags, int precision,
              long double x) {
#  ifdef USE_SPRINTF_INSTEAD
  /* If we want 'abitrary' precision, we should use 'abitrary' buffer size
   * below. - ptr
   */
  char static_buf[128];
  // char *static_buf = new char [128+precision];
  char fmtbuf[64];
  int i = fill_fmtbuf(fmtbuf, flags, 'L');
  // snprintf(static_buf, 128+precision, fmtbuf, precision, x);
#   ifndef N_PLAT_NLM
  snprintf(ARRAY_AND_SIZE(static_buf), fmtbuf, precision, x);    
#   else
  sprintf(static_buf, fmtbuf, precision, x);
#   endif
  // we should be able to return buf + sprintf(), but we do not trust'em...
  buf = static_buf;
  // delete [] static_buf;
  return find_if(buf.begin(), buf.end(), GroupPos()) - buf.begin();
#  else
  char cvtbuf[NDIG+2];
  char * bp;
  int decpt, sign;

  switch (flags & ios_base::floatfield) {
  case ios_base::fixed:
    bp = _Stl_qfcvtR(x, (min) (precision, MAXFCVT), &decpt, &sign, cvtbuf);
    break;
  case ios_base::scientific:
    bp = _Stl_qecvtR(x, (min) (precision + 1, MAXECVT), &decpt, &sign, cvtbuf);
    break;
  default :
    bp = _Stl_qecvtR(x, (min) (precision, MAXECVT), &decpt, &sign, cvtbuf);
    break;
  }
  return __format_float(buf, bp, decpt, sign, x, flags, precision, true);
#  endif /* USE_SPRINTF_INSTEAD */
}