Skip to content
Permalink
Browse files

QRegularExpression only offers exactMatch starting from 5.15

  • Loading branch information
m-kuhn committed Dec 24, 2020
1 parent b666edd commit cf7ee1a1e42a136c75eca239195aeb0096b63182
Showing with 19 additions and 25 deletions.
  1. +5 −7 src/core/expression/qgsexpressionnodeimpl.cpp
  2. +14 −18 src/core/qgscoordinatereferencesystem.cpp
@@ -532,7 +532,7 @@ QVariant QgsExpressionNodeBinaryOperator::evalNode( QgsExpression *parent, const
bool matches;
if ( mOp == boLike || mOp == boILike || mOp == boNotLike || mOp == boNotILike ) // change from LIKE syntax to regexp
{
QString esc_regexp = QRegularExpression::escape( regexp );
QString esc_regexp = QRegExp::escape( regexp );
// manage escape % and _
if ( esc_regexp.startsWith( '%' ) )
{
@@ -559,10 +559,8 @@ QVariant QgsExpressionNodeBinaryOperator::evalNode( QgsExpression *parent, const
pos += 1;
}
esc_regexp.replace( QStringLiteral( "\\\\_" ), QStringLiteral( "_" ) );
QRegularExpression::PatternOption option;
if ( mOp == boILike || mOp == boNotILike )
option = QRegularExpression::CaseInsensitiveOption;
matches = QRegularExpression( esc_regexp, option ).match( str ).hasMatch();

matches = QRegExp( esc_regexp, mOp == boLike || mOp == boNotLike ? Qt::CaseSensitive : Qt::CaseInsensitive ).exactMatch( str );
}
else
{
@@ -1365,8 +1363,8 @@ bool QgsExpressionNodeColumnRef::prepareNode( QgsExpression *parent, const QgsEx

QString QgsExpressionNodeColumnRef::dump() const
{
const thread_local QRegularExpression re( QStringLiteral( "^[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*$" ) );
return re.match( mName ).hasMatch() ? mName : QgsExpression::quotedColumnRef( mName );
const thread_local QRegExp re( QStringLiteral( "^[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*$" ) );
return re.exactMatch( mName ) ? mName : QgsExpression::quotedColumnRef( mName );
}

QSet<QString> QgsExpressionNodeColumnRef::referencedColumns() const
@@ -405,29 +405,25 @@ bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( const QString &crs )

QString wmsCrs = crs;

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

0 comments on commit cf7ee1a

Please sign in to comment.
You can’t perform that action at this time.