summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-09-13 14:27:57 -0700
committerChris Loer <chris.loer@mapbox.com>2018-09-19 14:54:38 -0700
commit89b075f592271bc11d58ebb7f854c453e81e3cf1 (patch)
tree52a10397008d073a60e6c0524ee42f971b3a954c
parenta991eec597541c32682946b541e22ccad0f98dd1 (diff)
downloadqtlocation-mapboxgl-89b075f592271bc11d58ebb7f854c453e81e3cf1.tar.gz
[core] Auto-convert concat arguments to strings
-rw-r--r--include/mbgl/style/expression/value.hpp2
-rw-r--r--src/mbgl/style/expression/compound_expression.cpp13
-rw-r--r--src/mbgl/style/expression/value.cpp9
3 files changed, 15 insertions, 9 deletions
diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp
index b1126118a9..2036ab8abe 100644
--- a/include/mbgl/style/expression/value.hpp
+++ b/include/mbgl/style/expression/value.hpp
@@ -46,6 +46,8 @@ struct Value : ValueBase {
constexpr NullValue Null = NullValue();
type::Type typeOf(const Value& value);
+
+std::string toString(const Value& value);
std::string stringify(const Value& value);
/*
diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp
index 6e87167d5a..f5cbd7030b 100644
--- a/src/mbgl/style/expression/compound_expression.cpp
+++ b/src/mbgl/style/expression/compound_expression.cpp
@@ -310,12 +310,7 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali
define("typeof", [](const Value& v) -> Result<std::string> { return toString(typeOf(v)); });
define("to-string", [](const Value& value) -> Result<std::string> {
- return value.match(
- [](const NullValue&) -> Result<std::string> { return std::string(); },
- [](const Color& c) -> Result<std::string> { return c.stringify(); }, // avoid quoting
- [](const std::string& s) -> Result<std::string> { return s; }, // avoid quoting
- [](const auto& v) -> Result<std::string> { return stringify(v); }
- );
+ return toString(value);
});
define("to-boolean", [](const Value& v) -> Result<bool> {
@@ -507,10 +502,10 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali
define("downcase", [](const std::string& input) -> Result<std::string> {
return platform::lowercase(input);
});
- define("concat", [](const Varargs<std::string>& args) -> Result<std::string> {
+ define("concat", [](const Varargs<Value>& args) -> Result<std::string> {
std::string s;
- for (const std::string& arg : args) {
- s += arg;
+ for (const Value& arg : args) {
+ s += toString(arg);
}
return s;
});
diff --git a/src/mbgl/style/expression/value.cpp b/src/mbgl/style/expression/value.cpp
index f089c918cd..4bac8116c2 100644
--- a/src/mbgl/style/expression/value.cpp
+++ b/src/mbgl/style/expression/value.cpp
@@ -34,6 +34,15 @@ type::Type typeOf(const Value& value) {
);
}
+std::string toString(const Value& value) {
+ return value.match(
+ [](const NullValue&) { return std::string(); },
+ [](const Color& c) { return c.stringify(); }, // avoid quoting
+ [](const std::string& s) { return s; }, // avoid quoting
+ [](const auto& v_) { return stringify(v_); }
+ );
+}
+
void writeJSON(rapidjson::Writer<rapidjson::StringBuffer>& writer, const Value& value) {
value.match(
[&] (const NullValue&) { writer.Null(); },