diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index b1126118a..2036ab8ab 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 6e87167d5..f5cbd7030 100644 --- a/src/mbgl/style/expression/compound_expression.cpp +++ b/src/mbgl/style/expression/compound_expression.cpp @@ -310,12 +310,7 @@ std::unordered_map initiali define("typeof", [](const Value& v) -> Result { return toString(typeOf(v)); }); define("to-string", [](const Value& value) -> Result { - return value.match( - [](const NullValue&) -> Result { return std::string(); }, - [](const Color& c) -> Result { return c.stringify(); }, // avoid quoting - [](const std::string& s) -> Result { return s; }, // avoid quoting - [](const auto& v) -> Result { return stringify(v); } - ); + return toString(value); }); define("to-boolean", [](const Value& v) -> Result { @@ -507,10 +502,10 @@ std::unordered_map initiali define("downcase", [](const std::string& input) -> Result { return platform::lowercase(input); }); - define("concat", [](const Varargs& args) -> Result { + define("concat", [](const Varargs& args) -> Result { 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 f089c918c..4bac8116c 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& writer, const Value& value) { value.match( [&] (const NullValue&) { writer.Null(); },