X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstrings%2Flexicalcast.cpp;h=ab83b110b432ba408f8bdfa3bd2fb53d3e848c8f;hp=71e346b7651818f9c91006fdfacaa8dce05613ed;hb=faeafc9d652ba6caa350ca95dff14408b036ccfb;hpb=95bd04e16acacde19fcfdcc722baf72b06dcdfee diff --git a/source/strings/lexicalcast.cpp b/source/strings/lexicalcast.cpp index 71e346b..ab83b11 100644 --- a/source/strings/lexicalcast.cpp +++ b/source/strings/lexicalcast.cpp @@ -14,16 +14,6 @@ template struct IsSigned { enum { result = !(static_cast(-1)>0) }; }; -templatesizeof(unsigned long))> -struct Temporary -{ typedef unsigned long Type; }; - -template -struct Temporary -{ - typedef UInt64 Type; -}; - /* Helper to avoid warnings about an unsigned type never being < 0 */ template::result> struct IsNegative @@ -69,7 +59,7 @@ char *int_to_str(T v, const Fmt &f, char *end) const char *digits = (f.get_uppercase() ? udigits : ldigits); if(v) { - typename Temporary::Type w = Absolute::eval(v); + typename MatchingInt::UnsignedType w = Absolute::eval(v); while(w) { *--ptr = digits[w%base]; @@ -247,7 +237,7 @@ string flt_to_str(T v, const Fmt &f) if(w>=10) { long double div = 1; - while(div*10(digits)); - if(w>10) + if(w>=10) { // Rounding bumped us to the next exponent, deal with it w /= 10; @@ -308,13 +300,19 @@ string flt_to_str(T v, const Fmt &f) } if(!showexp) { - ++digits; - ++point; + if(mode==Fmt::FIXED) + ++digits; + if(leading_zeroes) + --leading_zeroes; + else + ++point; } else ++exp; } + digits += leading_zeroes; + // Create a buffer and start from the end unsigned size = max(f.get_width(), digits+8); char *buf = new char[size]; @@ -336,14 +334,17 @@ string flt_to_str(T v, const Fmt &f) { if(i==point) *mptr++ = '.'; - if(showexp || static_cast(i)>=-exp) + if(!leading_zeroes) { int digit = static_cast(w); *mptr++ = '0'+digit; w = (w-digit)*10; } else + { *mptr++ = '0'; + --leading_zeroes; + } } if(f.get_showpoint()) @@ -544,7 +545,7 @@ void operator<<(LexicalConverter &c, const char *s) { c.result(str_to_str(s, c.get_fmt())); } void operator<<(LexicalConverter &c, const void *p) -{ c.result(int_to_str(reinterpret_cast(p), c.get_fmt())); } +{ c.result(int_to_str(reinterpret_cast(p), c.get_fmt())); } /*** operator>> ***/