diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-07-26 10:49:23 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-07-26 10:49:23 +0100 |
commit | 537a7180a0d5132c11636c4fd8b1450cd99d352c (patch) | |
tree | fb9f8c84955a411bdffbd6371ea32f2716fb3687 /src/libserver/css/css_util.cxx | |
parent | 5fd7a90fdaa33f52c59bdb0ca84451e5c1e22365 (diff) | |
download | rspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.tar.gz rspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.zip |
[Rework] Use clang-format to unify formatting in all sources
No meaningful changes.
Diffstat (limited to 'src/libserver/css/css_util.cxx')
-rw-r--r-- | src/libserver/css/css_util.cxx | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/src/libserver/css/css_util.cxx b/src/libserver/css/css_util.cxx index 7add8043c..07f87229c 100644 --- a/src/libserver/css/css_util.cxx +++ b/src/libserver/css/css_util.cxx @@ -25,7 +25,7 @@ std::string_view unescape_css(rspamd_mempool_t *pool, { auto *nspace = reinterpret_cast<char *>(rspamd_mempool_alloc(pool, sv.length())); auto *d = nspace; - auto nleft = sv.length (); + auto nleft = sv.length(); enum { normal = 0, @@ -37,28 +37,29 @@ std::string_view unescape_css(rspamd_mempool_t *pool, char quote_char, prev_c = 0; auto escape_offset = 0, i = 0; -#define MAYBE_CONSUME_CHAR(c) do { \ - if ((c) == '"' || (c) == '\'') { \ - state = quoted; \ - quote_char = (c); \ - nleft--; \ - *d++ = (c); \ - } \ - else if ((c) == '\\') { \ - escape_offset = i; \ - state = escape; \ - } \ - else { \ - state = normal; \ - nleft--; \ - *d++ = g_ascii_tolower(c); \ - } \ -} while (0) +#define MAYBE_CONSUME_CHAR(c) \ + do { \ + if ((c) == '"' || (c) == '\'') { \ + state = quoted; \ + quote_char = (c); \ + nleft--; \ + *d++ = (c); \ + } \ + else if ((c) == '\\') { \ + escape_offset = i; \ + state = escape; \ + } \ + else { \ + state = normal; \ + nleft--; \ + *d++ = g_ascii_tolower(c); \ + } \ + } while (0) - for (const auto c : sv) { + for (const auto c: sv) { if (nleft == 0) { msg_err_css("cannot unescape css: truncated buffer of size %d", - (int)sv.length()); + (int) sv.length()); break; } switch (state) { @@ -72,7 +73,7 @@ std::string_view unescape_css(rspamd_mempool_t *pool, } } prev_c = c; - nleft --; + nleft--; *d++ = c; break; case escape: @@ -84,19 +85,19 @@ std::string_view unescape_css(rspamd_mempool_t *pool, if (!rspamd_xstrtoul(escape_start, i - escape_offset - 1, &val)) { msg_debug_css("invalid broken escape found at pos %d", - escape_offset); + escape_offset); } else { if (val < 0x80) { /* Trivial case: ascii character */ - *d++ = (unsigned char)g_ascii_tolower(val); - nleft --; + *d++ = (unsigned char) g_ascii_tolower(val); + nleft--; } else { UChar32 uc = val; auto off = 0; UTF8_APPEND_CHAR_SAFE((uint8_t *) d, off, - sv.length (), u_tolower(uc)); + sv.length(), u_tolower(uc)); d += off; nleft -= off; } @@ -105,16 +106,16 @@ std::string_view unescape_css(rspamd_mempool_t *pool, else { /* Empty escape, ignore it */ msg_debug_css("invalid empty escape found at pos %d", - escape_offset); + escape_offset); } if (nleft <= 0) { msg_err_css("cannot unescape css: truncated buffer of size %d", - (int)sv.length()); + (int) sv.length()); } else { /* Escape is done, advance forward */ - if (g_ascii_isspace (c)) { + if (g_ascii_isspace(c)) { state = skip_spaces; } else { @@ -131,21 +132,21 @@ std::string_view unescape_css(rspamd_mempool_t *pool, break; } - i ++; + i++; } return std::string_view{nspace, sv.size() - nleft}; } -} +}// namespace rspamd::css /* C API */ -const gchar *rspamd_css_unescape (rspamd_mempool_t *pool, - const guchar *begin, - gsize len, - gsize *outlen) +const gchar *rspamd_css_unescape(rspamd_mempool_t *pool, + const guchar *begin, + gsize len, + gsize *outlen) { - auto sv = rspamd::css::unescape_css(pool, {(const char*)begin, len}); + auto sv = rspamd::css::unescape_css(pool, {(const char *) begin, len}); const auto *v = sv.begin(); if (outlen) { |