aboutsummaryrefslogtreecommitdiff
path: root/lib/util.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-07-06 23:08:24 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-07-06 23:08:24 +0900
commit717f3bc6c91b14905f222e094e439b4cdcdab2c8 (patch)
treef3e43f5427e8b124b8aec4b6f437017fca65356b /lib/util.cpp
parenta4d1acb8e9e3f101c891f9089a07e214e5cc55f8 (diff)
parentf58819e4e930ee66e790eccaedf551f807956d72 (diff)
downloadlibquotient-717f3bc6c91b14905f222e094e439b4cdcdab2c8.tar.gz
libquotient-717f3bc6c91b14905f222e094e439b4cdcdab2c8.zip
Merge branch 'master' into e2ee-enc-mng
Diffstat (limited to 'lib/util.cpp')
-rw-r--r--lib/util.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/util.cpp b/lib/util.cpp
index 4e17d2f9..88cba959 100644
--- a/lib/util.cpp
+++ b/lib/util.cpp
@@ -23,6 +23,10 @@
#include <QtCore/QDir>
#include <QtCore/QStringBuilder>
+#include <QtCore/QCryptographicHash>
+#include <QtCore/QtEndian>
+#include <QtCore/QDataStream>
+
static const auto RegExpOptions =
QRegularExpression::CaseInsensitiveOption
| QRegularExpression::OptimizeOnFirstUsageOption
@@ -41,7 +45,7 @@ void QMatrixClient::linkifyUrls(QString& htmlEscapedText)
// <, >, ' or ", and ends before whitespaces, <, >, ', ", ], !, ), :,
// comma or dot
static const QRegularExpression FullUrlRegExp(QStringLiteral(
- R"(\b((www\.(?!\.)(?!(\w|\.|-)+@)|(https?|ftp|magnet)://)(&(?![lg]t;)|[^&\s<>'"])+(&(?![lg]t;)|[^&!,.\s<>'"\]):])))"
+ R"(\b((www\.(?!\.)(?!(\w|\.|-)+@)|(https?|ftp|magnet|matrix):(//)?)(&(?![lg]t;)|[^&\s<>'"])+(&(?![lg]t;)|[^&!,.\s<>'"\]):])))"
), RegExpOptions);
// email address:
// [word chars, dots or dashes]@[word chars, dots or dashes].[word chars]
@@ -93,6 +97,21 @@ QString QMatrixClient::cacheLocation(const QString& dirName)
return cachePath;
}
+qreal QMatrixClient::stringToHueF(const QString &string)
+{
+ Q_ASSERT(!string.isEmpty());
+ QByteArray hash = QCryptographicHash::hash(string.toUtf8(),
+ QCryptographicHash::Sha1);
+ QDataStream dataStream(qToLittleEndian(hash).left(2));
+ dataStream.setByteOrder(QDataStream::LittleEndian);
+ quint16 hashValue;
+ dataStream >> hashValue;
+ const auto hueF =
+ qreal(hashValue)/std::numeric_limits<quint16>::max();
+ Q_ASSERT((0 <= hueF) && (hueF <= 1));
+ return hueF;
+}
+
// Tests for function_traits<>
#ifdef Q_CC_CLANG