expression: allow array of strings
There are cases where the expressions can be very long and the
resulting string is fairly ugly. JSON doesn't allow multi-line
strings in the standard, but it does allow arrays of strings. Allow
the Expression to optionally be an array of string to allow nicer
formatting.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ic21a7c00d4ce96d8d993902d6c3b36f027972947
diff --git a/virtualSensor.cpp b/virtualSensor.cpp
index 4ce18a9..5883d23 100644
--- a/virtualSensor.cpp
+++ b/virtualSensor.cpp
@@ -289,7 +289,23 @@
}
/* Get expression string */
- exprStr = sensorConfig.value("Expression", "");
+ static constexpr auto exprKey = "Expression";
+ if (sensorConfig.contains(exprKey))
+ {
+ auto ref = sensorConfig.at(exprKey);
+ if (ref.is_array())
+ {
+ exprStr = std::string{};
+ for (auto& s : ref)
+ {
+ exprStr += s;
+ }
+ }
+ else if (ref.is_string())
+ {
+ exprStr = std::string{ref};
+ }
+ }
/* Get all the parameter listed in configuration */
auto params = sensorConfig.value("Params", empty);