21 #include <QDesktopServices>
22 #include <QModelIndex>
38 if (!str.contains(
"://"))
39 str =
"http://" + str;
40 QDesktopServices::openUrl(QUrl::fromEncoded(str.toUtf8(), QUrl::TolerantMode));
56 static QString scheme(
"(?:(?:mailto:|(?:[+.-]?\\w)+://)|www(?=\\.\\S+\\.))");
57 static QString authority(
"(?:(?:[,.;@:]?[-\\w]+)+\\.?|\\[[0-9a-f:.]+\\])(?::\\d+)?");
58 static QString urlChars(
"(?:[,.;:]*[\\w~@/?&=+$()!%#*-])");
59 static QString urlEnd(
"(?:>|[,.;:\"]*\\s|\\b|$)");
61 static QRegExp regExp[] = {
64 QRegExp(QString(
"\\b(%1%2(?:/%3*)?)%4").arg(scheme, authority, urlChars, urlEnd), Qt::CaseInsensitive),
68 QRegExp(
"((?:#|![A-Z0-9]{5})[^,:\\s]+(?::[^,:\\s]+)?)\\b", Qt::CaseInsensitive)
73 static const int regExpCount = 2;
75 qint16 matches[] = { 0, 0, 0 };
76 qint16 matchEnd[] = { 0, 0, 0 };
87 minidx = str.length();
88 for (
int i = 0; i < regExpCount; i++) {
89 if (matches[i] < 0 || matchEnd[i] > str.length())
continue;
90 if (idx >= matchEnd[i]) {
91 matches[i] = regExp[i].indexIn(str, qMax(matchEnd[i], idx));
92 if (matches[i] >= 0) matchEnd[i] = matches[i] + regExp[i].cap(1).length();
94 if (matches[i] >= 0 && matches[i] < minidx) {
100 idx = matchEnd[type];
101 QString match = str.mid(matches[type], matchEnd[type] - matches[type]);
103 if (!match.contains(
'(')) {
110 if (QRegExp(
"^#\\d+$").exactMatch(match))