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

Changeset 3251

Show
Ignore:
Timestamp:
02/23/08 00:00:56 (10 months ago)
Author:
kris
Message:

added radix support to atoi/itoa. Fixes #906

Files:

Legend:

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

    r3162 r3251  
    466466******************************************************************************/ 
    467467 
    468 uint atoi(T) (T[] s
     468uint atoi(T) (T[] s, int radix = 10
    469469{ 
    470470        uint value; 
     
    472472        foreach (c; s) 
    473473                 if (c >= '0' && c <= '9') 
    474                      value = value * 10 + (c - '0'); 
     474                     value = value * radix + (c - '0'); 
    475475                 else 
    476476                    break; 
     
    489489******************************************************************************/ 
    490490 
    491 T[] itoa(T, U=uint) (T[] output, U value
    492 {return itoa!(T)(output, value);} 
    493  
    494 T[] itoa(T) (T[] output, uint value
     491T[] itoa(T, U=uint) (T[] output, U value, int radix = 10
     492{return itoa!(T)(output, value, radix);} 
     493 
     494T[] itoa(T) (T[] output, uint value, int radix = 10
    495495{ 
    496496        T* p = output.ptr + output.length; 
    497497 
    498498        do { 
    499            *--p = value % 10 + '0'; 
    500            } while (value /= 10); 
     499           *--p = value % radix + '0'; 
     500           } while (value /= radix); 
    501501        return output[p-output.ptr .. $]; 
    502502}