Skip to content

Commit 2e6386e

Browse files
committed
Use more performant QRegularExpression for matching
1 parent 8cb4893 commit 2e6386e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/core/qgscoordinatereferencesystem.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <QRegExp>
2929
#include <QTextStream>
3030
#include <QFile>
31+
#include <QRegularExpression>
3132

3233
#include "qgsapplication.h"
3334
#include "qgslogger.h"
@@ -220,26 +221,28 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString &definition )
220221
sCrsStringLock.unlock();
221222

222223
bool result = false;
223-
QRegExp reCrsId( "^(epsg|postgis|internal|user)\\:(\\d+)$", Qt::CaseInsensitive );
224-
if ( reCrsId.indexIn( definition ) == 0 )
224+
QRegularExpression reCrsId( "^(epsg|postgis|internal|user)\\:(\\d+)$", QRegularExpression::CaseInsensitiveOption );
225+
QRegularExpressionMatch match = reCrsId.match( definition );
226+
if ( match.capturedStart() == 0 )
225227
{
226-
QString authName = reCrsId.cap( 1 ).toLower();
228+
QString authName = match.captured( 1 ).toLower();
227229
CrsType type = InternalCrsId;
228230
if ( authName == QLatin1String( "epsg" ) )
229231
type = EpsgCrsId;
230232
if ( authName == QLatin1String( "postgis" ) )
231233
type = PostgisCrsId;
232-
long id = reCrsId.cap( 2 ).toLong();
234+
long id = match.captured( 2 ).toLong();
233235
result = createFromId( id, type );
234236
}
235237
else
236238
{
237-
QRegExp reCrsStr( "^(?:(wkt|proj4)\\:)?(.+)$", Qt::CaseInsensitive );
238-
if ( reCrsStr.indexIn( definition ) == 0 )
239+
QRegularExpression reCrsStr( "^(?:(wkt|proj4)\\:)?(.+)$", QRegularExpression::CaseInsensitiveOption );
240+
match = reCrsStr.match( definition );
241+
if ( match.capturedStart() == 0 )
239242
{
240-
if ( reCrsStr.cap( 1 ).toLower() == QLatin1String( "proj4" ) )
243+
if ( match.captured( 1 ).toLower() == QLatin1String( "proj4" ) )
241244
{
242-
result = createFromProj4( reCrsStr.cap( 2 ) );
245+
result = createFromProj4( match.captured( 2 ) );
243246
//TODO: createFromProj4 used to save to the user database any new CRS
244247
// this behavior was changed in order to separate creation and saving.
245248
// Not sure if it necessary to save it here, should be checked by someone
@@ -254,7 +257,7 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString &definition )
254257
}
255258
else
256259
{
257-
result = createFromWkt( reCrsStr.cap( 2 ) );
260+
result = createFromWkt( match.captured( 2 ) );
258261
}
259262
}
260263
}

0 commit comments

Comments
 (0)