From: Vsevolod Stakhov Date: Thu, 30 Sep 2021 09:18:23 +0000 (+0100) Subject: [Minor] Remove const_iterator, template filter functor X-Git-Tag: 3.1~104 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=856eec0e2a5ec113ce4b6ff06717cd4935291558;p=thirdparty%2Frspamd.git [Minor] Remove const_iterator, template filter functor --- diff --git a/src/libmime/mime_string.hxx b/src/libmime/mime_string.hxx index 32eafde191..9ef7b8dcdf 100644 --- a/src/libmime/mime_string.hxx +++ b/src/libmime/mime_string.hxx @@ -32,11 +32,14 @@ namespace rspamd::mime { /* * The motivation for another string is to have utf8 valid string replacing * all bad things with FFFFD replacement character and filtering \0 and other - * strange stuff defined by policies + * strange stuff defined by policies. * This string always exclude \0 characters and ignore them! This is how MUA acts, - * and we also store a flag about bad characters + * and we also store a flag about bad characters. + * Mime string iterators are always const, so the underlying storage should not + * be modified externally. */ -template> class basic_mime_string; +template, + class Functor = fu2::function_view> class basic_mime_string; using mime_string = basic_mime_string; @@ -68,7 +71,7 @@ bool operator !(mime_string_flags fl) template struct iterator_base { - template + template friend class basic_mime_string; public: @@ -154,7 +157,7 @@ public: iterator_base& operator=( const iterator_base& ) noexcept = default; Container* get_instance() const noexcept { return cont_instance; } - value_type get_value() const noexcept { return cont_instance->storage.at(idx, std::nothrow); } + value_type get_value() const noexcept { return cont_instance->get_storage().at(idx); } protected: difference_type idx; Container* cont_instance = nullptr; @@ -248,43 +251,17 @@ struct iterator : iterator_base { } }; -template -struct const_iterator : iterator { - const_iterator(typename iterator_base::difference_type index, const Container *instance) noexcept: - iterator(index, const_cast(instance)) - { - } - - const_iterator(const iterator &other) noexcept: - iterator(other) - { - } - - const_iterator() noexcept = default; - - const_iterator(const const_iterator &) noexcept = default; - - const_iterator &operator=(const const_iterator &) noexcept = default; - - const typename iterator::reference_type operator*() const noexcept - { - return this->get_value(); - } -}; - -template +template class basic_mime_string : private Allocator { public: using storage_type = std::basic_string, Allocator>; using view_type = std::basic_string_view>; - using filter_type = fu2::function_view; + using filter_type = Functor; using codepoint_type = UChar32; using value_type = T; using difference_type = std::ptrdiff_t; using iterator = rspamd::mime::iterator; - using const_iterator = rspamd::mime::const_iterator; using raw_iterator = rspamd::mime::iterator; - using raw_const_iterator = rspamd::mime::const_iterator; /* Ctors */ basic_mime_string() noexcept : Allocator() {} explicit basic_mime_string(const Allocator& alloc) noexcept : Allocator(alloc) {} @@ -419,44 +396,29 @@ public: return false; } - inline iterator begin() noexcept - { - return {0, this}; - } - - inline const_iterator begin() const noexcept - { - return {0, this}; - } - - inline raw_iterator raw_begin() noexcept + inline auto begin() noexcept -> iterator { return {0, this}; } - inline raw_const_iterator raw_begin() const noexcept + inline auto raw_begin() noexcept -> raw_iterator { return {0, this}; } - inline iterator end() noexcept + inline auto end() noexcept -> iterator { return {(difference_type) size(), this}; } - inline const_iterator end() const noexcept + inline auto raw_end() noexcept -> raw_iterator { return {(difference_type) size(), this}; } - inline raw_iterator raw_end() noexcept + inline auto get_storage() const noexcept -> const storage_type & { - return {(difference_type) size(), this}; - } - - inline raw_const_iterator raw_end() const noexcept - { - return {(difference_type) size(), this}; + return storage; } /* For doctest stringify */