Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Title case conversion works correctly on all uppercase string inputs
  • Loading branch information
nyalldawson committed Sep 16, 2020
1 parent ae71913 commit 6bd3dc5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/qgsstringutils.cpp
Expand Up @@ -73,7 +73,8 @@ QString QgsStringUtils::capitalize( const QString &string, QgsStringUtils::Capit
splitWords = QRegularExpression( QStringLiteral( "\\b" ), QRegularExpression::UseUnicodePropertiesOption );
}

const QStringList parts = string.split( splitWords, QString::SkipEmptyParts );
const bool allSameCase = string.toLower() == string || string.toUpper() == string;
const QStringList parts = ( allSameCase ? string.toLower() : string ).split( splitWords, QString::SkipEmptyParts );
QString result;
bool firstWord = true;
int i = 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/src/core/testqgsstringutils.cpp
Expand Up @@ -173,6 +173,8 @@ void TestQgsStringUtils::titleCase_data()
QTest::newRow( "empty string" ) << "" << "";
QTest::newRow( "single character" ) << "a" << "A";
QTest::newRow( "string 1" ) << "follow step-by-step instructions" << "Follow Step-by-Step Instructions";
QTest::newRow( "originally uppercase" ) << "FOLLOW STEP-BY-STEP INSTRUCTIONS" << "Follow Step-by-Step Instructions";
QTest::newRow( "string 1" ) << "Follow step-by-step instructions" << "Follow Step-by-Step Instructions";
QTest::newRow( "string 2" ) << "this sub-phrase is nice" << "This Sub-Phrase Is Nice";
QTest::newRow( "" ) << "catchy title: a subtitle" << "Catchy Title: A Subtitle";
QTest::newRow( "string 3" ) << "all words capitalized" << "All Words Capitalized";
Expand Down

0 comments on commit 6bd3dc5

Please sign in to comment.