diff options
Diffstat (limited to 'src/mbgl/style/conversion/function.cpp')
-rw-r--r-- | src/mbgl/style/conversion/function.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp index 69fb0725d8..34ac52ec1b 100644 --- a/src/mbgl/style/conversion/function.cpp +++ b/src/mbgl/style/conversion/function.cpp @@ -6,6 +6,7 @@ #include <mbgl/style/expression/interpolate.hpp> #include <mbgl/style/expression/match.hpp> #include <mbgl/style/expression/case.hpp> +#include <mbgl/style/expression/format_expression.hpp> #include <mbgl/util/string.hpp> #include <cassert> @@ -36,6 +37,13 @@ bool hasTokens(const std::string& source) { return false; } + +std::unique_ptr<Expression> convertTokenStringToFormatExpression(const std::string& source) { + auto textExpression = convertTokenStringToExpression(source); + std::vector<FormatExpressionSection> sections; + sections.emplace_back(std::move(textExpression), nullopt, nullopt); + return std::make_unique<FormatExpression>(sections); +} std::unique_ptr<Expression> convertTokenStringToExpression(const std::string& source) { std::vector<std::unique_ptr<Expression>> inputs; @@ -138,6 +146,9 @@ template optional<PropertyExpression<TextTransformType>> convertFunctionToExpression<TextTransformType>(const Convertible&, Error&, bool); template optional<PropertyExpression<TranslateAnchorType>> convertFunctionToExpression<TranslateAnchorType>(const Convertible&, Error&, bool); + +template optional<PropertyExpression<Formatted>> + convertFunctionToExpression<Formatted>(const Convertible&, Error&, bool); // Ad-hoc Converters for double and int64_t. We should replace float with double wholesale, // and promote the int64_t Converter to general use (and it should check that the input is @@ -280,6 +291,15 @@ static optional<std::unique_ptr<Expression>> convertLiteral(type::Type type, con [&] (const type::CollatorType&) -> optional<std::unique_ptr<Expression>> { assert(false); // No properties use this type. return nullopt; + }, + [&] (const type::FormattedType&) -> optional<std::unique_ptr<Expression>> { + auto result = convert<std::string>(value, error); + if (!result) { + return nullopt; + } + return convertTokens ? + convertTokenStringToFormatExpression(*result) : + literal(Formatted(result->c_str())); } ); } |