Replaced deprecated QRegExp by QRegularExpression

This commit is contained in:
thunder2 2025-07-21 00:37:10 +02:00
parent f0286740f4
commit 13b294838b
8 changed files with 26 additions and 18 deletions

View file

@ -20,6 +20,8 @@
* *
*******************************************************************************/
#include <QRegularExpression>
#include "guiexprelement.h"
#include "util/DateTime.h"
@ -400,10 +402,10 @@ void ExprParamElement::adjustForSearchType(ExprSearchType type)
{
// record which search type is active
searchType = type;
QRegExp regExp("0|[1-9][0-9]*");
numValidator = new QRegExpValidator(regExp, this);
QRegExp hexRegExp("[A-Fa-f0-9]*");
hexValidator = new QRegExpValidator(hexRegExp, this);
QRegularExpression regExp("0|[1-9][0-9]*");
numValidator = new QRegularExpressionValidator(regExp, this);
QRegularExpression hexRegExp("[A-Fa-f0-9]*");
hexValidator = new QRegularExpressionValidator(hexRegExp, this);
QHBoxLayout* hbox = static_cast<QHBoxLayout*>(layout());
clearLayout(hbox);

View file

@ -34,6 +34,8 @@
#include <iostream>
class QRegularExpressionValidator;
enum ExprSearchType
{
NameSearch,
@ -191,8 +193,8 @@ public:
virtual QString toString();
private:
QRegExpValidator * numValidator;
QRegExpValidator * hexValidator;
QRegularExpressionValidator * numValidator;
QRegularExpressionValidator * hexValidator;
QFrame * rangeParamsFrame;
bool inRangedConfig;
uint64_t getIntValueFromField(QString fieldName, bool isToField=false,bool *ok = NULL);

View file

@ -103,6 +103,7 @@
#include <QXmlStreamReader>
#include <QDomDocument>
#include <QTextStream>
#include <QRegularExpression>
#include "ChatStyle.h"
#include "gui/settings/rsharesettings.h"
@ -376,7 +377,7 @@ QString ChatStyle::formatMessage(enumFormatMessage type
QString strDate = DateTime::formatDate(timestamp.date()).prepend(QString("<a name=\"date\">")).append(QString("</a>"));
QString strTime = DateTime::formatTime(timestamp.time()).prepend(QString("<a name=\"time\">")).append(QString("</a>"));
int bi = name.lastIndexOf(QRegExp(" \\(.*\\)")); //trim location from the end
int bi = name.lastIndexOf(QRegularExpression(" \\(.*\\)")); //trim location from the end
QString strShortName = RsHtml::plainText(name.left(bi)).prepend(QString("<a name=\"name\">")).append(QString("</a>"));
//handle /me
@ -384,9 +385,9 @@ QString ChatStyle::formatMessage(enumFormatMessage type
//meName class for modifying the style of the name in the palce of /me
if(me){
messageBody = messageBody.replace(messageBody.indexOf("/me "), 3, strShortName.prepend(QString("<span class=\"meName\">")).append(QString("</span>"))); //replace only the first /me
style = style.remove(QRegExp("%nome%.*%/nome%")).remove("%me%").remove("%/me%");
style = style.remove(QRegularExpression("%nome%.*%/nome%")).remove("%me%").remove("%/me%");
} else {
style = style.remove(QRegExp("%me%.*%/me%")).remove("%nome%").remove("%/nome%");
style = style.remove(QRegularExpression("%me%.*%/me%")).remove("%nome%").remove("%/nome%");
}
QString formatMsg = style.replace("%name%", strName)

View file

@ -640,7 +640,7 @@ void MessageWidget::fill(const std::string &msgId)
ui.trans_ToText->setText(to_text);
int recipientsCount = ui.trans_ToText->toPlainText().split(QRegExp("(\\s|\\n|\\r)+"), QtSkipEmptyParts).count();
int recipientsCount = ui.trans_ToText->toPlainText().split(QRegularExpression("(\\s|\\n|\\r)+"), QtSkipEmptyParts).count();
ui.expandButton->setText( QString::number(recipientsCount)+ " " + tr("more"));
if (recipientsCount >=20) {

View file

@ -27,7 +27,7 @@
#include <QFileOpenEvent>
#include <QLocale>
#include <QLocalSocket>
#include <QRegExp>
#include <QRegularExpression>
#include <QSharedMemory>
#include <QShortcut>
#include <QString>
@ -311,8 +311,8 @@ void RsApplication::customizeDateFormat()
QLocale locale = QLocale(); // set to default locale
/* get long date format without weekday */
options.dateformat = locale.dateFormat(QLocale::LongFormat);
options.dateformat.replace(QRegExp("^dddd,*[^ ]* *('[^']+' )*"), "");
options.dateformat.replace(QRegExp(",* *dddd"), "");
options.dateformat.replace(QRegularExpression("^dddd,*[^ ]* *('[^']+' )*"), "");
options.dateformat.replace(QRegularExpression(",* *dddd"), "");
options.dateformat = options.dateformat.trimmed();
}

View file

@ -26,6 +26,7 @@
#include <QTextDocumentFragment>
#include <qmath.h>
#include <QUrl>
#include <QRegularExpression>
#include "HandleRichText.h"
#include "gui/RetroShareLink.h"
@ -1171,7 +1172,7 @@ void RsHtml::optimizeHtml(QString &text, unsigned int flag /*= 0*/
{
// remove doctype
text.remove(QRegExp("<!DOCTYPE[^>]*>"));
text.remove(QRegularExpression("<!DOCTYPE[^>]*>"));
//remove all prepend char that make doc.setContent() fail
text.remove(0,text.indexOf("<"));
// Save Space and Tab because doc loose it.
@ -1253,7 +1254,7 @@ QString RsHtml::makeQuotedText(RSTextBrowser *browser)
{
text = browser->toPlainText();
}
QStringList sl = text.split(QRegExp("[\r\n]"),QtSkipEmptyParts);
QStringList sl = text.split(QRegularExpression("[\r\n]"),QtSkipEmptyParts);
text = sl.join("\n> ");
text.replace("\n> >","\n>>"); // Don't add space for already quotted lines.
text.replace(QChar(-4)," ");//Char used when image on text.

View file

@ -547,9 +547,9 @@ void RichTextEdit::slotClipboardDataChanged() {
QString RichTextEdit::toHtml() const {
QString s = f_textedit->toHtml();
// convert emails to links
s = s.replace(QRegExp("(<[^a][^>]+>(?:<span[^>]+>)?|\\s)([a-zA-Z\\d]+@[a-zA-Z\\d]+\\.[a-zA-Z]+)"), "\\1<a href=\"mailto:\\2\">\\2</a>");
s = s.replace(QRegularExpression("(<[^a][^>]+>(?:<span[^>]+>)?|\\s)([a-zA-Z\\d]+@[a-zA-Z\\d]+\\.[a-zA-Z]+)"), "\\1<a href=\"mailto:\\2\">\\2</a>");
// convert links
s = s.replace(QRegExp("(<[^a][^>]+>(?:<span[^>]+>)?|\\s)((?:https?|ftp|file)://[^\\s'\"<>]+)"), "\\1<a href=\"\\2\">\\2</a>");
s = s.replace(QRegularExpression("(<[^a][^>]+>(?:<span[^>]+>)?|\\s)((?:https?|ftp|file)://[^\\s'\"<>]+)"), "\\1<a href=\"\\2\">\\2</a>");
// see also: Utils::linkify()
return s;
}

View file

@ -18,6 +18,8 @@
* *
*******************************************************************************/
#include <QRegularExpression>
#include "RsSyntaxHighlighter.h"
RsSyntaxHighlighter::RsSyntaxHighlighter(QTextEdit *parent)
@ -65,7 +67,7 @@ void RsSyntaxHighlighter::highlightBlock(const QString &text)
{
if (text == "") return;
QRegExp endl("[\\r\\n\\x2028]"); //Usually 0x2028 character is used for newline, no idea why
QRegularExpression endl("[\\r\\n\\x2028]"); //Usually 0x2028 character is used for newline, no idea why
int index = 0;
QStringList lines = text.split(endl);
foreach (const QString &cLine, lines) {