aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/utils')
-rw-r--r--src/core/utils/CommonUtils.cpp7
-rw-r--r--src/core/utils/CommonUtils.h8
-rw-r--r--src/core/utils/MemoryUtils.h19
3 files changed, 16 insertions, 18 deletions
diff --git a/src/core/utils/CommonUtils.cpp b/src/core/utils/CommonUtils.cpp
index 0adc4d7f..ce36c71e 100644
--- a/src/core/utils/CommonUtils.cpp
+++ b/src/core/utils/CommonUtils.cpp
@@ -107,4 +107,11 @@ auto GPGFRONTEND_CORE_EXPORT ParseHexEncodedVersionTuple(const QString& s)
const auto version = s.toUtf8().toUInt(&ok, 16);
return ok ? static_cast<int>(version) : -1;
}
+
+const auto kReEmail = QRegularExpression{
+ R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"};
+
+auto GPGFRONTEND_CORE_EXPORT IsEmailAddress(const QString& str) -> bool {
+ return kReEmail.match(str).hasMatch();
+}
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/utils/CommonUtils.h b/src/core/utils/CommonUtils.h
index 468d8a59..d62f4867 100644
--- a/src/core/utils/CommonUtils.h
+++ b/src/core/utils/CommonUtils.h
@@ -82,4 +82,12 @@ auto GPGFRONTEND_CORE_EXPORT IsFlatpakENV() -> bool;
auto GPGFRONTEND_CORE_EXPORT ParseHexEncodedVersionTuple(const QString &s)
-> int;
+/**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+auto GPGFRONTEND_CORE_EXPORT IsEmailAddress(const QString &) -> bool;
+
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/utils/MemoryUtils.h b/src/core/utils/MemoryUtils.h
index 223c6f82..6c2bb69f 100644
--- a/src/core/utils/MemoryUtils.h
+++ b/src/core/utils/MemoryUtils.h
@@ -143,24 +143,7 @@ static auto SecureCreateUniqueObject(Args &&...args)
}
template <typename T, typename... Args>
-auto SecureCreateSharedObject(Args &&...args) -> std::shared_ptr<T> {
- void *mem = SecureMemoryAllocator::Allocate(sizeof(T));
- if (!mem) throw std::bad_alloc();
-
- try {
- T *obj = new (mem) T(std::forward<Args>(args)...);
- return std::shared_ptr<T>(obj, [](T *ptr) {
- ptr->~T();
- SecureMemoryAllocator::Deallocate(ptr);
- });
- } catch (...) {
- SecureMemoryAllocator::Deallocate(mem);
- throw;
- }
-}
-
-template <typename T, typename... Args>
-auto SecureCreateQSharedObject(Args &&...args) -> QSharedPointer<T> {
+auto SecureCreateSharedObject(Args &&...args) -> QSharedPointer<T> {
void *mem = SecureMemoryAllocator::Allocate(sizeof(T));
if (!mem) throw std::bad_alloc();