@@ -1014,73 +1014,9 @@ static QVariant fcnWordwrap( const QVariantList &values, const QgsExpressionCont
1014
1014
QString str = QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent );
1015
1015
qlonglong wrap = QgsExpressionUtils::getIntValue ( values.at ( 1 ), parent );
1016
1016
1017
- if ( !str.isEmpty () && wrap != 0 )
1018
- {
1019
- QString newstr;
1020
- QRegExp rx;
1021
- QString customdelimiter = QgsExpressionUtils::getStringValue ( values.at ( 2 ), parent );
1022
- int delimiterlength;
1023
-
1024
- if ( customdelimiter.length () > 0 )
1025
- {
1026
- rx.setPatternSyntax ( QRegExp::FixedString );
1027
- rx.setPattern ( customdelimiter );
1028
- delimiterlength = customdelimiter.length ();
1029
- }
1030
- else
1031
- {
1032
- // \x200B is a ZERO-WIDTH SPACE, needed for worwrap to support a number of complex scripts (Indic, Arabic, etc.)
1033
- rx.setPattern ( QStringLiteral ( " [\\ s\\ x200B]" ) );
1034
- delimiterlength = 1 ;
1035
- }
1036
-
1017
+ QString customdelimiter = QgsExpressionUtils::getStringValue ( values.at ( 2 ), parent );
1037
1018
1038
- QStringList lines = str.split ( ' \n ' );
1039
- int strlength, strcurrent, strhit, lasthit;
1040
-
1041
- for ( int i = 0 ; i < lines.size (); i++ )
1042
- {
1043
- strlength = lines[i].length ();
1044
- strcurrent = 0 ;
1045
- strhit = 0 ;
1046
- lasthit = 0 ;
1047
-
1048
- while ( strcurrent < strlength )
1049
- {
1050
- // positive wrap value = desired maximum line width to wrap
1051
- // negative wrap value = desired minimum line width before wrap
1052
- if ( wrap > 0 )
1053
- {
1054
- // first try to locate delimiter backwards
1055
- strhit = lines[i].lastIndexOf ( rx, strcurrent + wrap );
1056
- if ( strhit == lasthit || strhit == -1 )
1057
- {
1058
- // if no new backward delimiter found, try to locate forward
1059
- strhit = lines[i].indexOf ( rx, strcurrent + std::labs ( wrap ) );
1060
- }
1061
- lasthit = strhit;
1062
- }
1063
- else
1064
- {
1065
- strhit = lines[i].indexOf ( rx, strcurrent + std::labs ( wrap ) );
1066
- }
1067
- if ( strhit > -1 )
1068
- {
1069
- newstr.append ( lines[i].midRef ( strcurrent, strhit - strcurrent ) );
1070
- newstr.append ( ' \n ' );
1071
- strcurrent = strhit + delimiterlength;
1072
- }
1073
- else
1074
- {
1075
- newstr.append ( lines[i].midRef ( strcurrent ) );
1076
- strcurrent = strlength;
1077
- }
1078
- }
1079
- if ( i < lines.size () - 1 ) newstr.append ( ' \n ' );
1080
- }
1081
-
1082
- return QVariant ( newstr );
1083
- }
1019
+ return QgsStringUtils::wordWrap ( str, static_cast < int >( wrap ), wrap > 0 , customdelimiter );
1084
1020
}
1085
1021
1086
1022
return QVariant ();
0 commit comments