Skip to content
Permalink
Browse files
Migrate remaining(*) uses of QRegExp in src/providers
(*) the stagnant GRASS provider hasn't been ported, no
interest on my side
  • Loading branch information
nirvn committed Jul 15, 2021
1 parent 3a07af0 commit adb53624631049b656b1c6c77d54e79aa494a8cd
@@ -30,6 +30,7 @@
#include <QListWidgetItem>
#include <QMessageBox>
#include <QFileDialog>
#include <QRegularExpression>

enum
{
@@ -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() );
}

@@ -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>
@@ -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;
}
@@ -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"
@@ -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" );
@@ -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 ) );

@@ -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 );

@@ -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
{
@@ -42,6 +42,7 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QPainter>
#include <QRegularExpression>

enum
{
@@ -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() );
}

0 comments on commit adb5362

Please sign in to comment.