Skip to content

Commit

Permalink
Merge pull request #44140 from nirvn/regexp_more_more_more
Browse files Browse the repository at this point in the history
[qt6] Easy src/core QRegExp migrations
  • Loading branch information
nirvn committed Jul 13, 2021
2 parents 6db6de3 + 60f947d commit 5762fe3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 26 deletions.
16 changes: 8 additions & 8 deletions src/core/geometry/qgsrectangle.cpp
Expand Up @@ -15,14 +15,6 @@
* *
***************************************************************************/

#include <algorithm>
#include <cmath>
#include <limits>
#include <QString>
#include <QTextStream>
#include <QTransform>
#include <QRegExp>

#include "qgsgeometry.h"
#include "qgspointxy.h"
#include "qgsrectangle.h"
Expand All @@ -31,6 +23,14 @@
#include "qgspolygon.h"
#include "qgslinestring.h"

#include <QString>
#include <QTextStream>
#include <QTransform>

#include <algorithm>
#include <cmath>
#include <limits>

QgsRectangle QgsRectangle::fromWkt( const QString &wkt )
{
QgsGeometry geom = QgsGeometry::fromWkt( wkt );
Expand Down
8 changes: 5 additions & 3 deletions src/core/qgscolorscheme.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsdatasourceuri.cpp
Expand Up @@ -23,7 +23,7 @@
#include "qgsapplication.h"

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

Expand Down Expand Up @@ -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=" ) ) )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgserror.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/core/qgsinterval.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsmessageoutput.cpp
Expand Up @@ -17,7 +17,7 @@
#include "qgslogger.h"
#include "qgsmessagelog.h"

#include <QRegExp>
#include <QRegularExpression>

static QgsMessageOutput *messageOutputConsole_()
{
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgssqlstatement.cpp
Expand Up @@ -17,6 +17,8 @@
#include "qgssqlstatement.h"
#include "qgis.h"

#include <QRegularExpression>

#include <cmath>
#include <limits>

Expand Down Expand Up @@ -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 );
const thread_local 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 )
Expand Down

0 comments on commit 5762fe3

Please sign in to comment.