Skip to content

Commit

Permalink
Fix regression in word wrapping
Browse files Browse the repository at this point in the history
The switch to QRegularExpression mean that word wrapping was ALWAYS
being applied, even when the string was short enough to not require it
  • Loading branch information
nyalldawson committed Oct 20, 2021
1 parent ffc4eac commit 320260a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/qgsstringutils.cpp
Expand Up @@ -633,17 +633,17 @@ QString QgsStringUtils::wordWrap( const QString &string, const int length, const
if ( useMaxLineLength )
{
//first try to locate delimiter backwards
strHit = lines.at( i ).lastIndexOf( rx, strCurrent + length );
strHit = ( strCurrent + length >= strLength ) ? -1 : lines.at( i ).lastIndexOf( rx, strCurrent + length );
if ( strHit == lastHit || strHit == -1 )
{
//if no new backward delimiter found, try to locate forward
strHit = lines.at( i ).indexOf( rx, strCurrent + std::abs( length ) );
strHit = ( strCurrent + std::abs( length ) >= strLength ) ? -1 : lines.at( i ).indexOf( rx, strCurrent + std::abs( length ) );
}
lastHit = strHit;
}
else
{
strHit = lines.at( i ).indexOf( rx, strCurrent + std::abs( length ) );
strHit = ( strCurrent + std::abs( length ) >= strLength ) ? -1 : lines.at( i ).indexOf( rx, strCurrent + std::abs( length ) );
}
if ( strHit > -1 )
{
Expand Down
2 changes: 2 additions & 0 deletions tests/src/core/testqgsstringutils.cpp
Expand Up @@ -239,6 +239,8 @@ void TestQgsStringUtils::wordWrap_data()
QTest::addColumn<QString>( "expected" );

QTest::newRow( "wordwrap" ) << "university of qgis" << 13 << true << QString() << "university of\nqgis";
QTest::newRow( "wordwrap not possible" ) << "universityofqgis" << 13 << true << QString() << "universityofqgis";
QTest::newRow( "wordwrap not required" ) << "uni of qgis" << 13 << true << QString() << "uni of qgis";
QTest::newRow( "optional parameters unspecified" ) << "test string" << 5 << true << QString() << "test\nstring";
QTest::newRow( "wordwrap with delim" ) << "university of qgis" << 13 << true << QStringLiteral( " " ) << "university of\nqgis";
QTest::newRow( "wordwrap min" ) << "university of qgis" << 3 << false << QStringLiteral( " " ) << "university\nof qgis";
Expand Down

0 comments on commit 320260a

Please sign in to comment.