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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 = L'\0';
    12     return;
    13   }
    14   char temp[72];
    15   int pos = 0;
    16   do 
    17   {
    18     int delta = (int)(value % base);
    19     temp[pos++] = (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++] = 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 }

mercurial