Commit 2c1bdd16 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

[PATCH 1] Port some usage of QRegExp to QRegularExpression

parent 5dfb6583
......@@ -150,7 +150,11 @@ QString ChatWindow::getURI(bool passNetwork)
if (getType() == Channel)
{
channel = getName().remove(QRegExp(QStringLiteral("^#")));
channel = getName();
if (channel.startsWith(QLatin1Char('#'))) {
channel.remove(0, 1);
}
// must protect second #, but might as well protect all of them
channel.replace(QLatin1String("#"), QLatin1String("%23"));
}
......
......@@ -6,6 +6,7 @@
#include "highlight.h"
#include <QRegularExpression>
unsigned int Highlight::s_id = 0; // static
......@@ -85,9 +86,9 @@ void Highlight::setChatWindows(const QString& chatWindows)
// split string list of chat windows and trim all entries
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
m_chatWindowList = m_chatWindows.split(QRegExp(QStringLiteral("[,;]")), QString::SkipEmptyParts);
m_chatWindowList = m_chatWindows.split(QRegularExpression(QStringLiteral("[,;]")), QString::SkipEmptyParts);
#else
m_chatWindowList = m_chatWindows.split(QRegExp(QStringLiteral("[,;]")), Qt::SkipEmptyParts);
m_chatWindowList = m_chatWindows.split(QRegularExpression(QStringLiteral("[,;]")), Qt::SkipEmptyParts);
#endif
for (QString& chatWindow : m_chatWindowList) {
......
......@@ -13,6 +13,7 @@
#include <QClipboard>
#include <QKeyEvent>
#include <QMimeData>
#include <QRegularExpression>
#include <KMessageBox>
#include <KCompletionBox>
......@@ -400,11 +401,11 @@ void IRCInput::insertFromMimeData(const QMimeData * source)
while(pasteText.contains(QLatin1String("\n\n")))
pasteText.replace(QLatin1String("\n\n"),QLatin1String("\n"));
QRegExp reTopSpace(QStringLiteral("^ *\n"));
const QRegularExpression reTopSpace(QStringLiteral("^ *\n"));
while(pasteText.contains(reTopSpace))
pasteText.remove(reTopSpace);
QRegExp reBottomSpace(QStringLiteral("\n *$"));
const QRegularExpression reBottomSpace(QStringLiteral("\n *$"));
while(pasteText.contains(reBottomSpace))
pasteText.remove(reBottomSpace);
......
......@@ -260,7 +260,7 @@ QVariant IrcViewMimeData::retrieveData(const QString &mimeType, QVariant::Type t
IrcViewMimeData *that = const_cast<IrcViewMimeData *>(this);
//Copy the text, skipping any QChar::ObjectReplacementCharacter
QRegExp needle(QStringLiteral("\\xFFFC\\n?"));
const QRegularExpression needle(QStringLiteral("\\x{FFFC}\\n?"));
that->setText(fragment.toPlainText().remove(needle));
fragment = QTextDocumentFragment();
......@@ -1124,9 +1124,9 @@ QString IRCView::filter(const QString& line, const QString& defaultColor, const
QString highlightColor;
if (Preferences::self()->highlightNick() &&
line.toLower().contains(QRegExp(QLatin1String("(^|[^\\d\\w])") +
QRegExp::escape(ownNick.toLower()) +
QLatin1String("([^\\d\\w]|$)"))))
line.toLower().contains(QRegularExpression(QLatin1String("(^|[^\\d\\w])")
+ QRegularExpression::escape(ownNick.toLower())
+ QLatin1String("([^\\d\\w]|$)"))))
{
// highlight current nickname
highlightColor = Preferences::self()->highlightNickColor().name();
......@@ -1147,15 +1147,15 @@ QString IRCView::filter(const QString& line, const QString& defaultColor, const
bool patternFound = false;
if (highlight->getRegExp())
{
QRegExp needleReg(highlight->getPattern());
needleReg.setCaseSensitivity(Qt::CaseInsensitive);
// highlight regexp in text
patternFound = ((line.contains(needleReg)) ||
// highlight regexp in nickname
(whoSent.contains(needleReg)));
const QRegularExpression needleReg(highlight->getPattern(),
QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch rmatch;
patternFound = line.contains(needleReg, &rmatch) // highlight regexp in text
|| whoSent.contains(needleReg, &rmatch); // highlight regexp in nickname
// remember captured patterns for later
captures = needleReg.capturedTexts();
captures = rmatch.capturedTexts();
}
else
......@@ -1196,7 +1196,7 @@ QString IRCView::filter(const QString& line, const QString& defaultColor, const
{
m_autoTextToSend.replace(QStringLiteral("%%1").arg(capture), captures[capture]);
}
m_autoTextToSend.remove(QRegExp(QStringLiteral("%[0-9]")));
m_autoTextToSend.remove(QRegularExpression(QStringLiteral("%[0-9]")));
}
}
......@@ -1965,13 +1965,16 @@ void IRCView::adjustUrlRanges(QList< QPair<int, int> >& urlRanges, const QString
QString IRCView::getColors(const QString& text, int start, QString& _fgColor, QString& _bgColor, bool* fgValueOK, bool* bgValueOK)
{
QRegExp ircColorRegExp(QStringLiteral("(\003([0-9][0-9]|[0-9]|)(,([0-9][0-9]|[0-9]|)|,|)|\017)"));
if (ircColorRegExp.indexIn(text,start) == -1)
return QString();
static const QRegularExpression ircColorRegExp(QStringLiteral("(\003([0-9]{2}|[0-9]|)(,([0-9]{2}|[0-9]|)|,|)|\017)"));
const QRegularExpressionMatch match = ircColorRegExp.match(text, start);
if (!match.hasMatch()) {
return QString{};
}
QString ret(ircColorRegExp.cap(0));
const QString ret(match.captured(0));
QString fgColor(ircColorRegExp.cap(2)), bgColor(ircColorRegExp.cap(4));
const QString fgColor(match.captured(2));
if (!fgColor.isEmpty())
{
int foregroundColor = fgColor.toInt();
......@@ -1993,6 +1996,7 @@ QString IRCView::getColors(const QString& text, int start, QString& _fgColor, QS
*fgValueOK = true;
}
const QString bgColor(match.captured(4));
if (!bgColor.isEmpty())
{
int backgroundColor = bgColor.toInt();
......
......@@ -18,7 +18,7 @@
#include <QPainter>
#include <QPixmap>
#include <QBitmap>
#include <QRegExp>
#include <QRegularExpression>
#include <QTimer>
#include <QScreen>
#include <QApplication>
......@@ -133,9 +133,9 @@ QRect OSDWidget::determineMetrics( const int M )
const QSize max = QApplication::screens()[m_screen]->size() - margin;
// If we don't do that, the boundingRect() might not be suitable for drawText() (Qt issue N67674)
m_currentText.replace(QRegExp(QStringLiteral(" +\n")), QStringLiteral("\n"));
m_currentText.replace(QRegularExpression(QStringLiteral(" +\n")), QStringLiteral("\n"));
// remove consecutive line breaks
m_currentText.replace(QRegExp(QStringLiteral("\n+")), QStringLiteral("\n"));
m_currentText.replace(QRegularExpression(QStringLiteral("\n{2,}")), QStringLiteral("\n"));
QFont titleFont = font();
titleFont.setBold(true);
......
......@@ -80,7 +80,7 @@ void PasteEditor::removeNewlines()
{
QString text(m_textEditor->toPlainText());
text.remove(QLatin1Char('\r'));
text.remove(QRegExp(QStringLiteral("^\n+|\n+$")));
text.remove(QRegularExpression(QStringLiteral("^\n+|\n+$")));
int i = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment