@@ -631,6 +631,32 @@ static QVariant fcnTrim( const QVariantList& values, const QgsFeature* , QgsExpr
631
631
return QVariant ( str.trimmed () );
632
632
}
633
633
634
+ static QVariant fcnWordwrap ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
635
+ {
636
+ QString str = getStringValue ( values.at ( 0 ), parent );
637
+ QString delimiterstr = getStringValue ( values.at (1 ), parent );
638
+ QString wrapstr = " \n " ;
639
+ QString newstr;
640
+
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 ;
652
+ } else {
653
+ newstr.append ( str.midRef ( current ) );
654
+ current = length;
655
+ }
656
+ }
657
+ return QVariant ( newstr );
658
+ }
659
+
634
660
static QVariant fcnLength ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
635
661
{
636
662
QString str = getStringValue ( values.at ( 0 ), parent );
@@ -1484,6 +1510,7 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
1484
1510
<< new StaticFunction ( " upper" , 1 , fcnUpper, " String" )
1485
1511
<< new StaticFunction ( " title" , 1 , fcnTitle, " String" )
1486
1512
<< new StaticFunction ( " trim" , 1 , fcnTrim, " String" )
1513
+ << new StaticFunction ( " wordwrap" , 3 , fcnWordwrap, " String" )
1487
1514
<< new StaticFunction ( " length" , 1 , fcnLength, " String" )
1488
1515
<< new StaticFunction ( " replace" , 3 , fcnReplace, " String" )
1489
1516
<< new StaticFunction ( " regexp_replace" , 3 , fcnRegexpReplace, " String" )
0 commit comments