Ticket #2106: toulong.patch
| File toulong.patch, 2.2 kB (added by llucax, 4 months ago) |
|---|
Patch |
-
a/tango/text/convert/Integer.d
old new 83 83 84 84 /****************************************************************************** 85 85 86 Parse an unsignedinteger value from the provided 'digits' string. 87 88 The string is inspected for an optional radix prefix. A 89 radix may be provided as an argument instead, whereupon 90 it must match the prefix (where present). When radix is 91 set to zero, conversion will default to decimal. 92 93 Throws: IllegalArgumentException where the input text is not parsable 94 in its entirety. 95 96 See_also: the low level functions parse() and convert() 97 98 ******************************************************************************/ 99 100 ulong toUlong(T, U=uint) (T[] digits, U radix=0) 101 {return toLong!(T)(digits, radix);} 102 103 ulong toUlong(T) (T[] digits, uint radix=0) 104 { 105 bool sign = false; 106 107 auto eaten = trim (digits, sign, radix); 108 if (sign) 109 throw new IllegalArgumentException ("Integer.toUlong :: invalid literal"); 110 111 uint len = 0; 112 auto value = convert (digits[eaten..$], radix, &len); 113 if (len == 0 || eaten + len < digits.length) 114 throw new IllegalArgumentException ("Integer.toUlong :: invalid literal"); 115 116 return value; 117 } 118 119 /****************************************************************************** 120 86 121 Wrapper to make life simpler. Returns a text version 87 122 of the provided value. 88 123 … … 607 642 assert (toLong("1") is 1); 608 643 assert (toInt("1", 10) is 1); 609 644 assert (toLong("1", 10) is 1); 645 assert (toUlong("1", 10) is 1); 646 assert (toUlong("18446744073709551615") is ulong.max); 610 647 611 648 assert (atoi ("12345") is 12345); 612 649 assert (itoa (tmp, 12345) == "12345");










