Skip to content

Commit

Permalink
More efficient case insensitive string comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 4, 2018
1 parent 3014bbf commit 0b4694f
Show file tree
Hide file tree
Showing 49 changed files with 133 additions and 133 deletions.
4 changes: 2 additions & 2 deletions src/app/dwg/qgsdwgimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa

DRW::error result( DRW::BAD_NONE );

if ( fi.suffix().toLower() == QLatin1String( "dxf" ) )
if ( fi.suffix().compare( QLatin1String( "dxf" ), Qt::CaseInsensitive ) == 0 )
{
//loads dxf
std::unique_ptr<dxfRW> dxf( new dxfRW( drawing.toLocal8Bit() ) );
Expand All @@ -602,7 +602,7 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa
result = DRW::BAD_UNKNOWN;
}
}
else if ( fi.suffix().toLower() == QLatin1String( "dwg" ) )
else if ( fi.suffix().compare( QLatin1String( "dwg" ), Qt::CaseInsensitive ) == 0 )
{
//loads dwg
std::unique_ptr<dwgR> dwg( new dwgR( drawing.toLocal8Bit() ) );
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout/qgslayoutmanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ QMap<QString, QString> QgsLayoutManagerDialog::templatesFromPath( const QString
QFileInfoList::const_iterator infoIt = fileInfoList.constBegin();
for ( ; infoIt != fileInfoList.constEnd(); ++infoIt )
{
if ( infoIt->suffix().toLower() == QLatin1String( "qpt" ) )
if ( infoIt->suffix().compare( QLatin1String( "qpt" ), Qt::CaseInsensitive ) == 0 )
{
templateMap.insert( infoIt->baseName(), infoIt->absoluteFilePath() );
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6201,20 +6201,20 @@ void QgisApp::openFile( const QString &fileName, const QString &fileTypeHint )
{
// check to see if we are opening a project file
QFileInfo fi( fileName );
if ( fileTypeHint == QStringLiteral( "project" ) || fi.suffix().toLower() == QLatin1String( "qgs" ) || fi.suffix().toLower() == QLatin1String( "qgz" ) )
if ( fileTypeHint == QStringLiteral( "project" ) || fi.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) == 0 || fi.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) == 0 )
{
QgsDebugMsg( "Opening project " + fileName );
openProject( fileName );
}
else if ( fi.suffix().toLower() == QLatin1String( "qlr" ) )
else if ( fi.suffix().compare( QLatin1String( "qlr" ), Qt::CaseInsensitive ) == 0 )
{
openLayerDefinition( fileName );
}
else if ( fi.suffix().toLower() == QLatin1String( "qpt" ) )
else if ( fi.suffix().compare( QLatin1String( "qpt" ), Qt::CaseInsensitive ) == 0 )
{
openTemplate( fileName );
}
else if ( fi.suffix().toLower() == QLatin1String( "py" ) )
else if ( fi.suffix().compare( QLatin1String( "py" ), Qt::CaseInsensitive ) == 0 )
{
runScript( fileName );
}
Expand Down Expand Up @@ -12790,7 +12790,7 @@ bool QgisApp::addRasterLayers( QStringList const &fileNameQStringList, bool guiW
//time to prevent the user selecting all adfs in 1 dir which
//actually represent 1 coverate,

if ( myFileInfo.fileName().toLower().endsWith( QLatin1String( ".adf" ) ) )
if ( myFileInfo.fileName().endsWith( QLatin1String( ".adf" ), Qt::CaseInsensitive ) )
{
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsaddattrdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void QgsAddAttrDialog::setPrecisionMinMax()

void QgsAddAttrDialog::accept()
{
if ( mIsShapeFile && mNameEdit->text().toLower() == QLatin1String( "shape" ) )
if ( mIsShapeFile && mNameEdit->text().compare( QLatin1String( "shape" ), Qt::CaseInsensitive ) == 0 )
{
QMessageBox::warning( this, tr( "Add Field" ),
tr( "Invalid field name. This field name is reserved and cannot be used." ) );
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsappbrowserproviders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ QgsDataItem *QgsQlrDataItemProvider::createDataItem( const QString &path, QgsDat
{
QFileInfo fileInfo( path );

if ( fileInfo.suffix().compare( QStringLiteral( "qlr" ), Qt::CaseInsensitive ) == 0 )
if ( fileInfo.suffix().compare( QLatin1String( "qlr" ), Qt::CaseInsensitive ) == 0 )
{
return new QgsQlrDataItem( parentItem, fileInfo.fileName(), path );
}
Expand Down Expand Up @@ -98,7 +98,7 @@ QgsDataItem *QgsQptDataItemProvider::createDataItem( const QString &path, QgsDat
{
QFileInfo fileInfo( path );

if ( fileInfo.suffix().compare( QStringLiteral( "qpt" ), Qt::CaseInsensitive ) == 0 )
if ( fileInfo.suffix().compare( QLatin1String( "qpt" ), Qt::CaseInsensitive ) == 0 )
{
return new QgsQptDataItem( parentItem, fileInfo.baseName(), path );
}
Expand All @@ -123,7 +123,7 @@ void QgsQptDropHandler::handleCustomUriDrop( const QgsMimeDataUtils::Uri &uri )
bool QgsQptDropHandler::handleFileDrop( const QString &file )
{
QFileInfo fi( file );
if ( fi.completeSuffix().compare( QStringLiteral( "qpt" ), Qt::CaseInsensitive ) == 0 )
if ( fi.completeSuffix().compare( QLatin1String( "qpt" ), Qt::CaseInsensitive ) == 0 )
{
QgisApp::instance()->openTemplate( file );
return true;
Expand Down Expand Up @@ -240,7 +240,7 @@ QgsDataItem *QgsPyDataItemProvider::createDataItem( const QString &path, QgsData
{
QFileInfo fileInfo( path );

if ( fileInfo.suffix().compare( QStringLiteral( "py" ), Qt::CaseInsensitive ) == 0 )
if ( fileInfo.suffix().compare( QLatin1String( "py" ), Qt::CaseInsensitive ) == 0 )
{
return new QgsPyDataItem( parentItem, fileInfo.baseName(), path );
}
Expand All @@ -265,7 +265,7 @@ void QgsPyDropHandler::handleCustomUriDrop( const QgsMimeDataUtils::Uri &uri ) c
bool QgsPyDropHandler::handleFileDrop( const QString &file )
{
QFileInfo fi( file );
if ( fi.completeSuffix().compare( QStringLiteral( "py" ), Qt::CaseInsensitive ) == 0 )
if ( fi.completeSuffix().compare( QLatin1String( "py" ), Qt::CaseInsensitive ) == 0 )
{
QgisApp::instance()->runScript( file );
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdecorationnortharrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void QgsDecorationNorthArrow::run()

QString QgsDecorationNorthArrow::svgPath()
{
if ( mSvgPath.startsWith( QStringLiteral( "base64:" ), Qt::CaseInsensitive ) )
if ( mSvgPath.startsWith( QLatin1String( "base64:" ), Qt::CaseInsensitive ) )
return mSvgPath;

if ( !mSvgPath.isEmpty() )
Expand Down
20 changes: 10 additions & 10 deletions src/auth/basic/qgsauthbasicmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
if ( ! username.isEmpty() )
{
// Inject credentials
if ( uri.startsWith( QStringLiteral( "PG:" ) ) )
if ( uri.startsWith( QLatin1String( "PG:" ) ) )
{
bool chopped = false;
if ( uri.endsWith( '"' ) )
Expand All @@ -159,11 +159,11 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
if ( chopped )
uri += '"';
}
else if ( uri.startsWith( QStringLiteral( "SDE:" ) ) )
else if ( uri.startsWith( QLatin1String( "SDE:" ) ) )
{
uri = uri.replace( QRegExp( ",$" ), QStringLiteral( ",%1,%2" ).arg( username, password ) );
}
else if ( uri.startsWith( QStringLiteral( "IDB" ) ) )
else if ( uri.startsWith( QLatin1String( "IDB" ) ) )
{
bool chopped = false;
if ( uri.endsWith( '"' ) )
Expand All @@ -177,32 +177,32 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
if ( chopped )
uri += '"';
}
else if ( uri.startsWith( QStringLiteral( "@driver=ingres" ) ) )
else if ( uri.startsWith( QLatin1String( "@driver=ingres" ) ) )
{
uri += QStringLiteral( ",userid=%1" ).arg( username );
if ( !password.isEmpty() )
uri += QStringLiteral( ",password=%1" ).arg( password );
}
else if ( uri.startsWith( QStringLiteral( "MySQL:" ) ) )
else if ( uri.startsWith( QLatin1String( "MySQL:" ) ) )
{
uri += QStringLiteral( ",user=%1" ).arg( username );
if ( !password.isEmpty() )
uri += QStringLiteral( ",password=%1" ).arg( password );
}
else if ( uri.startsWith( QStringLiteral( "MSSQL:" ) ) )
else if ( uri.startsWith( QLatin1String( "MSSQL:" ) ) )
{
uri += QStringLiteral( ";uid=%1" ).arg( username );
uri = uri.replace( QLatin1String( ";trusted_connection=yes" ), QString() );

if ( !password.isEmpty() )
uri += QStringLiteral( ";pwd=%1" ).arg( password );
}
else if ( uri.startsWith( QStringLiteral( "OCI:" ) ) )
else if ( uri.startsWith( QLatin1String( "OCI:" ) ) )
{
// OCI:userid/password@database_instance:table,table
uri = uri.replace( QStringLiteral( "OCI:/" ), QStringLiteral( "OCI:%1/%2" ).arg( username, password ) );
}
else if ( uri.startsWith( QStringLiteral( "ODBC:" ) ) )
else if ( uri.startsWith( QLatin1String( "ODBC:" ) ) )
{
if ( password.isEmpty() )
{
Expand All @@ -213,8 +213,8 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
uri = uri.replace( QRegExp( "^ODBC:@?" ), "ODBC:" + username + '/' + password + '@' );
}
}
else if ( uri.startsWith( QStringLiteral( "couchdb" ) )
|| uri.startsWith( QStringLiteral( "DODS" ) )
else if ( uri.startsWith( QLatin1String( "couchdb" ) )
|| uri.startsWith( QLatin1String( "DODS" ) )
|| uri.startsWith( "http://" )
|| uri.startsWith( "/vsicurl/http://" )
|| uri.startsWith( "https://" )
Expand Down
10 changes: 5 additions & 5 deletions src/core/layout/qgscompositionconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1543,15 +1543,15 @@ bool QgsCompositionConverter::readXml( QgsLayoutItem *layoutItem, const QDomElem

//frame
QString frame = itemElem.attribute( QStringLiteral( "frame" ) );
layoutItem->setFrameEnabled( frame.compare( QStringLiteral( "true" ), Qt::CaseInsensitive ) == 0 ) ;
layoutItem->setFrameEnabled( frame.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 ) ;

//frame
QString background = itemElem.attribute( QStringLiteral( "background" ) );
layoutItem->setBackgroundEnabled( background.compare( QStringLiteral( "true" ), Qt::CaseInsensitive ) == 0 );
layoutItem->setBackgroundEnabled( background.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 );

//position lock for mouse moves/resizes
QString positionLock = itemElem.attribute( QStringLiteral( "positionLock" ) );
layoutItem->setLocked( positionLock.compare( QStringLiteral( "true" ), Qt::CaseInsensitive ) == 0 );
layoutItem->setLocked( positionLock.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 );

//visibility
layoutItem->setVisibility( itemElem.attribute( QStringLiteral( "visibility" ), QStringLiteral( "1" ) ) != QStringLiteral( "0" ) );
Expand Down Expand Up @@ -1711,7 +1711,7 @@ QgsProperty QgsCompositionConverter::readOldDataDefinedProperty( const QgsCompos

QString active = ddElem.attribute( QStringLiteral( "active" ) );
bool isActive = false;
if ( active.compare( QStringLiteral( "true" ), Qt::CaseInsensitive ) == 0 )
if ( active.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
{
isActive = true;
}
Expand All @@ -1720,7 +1720,7 @@ QgsProperty QgsCompositionConverter::readOldDataDefinedProperty( const QgsCompos

QString useExpr = ddElem.attribute( QStringLiteral( "useExpr" ) );
bool isExpression = false;
if ( useExpr.compare( QStringLiteral( "true" ), Qt::CaseInsensitive ) == 0 )
if ( useExpr.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
{
isExpression = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ bool QgsLayoutItem::readXml( const QDomElement &element, const QDomDocument &doc

//position lock for mouse moves/resizes
QString positionLock = element.attribute( QStringLiteral( "positionLock" ) );
if ( positionLock.compare( QStringLiteral( "true" ), Qt::CaseInsensitive ) == 0 )
if ( positionLock.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
{
setLocked( true );
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayoutitempage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ QgsLayoutItemPage::Orientation QgsLayoutItemPage::decodePageOrientation( const Q
*ok = false;

QString trimmedString = string.trimmed();
if ( trimmedString.compare( QStringLiteral( "portrait" ), Qt::CaseInsensitive ) == 0 )
if ( trimmedString.compare( QLatin1String( "portrait" ), Qt::CaseInsensitive ) == 0 )
{
if ( ok )
*ok = true;
return Portrait;
}
else if ( trimmedString.compare( QStringLiteral( "landscape" ), Qt::CaseInsensitive ) == 0 )
else if ( trimmedString.compare( QLatin1String( "landscape" ), Qt::CaseInsensitive ) == 0 )
{
if ( ok )
*ok = true;
Expand Down

0 comments on commit 0b4694f

Please sign in to comment.