Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3444

Show
Ignore:
Timestamp:
04/18/08 00:52:37 (4 months ago)
Author:
kris
Message:

fixes #1047 :: Layout doesn't handle non-decimal negative numbers very well.

kudos to fvbommel

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/text/convert/Layout.d

    r3426 r3444  
    530530 
    531531                       case TypeCode.BYTE: 
    532                             return integer (result, *cast(byte*) p, format); 
     532                            return integer (result, *cast(byte*) p, format, ubyte.max); 
    533533 
    534534                       case TypeCode.UBYTE: 
    535                             return integer (result, *cast(ubyte*) p, format, 'u'); 
     535                            return integer (result, *cast(ubyte*) p, format, ubyte.max, 'u'); 
    536536 
    537537                       case TypeCode.SHORT: 
    538                             return integer (result, *cast(short*) p, format); 
     538                            return integer (result, *cast(short*) p, format, ushort.max); 
    539539 
    540540                       case TypeCode.USHORT: 
    541                             return integer (result, *cast(ushort*) p, format, 'u'); 
     541                            return integer (result, *cast(ushort*) p, format, ushort.max, 'u'); 
    542542 
    543543                       case TypeCode.INT: 
    544                             return integer (result, *cast(int*) p, format); 
     544                            return integer (result, *cast(int*) p, format, uint.max); 
    545545 
    546546                       case TypeCode.UINT: 
    547                             return integer (result, *cast(uint*) p, format, 'u'); 
     547                            return integer (result, *cast(uint*) p, format, uint.max, 'u'); 
    548548 
    549549                       case TypeCode.ULONG: 
    550                             return integer (result, *cast(long*) p, format, 'u'); 
     550                            return integer (result, *cast(long*) p, format, ulong.max, 'u'); 
    551551 
    552552                       case TypeCode.LONG: 
    553                             return integer (result, *cast(long*) p, format); 
     553                            return integer (result, *cast(long*) p, format, ulong.max); 
    554554 
    555555                       case TypeCode.FLOAT: 
     
    572572 
    573573                       case TypeCode.POINTER: 
    574                             return integer (result, *cast(size_t*) p, format, 'x'); 
     574                            return integer (result, *cast(size_t*) p, format, size_t.max, 'x'); 
    575575 
    576576                       case TypeCode.CLASS: 
     
    622622        **********************************************************************/ 
    623623 
    624         protected T[] integer (T[] output, long v, T[] format, T style = 'd') 
     624        protected T[] integer (T[] output, long v, T[] format, ulong mask = ulong.max, T style = 'd') 
    625625        { 
    626626                Integer.Flags flags; 
     
    633633                       flags |= flags.Zero; 
    634634                       } 
     635                if (style != 'd') 
     636                    v &= mask; 
    635637                return Integer.format (output, v, cast(Integer.Style) style, flags); 
    636638        } 
     
    844846        assert( Formatter( "d{0}d", "s" ) == "dsd" ); 
    845847 
     848        // Negative numbers in various bases 
     849        assert( Formatter( "{:b}", cast(byte) -1 ) == "11111111" ); 
     850        assert( Formatter( "{:b}", cast(short) -1 ) == "1111111111111111" ); 
     851        assert( Formatter( "{:b}", cast(int) -1 ) 
     852                == "11111111111111111111111111111111" ); 
     853        assert( Formatter( "{:b}", cast(long) -1 ) 
     854                == "1111111111111111111111111111111111111111111111111111111111111111" ); 
     855 
     856        assert( Formatter( "{:o}", cast(byte) -1 ) == "377" ); 
     857        assert( Formatter( "{:o}", cast(short) -1 ) == "177777" ); 
     858        assert( Formatter( "{:o}", cast(int) -1 ) == "37777777777" ); 
     859        assert( Formatter( "{:o}", cast(long) -1 ) == "1777777777777777777777" ); 
     860 
     861        assert( Formatter( "{:d}", cast(byte) -1 ) == "-1" ); 
     862        assert( Formatter( "{:d}", cast(short) -1 ) == "-1" ); 
     863        assert( Formatter( "{:d}", cast(int) -1 ) == "-1" ); 
     864        assert( Formatter( "{:d}", cast(long) -1 ) == "-1" ); 
     865 
     866        assert( Formatter( "{:x}", cast(byte) -1 ) == "ff" ); 
     867        assert( Formatter( "{:x}", cast(short) -1 ) == "ffff" ); 
     868        assert( Formatter( "{:x}", cast(int) -1 ) == "ffffffff" ); 
     869        assert( Formatter( "{:x}", cast(long) -1 ) == "ffffffffffffffff" ); 
     870 
    846871        // argument index 
    847872        assert( Formatter( "a{0}b{1}c{2}", "x", "y", "z" ) == "axbycz" ); 
  • trunk/tango/text/locale/Locale.d

    r2978 r3444  
    9494        **********************************************************************/ 
    9595 
    96         protected override char[] integer (char[] output, long v, char[] alt, char format='d') 
     96        protected override char[] integer (char[] output, long v, char[] alt, ulong mask=ulong.max, char format='d') 
    9797        { 
    9898                return formatInteger (output, v, alt, numberFormat);