void _STLP_CALL __get_floor_digits(__iostring &out, _STLP_LONG_DOUBLE __x) { #ifdef USE_SPRINTF_INSTEAD char cvtbuf[128]; # ifndef _STLP_NO_LONG_DOUBLE # ifndef N_PLAT_NLM snprintf(ARRAY_AND_SIZE(cvtbuf), "%Lf", __x); // check for 1234.56! # else sprintf(cvtbuf, "%Lf", __x); // check for 1234.56! # endif # else snprintf(ARRAY_AND_SIZE(cvtbuf), "%f", __x); // check for 1234.56! # endif char *p = strchr( cvtbuf, '.' ); if ( p == 0 ) { out.append( cvtbuf ); } else { out.append( cvtbuf, p ); } #else char cvtbuf[NDIG+2]; char * bp; int decpt, sign; #ifndef _STLP_NO_LONG_DOUBLE bp = _Stl_qfcvtR(__x, 0, &decpt, &sign, cvtbuf); #else bp = _Stl_fcvtR(__x, 0, &decpt, &sign, cvtbuf); #endif if (sign) { out += '-'; } out.append(bp, bp + decpt); #endif // USE_PRINTF_INSTEAD }
bool _STLP_CALL __read_float(__iostring& __buf, _InputIter& __in_ite, _InputIter& __end, ios_base& __s, _CharT*) { // Create a string, copying characters of the form // [+-]? [0-9]* .? [0-9]* ([eE] [+-]? [0-9]+)? bool __digits_before_dot /* = false */; bool __digits_after_dot = false; bool __ok; bool __grouping_ok = true; const ctype<_CharT>& __ct = *__STATIC_CAST(const ctype<_CharT>*, __s._M_ctype_facet()); const numpunct<_CharT>& __numpunct = *__STATIC_CAST(const numpunct<_CharT>*, __s._M_numpunct_facet()); const string& __grouping = __s._M_grouping(); // cached copy _CharT __dot = __numpunct.decimal_point(); _CharT __sep = __numpunct.thousands_sep(); _CharT __digits[10]; _CharT __xplus; _CharT __xminus; _CharT __pow_e; _CharT __pow_E; _Initialize_get_float(__ct, __xplus, __xminus, __pow_e, __pow_E, __digits); // Get an optional sign __in_ite = __copy_sign(__in_ite, __end, __buf, __xplus, __xminus); // Get an optional string of digits. if (!__grouping.empty()) __digits_before_dot = __copy_grouped_digits(__in_ite, __end, __buf, __digits, __sep, __grouping, __grouping_ok); else __digits_before_dot = __copy_digits(__in_ite, __end, __buf, __digits); // Get an optional decimal point, and an optional string of digits. if (__in_ite != __end && *__in_ite == __dot) { __buf.push_back('.'); ++__in_ite; __digits_after_dot = __copy_digits(__in_ite, __end, __buf, __digits); } // There have to be some digits, somewhere. __ok = __digits_before_dot || __digits_after_dot; // Get an optional exponent. if (__ok && __in_ite != __end && (*__in_ite == __pow_e || *__in_ite == __pow_E)) { __buf.push_back('e'); ++__in_ite; __in_ite = __copy_sign(__in_ite, __end, __buf, __xplus, __xminus); __ok = __copy_digits(__in_ite, __end, __buf, __digits); // If we have an exponent then the sign // is optional but the digits aren't. } return __ok; }
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); }
bool _STLP_CALL __copy_grouped_digits(_InputIter& __first, _InputIter __last, __iostring& __v, const _CharT * __digits, _CharT __sep, const string& __grouping, bool& __grouping_ok) { bool __ok = false; char __group_sizes[64]; char*__group_sizes_end = __group_sizes; char __current_group_size = 0; for ( ; __first != __last; ++__first) { _CharT __c = *__first; bool __tmp = __get_fdigit_or_sep(__c, __sep, __digits); if (__tmp) { if (__c == ',') { *__group_sizes_end++ = __current_group_size; __current_group_size = 0; } else { __ok = true; __v.push_back((char)__c); ++__current_group_size; } } else break; } if (__group_sizes_end != __group_sizes) *__group_sizes_end++ = __current_group_size; __grouping_ok = __valid_grouping(__group_sizes, __group_sizes_end, __grouping.data(), __grouping.data() + __grouping.size()); return __ok; }
void _STLP_CALL __adjust_float_buffer(__iostring &str, char dot) { if ('.' != dot) { size_t __dot_pos = str.find('.'); if (__dot_pos != string::npos) { str[__dot_pos] = dot; } } }
_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, '+', '-'); }
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 */ }
_InputIter _STLP_CALL __copy_sign(_InputIter __first, _InputIter __last, __iostring& __v, _CharT __xplus, _CharT __xminus) { if (__first != __last) { _CharT __c = *__first; if (__c == __xplus) ++__first; else if (__c == __xminus) { __v.push_back('-'); ++__first; } } return __first; }
bool _STLP_CALL __copy_digits(_InputIter& __first, _InputIter __last, __iostring& __v, const _CharT* __digits) { bool __ok = false; for ( ; __first != __last; ++__first) { _CharT __c = *__first; if (__get_fdigit(__c, __digits)) { __v.push_back((char)__c); __ok = true; } else break; } return __ok; }
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; }