aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/css/css_tokeniser.hxx
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-03-09 12:07:27 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-03-09 12:07:27 +0000
commitf0de57da10d978a4ceea1dcfad01c6a50d04b467 (patch)
tree7f33c38cdbf6c0d3b99227a6af6f75ce27a6423c /src/libserver/css/css_tokeniser.hxx
parentb1e10ef14ebb91fa2ca1b61494e25fa099e85429 (diff)
downloadrspamd-f0de57da10d978a4ceea1dcfad01c6a50d04b467.tar.gz
rspamd-f0de57da10d978a4ceea1dcfad01c6a50d04b467.zip
[Project] Css: Add opacity support
Diffstat (limited to 'src/libserver/css/css_tokeniser.hxx')
-rw-r--r--src/libserver/css/css_tokeniser.hxx35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libserver/css/css_tokeniser.hxx b/src/libserver/css/css_tokeniser.hxx
index 3776b36e5..53ec4f2db 100644
--- a/src/libserver/css/css_tokeniser.hxx
+++ b/src/libserver/css/css_tokeniser.hxx
@@ -111,6 +111,41 @@ struct css_parser_token {
return def;
}
+ auto get_number_or_default(double def) const -> double {
+ if (std::holds_alternative<double>(value)) {
+ auto dbl = std::get<double>(value);
+
+ if (flags & css_parser_token::number_percent) {
+ dbl /= 100.0;
+ }
+
+ return dbl;
+ }
+
+ return def;
+ }
+
+ auto get_normal_number_or_default(double def) const -> double {
+ if (std::holds_alternative<double>(value)) {
+ auto dbl = std::get<double>(value);
+
+ if (flags & css_parser_token::number_percent) {
+ dbl /= 100.0;
+ }
+
+ if (dbl < 0) {
+ return 0.0;
+ }
+ else if (dbl > 1.0) {
+ return 1.0;
+ }
+
+ return dbl;
+ }
+
+ return def;
+ }
+
/* Debugging routines */
constexpr auto get_token_type() -> const char *;
/* This function might be slow */