#include "css_property.hxx"
#include "frozen/unordered_map.h"
#include "frozen/string.h"
+#include "libutil/cxx/util.hxx"
namespace rspamd::css {
css_property_type ret = css_property_type::PROPERTY_NYI;
- auto known_type = prop_names_map.find(inp);
+ auto known_type = find_map(prop_names_map, inp);
- if (known_type != prop_names_map.end()) {
- ret = known_type->second;
+ if (known_type) {
+ ret = known_type.value().get();
}
return ret;
auto num = std::get<float>(value);
auto sv = std::get<std::string_view>(dim_token.value);
- auto dim_found = dimensions_map.find(sv);
+ auto dim_found = find_map(dimensions_map, sv);
- if (dim_found != dimensions_map.end()) {
- auto dim_elt = dim_found->second;
+ if (dim_found) {
+ auto dim_elt = dim_found.value().get();
dimension_type = dim_elt.dtype;
flags |= css_parser_token::number_dimension;
num *= dim_elt.mult;
#include <memory>
#include <array>
#include <string_view>
+#include <optional>
/*
* Common C++ utilities
return {{ std::forward<T>(t)... }};
}
+template<class C, class K, class V = typename C::mapped_type, typename std::enable_if_t<
+ std::is_constructible_v<typename C::key_type, K>
+ && std::is_constructible_v<typename C::mapped_type, V>, bool> = false>
+constexpr auto find_map(const C &c, const K &k) -> std::optional<std::reference_wrapper<const V>>
+{
+ auto f = c.find(k);
+
+ if (f != c.end()) {
+ return std::cref<V>(f->second);
+ }
+
+ return std::nullopt;
+}
+
}
#endif //RSPAMD_UTIL_HXX