Skip to content

Commit

Permalink
More qt6 + qt5 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Mar 14, 2024
1 parent 694f428 commit 3fa3901
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/msgmle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ void ChatEdit::contextMenuEvent(QContextMenuEvent *e)
tc.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
QString selected_word = tc.selectedText();
if (!selected_word.isEmpty() && !QRegularExpression("\\d+").exactMatch(selected_word)
static QRegularExpression numbers("^\\d+$");
if (!selected_word.isEmpty() && !numbers.match(selected_word).hasMatch()
&& !SpellChecker::instance()->isCorrect(selected_word)) {
QList<QString> suggestions = SpellChecker::instance()->suggestions(selected_word);
if (!suggestions.isEmpty() || SpellChecker::instance()->writable()) {
Expand Down
2 changes: 1 addition & 1 deletion src/pluginhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ bool PluginHost::incomingXml(int account, const QDomElement &e)
// regex filters
QMapIterator<QRegularExpression, IqNamespaceFilter *> i(iqNsxFilters_);
while (!handled && i.hasNext()) {
if (i.key().indexIn(ns) >= 0 && (i.value()->*handler)(account, e)) {
if (i.key().match(ns).hasMatch() && (i.value()->*handler)(account, e)) {
handled = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/psiiconset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class PsiIconset::Private {
// second level -- transport icon
if (jid.node().isEmpty() || status_icons.useServicesIcons) {
for (const StatusIconsets::IconsetItem &item : std::as_const(status_icons.list)) {
if (item.regexp.isEmpty() ? jid.node().isEmpty() : (item.regexp.indexIn(jid.domain()) != -1)) {
if (item.regexp.pattern().isEmpty() ? jid.node().isEmpty() : (item.regexp.match(jid.domain()).hasMatch())) {
const Iconset *is = psi->roster.value(item.iconset);
if (is) {
PsiIcon *i = const_cast<PsiIcon *>(is->icon(iconName));
Expand All @@ -200,7 +200,7 @@ class PsiIconset::Private {

// third level -- custom icons
for (const StatusIconsets::IconsetItem &item : std::as_const(status_icons.customList)) {
if (item.regexp.indexIn(jid.bare()) != -1) {
if (item.regexp.match(jid.bare()).hasMatch()) {
const Iconset *is = psi->roster.value(item.iconset);
if (is) {
PsiIcon *i = const_cast<PsiIcon *>(is->icon(iconName));
Expand Down
6 changes: 4 additions & 2 deletions src/serverlistquerier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QRegularExpression>
#include <QStringList>
#include <QUrl>

Expand Down Expand Up @@ -79,8 +80,9 @@ void ServerListQuerier::get_finished()
QString contents = QString::fromUtf8(reply->readAll());
int index = 0;
QRegularExpression re("data-original-title=\"([^\"]+)\"");
while ((index = contents.indexOf(re, index + 1)) != -1) {
servers.append(re.cap(1));
QRegularExpressionMatch match;
while ((index = contents.indexOf(re, index + 1, &match)) != -1) {
servers.append(match.captured(1));
}
#endif
emit listReceived(servers);
Expand Down
30 changes: 16 additions & 14 deletions src/textutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,17 @@ QString TextUtil::resolveEntities(const QStringView &in)

i = n; // should be n+1, but we'll let the loop increment do it

if (type == "amp")
if (type == QLatin1String{"amp"})
out += '&';
else if (type == "lt")
else if (type == QLatin1String{"lt"})
out += '<';
else if (type == "gt")
else if (type == QLatin1String{"gt"})
out += '>';
else if (type == "quot")
else if (type == QLatin1String{"quot"})
out += '\"';
else if (type == "apos")
else if (type == QLatin1String{"apos"})
out += '\'';
else if (type == "nbsp")
else if (type == QLatin1String{"nbsp"})
out += char(0xa0);
} else {
out += in[i];
Expand Down Expand Up @@ -531,29 +531,31 @@ QString TextUtil::emoticonify(const QString &in)

// find the closest match
const QRegularExpression &rx = icon->regExp();
int n = rx.indexIn(str, iii);
if (n == -1)
auto match = rx.match(str, iii);

if (!match.hasMatch())
continue;

if (ePos == -1 || n < ePos || (rx.matchedLength() > foundLen && n < ePos + foundLen)) {
int n = match.capturedStart();
if (ePos == -1 || n < ePos || (match.capturedLength() > foundLen && n < ePos + foundLen)) {
bool leftSpace = n == 0 || (n > 0 && str[n - 1].isSpace());
bool rightSpace = (n + rx.matchedLength() == int(str.length()))
|| (n + rx.matchedLength() < int(str.length())
&& str[n + rx.matchedLength()].isSpace());
bool rightSpace = (n + match.capturedLength() == int(str.length()))
|| (n + match.capturedLength() < int(str.length())
&& str[n + match.capturedLength()].isSpace());
// there must be whitespace at least on one side of the emoticon
if (leftSpace || rightSpace) {
ePos = n;
closest = icon;

foundPos = n;
foundLen = rx.matchedLength();
foundLen = match.capturedLength();
break;
}

searchAgain = true;
}

iii = n + rx.matchedLength();
iii = n + match.capturedLength();
} while (searchAgain);
}
}
Expand Down

0 comments on commit 3fa3901

Please sign in to comment.