view src/win32/7zip/7z/CPP/Common/IntToString.cpp @ 3:b05d00f19d80

fix some formatting
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:33:11 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 // Common/IntToString.cpp
3 #include "StdAfx.h"
5 #include "IntToString.h"
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 }
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 }
45 void ConvertInt64ToString(Int64 value, char *s)
46 {
47 if (value < 0)
48 {
49 *s++ = '-';
50 value = -value;
51 }
52 ConvertUInt64ToString(value, s);
53 }
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 }