Skip to content

Commit

Permalink
Switch QString ref functions to QStringView
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and nyalldawson committed Mar 26, 2021
1 parent 08c1275 commit ce2bce5
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/app/main.cpp
Expand Up @@ -1434,7 +1434,11 @@ int main( int argc, char *argv[] )
break;
}

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok );
#else
coords[i] = QStringView {myInitialExtent}.mid( posOld, pos - posOld ).toDouble( &ok );
#endif
if ( !ok )
break;

Expand All @@ -1443,7 +1447,13 @@ int main( int argc, char *argv[] )

// parse last coordinate
if ( ok )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );
#else
coords[3] = QStringView {myInitialExtent}.mid( posOld ).toDouble( &ok );
#endif
}

if ( !ok )
{
Expand Down
12 changes: 12 additions & 0 deletions src/core/expression/qgsexpression.cpp
Expand Up @@ -452,7 +452,11 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
if ( exp.hasParserError() )
{
QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
expr_action += action.midRef( start, index - start );
#else
expr_action += QStringView {action}.mid( start, index - start );
#endif
continue;
}

Expand All @@ -467,15 +471,23 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
if ( exp.hasEvalError() )
{
QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
expr_action += action.midRef( start, index - start );
#else
expr_action += QStringView {action}.mid( start, index - start );
#endif
continue;
}

QgsDebugMsgLevel( "Expression result is: " + result.toString(), 3 );
expr_action += action.mid( start, pos - start ) + result.toString();
}

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
expr_action += action.midRef( index );
#else
expr_action += QStringView {action}.mid( index ).toString();
#endif

return expr_action;
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgscolorramp.cpp
Expand Up @@ -75,7 +75,11 @@ QgsColorRamp *QgsGradientColorRamp::create( const QVariantMap &props )
continue;

QColor c = QgsSymbolLayerUtils::decodeColor( stop.mid( i + 1 ) );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
stops.append( QgsGradientStop( stop.leftRef( i ).toDouble(), c ) );
#else
stops.append( QgsGradientStop( QStringView {stop}.left( i ).toDouble(), c ) );
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgshstoreutils.cpp
Expand Up @@ -42,7 +42,7 @@ QVariantMap QgsHstoreUtils::parse( const QString &string )
while ( i < string.length() && string.at( i ).isSpace() )
++i;

if ( string.midRef( i ).startsWith( sep ) )
if ( QStringView{string}.mid( i ).startsWith( sep ) )
{
i += sep.length();
}
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsogcutils.cpp
Expand Up @@ -2680,8 +2680,13 @@ QDomElement QgsOgcUtilsSQLStatementToFilter::toOgcFilter( const QgsSQLStatement:
static QString mapBinarySpatialToOgc( const QString &name )
{
QString nameCompare( name );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
if ( name.size() > 3 && name.midRef( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
nameCompare = name.mid( 3 );
#else
if ( name.size() > 3 && QStringView {name}.mid( 0, 3 ).toString().compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
nameCompare = name.mid( 3 );
#endif
QStringList spatialOps;
spatialOps << QStringLiteral( "BBOX" ) << QStringLiteral( "Intersects" ) << QStringLiteral( "Contains" ) << QStringLiteral( "Crosses" ) << QStringLiteral( "Equals" )
<< QStringLiteral( "Disjoint" ) << QStringLiteral( "Overlaps" ) << QStringLiteral( "Touches" ) << QStringLiteral( "Within" );
Expand All @@ -2697,8 +2702,13 @@ static QString mapBinarySpatialToOgc( const QString &name )
static QString mapTernarySpatialToOgc( const QString &name )
{
QString nameCompare( name );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
if ( name.size() > 3 && name.midRef( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
nameCompare = name.mid( 3 );
#else
if ( name.size() > 3 && QStringView {name}.mid( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
nameCompare = name.mid( 3 );
#endif
if ( nameCompare.compare( QLatin1String( "DWithin" ), Qt::CaseInsensitive ) == 0 )
return QStringLiteral( "DWithin" );
if ( nameCompare.compare( QLatin1String( "Beyond" ), Qt::CaseInsensitive ) == 0 )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspostgresstringutils.cpp
Expand Up @@ -40,7 +40,7 @@ QString QgsPostgresStringUtils::getNextString( const QString &txt, int &i, const
}
i += stringRe.cap( 1 ).length() + 2;
jumpSpace( txt, i );
if ( !txt.midRef( i ).startsWith( sep ) && i < txt.length() )
if ( !QStringView{txt}.mid( i ).startsWith( sep ) && i < txt.length() )
{
QgsMessageLog::logMessage( QObject::tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), QObject::tr( "PostgresStringUtils" ) );
return QString();
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsstringutils.cpp
Expand Up @@ -635,13 +635,21 @@ QString QgsStringUtils::wordWrap( const QString &string, const int length, const
}
if ( strHit > -1 )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
newstr.append( lines.at( i ).midRef( strCurrent, strHit - strCurrent ) );
#else
newstr.append( QStringView {lines.at( i )}.mid( strCurrent, strHit - strCurrent ) );
#endif
newstr.append( '\n' );
strCurrent = strHit + delimiterLength;
}
else
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
newstr.append( lines.at( i ).midRef( strCurrent ) );
#else
newstr.append( QStringView {lines.at( i )}.mid( strCurrent ) );
#endif
strCurrent = strLength;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -4739,7 +4739,7 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS
}
i += stringRe.cap( 1 ).length() + 2;
jumpSpace( txt, i );
if ( !txt.midRef( i ).startsWith( sep ) && i < txt.length() )
if ( !QStringView{txt}.mid( i ).startsWith( sep ) && i < txt.length() )
{
QgsMessageLog::logMessage( tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), tr( "PostGIS" ) );
return QString();
Expand All @@ -4752,14 +4752,14 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS
int start = i;
for ( ; i < txt.length(); i++ )
{
if ( txt.midRef( i ).startsWith( sep ) )
if ( QStringView{txt}.mid( i ).startsWith( sep ) )
{
QStringRef r( txt.midRef( start, i - start ) );
QStringView v( QStringView{txt}.mid( start, i - start ) );
i += sep.length();
return r.trimmed().toString();
return v.trimmed().toString();
}
}
return txt.midRef( start, i - start ).trimmed().toString();
return QStringView{txt}.mid( start, i - start ).trimmed().toString();
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -570,7 +570,11 @@ namespace QgsWms
const QRegExp composerParamRegExp( QStringLiteral( "^MAP\\d+:" ), Qt::CaseInsensitive );
if ( key.contains( composerParamRegExp ) )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
const int mapId = key.midRef( 3, key.indexOf( ':' ) - 3 ).toInt();
#else
const int mapId = QStringView {key}.mid( 3, key.indexOf( ':' ) - 3 ).toInt();
#endif
const QString theKey = key.mid( key.indexOf( ':' ) + 1 );
const QgsWmsParameter::Name name = QgsWmsParameter::name( theKey );

Expand Down
10 changes: 9 additions & 1 deletion tests/bench/main.cpp
Expand Up @@ -562,17 +562,25 @@ int main( int argc, char *argv[] )
ok = false;
break;
}

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok );
#else
coords[i] = QStringView {myInitialExtent}.mid( posOld, pos - posOld ).toDouble( &ok );
#endif
if ( !ok )
break;

posOld = pos + 1;
}

// parse last coordinate
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
if ( ok )
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );
#else
if ( ok )
coords[3] = QStringView {myInitialExtent}.mid( posOld ).toDouble( &ok );
#endif

if ( !ok )
{
Expand Down

0 comments on commit ce2bce5

Please sign in to comment.