annotate src/win32/7zip/7z/CPP/Common/StringToInt.cpp @ 4:5f6f2134e8ce

apu appears to not be used
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:35:58 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 // Common/StringToInt.cpp
rlm@1 2
rlm@1 3 #include "StdAfx.h"
rlm@1 4
rlm@1 5 #include "StringToInt.h"
rlm@1 6
rlm@1 7 UInt64 ConvertStringToUInt64(const char *s, const char **end)
rlm@1 8 {
rlm@1 9 UInt64 result = 0;
rlm@1 10 for (;;)
rlm@1 11 {
rlm@1 12 char c = *s;
rlm@1 13 if (c < '0' || c > '9')
rlm@1 14 {
rlm@1 15 if (end != NULL)
rlm@1 16 *end = s;
rlm@1 17 return result;
rlm@1 18 }
rlm@1 19 result *= 10;
rlm@1 20 result += (c - '0');
rlm@1 21 s++;
rlm@1 22 }
rlm@1 23 }
rlm@1 24
rlm@1 25 UInt64 ConvertOctStringToUInt64(const char *s, const char **end)
rlm@1 26 {
rlm@1 27 UInt64 result = 0;
rlm@1 28 for (;;)
rlm@1 29 {
rlm@1 30 char c = *s;
rlm@1 31 if (c < '0' || c > '7')
rlm@1 32 {
rlm@1 33 if (end != NULL)
rlm@1 34 *end = s;
rlm@1 35 return result;
rlm@1 36 }
rlm@1 37 result <<= 3;
rlm@1 38 result += (c - '0');
rlm@1 39 s++;
rlm@1 40 }
rlm@1 41 }
rlm@1 42
rlm@1 43 UInt64 ConvertHexStringToUInt64(const char *s, const char **end)
rlm@1 44 {
rlm@1 45 UInt64 result = 0;
rlm@1 46 for (;;)
rlm@1 47 {
rlm@1 48 char c = *s;
rlm@1 49 UInt32 v;
rlm@1 50 if (c >= '0' && c <= '9') v = (c - '0');
rlm@1 51 else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A');
rlm@1 52 else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a');
rlm@1 53 else
rlm@1 54 {
rlm@1 55 if (end != NULL)
rlm@1 56 *end = s;
rlm@1 57 return result;
rlm@1 58 }
rlm@1 59 result <<= 4;
rlm@1 60 result |= v;
rlm@1 61 s++;
rlm@1 62 }
rlm@1 63 }
rlm@1 64
rlm@1 65
rlm@1 66 UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)
rlm@1 67 {
rlm@1 68 UInt64 result = 0;
rlm@1 69 for (;;)
rlm@1 70 {
rlm@1 71 wchar_t c = *s;
rlm@1 72 if (c < '0' || c > '9')
rlm@1 73 {
rlm@1 74 if (end != NULL)
rlm@1 75 *end = s;
rlm@1 76 return result;
rlm@1 77 }
rlm@1 78 result *= 10;
rlm@1 79 result += (c - '0');
rlm@1 80 s++;
rlm@1 81 }
rlm@1 82 }
rlm@1 83
rlm@1 84
rlm@1 85 Int64 ConvertStringToInt64(const char *s, const char **end)
rlm@1 86 {
rlm@1 87 if (*s == '-')
rlm@1 88 return -(Int64)ConvertStringToUInt64(s + 1, end);
rlm@1 89 return ConvertStringToUInt64(s, end);
rlm@1 90 }