From: Vsevolod Stakhov Date: Sat, 2 Oct 2021 13:57:04 +0000 (+0100) Subject: [Minor] Add some utility methods X-Git-Tag: 3.1~98 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0751ed286c565d0aaf7b3eacc0773c2e1ed6625a;p=rspamd.git [Minor] Add some utility methods --- diff --git a/src/libmime/mime_string.hxx b/src/libmime/mime_string.hxx index 7474c6381..3294cd980 100644 --- a/src/libmime/mime_string.hxx +++ b/src/libmime/mime_string.hxx @@ -353,6 +353,16 @@ public: * @param other * @return */ + auto assign_copy(const view_type &other) { + storage.clear(); + + if (filter_func) { + append_c_string_filtered(other.data(), other.size()); + } + else { + append_c_string_unfiltered(other.data(), other.size()); + } + } auto assign_copy(const storage_type &other) { storage.clear(); @@ -363,7 +373,7 @@ public: append_c_string_unfiltered(other.data(), other.size()); } } - auto assign_copy(const view_type &other) { + auto assign_copy(const basic_mime_string &other) { storage.clear(); if (filter_func) { @@ -462,6 +472,18 @@ public: return storage; } + inline auto as_view() const noexcept -> view_type { + return view_type{storage}; + } + + constexpr CharT operator[](std::size_t pos) const { + return storage[pos]; + } + constexpr CharT at(std::size_t pos) const { + return storage.at(pos); + } + + /* For doctest stringify */ friend std::ostream& operator<< (std::ostream& os, const CharT& value) { os << value.storage; @@ -556,4 +578,5 @@ private: } + #endif //RSPAMD_MIME_STRING_HXX