@@ -634,25 +634,35 @@ static QVariant fcnTrim( const QVariantList& values, const QgsFeature* , QgsExpr
634
634
static QVariant fcnWordwrap ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
635
635
{
636
636
QString str = getStringValue ( values.at ( 0 ), parent );
637
- QString delimiterstr = getStringValue ( values.at (1 ), parent );
638
- QString wrapstr = " \n " ;
639
637
QString newstr;
640
638
641
- int length = str.length ();
642
- int min = getIntValue ( values.at (2 ), parent );
643
- int current = 0 ;
644
- int hit = 0 ;
645
-
646
- while (current < length) {
647
- hit = str.indexOf ( delimiterstr, current + min );
648
- if (hit > -1 ) {
649
- newstr.append ( str.midRef ( current , hit - current ) );
650
- newstr.append ( wrapstr );
651
- current = hit + 1 ;
639
+ QString delimiterstr = getStringValue ( values.at (1 ), parent );
640
+ int delimiterlength = delimiterstr.length ();
641
+
642
+ int wrapmin = getIntValue ( values.at (2 ), parent );
643
+
644
+ QStringList lines = str.split ( " \n " );
645
+ int strlength, strcurrent, strhit;
646
+
647
+ for ( int i = 0 ; i < lines.size (); i++ )
648
+ {
649
+ strlength = lines[i].length ();
650
+ strcurrent = 0 ;
651
+ strhit = 0 ;
652
+
653
+ while (strcurrent < strlength)
654
+ {
655
+ strhit = lines[i].indexOf ( delimiterstr, strcurrent + wrapmin );
656
+ if (strhit > -1 ) {
657
+ newstr.append ( lines[i].midRef ( strcurrent , strhit - strcurrent ) );
658
+ newstr.append ( " \n " );
659
+ strcurrent = strhit + delimiterlength;
652
660
} else {
653
- newstr.append ( str .midRef ( current ) );
654
- current = length ;
661
+ newstr.append ( lines[i] .midRef ( strcurrent ) );
662
+ strcurrent = strlength ;
655
663
}
664
+ }
665
+ if (i < lines.size () - 1 ) newstr.append ( " \n " );
656
666
}
657
667
return QVariant ( newstr );
658
668
}
0 commit comments