Skip to content

Commit

Permalink
Merge pull request #44171 from nirvn/providers_regexp_gone
Browse files Browse the repository at this point in the history
Migrate remaining(*) uses of QRegExp in src/providers and tests/
  • Loading branch information
nirvn committed Jul 15, 2021
2 parents 5c35421 + 9d64e14 commit 14c645e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 33 deletions.
7 changes: 3 additions & 4 deletions src/providers/geonode/qgsgeonodesourceselect.cpp
Expand Up @@ -30,6 +30,7 @@
#include <QListWidgetItem>
#include <QMessageBox>
#include <QFileDialog>
#include <QRegularExpression>

enum
{
Expand Down Expand Up @@ -351,10 +352,8 @@ void QgsGeoNodeSourceSelect::loadGeonodeConnection()

void QgsGeoNodeSourceSelect::filterChanged( const QString &text )
{
QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax( QRegExp::RegExp );
Qt::CaseSensitivity myCaseSensitivity = Qt::CaseInsensitive;
QRegExp myRegExp( text, myCaseSensitivity, mySyntax );
mModelProxy->setFilterRegExp( myRegExp );
QRegularExpression regExp( text, QRegularExpression::CaseInsensitiveOption );
mModelProxy->setFilterRegularExpression( regExp );
mModelProxy->sort( mModelProxy->sortColumn(), mModelProxy->sortOrder() );
}

Expand Down
9 changes: 5 additions & 4 deletions src/providers/oracle/ocispatial/qsql_ocispatial.cpp
Expand Up @@ -62,7 +62,7 @@
#include <qvariant.h>
#include <qdatetime.h>
#include <qmetatype.h>
#include <qregexp.h>
#include <qregularexpression.h>
#include <qshareddata.h>
#include <qsqlerror.h>
#include <qsqlfield.h>
Expand Down Expand Up @@ -3903,9 +3903,10 @@ bool QOCISpatialDriver::open( const QString &db,
{
QString versionStr;
versionStr = QString( reinterpret_cast<const QChar *>( vertxt ) );
QRegExp vers( QLatin1String( "([0-9]+)\\.[0-9\\.]+[0-9]" ) );
if ( vers.indexIn( versionStr ) >= 0 )
d->serverVersion = vers.cap( 1 ).toInt();
QRegularExpression vers( QLatin1String( "([0-9]+)\\.[0-9\\.]+[0-9]" ) );
QRegularExpressionMatch match = vers.match( versionStr );
if ( match.hasMatch() )
d->serverVersion = match.captured( 1 ).toInt();
if ( d->serverVersion == 0 )
d->serverVersion = -1;
}
Expand Down
26 changes: 13 additions & 13 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -26,10 +26,6 @@
#include "qgscoordinatereferencesystem.h"
#include "qgsxmlutils.h"
#include "qgsvectorlayer.h"

#include <QMessageBox>
#include <QRegularExpression>

#include "qgsvectorlayerexporter.h"
#include "qgspostgresprovider.h"
#include "qgspostgresconn.h"
Expand All @@ -43,12 +39,15 @@
#include "qgslogger.h"
#include "qgsfeedback.h"
#include "qgssettings.h"
#include "qgsstringutils.h"
#include "qgsjsonutils.h"

#include "qgspostgresprovider.h"
#include "qgsprovidermetadata.h"
#include "qgspostgresproviderconnection.h"

#include <QMessageBox>
#include <QRegularExpression>

const QString QgsPostgresProvider::POSTGRES_KEY = QStringLiteral( "postgres" );
const QString QgsPostgresProvider::POSTGRES_DESCRIPTION = QStringLiteral( "PostgreSQL/PostGIS data provider" );
Expand Down Expand Up @@ -1463,13 +1462,13 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()
// get a new alias for the subquery
int index = 0;
QString alias;
QRegExp regex;
QRegularExpression regex;
do
{
alias = QStringLiteral( "subQuery_%1" ).arg( QString::number( index++ ) );
QString pattern = QStringLiteral( "(\\\"?)%1\\1" ).arg( QRegExp::escape( alias ) );
QString pattern = QStringLiteral( "(\\\"?)%1\\1" ).arg( QgsStringUtils::qRegExpEscape( alias ) );
regex.setPattern( pattern );
regex.setCaseSensitivity( Qt::CaseInsensitive );
regex.setPatternOptions( QRegularExpression::CaseInsensitiveOption );
}
while ( mQuery.contains( regex ) );

Expand Down Expand Up @@ -2057,8 +2056,8 @@ bool QgsPostgresProvider::parseDomainCheckConstraint( QStringList &enumValues, c
//we assume that the constraint is of the following form:
//(VALUE = ANY (ARRAY['a'::text, 'b'::text, 'c'::text, 'd'::text]))
//normally, PostgreSQL creates that if the constraint has been specified as 'VALUE in ('a', 'b', 'c', 'd')

int anyPos = checkDefinition.indexOf( QRegExp( "VALUE\\s*=\\s*ANY\\s*\\(\\s*ARRAY\\s*\\[" ) );
const thread_local QRegularExpression definitionRegExp( "VALUE\\s*=\\s*ANY\\s*\\(\\s*ARRAY\\s*\\[" );
int anyPos = checkDefinition.indexOf( definitionRegExp );
int arrayPosition = checkDefinition.lastIndexOf( QLatin1String( "ARRAY[" ) );
int closingBracketPos = checkDefinition.indexOf( ']', arrayPosition + 6 );

Expand Down Expand Up @@ -4758,21 +4757,22 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS
jumpSpace( txt, i );
if ( i < txt.length() && txt.at( i ) == '"' )
{
QRegExp stringRe( "^\"((?:\\\\.|[^\"\\\\])*)\".*" );
if ( !stringRe.exactMatch( txt.mid( i ) ) )
const thread_local QRegularExpression stringRe( QRegularExpression::anchoredPattern( "^\"((?:\\\\.|[^\"\\\\])*)\".*" ) );
const QRegularExpressionMatch match = stringRe.match( txt.mid( i ) );
if ( !match.hasMatch() )
{
QgsMessageLog::logMessage( tr( "Cannot find end of double quoted string: %1" ).arg( txt ), tr( "PostGIS" ) );
return QString();
}
i += stringRe.cap( 1 ).length() + 2;
i += match.captured( 1 ).length() + 2;
jumpSpace( txt, i );
if ( !QStringView{txt}.mid( i ).startsWith( sep ) && i < txt.length() )
{
QgsMessageLog::logMessage( tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), tr( "PostGIS" ) );
return QString();
}
i += sep.length();
return stringRe.cap( 1 ).replace( QLatin1String( "\\\"" ), QLatin1String( "\"" ) ).replace( QLatin1String( "\\\\" ), QLatin1String( "\\" ) );
return match.captured( 1 ).replace( QLatin1String( "\\\"" ), QLatin1String( "\"" ) ).replace( QLatin1String( "\\\\" ), QLatin1String( "\\" ) );
}
else
{
Expand Down
7 changes: 3 additions & 4 deletions src/providers/wfs/qgswfssourceselect.cpp
Expand Up @@ -42,6 +42,7 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QPainter>
#include <QRegularExpression>

enum
{
Expand Down Expand Up @@ -751,10 +752,8 @@ void QgsWFSSourceSelect::buildQueryButtonClicked()
void QgsWFSSourceSelect::filterChanged( const QString &text )
{
QgsDebugMsgLevel( "WFS FeatureType filter changed to :" + text, 2 );
QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax( QRegExp::RegExp );
Qt::CaseSensitivity myCaseSensitivity = Qt::CaseInsensitive;
QRegExp myRegExp( text, myCaseSensitivity, mySyntax );
mModelProxy->setFilterRegExp( myRegExp );
QRegularExpression regExp( text, QRegularExpression::CaseInsensitiveOption );
mModelProxy->setFilterRegularExpression( regExp );
mModelProxy->sort( mModelProxy->sortColumn(), mModelProxy->sortOrder() );
}

Expand Down
3 changes: 2 additions & 1 deletion tests/qt_modeltest/tst_modeltest.cpp
Expand Up @@ -52,6 +52,7 @@
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QStandardItemModel>
#include <QRegularExpression>

#include "modeltest.h"
#include "dynamictreemodel.h"
Expand Down Expand Up @@ -116,7 +117,7 @@ void tst_ModelTest::stringListModel()
model.setStringList( QStringList() << "a" << "e" << "plop" << "b" << "c" );

proxy.setDynamicSortFilter( true );
proxy.setFilterRegExp( QRegExp( "[^b]" ) );
proxy.setFilterRegularExpression( QRegularExpression( "[^b]" ) );
}

void tst_ModelTest::treeWidgetModel()
Expand Down
7 changes: 4 additions & 3 deletions tests/src/app/testqgisappclipboard.cpp
Expand Up @@ -19,6 +19,7 @@
#include <QSplashScreen>
#include <QString>
#include <QStringList>
#include <QRegularExpression>

#include "qgisapp.h"
#include "qgsapplication.h"
Expand Down Expand Up @@ -179,9 +180,9 @@ void TestQgisAppClipboard::copyToText()

// just test coordinates as integers - that's enough to verify that reprojection has occurred
// and helps avoid rounding issues
QRegExp regex( "\\[([-\\d.]+),([-\\d.]+)\\]" );
( void )regex.indexIn( result );
QStringList list = regex.capturedTexts();
QRegularExpression regex( "\\[([-\\d.]+),([-\\d.]+)\\]" );
QRegularExpressionMatch match = regex.match( result );
QStringList list = match.capturedTexts();
QCOMPARE( list.count(), 3 );

int x = std::round( list.at( 1 ).toDouble() );
Expand Down
6 changes: 4 additions & 2 deletions tests/src/core/testqgsogcutils.cpp
Expand Up @@ -23,6 +23,8 @@
#include "qgsapplication.h"
#include "qgsvectorlayer.h"

#include <QRegularExpression>

/**
* \ingroup UnitTests
* This is a unit test for OGC utilities
Expand Down Expand Up @@ -103,9 +105,9 @@ void TestQgsOgcUtils::testGeometryFromGML()
static bool compareElements( QDomElement &element1, QDomElement &element2 )
{
QString tag1 = element1.tagName();
tag1.replace( QRegExp( ".*:" ), QString() );
tag1.replace( QRegularExpression( ".*:" ), QString() );
QString tag2 = element2.tagName();
tag2.replace( QRegExp( ".*:" ), QString() );
tag2.replace( QRegularExpression( ".*:" ), QString() );
if ( tag1 != tag2 )
{
qDebug( "Different tag names: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
Expand Down
5 changes: 3 additions & 2 deletions tests/src/providers/testqgswcspublicservers.cpp
Expand Up @@ -21,6 +21,7 @@
#include <QString>
#include <QStringList>
#include <QTextStream>
#include <QRegularExpression>

#include "qgsapplication.h"
#include "qgsdatasourceuri.h"
Expand Down Expand Up @@ -272,8 +273,8 @@ void TestQgsWcsPublicServers::test()
QStringList myServerLog;
myServerLog << "server:" + serverUrl;
QString myServerDirName = serverUrl;
myServerDirName.replace( QRegExp( "[:/]+" ), QStringLiteral( "." ) );
myServerDirName.remove( QRegExp( "\\.$" ) );
myServerDirName.replace( QRegularExpression( "[:/]+" ), QStringLiteral( "." ) );
myServerDirName.remove( QRegularExpression( "\\.$" ) );
QgsDebugMsg( "myServerDirName = " + myServerDirName );

QDir myServerDir( mCacheDir.absolutePath() + '/' + myServerDirName );
Expand Down

0 comments on commit 14c645e

Please sign in to comment.