Add parseKernelConfigTypedValue
For text like:
CONFIG_FOO=123
CONFIG_BAR=y
CONFIG_BAZ=hwbinder
It guessed the type set the value accordingly.
CONFIG_FOO: integer, value=123
CONFIG_BAR: tristate, value=yes
CONFIG_BAZ: string, value="hwbinder"
This is useful when parsing android-base.cfg.
Test: assemble_vintf works
Bug: 38324908
Change-Id: I30040177728202149120dc456f704193a573e6a4
diff --git a/parse_string.cpp b/parse_string.cpp
index 4d7ae9a..a6bb418 100644
--- a/parse_string.cpp
+++ b/parse_string.cpp
@@ -168,6 +168,21 @@
}
}
+bool parseKernelConfigTypedValue(const std::string& s, KernelConfigTypedValue* kctv) {
+ if (parseKernelConfigInt(s, &kctv->mIntegerValue)) {
+ kctv->mType = KernelConfigType::INTEGER;
+ return true;
+ }
+ if (parse(s, &kctv->mTristateValue)) {
+ kctv->mType = KernelConfigType::TRISTATE;
+ return true;
+ }
+ // Do not test for KernelConfigType::RANGE.
+ kctv->mType = KernelConfigType::STRING;
+ kctv->mStringValue = s;
+ return true;
+}
+
bool parse(const std::string &s, Version *ver) {
std::vector<std::string> v = SplitString(s, '.');
if (v.size() != 2) {