Skip to content
Permalink
Browse files
Migrate remaining uses of QRegExp in src/core
  • Loading branch information
nirvn authored and nyalldawson committed Jul 16, 2021
1 parent eaa3e52 commit 2006c975f4a6ca87576abaeb76c837ed9493f1d0
@@ -10,6 +10,7 @@




class QgsRenderChecker
{
%Docstring(signature="appended")
@@ -212,7 +212,7 @@ may span multiple records. The default type is csv.
escape themselves within quotes. Elsewhere they are treated as
quote characters. The defaults for delimiter, quote, and escape
are ',', '"', '"'.
- "regexp" splits each record using a regular expression (see QRegExp
- "regexp" splits each record using a regular expression (see QRegularExpression
documentation for details).
- "whitespace" splits each record based on whitespace (on or more whitespace
characters. Leading whitespace in the record is ignored.
@@ -18,6 +18,8 @@
#include "qgslayeritem.h"
#include "qgsdatacollectionitem.h"

#include <QRegularExpression>

QgsBrowserProxyModel::QgsBrowserProxyModel( QObject *parent )
: QSortFilterProxyModel( parent )
{
@@ -86,9 +88,8 @@ void QgsBrowserProxyModel::updateFilter()
const QStringList filterParts = mFilter.split( '|' );
for ( const QString &f : filterParts )
{
QRegExp rx( QStringLiteral( "*%1*" ).arg( f.trimmed() ) );
rx.setPatternSyntax( QRegExp::Wildcard );
rx.setCaseSensitivity( mCaseSensitivity );
QRegularExpression rx( QRegularExpression::wildcardToRegularExpression( QStringLiteral( "*%1*" ).arg( f.trimmed() ) ) );
rx.setPatternOptions( mCaseSensitivity == Qt::CaseInsensitive ? QRegularExpression::CaseInsensitiveOption : QRegularExpression::NoPatternOption );
mREList.append( rx );
}
break;
@@ -98,18 +99,16 @@ void QgsBrowserProxyModel::updateFilter()
const QStringList filterParts = mFilter.split( '|' );
for ( const QString &f : filterParts )
{
QRegExp rx( f.trimmed() );
rx.setPatternSyntax( QRegExp::Wildcard );
rx.setCaseSensitivity( mCaseSensitivity );
QRegularExpression rx( QRegularExpression::wildcardToRegularExpression( f.trimmed() ) );
rx.setPatternOptions( mCaseSensitivity == Qt::CaseInsensitive ? QRegularExpression::CaseInsensitiveOption : QRegularExpression::NoPatternOption );
mREList.append( rx );
}
break;
}
case RegularExpression:
{
QRegExp rx( mFilter.trimmed() );
rx.setPatternSyntax( QRegExp::RegExp );
rx.setCaseSensitivity( mCaseSensitivity );
QRegularExpression rx( mFilter.trimmed() );
rx.setPatternOptions( mCaseSensitivity == Qt::CaseInsensitive ? QRegularExpression::CaseInsensitiveOption : QRegularExpression::NoPatternOption );
mREList.append( rx );
break;
}
@@ -124,19 +123,19 @@ bool QgsBrowserProxyModel::filterAcceptsString( const QString &value ) const
case Normal:
case Wildcards:
{
for ( const QRegExp &rx : mREList )
for ( const QRegularExpression &rx : mREList )
{
if ( rx.exactMatch( value ) )
if ( rx.match( value ).hasMatch() )
return true;
}
break;
}

case RegularExpression:
{
for ( const QRegExp &rx : mREList )
for ( const QRegularExpression &rx : mREList )
{
if ( rx.indexIn( value ) != -1 )
if ( rx.match( value ).hasMatch() )
return true;
}
break;
@@ -209,7 +209,7 @@ class CORE_EXPORT QgsBrowserProxyModel : public QSortFilterProxyModel
QStringList mHiddenDataItemsKeys;
QStringList mShownDataItemsKeys;
QString mFilter; //filter string provided
QVector<QRegExp> mREList; //list of filters, separated by "|"
QVector<QRegularExpression> mREList; //list of filters, separated by "|"
FilterSyntax mPatternSyntax = Normal;
Qt::CaseSensitivity mCaseSensitivity = Qt::CaseInsensitive;

@@ -15,6 +15,21 @@
* *
***************************************************************************/

#include "qgis.h"
#include "qgsdataitem.h"
#include "qgsapplication.h"
#include "qgsdataitemprovider.h"
#include "qgsdataitemproviderregistry.h"
#include "qgsdataprovider.h"
#include "qgslogger.h"
#include "qgsproviderregistry.h"
#include "qgsconfig.h"
#include "qgssettings.h"
#include "qgsanimatedicon.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsprovidermetadata.h"

#include <QApplication>
#include <QtConcurrentMap>
#include <QtConcurrentRun>
@@ -32,21 +47,6 @@
#include <mutex>
#include <QRegularExpression>

#include "qgis.h"
#include "qgsdataitem.h"
#include "qgsapplication.h"
#include "qgsdataitemprovider.h"
#include "qgsdataitemproviderregistry.h"
#include "qgsdataprovider.h"
#include "qgslogger.h"
#include "qgsproviderregistry.h"
#include "qgsconfig.h"
#include "qgssettings.h"
#include "qgsanimatedicon.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsprovidermetadata.h"

// use GDAL VSI mechanism
#define CPL_SUPRESS_CPLUSPLUS //#spellok
#include "cpl_vsi.h"
@@ -89,7 +89,7 @@ QgsDataItem::~QgsDataItem()

QString QgsDataItem::pathComponent( const QString &string )
{
return QString( string ).replace( QRegExp( "[\\\\/]" ), QStringLiteral( "|" ) );
return QString( string ).replace( QRegularExpression( "[\\\\/]" ), QStringLiteral( "|" ) );
}

QVariant QgsDataItem::sortKey() const
@@ -21,7 +21,7 @@

#include <QNetworkReply>
#include <QObject>
#include <QRegExp>
#include <QRegularExpression>
#include <QString>
#include <QStringList>

@@ -51,15 +51,15 @@ QgsNetworkReplyParser::QgsNetworkReplyParser( QNetworkReply *reply )
QString contentType = mReply->header( QNetworkRequest::ContentTypeHeader ).toString();
QgsDebugMsg( "contentType: " + contentType );

QRegExp re( ".*boundary=\"?([^\"]+)\"?\\s?", Qt::CaseInsensitive );

if ( !( re.indexIn( contentType ) == 0 ) )
const QRegularExpression re( ".*boundary=\"?([^\"]+)\"?\\s?", QRegularExpression::CaseInsensitiveOption );
const QRegularExpressionMatch match = re.match( contentType );
if ( !( match.capturedStart( 0 ) == 0 ) )
{
mError = tr( "Cannot find boundary in multipart content type" );
return;
}

QString boundary = re.cap( 1 );
QString boundary = match.captured( 1 );
QgsDebugMsg( QStringLiteral( "boundary = %1 size = %2" ).arg( boundary ).arg( boundary.size() ) );
boundary = "--" + boundary;

@@ -118,7 +118,7 @@ QgsNetworkReplyParser::QgsNetworkReplyParser( QNetworkReply *reply )
QByteArray headers = part.left( pos );
QgsDebugMsg( "headers:\n" + headers );

QStringList headerRows = QString( headers ).split( QRegExp( "[\n\r]+" ) );
QStringList headerRows = QString( headers ).split( QRegularExpression( "[\n\r]+" ) );
const auto constHeaderRows = headerRows;
for ( const QString &row : constHeaderRows )
{
@@ -28,10 +28,9 @@
#include <QDomNode>
#include <QDomElement>
#include <QFileInfo>
#include <QRegExp>
#include <QRegularExpression>
#include <QTextStream>
#include <QFile>
#include <QRegularExpression>

#include "qgsapplication.h"
#include "qgslogger.h"
@@ -393,25 +392,31 @@ bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( const QString &crs )

QString wmsCrs = crs;

thread_local const QRegExp re_uri( QStringLiteral( "http://www\\.opengis\\.net/def/crs/([^/]+).+/([^/]+)" ), Qt::CaseInsensitive );
thread_local const QRegExp re_urn( QStringLiteral( "urn:ogc:def:crs:([^:]+).+([^:]+)" ), Qt::CaseInsensitive );
if ( re_uri.exactMatch( wmsCrs ) )
{
wmsCrs = re_uri.cap( 1 ) + ':' + re_uri.cap( 2 );
}
else if ( re_urn.exactMatch( wmsCrs ) )
thread_local const QRegularExpression re_uri( QRegularExpression::anchoredPattern( QStringLiteral( "http://www\\.opengis\\.net/def/crs/([^/]+).+/([^/]+)" ) ), QRegularExpression::CaseInsensitiveOption );
QRegularExpressionMatch match = re_uri.match( wmsCrs );
if ( match.hasMatch() )
{
wmsCrs = re_urn.cap( 1 ) + ':' + re_urn.cap( 2 );
wmsCrs = match.captured( 1 ) + ':' + match.captured( 2 );
}
else
{
thread_local const QRegExp re_urn_custom( QStringLiteral( "(user|custom|qgis):(\\d+)" ), Qt::CaseInsensitive );
if ( re_urn_custom.exactMatch( wmsCrs ) && createFromSrsId( re_urn_custom.cap( 2 ).toInt() ) )
thread_local const QRegularExpression re_urn( QRegularExpression::anchoredPattern( QStringLiteral( "urn:ogc:def:crs:([^:]+).+([^:]+)" ) ), QRegularExpression::CaseInsensitiveOption );
match = re_urn.match( wmsCrs );
if ( match.hasMatch() )
{
locker.changeMode( QgsReadWriteLocker::Write );
if ( !sDisableOgcCache )
sOgcCache()->insert( crs, *this );
return d->mIsValid;
wmsCrs = match.captured( 1 ) + ':' + match.captured( 2 );
}
else
{
thread_local const QRegularExpression re_urn_custom( QRegularExpression::anchoredPattern( QStringLiteral( "(user|custom|qgis):(\\d+)" ) ), QRegularExpression::CaseInsensitiveOption );
match = re_urn_custom.match( wmsCrs );
if ( match.hasMatch() && createFromSrsId( match.captured( 2 ).toInt() ) )
{
locker.changeMode( QgsReadWriteLocker::Write );
if ( !sDisableOgcCache )
sOgcCache()->insert( crs, *this );
return d->mIsValid;
}
}
}

@@ -23,19 +23,21 @@
#include "qgsreadwritecontext.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include <QTextStream>
#include <QDomDocument>
#ifndef QT_NO_PRINTER
#include <QPrinter> //to find out screen resolution
#endif
#include <cstdlib>
#include "qgspathresolver.h"
#include "qgsproject.h"
#include "qgsprojectproperty.h"
#include "qgsrasterbandstats.h"
#include "qgsrasterdataprovider.h"
#include "qgsxmlutils.h"

#include <QTextStream>
#include <QDomDocument>
#include <QRegularExpression>
#ifndef QT_NO_PRINTER
#include <QPrinter> //to find out screen resolution
#endif
#include <cstdlib>

typedef QgsProjectVersion PFV;

// Transformer functions below. Declare functions here,
@@ -1120,11 +1122,11 @@ int rasterBandNumber( const QDomElement &rasterPropertiesElem, const QString &ba
QDomElement rasterBandElem = rasterPropertiesElem.firstChildElement( bandName );
if ( !rasterBandElem.isNull() )
{
QRegExp re( "(\\d+)" );

if ( re.indexIn( rasterBandElem.text() ) >= 0 )
const thread_local QRegularExpression re( "(\\d+)" );
const QRegularExpressionMatch match = re.match( rasterBandElem.text() );
if ( match.hasMatch() )
{
return re.cap( 1 ).toInt();
return match.captured( 1 ).toInt();
}
}
return band;
@@ -1252,7 +1252,6 @@ QString QgsGdalProvider::generateBandName( int bandNumber ) const
if ( values.at( 0 ) == QLatin1String( "NETCDF_DIM_EXTRA" ) || values.at( 0 ) == QLatin1String( "GTIFF_DIM_EXTRA" ) )
{
dimExtraValues = val.replace( '{', QString() ).replace( '}', QString() ).split( ',' );
//http://qt-project.org/doc/qt-4.8/qregexp.html#capturedTexts
}
else
{
@@ -16,23 +16,6 @@
***************************************************************************/


#include <QDir>
#include <QDomDocument>
#include <QDomElement>
#include <QDomImplementation>
#include <QDomNode>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
#include <QUrl>
#include <QTimer>
#include <QStandardPaths>
#include <QUuid>

#include <sqlite3.h>

#include "qgssqliteutils.h"

#include "qgssqliteutils.h"
#include "qgs3drendererregistry.h"
#include "qgsabstract3drenderer.h"
@@ -64,6 +47,22 @@
#include "qgsdatums.h"
#include "qgsprojoperation.h"

#include <QDir>
#include <QDomDocument>
#include <QDomElement>
#include <QDomImplementation>
#include <QDomNode>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
#include <QUrl>
#include <QTimer>
#include <QStandardPaths>
#include <QUuid>
#include <QRegularExpression>

#include <sqlite3.h>

QString QgsMapLayer::extensionPropertyType( QgsMapLayer::PropertyType type )
{
switch ( type )
@@ -259,8 +258,8 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteCon
mDataSource = context.pathResolver().readPath( mne.text() );

// if the layer needs authentication, ensure the master password is set
QRegExp rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
if ( ( rx.indexIn( mDataSource ) != -1 )
const thread_local QRegularExpression rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
if ( rx.match( mDataSource ).hasMatch()
&& !QgsApplication::authManager()->setMasterPassword( true ) )
{
return false;
@@ -2067,7 +2066,7 @@ QString QgsMapLayer::generateId( const QString &layerName )
// underscore) with an underscore.
// Note that the first backslash in the regular expression is
// there for the compiler, so the pattern is actually \W
id.replace( QRegExp( "[\\W]" ), QStringLiteral( "_" ) );
id.replace( QRegularExpression( "[\\W]" ), QStringLiteral( "_" ) );
return id;
}

@@ -365,7 +365,7 @@ void QgsOfflineEditing::synchronize()

// disable offline project
QString projectTitle = QgsProject::instance()->title();
projectTitle.remove( QRegExp( " \\(offline\\)$" ) );
projectTitle.remove( QRegularExpression( " \\(offline\\)$" ) );
QgsProject::instance()->setTitle( projectTitle );
QgsProject::instance()->removeEntry( PROJECT_ENTRY_SCOPE_OFFLINE, PROJECT_ENTRY_KEY_OFFLINE_DB_PATH );
remoteLayer->reload(); //update with other changes

0 comments on commit 2006c97

Please sign in to comment.