aboutsummaryrefslogtreecommitdiff
path: root/lib/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util.cpp')
-rw-r--r--lib/util.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/util.cpp b/lib/util.cpp
index 88cba959..b9639843 100644
--- a/lib/util.cpp
+++ b/lib/util.cpp
@@ -112,6 +112,20 @@ qreal QMatrixClient::stringToHueF(const QString &string)
return hueF;
}
+static const auto ServerPartRegEx = QStringLiteral(
+ "(\\[[^]]+\\]|[^:@]+)" // Either IPv6 address or hostname/IPv4 address
+ "(?::(\\d{1,5}))?" // Optional port
+);
+
+QString QMatrixClient::serverPart(const QString& mxId)
+{
+ static QString re = "^[@!#$+].+?:(" // Localpart and colon
+ % ServerPartRegEx % ")$";
+ static QRegularExpression parser(re,
+ QRegularExpression::UseUnicodePropertiesOption); // Because Asian digits
+ return parser.match(mxId).captured(1);
+}
+
// Tests for function_traits<>
#ifdef Q_CC_CLANG