rlm@1: // Common/StringToInt.cpp rlm@1: rlm@1: #include "StdAfx.h" rlm@1: rlm@1: #include "StringToInt.h" rlm@1: rlm@1: UInt64 ConvertStringToUInt64(const char *s, const char **end) rlm@1: { rlm@1: UInt64 result = 0; rlm@1: for (;;) rlm@1: { rlm@1: char c = *s; rlm@1: if (c < '0' || c > '9') rlm@1: { rlm@1: if (end != NULL) rlm@1: *end = s; rlm@1: return result; rlm@1: } rlm@1: result *= 10; rlm@1: result += (c - '0'); rlm@1: s++; rlm@1: } rlm@1: } rlm@1: rlm@1: UInt64 ConvertOctStringToUInt64(const char *s, const char **end) rlm@1: { rlm@1: UInt64 result = 0; rlm@1: for (;;) rlm@1: { rlm@1: char c = *s; rlm@1: if (c < '0' || c > '7') rlm@1: { rlm@1: if (end != NULL) rlm@1: *end = s; rlm@1: return result; rlm@1: } rlm@1: result <<= 3; rlm@1: result += (c - '0'); rlm@1: s++; rlm@1: } rlm@1: } rlm@1: rlm@1: UInt64 ConvertHexStringToUInt64(const char *s, const char **end) rlm@1: { rlm@1: UInt64 result = 0; rlm@1: for (;;) rlm@1: { rlm@1: char c = *s; rlm@1: UInt32 v; rlm@1: if (c >= '0' && c <= '9') v = (c - '0'); rlm@1: else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A'); rlm@1: else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a'); rlm@1: else rlm@1: { rlm@1: if (end != NULL) rlm@1: *end = s; rlm@1: return result; rlm@1: } rlm@1: result <<= 4; rlm@1: result |= v; rlm@1: s++; rlm@1: } rlm@1: } rlm@1: rlm@1: rlm@1: UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end) rlm@1: { rlm@1: UInt64 result = 0; rlm@1: for (;;) rlm@1: { rlm@1: wchar_t c = *s; rlm@1: if (c < '0' || c > '9') rlm@1: { rlm@1: if (end != NULL) rlm@1: *end = s; rlm@1: return result; rlm@1: } rlm@1: result *= 10; rlm@1: result += (c - '0'); rlm@1: s++; rlm@1: } rlm@1: } rlm@1: rlm@1: rlm@1: Int64 ConvertStringToInt64(const char *s, const char **end) rlm@1: { rlm@1: if (*s == '-') rlm@1: return -(Int64)ConvertStringToUInt64(s + 1, end); rlm@1: return ConvertStringToUInt64(s, end); rlm@1: }