• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Itoa.cpp

Go to the documentation of this file.
00001 
00002 // Fast itoa from http://www.jb.man.ac.uk/~slowe/cpp/itoa.html for Linux since it seems like Linux doesn't support this function.
00003 // I modified it to remove the std dependencies.
00004 char* Itoa( int value, char* result, int base )
00005  {
00006         // check that the base if valid
00007         if (base < 2 || base > 16) { *result = 0; return result; }
00008         char* out = result;
00009         int quotient = value;
00010 
00011         int absQModB;
00012 
00013         do {
00014                 // KevinJ - get rid of this dependency
00015                 //*out = "0123456789abcdef"[ std::abs( quotient % base ) ];
00016                 absQModB=quotient % base;
00017                 if (absQModB < 0)
00018                         absQModB=-absQModB;
00019                 *out = "0123456789abcdef"[ absQModB ];
00020                 ++out;
00021                 quotient /= base;
00022         } while ( quotient );
00023 
00024         // Only apply negative sign for base 10
00025         if ( value < 0 && base == 10) *out++ = '-';
00026 
00027         // KevinJ - get rid of this dependency
00028         // std::reverse( result, out );
00029         *out = 0;
00030 
00031         // KevinJ - My own reverse code
00032     char *start = result;
00033         char temp;
00034         out--;
00035         while (start < out)
00036         {
00037                 temp=*start;
00038                 *start=*out;
00039                 *out=temp;
00040                 start++;
00041                 out--;
00042         }
00043 
00044         return result;
00045 }
00046 

Generated on Thu Sep 30 2010 01:27:24 for RakNet by  doxygen 1.7.1