diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/style/expression/collator.hpp | 29 | ||||
-rw-r--r-- | include/mbgl/style/expression/collator_expression.hpp | 44 | ||||
-rw-r--r-- | include/mbgl/style/expression/equals.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/style/expression/type.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/style/expression/value.hpp | 2 |
5 files changed, 86 insertions, 1 deletions
diff --git a/include/mbgl/style/expression/collator.hpp b/include/mbgl/style/expression/collator.hpp new file mode 100644 index 0000000000..2a79e55556 --- /dev/null +++ b/include/mbgl/style/expression/collator.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include <mbgl/util/feature.hpp> +#include <mbgl/util/optional.hpp> + +#include <string> +#include <memory> + +namespace mbgl { +namespace style { +namespace expression { + +class Collator { +public: + Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale = {}); + + bool operator==(const Collator& other) const; + + int compare(const std::string& lhs, const std::string& rhs) const; + + std::string resolvedLocale() const; +private: + class Impl; + std::shared_ptr<Impl> impl; +}; + +} // namespace expression +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/expression/collator_expression.hpp b/include/mbgl/style/expression/collator_expression.hpp new file mode 100644 index 0000000000..2551cd19c8 --- /dev/null +++ b/include/mbgl/style/expression/collator_expression.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/expression/parsing_context.hpp> +#include <mbgl/style/conversion.hpp> + +#include <memory> + +namespace mbgl { +namespace style { +namespace expression { + +class CollatorExpression : public Expression { +public: + CollatorExpression(std::unique_ptr<Expression> caseSensitive, + std::unique_ptr<Expression> diacriticSensitive, + optional<std::unique_ptr<Expression>> locale); + + EvaluationResult evaluate(const EvaluationContext&) const override; + static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); + + void eachChild(const std::function<void(const Expression&)>&) const override; + + bool operator==(const Expression& e) const override; + + std::vector<optional<Value>> possibleOutputs() const override { + // Technically the set of possible outputs is the combinatoric set of Collators produced + // by all possibleOutputs of locale/caseSensitive/diacriticSensitive + // But for the primary use of Collators in comparison operators, we ignore the Collator's + // possibleOutputs anyway, so we can get away with leaving this undefined for now. + return { nullopt }; + } + + mbgl::Value serialize() const override; + std::string getOperator() const override { return "collator"; } +private: + std::unique_ptr<Expression> caseSensitive; + std::unique_ptr<Expression> diacriticSensitive; + optional<std::unique_ptr<Expression>> locale; +}; + +} // namespace expression +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/expression/equals.hpp b/include/mbgl/style/expression/equals.hpp index 54df890a68..1e8bf7acef 100644 --- a/include/mbgl/style/expression/equals.hpp +++ b/include/mbgl/style/expression/equals.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/style/expression/collator_expression.hpp> #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/conversion.hpp> @@ -12,7 +13,7 @@ namespace expression { class Equals : public Expression { public: - Equals(std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs, bool negate); + Equals(std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs, optional<std::unique_ptr<Expression>> collator, bool negate); static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); @@ -25,6 +26,7 @@ public: private: std::unique_ptr<Expression> lhs; std::unique_ptr<Expression> rhs; + optional<std::unique_ptr<Expression>> collator; bool negate; }; diff --git a/include/mbgl/style/expression/type.hpp b/include/mbgl/style/expression/type.hpp index 513c4bdc17..316496839b 100644 --- a/include/mbgl/style/expression/type.hpp +++ b/include/mbgl/style/expression/type.hpp @@ -60,6 +60,12 @@ struct ValueType { std::string getName() const { return "value"; } bool operator==(const ValueType&) const { return true; } }; + +struct CollatorType { + constexpr CollatorType() {}; // NOLINT + std::string getName() const { return "collator"; } + bool operator==(const CollatorType&) const { return true; } +}; constexpr NullType Null; constexpr NumberType Number; @@ -68,6 +74,7 @@ constexpr BooleanType Boolean; constexpr ColorType Color; constexpr ValueType Value; constexpr ObjectType Object; +constexpr CollatorType Collator; constexpr ErrorType Error; struct Array; @@ -81,6 +88,7 @@ using Type = variant< ObjectType, ValueType, mapbox::util::recursive_wrapper<Array>, + CollatorType, ErrorType>; struct Array { diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index 7839ff2ca7..fc38c36ff0 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/style/expression/collator.hpp> #include <mbgl/style/expression/type.hpp> #include <mbgl/style/position.hpp> #include <mbgl/style/types.hpp> @@ -23,6 +24,7 @@ using ValueBase = variant< double, std::string, Color, + Collator, mapbox::util::recursive_wrapper<std::vector<Value>>, mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>>>; struct Value : ValueBase { |