summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2018-08-09 10:26:59 -0700
committerSteven Moreland <smoreland@google.com>2018-08-09 10:49:45 -0700
commitf1911f4ba3b8476fc3c0b2b77e04f3704c0c8237 (patch)
tree34fa1f533afff6bf7eff1e85a1b5d89309611b27 /base
parent075c351af2b17030cbe064455f31765254e4bc6e (diff)
downloadsystem_core-f1911f4ba3b8476fc3c0b2b77e04f3704c0c8237.tar.gz
system_core-f1911f4ba3b8476fc3c0b2b77e04f3704c0c8237.tar.bz2
system_core-f1911f4ba3b8476fc3c0b2b77e04f3704c0c8237.zip
ParseFloat/ParseDouble, also take std::string
For convenience and to match the integer parsing functions. Bug: 110758329 Test: m only Change-Id: I33620d9a29465e1f425872fd57063ac32031988a
Diffstat (limited to 'base')
-rw-r--r--base/include/android-base/parsedouble.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/base/include/android-base/parsedouble.h b/base/include/android-base/parsedouble.h
index 7b1c648b7..ccffba232 100644
--- a/base/include/android-base/parsedouble.h
+++ b/base/include/android-base/parsedouble.h
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <limits>
+#include <string>
namespace android {
namespace base {
@@ -52,6 +53,11 @@ static inline bool ParseDouble(const char* s, double* out,
double max = std::numeric_limits<double>::max()) {
return ParseFloatingPoint<double, strtod>(s, out, min, max);
}
+static inline bool ParseDouble(const std::string& s, double* out,
+ double min = std::numeric_limits<double>::lowest(),
+ double max = std::numeric_limits<double>::max()) {
+ return ParseFloatingPoint<double, strtod>(s.c_str(), out, min, max);
+}
// Parse float 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
@@ -61,6 +67,11 @@ static inline bool ParseFloat(const char* s, float* out,
float max = std::numeric_limits<float>::max()) {
return ParseFloatingPoint<float, strtof>(s, out, min, max);
}
+static inline bool ParseFloat(const std::string& s, float* out,
+ float min = std::numeric_limits<float>::lowest(),
+ float max = std::numeric_limits<float>::max()) {
+ return ParseFloatingPoint<float, strtof>(s.c_str(), out, min, max);
+}
} // namespace base
} // namespace android