Skip to content

Commit

Permalink
QRegularExpression porting
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 30, 2021
1 parent 4da1c36 commit 5883b83
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/providers/postgres/raster/qgspostgresrasterprovider.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "qgsgdalutils.h" #include "qgsgdalutils.h"
#include "qgsstringutils.h" #include "qgsstringutils.h"


#include <QRegularExpression>

const QString QgsPostgresRasterProvider::PG_RASTER_PROVIDER_KEY = QStringLiteral( "postgresraster" ); const QString QgsPostgresRasterProvider::PG_RASTER_PROVIDER_KEY = QStringLiteral( "postgresraster" );
const QString QgsPostgresRasterProvider::PG_RASTER_PROVIDER_DESCRIPTION = QStringLiteral( "Postgres raster provider" ); const QString QgsPostgresRasterProvider::PG_RASTER_PROVIDER_DESCRIPTION = QStringLiteral( "Postgres raster provider" );


Expand Down Expand Up @@ -1671,11 +1673,12 @@ bool QgsPostgresRasterProvider::loadFields()
} }
else else
{ {
QRegExp re( "numeric\\((\\d+),(\\d+)\\)" ); QRegularExpression re( QRegularExpression::anchoredPattern( QStringLiteral( "numeric\\((\\d+),(\\d+)\\)" ) ) );
if ( re.exactMatch( formattedFieldType ) ) const QRegularExpressionMatch match = re.match( formattedFieldType );
if ( match.hasMatch() )
{ {
fieldSize = re.cap( 1 ).toInt(); fieldSize = match.captured( 1 ).toInt();
fieldPrec = re.cap( 2 ).toInt(); fieldPrec = match.captured( 2 ).toInt();
} }
else if ( formattedFieldType != QLatin1String( "numeric" ) ) else if ( formattedFieldType != QLatin1String( "numeric" ) )
{ {
Expand All @@ -1692,10 +1695,11 @@ bool QgsPostgresRasterProvider::loadFields()
{ {
fieldType = QVariant::String; fieldType = QVariant::String;


QRegExp re( "character varying\\((\\d+)\\)" ); const QRegularExpression re( QRegularExpression::anchoredPattern( QStringLiteral( "character varying\\((\\d+)\\)" ) ) );
if ( re.exactMatch( formattedFieldType ) ) const QRegularExpressionMatch match = re.match( formattedFieldType );
if ( match.hasMatch() )
{ {
fieldSize = re.cap( 1 ).toInt(); fieldSize = match.captured( 1 ).toInt();
} }
else else
{ {
Expand Down Expand Up @@ -1743,10 +1747,11 @@ bool QgsPostgresRasterProvider::loadFields()


fieldType = QVariant::String; fieldType = QVariant::String;


QRegExp re( "character\\((\\d+)\\)" ); const QRegularExpression re( QRegularExpression::anchoredPattern( QStringLiteral( "character\\((\\d+)\\)" ) ) );
if ( re.exactMatch( formattedFieldType ) ) const QRegularExpressionMatch match = re.match( formattedFieldType );
if ( match.hasMatch() )
{ {
fieldSize = re.cap( 1 ).toInt(); fieldSize = match.captured( 1 ).toInt();
} }
else else
{ {
Expand All @@ -1761,10 +1766,11 @@ bool QgsPostgresRasterProvider::loadFields()
{ {
fieldType = QVariant::String; fieldType = QVariant::String;


QRegExp re( "char\\((\\d+)\\)" ); const QRegularExpression re( QRegularExpression::anchoredPattern( QStringLiteral( "char\\((\\d+)\\)" ) ) );
if ( re.exactMatch( formattedFieldType ) ) const QRegularExpressionMatch match = re.match( formattedFieldType );
if ( match.hasMatch() )
{ {
fieldSize = re.cap( 1 ).toInt(); fieldSize = match.captured( 1 ).toInt();
} }
else else
{ {
Expand Down

0 comments on commit 5883b83

Please sign in to comment.