Expose ParseBool from libbase
Also change the properties implementation to call the new API. We use
this ParseBool API in the new SystemProperties implementation, with
which we want the libbase property API to be consistent.
Test: included
Change-Id: I89cb3eb4e1203a6bb0da41914dad720e44c00303
diff --git a/base/properties.cpp b/base/properties.cpp
index d5a5918..4731bf2 100644
--- a/base/properties.cpp
+++ b/base/properties.cpp
@@ -28,19 +28,22 @@
#include <map>
#include <string>
+#include <android-base/parsebool.h>
#include <android-base/parseint.h>
namespace android {
namespace base {
bool GetBoolProperty(const std::string& key, bool default_value) {
- std::string value = GetProperty(key, "");
- if (value == "1" || value == "y" || value == "yes" || value == "on" || value == "true") {
- return true;
- } else if (value == "0" || value == "n" || value == "no" || value == "off" || value == "false") {
- return false;
+ switch (ParseBool(GetProperty(key, ""))) {
+ case ParseBoolResult::kError:
+ return default_value;
+ case ParseBoolResult::kFalse:
+ return false;
+ case ParseBoolResult::kTrue:
+ return true;
}
- return default_value;
+ __builtin_unreachable();
}
template <typename T>