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

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial