diff --git a/src/formeditor/connectiondialog.cpp b/src/formeditor/connectiondialog.cpp --- a/src/formeditor/connectiondialog.cpp +++ b/src/formeditor/connectiondialog.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include using namespace KFormDesigner; @@ -312,7 +312,7 @@ return; QString signalArg(signal); - signalArg.remove(QRegExp(".*[(]|[)]")); + signalArg.remove(QRegularExpression(".*[(]|[)]")); const QList list( KexiUtils::methodsForMetaObjectWithParents(tree->widget()->metaObject(), @@ -320,7 +320,7 @@ foreach(const QMetaMethod &method, list) { // we add the slot only if it is compatible with the signal QString slotArg(method.signature()); - slotArg.remove(QRegExp(".*[(]|[)]")); + slotArg.remove(QRegularExpression(".*[(]|[)]")); if (!signalArg.startsWith(slotArg, Qt::CaseSensitive) && (!signal.isEmpty())) // args not compatible continue; @@ -364,9 +364,9 @@ // Then we check if signal/slot args are compatible QString signal = (*data)[2].toString(); - signal.remove(QRegExp(".*[(]|[)]")); // just keep the args list + signal.remove(QRegularExpression(".*[(]|[)]")); // just keep the args list QString slot = (*data)[4].toString(); - slot.remove(QRegExp(".*[(]|[)]")); + slot.remove(QRegularExpression(".*[(]|[)]")); if (!signal.startsWith(slot, Qt::CaseSensitive)) { setStatusError(xi18n("The signal/slot arguments are not compatible."), data); diff --git a/src/kexiutils/completer/KexiCompleter.cpp b/src/kexiutils/completer/KexiCompleter.cpp --- a/src/kexiutils/completer/KexiCompleter.cpp +++ b/src/kexiutils/completer/KexiCompleter.cpp @@ -1832,7 +1832,7 @@ doubleSlash.clear(); #endif - QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']')); + QRegularExpression re(QLatin1Char('[') + QRegularExpression::escape(sep) + QLatin1Char(']')); QStringList parts = pathCopy.split(re); #if defined(Q_OS_SYMBIAN) diff --git a/src/main/startup/KexiWelcomeStatusBar.cpp b/src/main/startup/KexiWelcomeStatusBar.cpp --- a/src/main/startup/KexiWelcomeStatusBar.cpp +++ b/src/main/startup/KexiWelcomeStatusBar.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include @@ -185,7 +186,7 @@ << "in line" << i+1 << "- no files will be updated"; return; } - if (remoteFname.contains(QRegExp("\\s"))) { + if (remoteFname.contains(QRegularExpression("\\s"))) { qWarning() << "Filename expected without whitespace but found" << remoteFname << "in line" << i+1 << "- no files will be updated"; return; @@ -315,20 +316,20 @@ foreach(QLabel* lbl, widget()->findChildren()) { QString t = lbl->text(); - QRegExp re(""); - re.setMinimal(true); + QRegularExpression re("", QRegularExpression::InvertedGreedinessOption); int pos = 0; int oldPos = 0; QString newText; + QRegularExpressionMatch match = re.match(t); //qDebug() << "t:" << t; - while ((pos = re.indexIn(t, pos)) != -1) { + while ((pos = match.capturedStart(pos)) != -1) { //qDebug() << "pos:" << pos; //qDebug() << "newText += t.mid(oldPos, pos - oldPos)" // << t.mid(oldPos, pos - oldPos); newText += t.mid(oldPos, pos - oldPos); //qDebug() << "newText1:" << newText; //qDebug() << lbl->objectName() << "~~~~" << t.mid(pos, re.matchedLength()); - QString a = t.mid(pos, re.matchedLength()); + QString a = t.mid(pos, match.capturedLength()); //qDebug() << "a:" << a; int colPos = a.indexOf("color:"); if (colPos == -1) { // add color @@ -352,7 +353,7 @@ //qDebug() << "a2:" << a; newText += a; //qDebug() << "newText2:" << newText; - pos += re.matchedLength(); + pos += match.capturedLength(); oldPos = pos; //qDebug() << "pos2:" << pos; } diff --git a/src/plugins/importexport/csv/kexicsvimportdialog.h b/src/plugins/importexport/csv/kexicsvimportdialog.h --- a/src/plugins/importexport/csv/kexicsvimportdialog.h +++ b/src/plugins/importexport/csv/kexicsvimportdialog.h @@ -30,7 +30,7 @@ #define KEXI_CSVIMPORTDIALOG_H #include -#include +#include #include #include #include @@ -240,7 +240,7 @@ QByteArray m_fileArray; Mode m_mode; - QRegExp m_dateRegExp, m_timeRegExp1, m_timeRegExp2, m_fpNumberRegExp1, m_fpNumberRegExp2; + QRegularExpression m_dateRegExp, m_timeRegExp1, m_timeRegExp2, m_fpNumberRegExp1, m_fpNumberRegExp2; bool m_columnsAdjusted; //!< to call adjustColumn() only once bool m_1stRowForFieldNamesDetected; //!< used to force rerun fillTable() after 1st row bool m_firstFillTableCall; //!< used to know whether it's 1st fillTable() call diff --git a/src/plugins/importexport/csv/kexicsvimportdialog.cpp b/src/plugins/importexport/csv/kexicsvimportdialog.cpp --- a/src/plugins/importexport/csv/kexicsvimportdialog.cpp +++ b/src/plugins/importexport/csv/kexicsvimportdialog.cpp @@ -337,12 +337,12 @@ } else if ( mode == File ) {*/ - m_dateRegExp = QRegExp("(\\d{1,4})([/\\-\\.])(\\d{1,2})([/\\-\\.])(\\d{1,4})"); - m_timeRegExp1 = QRegExp("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})"); - m_timeRegExp2 = QRegExp("(\\d{1,2}):(\\d{1,2})"); - m_fpNumberRegExp1 = QRegExp("[\\-]{0,1}\\d*[,\\.]\\d+"); + m_dateRegExp = QRegularExpression("(\\d{1,4})([/\\-\\.])(\\d{1,2})([/\\-\\.])(\\d{1,4})"); + m_timeRegExp1 = QRegularExpression("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})"); + m_timeRegExp2 = QRegularExpression("(\\d{1,2}):(\\d{1,2})"); + m_fpNumberRegExp1 = QRegularExpression("[\\-]{0,1}\\d*[,\\.]\\d+"); // E notation, e.g. 0.1e2, 0.1e+2, 0.1e-2, 0.1E2, 0.1E+2, 0.1E-2 - m_fpNumberRegExp2 = QRegExp("[\\-]{0,1}\\d*[,\\.]\\d+[Ee][+-]{0,1}\\d+"); + m_fpNumberRegExp2 = QRegularExpression("[\\-]{0,1}\\d*[,\\.]\\d+[Ee][+-]{0,1}\\d+"); m_loadingProgressDlg = 0; if (m_mode == Clipboard) { m_infoLbl->setIcon(koIconName("edit-paste")); @@ -1400,7 +1400,7 @@ if (!found && (row == 1 || type == KDbField::Integer || type == KDbField::Double || type == KDbField::InvalidType)) { - bool ok = text.isEmpty() || m_fpNumberRegExp1.exactMatch(text) || m_fpNumberRegExp2.exactMatch(text); + bool ok = text.isEmpty() || m_fpNumberRegExp1.match(text).hasMatch() || m_fpNumberRegExp2.match(text).hasMatch(); if (ok && (row == 1 || type == KDbField::InvalidType)) { d->setDetectedType(col, KDbField::Double); @@ -1420,7 +1420,7 @@ //-date? if (!found && (row == 1 || type == KDbField::Date || type == KDbField::InvalidType)) { if ((row == 1 || type == KDbField::InvalidType) - && (text.isEmpty() || m_dateRegExp.exactMatch(text))) { + && (text.isEmpty() || m_dateRegExp.match(text).hasMatch())) { d->setDetectedType(col, KDbField::Date); found = true; //yes } @@ -1428,7 +1428,7 @@ //-time? if (!found && (row == 1 || type == KDbField::Time || type == KDbField::InvalidType)) { if ((row == 1 || type == KDbField::InvalidType) - && (text.isEmpty() || m_timeRegExp1.exactMatch(text) || m_timeRegExp2.exactMatch(text))) + && (text.isEmpty() || m_timeRegExp1.match(text).hasMatch() || m_timeRegExp2.match(text).hasMatch())) { d->setDetectedType(col, KDbField::Time); found = true; //yes @@ -1447,8 +1447,8 @@ //try all combinations QString datePart(dateTimeList[0].trimmed()); QString timePart(dateTimeList[1].trimmed()); - ok = m_dateRegExp.exactMatch(datePart) - && (m_timeRegExp1.exactMatch(timePart) || m_timeRegExp2.exactMatch(timePart)); + ok = m_dateRegExp.match(datePart).hasMatch() + && (m_timeRegExp1.match(timePart).hasMatch() || m_timeRegExp2.match(timePart).hasMatch()); } detected = ok; } @@ -1500,17 +1500,18 @@ bool KexiCSVImportDialog::parseDate(const QString& text, QDate& date) { - if (!m_dateRegExp.exactMatch(text)) + QRegularExpressionMatch match = m_dateRegExp.match(text); + if (!match.hasMatch()) return false; //dddd - dd - dddd //1 2 3 4 5 <- pos - const int d1 = m_dateRegExp.cap(1).toInt(), d3 = m_dateRegExp.cap(3).toInt(), d5 = m_dateRegExp.cap(5).toInt(); + const int d1 = match.captured(1).toInt(), d3 = match.captured(3).toInt(), d5 = match.captured(5).toInt(); switch (m_options.dateFormat) { case KexiCSVImportOptions::DMY: date = buildDate(d5, d3, d1); break; case KexiCSVImportOptions::YMD: date = buildDate(d1, d3, d5); break; case KexiCSVImportOptions::MDY: date = buildDate(d5, d1, d3); break; case KexiCSVImportOptions::AutoDateFormat: - if (m_dateRegExp.cap(2) == "/") { //probably separator for american format mm/dd/yyyy + if (match.captured(2) == "/") { //probably separator for american format mm/dd/yyyy date = buildDate(d5, d1, d3); } else { if (d5 > 31) //d5 == year @@ -1529,9 +1530,11 @@ time = QTime::fromString(text, Qt::ISODate); //same as m_timeRegExp1 if (time.isValid()) return true; - if (m_timeRegExp2.exactMatch(text)) { //hh:mm:ss - time = QTime(m_timeRegExp2.cap(1).toInt(), - m_timeRegExp2.cap(3).toInt(), m_timeRegExp2.cap(5).toInt()); + + QRegularExpressionMatch match = m_timeRegExp2.match(text); + if (match.hasMatch()) { //hh:mm:ss + time = QTime(match.captured(1).toInt(), + match.captured(3).toInt(), match.captured(5).toInt()); return true; } return false; diff --git a/src/plugins/queries/kexiquerydesignerguieditor.cpp b/src/plugins/queries/kexiquerydesignerguieditor.cpp --- a/src/plugins/queries/kexiquerydesignerguieditor.cpp +++ b/src/plugins/queries/kexiquerydesignerguieditor.cpp @@ -53,7 +53,7 @@ #include #include -#include +#include #include #include #include @@ -1377,7 +1377,7 @@ return KDbExpression(); KDbExpression valueExpr; - QRegExp re; + QRegularExpressionMatch match; if (str.length() >= 2 && ( (str.startsWith(QLatin1Char('"')) && str.endsWith(QLatin1Char('"'))) @@ -1386,22 +1386,22 @@ valueExpr = KDbConstExpression(KDbToken::CHARACTER_STRING_LITERAL, str.mid(1, str.length() - 2)); } else if (str.startsWith(QLatin1Char('[')) && str.endsWith(QLatin1Char(']'))) { valueExpr = KDbQueryParameterExpression(str.mid(1, str.length() - 2)); - } else if ((re = QRegExp("(\\d{1,4})-(\\d{1,2})-(\\d{1,2})")).exactMatch(str)) { + } else if ((match = QRegularExpression("^(\\d{1,4})-(\\d{1,2})-(\\d{1,2})$").match(str)).hasMatch()) { valueExpr = KDbConstExpression(KDbToken::DATE_CONST, QDate::fromString( - re.cap(1).rightJustified(4, '0') + "-" + re.cap(2).rightJustified(2, '0') - + "-" + re.cap(3).rightJustified(2, '0'), Qt::ISODate)); - } else if ((re = QRegExp("(\\d{1,2}):(\\d{1,2})")).exactMatch(str) - || (re = QRegExp("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})")).exactMatch(str)) { - QString res = re.cap(1).rightJustified(2, '0') + ":" + re.cap(2).rightJustified(2, '0') - + ":" + re.cap(3).rightJustified(2, '0'); + match.captured(1).rightJustified(4, '0') + "-" + match.captured(2).rightJustified(2, '0') + + "-" + match.captured(3).rightJustified(2, '0'), Qt::ISODate)); + } else if ((match = QRegularExpression("^(\\d{1,2}):(\\d{1,2})$").match(str)).hasMatch() + || (match = QRegularExpression("^(\\d{1,2}):(\\d{1,2}):(\\d{1,2})$").match(str)).hasMatch()) { + QString res = match.captured(1).rightJustified(2, '0') + ":" + match.captured(2).rightJustified(2, '0') + + ":" + match.captured(3).rightJustified(2, '0'); // qDebug() << res; valueExpr = KDbConstExpression(KDbToken::TIME_CONST, QTime::fromString(res, Qt::ISODate)); - } else if ((re = QRegExp("(\\d{1,4})-(\\d{1,2})-(\\d{1,2})\\s+(\\d{1,2}):(\\d{1,2})")).exactMatch(str) - || (re = QRegExp("(\\d{1,4})-(\\d{1,2})-(\\d{1,2})\\s+(\\d{1,2}):(\\d{1,2}):(\\d{1,2})")).exactMatch(str)) { - QString res = re.cap(1).rightJustified(4, '0') + "-" + re.cap(2).rightJustified(2, '0') - + "-" + re.cap(3).rightJustified(2, '0') - + "T" + re.cap(4).rightJustified(2, '0') + ":" + re.cap(5).rightJustified(2, '0') - + ":" + re.cap(6).rightJustified(2, '0'); + } else if ((match = QRegularExpression("^(\\d{1,4})-(\\d{1,2})-(\\d{1,2})\\s+(\\d{1,2}):(\\d{1,2})$").match(str)).hasMatch() + || (match = QRegularExpression("^(\\d{1,4})-(\\d{1,2})-(\\d{1,2})\\s+(\\d{1,2}):(\\d{1,2}):(\\d{1,2})$").match(str)).hasMatch()) { + QString res = match.captured(1).rightJustified(4, '0') + "-" + match.captured(2).rightJustified(2, '0') + + "-" + match.captured(3).rightJustified(2, '0') + + "T" + match.captured(4).rightJustified(2, '0') + ":" + match.captured(5).rightJustified(2, '0') + + ":" + match.captured(6).rightJustified(2, '0'); // qDebug() << res; valueExpr = KDbConstExpression(KDbToken::DATETIME_CONST, QDateTime::fromString(res, Qt::ISODate)); diff --git a/src/plugins/scripting/kexidb/kexidbschema.cpp b/src/plugins/scripting/kexidb/kexidbschema.cpp --- a/src/plugins/scripting/kexidb/kexidbschema.cpp +++ b/src/plugins/scripting/kexidb/kexidbschema.cpp @@ -20,7 +20,7 @@ #include "kexidbschema.h" #include "kexidbfieldlist.h" -#include +#include #include using namespace Scripting; @@ -133,9 +133,9 @@ ///@todo use KDbParser for such kind of parser-functionality. QString s = whereexpression; - QRegExp re("[\"',]{1,1}"); + QRegularExpression re("[\"',]{1,1}"); while (true) { - s.remove(QRegExp("^[\\s,]+")); + s.remove(QRegularExpression("^[\\s,]+")); int pos = s.indexOf('='); if (pos < 0) break; QString key = s.left(pos).trimmed(); diff --git a/src/tests/altertable/altertable.cpp b/src/tests/altertable/altertable.cpp --- a/src/tests/altertable/altertable.cpp +++ b/src/tests/altertable/altertable.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include @@ -282,7 +282,7 @@ .arg(~result ? "cancelled" : "false")); return false; } - schemaDebugString.remove(QRegExp(",$")); //no need to have "," at the end of lines + schemaDebugString.remove(QRegularExpression(",$")); //no need to have "," at the end of lines return true; } @@ -313,7 +313,7 @@ expectedLine = testFileStream.readLine(); if (skipColonsAndStripWhiteSpace) { expectedLine = expectedLine.stripWhiteSpace(); - expectedLine.remove(QRegExp(",$")); //no need to have "," at the end of lines + expectedLine.remove(QRegularExpression(",$")); //no need to have "," at the end of lines } } if (testFileStreamAtEnd || endCommand == expectedLine.stripWhiteSpace()) { @@ -332,7 +332,7 @@ resultLine = resultStream.readLine(); if (skipColonsAndStripWhiteSpace) { resultLine = resultLine.stripWhiteSpace(); - resultLine.remove(QRegExp(",$")); //no need to have "," at the end of lines + resultLine.remove(QRegularExpressions(",$")); //no need to have "," at the end of lines } if (resultLine != expectedLine) { showError( diff --git a/src/widget/utils/kexidatetimeformatter.cpp b/src/widget/utils/kexidatetimeformatter.cpp --- a/src/widget/utils/kexidatetimeformatter.cpp +++ b/src/widget/utils/kexidatetimeformatter.cpp @@ -23,6 +23,7 @@ #include #include +#include class KexiDateFormatter::Private { @@ -53,10 +54,10 @@ { public: Private() - : hmsRegExp(new QRegExp( - QLatin1String("(\\d*):(\\d*):(\\d*).*( am| pm){,1}"), Qt::CaseInsensitive)) - , hmRegExp(new QRegExp( - QLatin1String("(\\d*):(\\d*).*( am| pm){,1}"), Qt::CaseInsensitive)) + : hmsRegExp(new QRegularExpression( + QLatin1String("(\\d*):(\\d*):(\\d*).*( am| pm){,1}"), QRegularExpression::CaseInsensitiveOption)) + , hmRegExp(new QRegularExpression( + QLatin1String("(\\d*):(\\d*).*( am| pm){,1}"), QRegularExpression::CaseInsensitiveOption)) { } @@ -82,7 +83,7 @@ //! Used in fromString(const QString&) to convert string back to QTime int hourpos, minpos, secpos, ampmpos; - QRegExp *hmsRegExp, *hmRegExp; + QRegularExpression *hmsRegExp, *hmRegExp; }; KexiDateFormatter::KexiDateFormatter() @@ -318,26 +319,28 @@ QTime time; int hour, min, sec; bool pm = false; - + QRegularExpressionMatch matchHms = d->hmsRegExp->match(str); + QRegularExpressionMatch matchHm = d->hmRegExp->match(str); bool tryWithoutSeconds = true; + if (d->secpos >= 0) { - if (-1 != d->hmsRegExp->indexIn(str)) { - hour = d->hmsRegExp->cap(1).toInt(); - min = d->hmsRegExp->cap(2).toInt(); - sec = d->hmsRegExp->cap(3).toInt(); + if (-1 != matchHms.capturedStart()) { + hour = matchHms.captured(1).toInt(); + min = matchHms.captured(2).toInt(); + sec = matchHms.captured(3).toInt(); if (d->ampmpos >= 0 && d->hmsRegExp->captureCount() > 3) - pm = d->hmsRegExp->cap(4).trimmed().toLower() == "pm"; + pm = matchHms.captured(4).trimmed().toLower() == "pm"; tryWithoutSeconds = false; } } if (tryWithoutSeconds) { - if (-1 == d->hmRegExp->indexIn(str)) + if (-1 == matchHm.capturedStart()) return QTime(99, 0, 0); - hour = d->hmRegExp->cap(1).toInt(); - min = d->hmRegExp->cap(2).toInt(); + hour = matchHm.captured(1).toInt(); + min = matchHm.captured(2).toInt(); sec = 0; if (d->ampmpos >= 0 && d->hmRegExp->captureCount() > 2) - pm = d->hmsRegExp->cap(4).toLower() == "pm"; + pm = matchHm.captured(4).toLower() == "pm"; } if (pm && hour < 12)