Skip to content
Permalink
Browse files
[qt6] Random small QRegExp migration
  • Loading branch information
nirvn committed Jul 13, 2021
1 parent 666b229 commit 5df7d305cb2a3fa36bcbb03788f8cf165ddeac1d
@@ -24,6 +24,7 @@
#include "qgssettings.h"

#include <QDir>
#include <QRegularExpression>
#include <QTextStream>

bool QgsColorScheme::setColors( const QgsNamedColorList &colors, const QString &context, const QColor &baseColor )
@@ -305,10 +306,11 @@ QgsUserColorScheme::QgsUserColorScheme( const QString &filename )
}
if ( !in.atEnd() )
{
QRegExp rx( "Name:\\s*(\\S.*)$" );
if ( rx.indexIn( line ) != -1 )
const QRegularExpression rx( "Name:\\s*(\\S.*)$" );
const QRegularExpressionMatch match = rx.match( line );
if ( match.hasMatch() )
{
mName = rx.cap( 1 );
mName = match.captured( 1 );
}
}
}
@@ -23,7 +23,7 @@
#include "qgsapplication.h"

#include <QStringList>
#include <QRegExp>
#include <QRegularExpression>
#include <QUrl>
#include <QUrlQuery>

@@ -219,8 +219,8 @@ QgsDataSourceUri::QgsDataSourceUri( const QString &u )

QString QgsDataSourceUri::removePassword( const QString &aUri )
{
QRegExp regexp;
regexp.setMinimal( true );
QRegularExpression regexp;
regexp.setPatternOptions( QRegularExpression::InvertedGreedinessOption );
QString safeName( aUri );
if ( aUri.contains( QLatin1String( " password=" ) ) )
{
@@ -20,7 +20,7 @@
#include "qgserror.h"
#include "qgslogger.h"

#include <QRegExp>
#include <QRegularExpression>

QgsErrorMessage::QgsErrorMessage( const QString &message, const QString &tag, const QString &file, const QString &function, int line )
: mMessage( message )
@@ -61,7 +61,7 @@ QString QgsError::message( QgsErrorMessage::Format format ) const
QString remote = QStringLiteral( QGS_GIT_REMOTE_URL );
if ( !hash.isEmpty() && !remote.isEmpty() && remote.contains( QLatin1String( "github.com" ) ) )
{
QString path = remote.remove( QRegExp( ".*github.com[:/]" ) ).remove( QStringLiteral( ".git" ) );
QString path = remote.remove( QRegularExpression( ".*github.com[:/]" ) ).remove( QStringLiteral( ".git" ) );
srcUrl = "https://github.com/" + path + "/blob/" + hash;
}
#endif
@@ -14,12 +14,14 @@
***************************************************************************/

#include "qgsinterval.h"

#include <QString>
#include <QStringList>
#include <QMap>
#include <QObject>
#include <QDebug>
#include <QDateTime>
#include <QRegularExpression>

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
@@ -209,14 +211,15 @@ void QgsInterval::setSeconds( double seconds )
QgsInterval QgsInterval::fromString( const QString &string )
{
double seconds = 0;
QRegExp rx( "([-+]?\\d*\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
const thread_local QRegularExpression rx( "([-+]?\\d*\\.?\\d+\\s+\\S+)", QRegularExpression::CaseInsensitiveOption );
QStringList list;
int pos = 0;

while ( ( pos = rx.indexIn( string, pos ) ) != -1 )
QRegularExpressionMatch match = rx.match( string );
while ( match.hasMatch() )
{
list << rx.cap( 1 );
pos += rx.matchedLength();
list << match.captured( 1 );
pos = match.capturedStart() + match.capturedLength();
match = rx.match( string, pos );
}

QMap<int, QStringList> map;
@@ -231,7 +234,8 @@ QgsInterval QgsInterval::fromString( const QString &string )
const auto constList = list;
for ( const QString &match : constList )
{
QStringList split = match.split( QRegExp( "\\s+" ) );
const thread_local QRegularExpression splitRx( "\\s+" );
QStringList split = match.split( splitRx );
bool ok;
double value = split.at( 0 ).toDouble( &ok );
if ( !ok )
@@ -17,7 +17,7 @@
#include "qgslogger.h"
#include "qgsmessagelog.h"

#include <QRegExp>
#include <QRegularExpression>

static QgsMessageOutput *messageOutputConsole_()
{
@@ -66,7 +66,7 @@ void QgsMessageOutputConsole::showMessage( bool )
{
mMessage.replace( QLatin1String( "<br>" ), QLatin1String( "\n" ) );
mMessage.replace( QLatin1String( "&nbsp;" ), QLatin1String( " " ) );
mMessage.replace( QRegExp( "</?[^>]+>" ), QString() );
mMessage.replace( QRegularExpression( "</?[^>]+>" ), QString() );
}
QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
emit destroyed();
@@ -17,6 +17,8 @@
#include "qgssqlstatement.h"
#include "qgis.h"

#include <QRegularExpression>

#include <cmath>
#include <limits>

@@ -89,8 +91,8 @@ QString QgsSQLStatement::quotedIdentifierIfNeeded( const QString &name )
return quotedIdentifier( name );
}
}
static const QRegExp IDENTIFIER_RE( "^[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*$" );
return IDENTIFIER_RE.exactMatch( name ) ? name : quotedIdentifier( name );
static const QRegularExpression IDENTIFIER_RE( "^[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*$" );
return IDENTIFIER_RE.match( name ).hasMatch() ? name : quotedIdentifier( name );
}

QString QgsSQLStatement::stripQuotedIdentifier( QString text )

0 comments on commit 5df7d30

Please sign in to comment.