| diff --git a/system/core/base/include/android-base/parseint.h b/system/core/base/include/android-base/parseint.h |
| index ed75e2d..e3ebce6 100644 |
| --- a/system/core/base/include/android-base/parseint.h |
| +++ b/system/core/base/include/android-base/parseint.h |
| @@ -21,6 +21,7 @@ |
| #include <stdlib.h> |
| |
| #include <limits> |
| +#include <string> |
| |
| namespace android { |
| namespace base { |
| @@ -31,7 +32,7 @@ namespace base { |
| template <typename T> |
| bool ParseUint(const char* s, T* out, |
| T max = std::numeric_limits<T>::max()) { |
| - int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10; |
| + int base = (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? 16 : 10; |
| errno = 0; |
| char* end; |
| unsigned long long int result = strtoull(s, &end, base); |
| @@ -45,6 +46,12 @@ bool ParseUint(const char* s, T* out, |
| return true; |
| } |
| |
| +// TODO: string_view |
| +template <typename T> |
| +bool ParseUint(const std::string& s, T* out, |
| + T max = std::numeric_limits<T>::max()) { |
| + return ParseUint(s.c_str(), out, max); |
| +} |
| // Parses the signed decimal integer in the string 's' and sets 'out' to |
| // that value. Optionally allows the caller to define a 'min' and 'max |
| // beyond which otherwise valid values will be rejected. Returns boolean |
| @@ -53,7 +60,7 @@ template <typename T> |
| bool ParseInt(const char* s, T* out, |
| T min = std::numeric_limits<T>::min(), |
| T max = std::numeric_limits<T>::max()) { |
| - int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10; |
| + int base = (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? 16 : 10; |
| errno = 0; |
| char* end; |
| long long int result = strtoll(s, &end, base); |
| @@ -67,6 +74,13 @@ bool ParseInt(const char* s, T* out, |
| return true; |
| } |
| |
| +// TODO: string_view |
| +template <typename T> |
| +bool ParseInt(const std::string& s, T* out, |
| + T min = std::numeric_limits<T>::min(), |
| + T max = std::numeric_limits<T>::max()) { |
| + return ParseInt(s.c_str(), out, min, max); |
| +} |
| } // namespace base |
| } // namespace android |
| |