misc/libphysfs/lzma/CPP/Common/StringToInt.cpp
changeset 12213 bb5522e88ab2
equal deleted inserted replaced
12212:ea891871f481 12213:bb5522e88ab2
       
     1 // Common/StringToInt.cpp
       
     2 
       
     3 #include "StdAfx.h"
       
     4 
       
     5 #include "StringToInt.h"
       
     6 
       
     7 UInt64 ConvertStringToUInt64(const char *s, const char **end)
       
     8 {
       
     9   UInt64 result = 0;
       
    10   for (;;)
       
    11   {
       
    12     char c = *s;
       
    13     if (c < '0' || c > '9')
       
    14     {
       
    15       if (end != NULL)
       
    16         *end = s;
       
    17       return result;
       
    18     }
       
    19     result *= 10;
       
    20     result += (c - '0');
       
    21     s++;
       
    22   }
       
    23 }
       
    24 
       
    25 UInt64 ConvertOctStringToUInt64(const char *s, const char **end)
       
    26 {
       
    27   UInt64 result = 0;
       
    28   for (;;)
       
    29   {
       
    30     char c = *s;
       
    31     if (c < '0' || c > '7')
       
    32     {
       
    33       if (end != NULL)
       
    34         *end = s;
       
    35       return result;
       
    36     }
       
    37     result <<= 3;
       
    38     result += (c - '0');
       
    39     s++;
       
    40   }
       
    41 }
       
    42 
       
    43 
       
    44 UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)
       
    45 {
       
    46   UInt64 result = 0;
       
    47   for (;;)
       
    48   {
       
    49     wchar_t c = *s;
       
    50     if (c < '0' || c > '9')
       
    51     {
       
    52       if (end != NULL)
       
    53         *end = s;
       
    54       return result;
       
    55     }
       
    56     result *= 10;
       
    57     result += (c - '0');
       
    58     s++;
       
    59   }
       
    60 }
       
    61 
       
    62 
       
    63 Int64 ConvertStringToInt64(const char *s, const char **end)
       
    64 {
       
    65   if (*s == '-')
       
    66     return -(Int64)ConvertStringToUInt64(s + 1, end);
       
    67   return ConvertStringToUInt64(s, end);
       
    68 }