misc/libphysfs/lzma/CPP/Common/IntToString.cpp
changeset 13881 99b265e0d1d0
parent 13880 5f819b90d479
child 13882 b172a5d40eee
equal deleted inserted replaced
13880:5f819b90d479 13881:99b265e0d1d0
     1 // Common/IntToString.cpp
       
     2 
       
     3 #include "StdAfx.h"
       
     4 
       
     5 #include "IntToString.h"
       
     6 
       
     7 void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)
       
     8 {
       
     9   if (base < 2 || base > 36)
       
    10   {
       
    11     *s = '\0';
       
    12     return;
       
    13   }
       
    14   char temp[72];
       
    15   int pos = 0;
       
    16   do 
       
    17   {
       
    18     int delta = (int)(value % base);
       
    19     temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));
       
    20     value /= base;
       
    21   }
       
    22   while (value != 0);
       
    23   do
       
    24     *s++ = temp[--pos];
       
    25   while(pos > 0);
       
    26   *s = '\0';
       
    27 }
       
    28 
       
    29 void ConvertUInt64ToString(UInt64 value, wchar_t *s)
       
    30 {
       
    31   wchar_t temp[32];
       
    32   int pos = 0;
       
    33   do 
       
    34   {
       
    35     temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));
       
    36     value /= 10;
       
    37   }
       
    38   while (value != 0);
       
    39   do 
       
    40     *s++ = temp[--pos];
       
    41   while(pos > 0);
       
    42   *s = L'\0';
       
    43 }
       
    44 
       
    45 void ConvertInt64ToString(Int64 value, char *s)
       
    46 {
       
    47   if (value < 0)
       
    48   {
       
    49     *s++ = '-';
       
    50     value = -value;
       
    51   }
       
    52   ConvertUInt64ToString(value, s);
       
    53 }
       
    54 
       
    55 void ConvertInt64ToString(Int64 value, wchar_t *s)
       
    56 {
       
    57   if (value < 0)
       
    58   {
       
    59     *s++ = L'-';
       
    60     value = -value;
       
    61   }
       
    62   ConvertUInt64ToString(value, s);
       
    63 }