Mercurial > vba-clojure
annotate 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 |
rev | line source |
---|---|
rlm@1 | 1 // Common/IntToString.cpp |
rlm@1 | 2 |
rlm@1 | 3 #include "StdAfx.h" |
rlm@1 | 4 |
rlm@1 | 5 #include "IntToString.h" |
rlm@1 | 6 |
rlm@1 | 7 void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base) |
rlm@1 | 8 { |
rlm@1 | 9 if (base < 2 || base > 36) |
rlm@1 | 10 { |
rlm@1 | 11 *s = '\0'; |
rlm@1 | 12 return; |
rlm@1 | 13 } |
rlm@1 | 14 char temp[72]; |
rlm@1 | 15 int pos = 0; |
rlm@1 | 16 do |
rlm@1 | 17 { |
rlm@1 | 18 int delta = (int)(value % base); |
rlm@1 | 19 temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10))); |
rlm@1 | 20 value /= base; |
rlm@1 | 21 } |
rlm@1 | 22 while (value != 0); |
rlm@1 | 23 do |
rlm@1 | 24 *s++ = temp[--pos]; |
rlm@1 | 25 while (pos > 0); |
rlm@1 | 26 *s = '\0'; |
rlm@1 | 27 } |
rlm@1 | 28 |
rlm@1 | 29 void ConvertUInt64ToString(UInt64 value, wchar_t *s) |
rlm@1 | 30 { |
rlm@1 | 31 wchar_t temp[32]; |
rlm@1 | 32 int pos = 0; |
rlm@1 | 33 do |
rlm@1 | 34 { |
rlm@1 | 35 temp[pos++] = (wchar_t)(L'0' + (int)(value % 10)); |
rlm@1 | 36 value /= 10; |
rlm@1 | 37 } |
rlm@1 | 38 while (value != 0); |
rlm@1 | 39 do |
rlm@1 | 40 *s++ = temp[--pos]; |
rlm@1 | 41 while (pos > 0); |
rlm@1 | 42 *s = L'\0'; |
rlm@1 | 43 } |
rlm@1 | 44 |
rlm@1 | 45 void ConvertInt64ToString(Int64 value, char *s) |
rlm@1 | 46 { |
rlm@1 | 47 if (value < 0) |
rlm@1 | 48 { |
rlm@1 | 49 *s++ = '-'; |
rlm@1 | 50 value = -value; |
rlm@1 | 51 } |
rlm@1 | 52 ConvertUInt64ToString(value, s); |
rlm@1 | 53 } |
rlm@1 | 54 |
rlm@1 | 55 void ConvertInt64ToString(Int64 value, wchar_t *s) |
rlm@1 | 56 { |
rlm@1 | 57 if (value < 0) |
rlm@1 | 58 { |
rlm@1 | 59 *s++ = L'-'; |
rlm@1 | 60 value = -value; |
rlm@1 | 61 } |
rlm@1 | 62 ConvertUInt64ToString(value, s); |
rlm@1 | 63 } |