| 2966 | |
| 2967 | template <class T> |
| 2968 | static Integer StringToInteger(const T *str) |
| 2969 | { |
| 2970 | int radix; |
| 2971 | // GCC workaround |
| 2972 | // std::char_traits<wchar_t>::length() not defined in GCC 3.2 and STLport 4.5.3 |
| 2973 | unsigned int length; |
| 2974 | for (length = 0; str[length] != 0; length++) {} |
| 2975 | |
| 2976 | Integer v; |
| 2977 | |
| 2978 | if (length == 0) |
| 2979 | return v; |
| 2980 | |
| 2981 | switch (str[length-1]) |
| 2982 | { |
| 2983 | case 'h': |
| 2984 | case 'H': |
| 2985 | radix=16; |
| 2986 | break; |
| 2987 | case 'o': |
| 2988 | case 'O': |
| 2989 | radix=8; |
| 2990 | break; |
| 2991 | case 'b': |
| 2992 | case 'B': |
| 2993 | radix=2; |
| 2994 | break; |
| 2995 | default: |
| 2996 | radix=10; |
| 2997 | } |
| 2998 | |
| 2999 | if (length > 2 && str[0] == '0' && str[1] == 'x') |
| 3000 | radix = 16; |
| 3001 | |
| 3002 | for (unsigned i=0; i<length; i++) |
| 3003 | { |
| 3004 | int digit; |
| 3005 | |
| 3006 | if (str[i] >= '0' && str[i] <= '9') |
| 3007 | digit = str[i] - '0'; |
| 3008 | else if (str[i] >= 'A' && str[i] <= 'F') |
| 3009 | digit = str[i] - 'A' + 10; |
| 3010 | else if (str[i] >= 'a' && str[i] <= 'f') |
| 3011 | digit = str[i] - 'a' + 10; |
| 3012 | else |
| 3013 | digit = radix; |
| 3014 | |
| 3015 | if (digit < radix) |
| 3016 | { |
| 3017 | v *= radix; |
| 3018 | v += digit; |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | if (str[0] == '-') |
| 3023 | v.Negate(); |
| 3024 | |
| 3025 | return v; |