aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/css/css_property.cxx
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-02-18 16:18:08 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-02-18 16:18:08 +0000
commit4658a093bf5cfc6c1961e6974772bdead4dda2f4 (patch)
treeee9b90dd5e07e7eb7829fc333e279dd96110f19c /src/libserver/css/css_property.cxx
parente2799764c4cd50a5efa220c76648eae667cd4491 (diff)
downloadrspamd-4658a093bf5cfc6c1961e6974772bdead4dda2f4.tar.gz
rspamd-4658a093bf5cfc6c1961e6974772bdead4dda2f4.zip
[Project] Css: Declarations parsing logic skeleton
Diffstat (limited to 'src/libserver/css/css_property.cxx')
-rw-r--r--src/libserver/css/css_property.cxx36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/libserver/css/css_property.cxx b/src/libserver/css/css_property.cxx
index 98543f75a..77927d724 100644
--- a/src/libserver/css/css_property.cxx
+++ b/src/libserver/css/css_property.cxx
@@ -15,12 +15,44 @@
*/
#include "css_property.hxx"
-
+#include "frozen/unordered_map.h"
+#include "frozen/string.h"
namespace rspamd::css {
-auto css_property::from_bytes (const char *input, size_t inlen) -> tl::expected<css_property,css_parse_error>
+constexpr const auto max_type = static_cast<int>(css_property_type::PROPERTY_NYI);
+constexpr frozen::unordered_map<frozen::string, css_property_type, max_type> type_map{
+ {"font", css_property_type::PROPERTY_FONT},
+ {"color", css_property_type::PROPERTY_COLOR},
+ {"bgcolor", css_property_type::PROPERTY_BGCOLOR},
+ {"background", css_property_type::PROPERTY_BACKGROUND},
+ {"height", css_property_type::PROPERTY_HEIGHT},
+ {"width", css_property_type::PROPERTY_WIDTH},
+ {"display", css_property_type::PROPERTY_DISPLAY},
+ {"visibility", css_property_type::PROPERTY_VISIBILITY},
+};
+
+auto token_string_to_property(const std::string_view &inp) -> css_property_type {
+
+ css_property_type ret = css_property_type::PROPERTY_NYI;
+
+ auto known_type = type_map.find(inp);
+
+ if (known_type != type_map.end()) {
+ ret = known_type->second;
+ }
+
+ return ret;
+}
+
+auto css_property::from_token(const css_parser_token &tok) -> tl::expected<css_property,css_parse_error>
{
+ if (tok.type == css_parser_token::token_type::ident_token) {
+ auto sv = tok.get_string_or_default("");
+
+ return css_property{token_string_to_property(sv)};
+ }
+
return tl::unexpected{css_parse_error(css_parse_error_type::PARSE_ERROR_NYI)};
}