diff src/win32/7zip/7z/CPP/Common/IntToString.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/CPP/Common/IntToString.cpp	Sat Mar 03 10:31:27 2012 -0600
     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 = '\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++] = (char)((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++] = (wchar_t)(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 +}