Mercurial > vba-clojure
diff src/win32/7zip/7z/CPP/Common/StringToInt.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/CPP/Common/StringToInt.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,90 @@ 1.4 +// Common/StringToInt.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include "StringToInt.h" 1.9 + 1.10 +UInt64 ConvertStringToUInt64(const char *s, const char **end) 1.11 +{ 1.12 + UInt64 result = 0; 1.13 + for (;;) 1.14 + { 1.15 + char c = *s; 1.16 + if (c < '0' || c > '9') 1.17 + { 1.18 + if (end != NULL) 1.19 + *end = s; 1.20 + return result; 1.21 + } 1.22 + result *= 10; 1.23 + result += (c - '0'); 1.24 + s++; 1.25 + } 1.26 +} 1.27 + 1.28 +UInt64 ConvertOctStringToUInt64(const char *s, const char **end) 1.29 +{ 1.30 + UInt64 result = 0; 1.31 + for (;;) 1.32 + { 1.33 + char c = *s; 1.34 + if (c < '0' || c > '7') 1.35 + { 1.36 + if (end != NULL) 1.37 + *end = s; 1.38 + return result; 1.39 + } 1.40 + result <<= 3; 1.41 + result += (c - '0'); 1.42 + s++; 1.43 + } 1.44 +} 1.45 + 1.46 +UInt64 ConvertHexStringToUInt64(const char *s, const char **end) 1.47 +{ 1.48 + UInt64 result = 0; 1.49 + for (;;) 1.50 + { 1.51 + char c = *s; 1.52 + UInt32 v; 1.53 + if (c >= '0' && c <= '9') v = (c - '0'); 1.54 + else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A'); 1.55 + else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a'); 1.56 + else 1.57 + { 1.58 + if (end != NULL) 1.59 + *end = s; 1.60 + return result; 1.61 + } 1.62 + result <<= 4; 1.63 + result |= v; 1.64 + s++; 1.65 + } 1.66 +} 1.67 + 1.68 + 1.69 +UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end) 1.70 +{ 1.71 + UInt64 result = 0; 1.72 + for (;;) 1.73 + { 1.74 + wchar_t c = *s; 1.75 + if (c < '0' || c > '9') 1.76 + { 1.77 + if (end != NULL) 1.78 + *end = s; 1.79 + return result; 1.80 + } 1.81 + result *= 10; 1.82 + result += (c - '0'); 1.83 + s++; 1.84 + } 1.85 +} 1.86 + 1.87 + 1.88 +Int64 ConvertStringToInt64(const char *s, const char **end) 1.89 +{ 1.90 + if (*s == '-') 1.91 + return -(Int64)ConvertStringToUInt64(s + 1, end); 1.92 + return ConvertStringToUInt64(s, end); 1.93 +}