Implement index-of expression (#1113)

This commit is contained in:
Siarhei Fedartsou
2023-05-09 00:16:58 +02:00
committed by GitHub
parent d716636d83
commit 379b1fc606
15 changed files with 458 additions and 1 deletions

View File

@@ -178,7 +178,8 @@ enum class Kind : int32_t {
ImageExpression,
In,
Within,
Distance
Distance,
IndexOf
};
class Expression {

View File

@@ -0,0 +1,41 @@
#pragma once
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/conversion.hpp>
#include <memory>
namespace mbgl {
namespace style {
namespace expression {
class IndexOf : public Expression {
public:
IndexOf(std::unique_ptr<Expression> keyword_,
std::unique_ptr<Expression> input_,
std::unique_ptr<Expression> fromIndex_);
static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx);
EvaluationResult evaluate(const EvaluationContext& params) const override;
void eachChild(const std::function<void(const Expression&)>&) const override;
bool operator==(const Expression& e) const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
std::string getOperator() const override;
private:
EvaluationResult evaluateForArrayInput(const std::vector<Value>& array,
const Value& keyword,
size_t fromIndex) const;
EvaluationResult evaluateForStringInput(const std::string& string, const Value& keyword, size_t fromIndex) const;
private:
std::unique_ptr<Expression> keyword;
std::unique_ptr<Expression> input;
std::unique_ptr<Expression> fromIndex;
};
} // namespace expression
} // namespace style
} // namespace mbgl