summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-09-29 20:29:52 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-09-29 20:29:52 +0100
commit63a6ecd9e685f87b1366e164a9a681005ae439a5 (patch)
tree91b5bed9ccdfcd8da8de5cc1d0d9dd54eb66c017 /src
parenta8e5ffed85ee6a725d97caeded32ad4fe9ed0e3f (diff)
downloadrspamd-63a6ecd9e685f87b1366e164a9a681005ae439a5.tar.gz
rspamd-63a6ecd9e685f87b1366e164a9a681005ae439a5.zip
[Minor] Remove optional as function_view has nullable semantics
Diffstat (limited to 'src')
-rw-r--r--src/libmime/mime_string.hxx21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/libmime/mime_string.hxx b/src/libmime/mime_string.hxx
index 2ebf8a29a..c15dfd566 100644
--- a/src/libmime/mime_string.hxx
+++ b/src/libmime/mime_string.hxx
@@ -20,7 +20,6 @@
#include <string>
#include <string_view>
#include <memory>
-#include <optional>
#include <cstdint>
#include <cstdlib>
#include <cstring>
@@ -89,6 +88,14 @@ public:
const Allocator& alloc = Allocator()) noexcept :
basic_mime_string(st.data(), st.size(), alloc) {}
+ /**
+ * Creates a string with a filter function. It is calee responsibility to
+ * ensure that the filter functor survives long enough to work with a string
+ * @param str
+ * @param sz
+ * @param filt
+ * @param alloc
+ */
basic_mime_string(const T* str, std::size_t sz,
filter_type &&filt,
const Allocator& alloc = Allocator()) noexcept :
@@ -132,7 +139,7 @@ public:
* @return
*/
[[nodiscard]] auto assign_if_valid(storage_type &&other) -> bool {
- if (filter_func.has_value()) {
+ if (filter_func) {
/* No way */
return false;
}
@@ -153,7 +160,7 @@ public:
auto assign_copy(const storage_type &other) {
storage.clear();
- if (filter_func.has_value()) {
+ if (filter_func) {
append_c_string_filtered(other.data(), other.size());
}
else {
@@ -162,7 +169,7 @@ public:
}
auto append(const T* str, std::size_t size) -> std::size_t {
- if (filter_func.has_value()) {
+ if (filter_func) {
return append_c_string_filtered(str, size);
}
else {
@@ -204,7 +211,7 @@ public:
private:
mime_string_flags flags = mime_string_flags::MIME_STRING_DEFAULT;
storage_type storage;
- std::optional<filter_type> filter_func;
+ filter_type filter_func;
auto append_c_string_unfiltered(const T* str, std::size_t len) -> std::size_t {
/* This is fast path */
@@ -268,8 +275,8 @@ private:
flags = flags | mime_string_flags::MIME_STRING_SEEN_INVALID;
}
else {
- if (filter_func.has_value()) {
- uc = filter_func.value()(uc);
+ if (filter_func) {
+ uc = filter_func(uc);
}
if (uc == 0) {