Loading base/include/android-base/parsedouble.h +4 −2 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ namespace android { namespace base { // Parse double value in the string 's' and sets 'out' to that value. // Parse double value in the string 's' and sets 'out' to that value if it exists. // Optionally allows the caller to define a 'min' and 'max' beyond which // otherwise valid values will be rejected. Returns boolean success. static inline bool ParseDouble(const char* s, double* out, Loading @@ -39,7 +39,9 @@ static inline bool ParseDouble(const char* s, double* out, if (result < min || max < result) { return false; } if (out != nullptr) { *out = result; } return true; } Loading base/include/android-base/parseint.h +6 −6 Original line number Diff line number Diff line Loading @@ -27,9 +27,9 @@ namespace android { namespace base { // Parses the unsigned decimal or hexadecimal integer in the string 's' and sets // 'out' to that value. Optionally allows the caller to define a 'max' beyond // which otherwise valid values will be rejected. Returns boolean success; 'out' // is untouched if parsing fails. // 'out' to that value if it is specified. Optionally allows the caller to define // a 'max' beyond which otherwise valid values will be rejected. Returns boolean // success; 'out' is untouched if parsing fails. template <typename T> bool ParseUint(const char* s, T* out, T max = std::numeric_limits<T>::max(), bool allow_suffixes = false) { Loading Loading @@ -72,9 +72,9 @@ bool ParseByteCount(const std::string& s, T* out, T max = std::numeric_limits<T> } // Parses the signed decimal or hexadecimal 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 // success; 'out' is untouched if parsing fails. // 'out' to that value if it is specified. Optionally allows the caller to define // a 'min' and 'max' beyond which otherwise valid values will be rejected. Returns // boolean success; 'out' is untouched if parsing fails. template <typename T> bool ParseInt(const char* s, T* out, T min = std::numeric_limits<T>::min(), Loading base/parsedouble_test.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -35,4 +35,9 @@ TEST(parsedouble, smoke) { ASSERT_FALSE(android::base::ParseDouble("3.0", &d, -1.0, 2.0)); ASSERT_TRUE(android::base::ParseDouble("1.0", &d, 0.0, 2.0)); ASSERT_DOUBLE_EQ(1.0, d); ASSERT_FALSE(android::base::ParseDouble("123.4x", nullptr)); ASSERT_TRUE(android::base::ParseDouble("-123.4", nullptr)); ASSERT_FALSE(android::base::ParseDouble("3.0", nullptr, -1.0, 2.0)); ASSERT_TRUE(android::base::ParseDouble("1.0", nullptr, 0.0, 2.0)); } Loading
base/include/android-base/parsedouble.h +4 −2 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ namespace android { namespace base { // Parse double value in the string 's' and sets 'out' to that value. // Parse double value in the string 's' and sets 'out' to that value if it exists. // Optionally allows the caller to define a 'min' and 'max' beyond which // otherwise valid values will be rejected. Returns boolean success. static inline bool ParseDouble(const char* s, double* out, Loading @@ -39,7 +39,9 @@ static inline bool ParseDouble(const char* s, double* out, if (result < min || max < result) { return false; } if (out != nullptr) { *out = result; } return true; } Loading
base/include/android-base/parseint.h +6 −6 Original line number Diff line number Diff line Loading @@ -27,9 +27,9 @@ namespace android { namespace base { // Parses the unsigned decimal or hexadecimal integer in the string 's' and sets // 'out' to that value. Optionally allows the caller to define a 'max' beyond // which otherwise valid values will be rejected. Returns boolean success; 'out' // is untouched if parsing fails. // 'out' to that value if it is specified. Optionally allows the caller to define // a 'max' beyond which otherwise valid values will be rejected. Returns boolean // success; 'out' is untouched if parsing fails. template <typename T> bool ParseUint(const char* s, T* out, T max = std::numeric_limits<T>::max(), bool allow_suffixes = false) { Loading Loading @@ -72,9 +72,9 @@ bool ParseByteCount(const std::string& s, T* out, T max = std::numeric_limits<T> } // Parses the signed decimal or hexadecimal 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 // success; 'out' is untouched if parsing fails. // 'out' to that value if it is specified. Optionally allows the caller to define // a 'min' and 'max' beyond which otherwise valid values will be rejected. Returns // boolean success; 'out' is untouched if parsing fails. template <typename T> bool ParseInt(const char* s, T* out, T min = std::numeric_limits<T>::min(), Loading
base/parsedouble_test.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -35,4 +35,9 @@ TEST(parsedouble, smoke) { ASSERT_FALSE(android::base::ParseDouble("3.0", &d, -1.0, 2.0)); ASSERT_TRUE(android::base::ParseDouble("1.0", &d, 0.0, 2.0)); ASSERT_DOUBLE_EQ(1.0, d); ASSERT_FALSE(android::base::ParseDouble("123.4x", nullptr)); ASSERT_TRUE(android::base::ParseDouble("-123.4", nullptr)); ASSERT_FALSE(android::base::ParseDouble("3.0", nullptr, -1.0, 2.0)); ASSERT_TRUE(android::base::ParseDouble("1.0", nullptr, 0.0, 2.0)); }