Skip to content

Commit a7cb2b2

Browse files
committed
[expression] check for maximum nb of arguments in wordwrap function
1 parent 5105f5f commit a7cb2b2

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/core/qgsexpression.cpp

+22-16
Original file line numberDiff line numberDiff line change
@@ -633,17 +633,17 @@ static QVariant fcnTrim( const QVariantList& values, const QgsFeature* , QgsExpr
633633

634634
static QVariant fcnWordwrap( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
635635
{
636-
if (values.length() > 1)
636+
if ( values.length() == 2 || values.length() == 3 )
637637
{
638638
QString str = getStringValue( values.at( 0 ), parent );
639-
int wrap = getIntValue( values.at(1), parent );
639+
int wrap = getIntValue( values.at( 1 ), parent );
640640

641-
if (!str.isEmpty() && wrap != 0)
641+
if ( !str.isEmpty() && wrap != 0 )
642642
{
643643
QString newstr;
644644
QString delimiterstr;
645-
if (values.length() == 3) delimiterstr = getStringValue ( values.at(2), parent );
646-
if (delimiterstr.isEmpty()) delimiterstr = " ";
645+
if ( values.length() == 3 ) delimiterstr = getStringValue( values.at( 2 ), parent );
646+
if ( delimiterstr.isEmpty() ) delimiterstr = " ";
647647
int delimiterlength = delimiterstr.length();
648648

649649
QStringList lines = str.split( "\n" );
@@ -656,32 +656,38 @@ static QVariant fcnWordwrap( const QVariantList& values, const QgsFeature* , Qgs
656656
strhit = 0;
657657
lasthit = 0;
658658

659-
while (strcurrent < strlength)
659+
while ( strcurrent < strlength )
660660
{
661661
// positive wrap value = desired maximum line width to wrap
662662
// negative wrap value = desired minimum line width before wrap
663-
if (wrap > 0)
663+
if ( wrap > 0 )
664664
{
665665
//first try to locate delimiter backwards
666-
strhit = lines[i].lastIndexOf( delimiterstr, strcurrent + wrap);
667-
if (strhit == lasthit || strhit == -1) {
666+
strhit = lines[i].lastIndexOf( delimiterstr, strcurrent + wrap );
667+
if ( strhit == lasthit || strhit == -1 )
668+
{
668669
//if no new backward delimiter found, try to locate forward
669-
strhit = lines[i].indexOf( delimiterstr, strcurrent + qAbs(wrap) );
670-
}
670+
strhit = lines[i].indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
671+
}
671672
lasthit = strhit;
672-
} else {
673-
strhit = lines[i].indexOf( delimiterstr, strcurrent + qAbs(wrap) );
674673
}
675-
if (strhit > -1) {
674+
else
675+
{
676+
strhit = lines[i].indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
677+
}
678+
if ( strhit > -1 )
679+
{
676680
newstr.append( lines[i].midRef( strcurrent , strhit - strcurrent ) );
677681
newstr.append( "\n" );
678682
strcurrent = strhit + delimiterlength;
679-
} else {
683+
}
684+
else
685+
{
680686
newstr.append( lines[i].midRef( strcurrent ) );
681687
strcurrent = strlength;
682688
}
683689
}
684-
if (i < lines.size() - 1) newstr.append( "\n" );
690+
if ( i < lines.size() - 1 ) newstr.append( "\n" );
685691
}
686692

687693
return QVariant( newstr );

0 commit comments

Comments
 (0)