Ticket #1047: Layout.negative.patch
| File Layout.negative.patch, 4.7 kB (added by fvbommel, 5 months ago) |
|---|
Proposed patch to fix this. |
-
tango/text/convert/Layout.d
old new 529 529 return (*cast(bool*) p) ? t : f; 530 530 531 531 case TypeCode.BYTE: 532 return integer (result, *cast(byte*) p, format );532 return integer (result, *cast(byte*) p, format, ubyte.max); 533 533 534 534 case TypeCode.UBYTE: 535 return integer (result, *cast(ubyte*) p, format, 'u');535 return integer (result, *cast(ubyte*) p, format, ubyte.max, 'u'); 536 536 537 537 case TypeCode.SHORT: 538 return integer (result, *cast(short*) p, format );538 return integer (result, *cast(short*) p, format, ushort.max); 539 539 540 540 case TypeCode.USHORT: 541 return integer (result, *cast(ushort*) p, format, 'u');541 return integer (result, *cast(ushort*) p, format, ushort.max, 'u'); 542 542 543 543 case TypeCode.INT: 544 return integer (result, *cast(int*) p, format );544 return integer (result, *cast(int*) p, format, uint.max); 545 545 546 546 case TypeCode.UINT: 547 return integer (result, *cast(uint*) p, format, 'u');547 return integer (result, *cast(uint*) p, format, uint.max, 'u'); 548 548 549 549 case TypeCode.ULONG: 550 return integer (result, *cast(long*) p, format, 'u');550 return integer (result, *cast(long*) p, format, ulong.max, 'u'); 551 551 552 552 case TypeCode.LONG: 553 return integer (result, *cast(long*) p, format );553 return integer (result, *cast(long*) p, format, ulong.max); 554 554 555 555 case TypeCode.FLOAT: 556 556 return floater (result, *cast(float*) p, format); … … 571 571 return fromUtf32 ((cast(dchar*) p)[0..1], result); 572 572 573 573 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'); 575 575 576 576 case TypeCode.CLASS: 577 577 auto c = *cast(Object*) p; … … 621 621 622 622 **********************************************************************/ 623 623 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') 625 625 { 626 626 Integer.Flags flags; 627 627 uint width = output.length; … … 632 632 output = output [0 .. width]; 633 633 flags |= flags.Zero; 634 634 } 635 if (style != 'd') 636 v &= mask; 635 637 return Integer.format (output, v, cast(Integer.Style) style, flags); 636 638 } 637 639 … … 843 845 // fragments before and after 844 846 assert( Formatter( "d{0}d", "s" ) == "dsd" ); 845 847 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 846 871 // argument index 847 872 assert( Formatter( "a{0}b{1}c{2}", "x", "y", "z" ) == "axbycz" ); 848 873 assert( Formatter( "a{2}b{1}c{0}", "x", "y", "z" ) == "azbycx" );










