commit 0751ed2: [Minor] Add some utility methods

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Oct 2 14:00:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-10-02 14:57:04 +0100
URL: https://github.com/rspamd/rspamd/commit/0751ed286c565d0aaf7b3eacc0773c2e1ed6625a (HEAD -> master)

[Minor] Add some utility methods

---
 src/libmime/mime_string.hxx | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

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


More information about the Commits mailing list