summaryrefslogtreecommitdiff
path: root/src/mbgl/style
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 /src/mbgl/style
parenta991eec597541c32682946b541e22ccad0f98dd1 (diff)
downloadqtlocation-mapboxgl-89b075f592271bc11d58ebb7f854c453e81e3cf1.tar.gz
[core] Auto-convert concat arguments to strings
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/expression/compound_expression.cpp13
-rw-r--r--src/mbgl/style/expression/value.cpp9
2 files changed, 13 insertions, 9 deletions
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(); },