other-licenses/7zstub/src/Common/IntToString.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/Common/IntToString.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +// Common/IntToString.cpp
     1.5 +
     1.6 +#include "StdAfx.h"
     1.7 +
     1.8 +#include "IntToString.h"
     1.9 +
    1.10 +void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)
    1.11 +{
    1.12 +  if (base < 2 || base > 36)
    1.13 +  {
    1.14 +    *s = L'\0';
    1.15 +    return;
    1.16 +  }
    1.17 +  char temp[72];
    1.18 +  int pos = 0;
    1.19 +  do 
    1.20 +  {
    1.21 +    int delta = (int)(value % base);
    1.22 +    temp[pos++] = (delta < 10) ? ('0' + delta) : ('a' + (delta - 10));
    1.23 +    value /= base;
    1.24 +  }
    1.25 +  while (value != 0);
    1.26 +  do
    1.27 +    *s++ = temp[--pos];
    1.28 +  while(pos > 0);
    1.29 +  *s = '\0';
    1.30 +}
    1.31 +
    1.32 +void ConvertUInt64ToString(UInt64 value, wchar_t *s)
    1.33 +{
    1.34 +  wchar_t temp[32];
    1.35 +  int pos = 0;
    1.36 +  do 
    1.37 +  {
    1.38 +    temp[pos++] = L'0' + (int)(value % 10);
    1.39 +    value /= 10;
    1.40 +  }
    1.41 +  while (value != 0);
    1.42 +  do 
    1.43 +    *s++ = temp[--pos];
    1.44 +  while(pos > 0);
    1.45 +  *s = L'\0';
    1.46 +}
    1.47 +
    1.48 +void ConvertInt64ToString(Int64 value, char *s)
    1.49 +{
    1.50 +  if (value < 0)
    1.51 +  {
    1.52 +    *s++ = '-';
    1.53 +    value = -value;
    1.54 +  }
    1.55 +  ConvertUInt64ToString(value, s);
    1.56 +}
    1.57 +
    1.58 +void ConvertInt64ToString(Int64 value, wchar_t *s)
    1.59 +{
    1.60 +  if (value < 0)
    1.61 +  {
    1.62 +    *s++ = L'-';
    1.63 +    value = -value;
    1.64 +  }
    1.65 +  ConvertUInt64ToString(value, s);
    1.66 +}

mercurial