blob: 136fcc47a4d10980425f31e42c6531e73e9562bb [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001diff --git a/system/core/base/include/android-base/parseint.h b/system/core/base/include/android-base/parseint.h
2index ed75e2d..e3ebce6 100644
3--- a/system/core/base/include/android-base/parseint.h
4+++ b/system/core/base/include/android-base/parseint.h
5@@ -21,6 +21,7 @@
6 #include <stdlib.h>
7
8 #include <limits>
9+#include <string>
10
11 namespace android {
12 namespace base {
13@@ -31,7 +32,7 @@ namespace base {
14 template <typename T>
15 bool ParseUint(const char* s, T* out,
16 T max = std::numeric_limits<T>::max()) {
17- int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10;
18+ int base = (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? 16 : 10;
19 errno = 0;
20 char* end;
21 unsigned long long int result = strtoull(s, &end, base);
22@@ -45,6 +46,12 @@ bool ParseUint(const char* s, T* out,
23 return true;
24 }
25
26+// TODO: string_view
27+template <typename T>
28+bool ParseUint(const std::string& s, T* out,
29+ T max = std::numeric_limits<T>::max()) {
30+ return ParseUint(s.c_str(), out, max);
31+}
32 // Parses the signed decimal integer in the string 's' and sets 'out' to
33 // that value. Optionally allows the caller to define a 'min' and 'max
34 // beyond which otherwise valid values will be rejected. Returns boolean
35@@ -53,7 +60,7 @@ template <typename T>
36 bool ParseInt(const char* s, T* out,
37 T min = std::numeric_limits<T>::min(),
38 T max = std::numeric_limits<T>::max()) {
39- int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10;
40+ int base = (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? 16 : 10;
41 errno = 0;
42 char* end;
43 long long int result = strtoll(s, &end, base);
44@@ -67,6 +74,13 @@ bool ParseInt(const char* s, T* out,
45 return true;
46 }
47
48+// TODO: string_view
49+template <typename T>
50+bool ParseInt(const std::string& s, T* out,
51+ T min = std::numeric_limits<T>::min(),
52+ T max = std::numeric_limits<T>::max()) {
53+ return ParseInt(s.c_str(), out, min, max);
54+}
55 } // namespace base
56 } // namespace android
57