@@ -1398,30 +1398,19 @@ static QVariant fcnUuid( const QVariantList&, const QgsExpressionContext*, QgsEx
1398
1398
return QUuid::createUuid ().toString ();
1399
1399
}
1400
1400
1401
- static QVariant fcnSubstr ( const QVariantList& values, const QgsExpressionContext* context , QgsExpression* parent )
1401
+ static QVariant fcnSubstr ( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
1402
1402
{
1403
+ if ( !values.at ( 0 ).isValid () || !values.at ( 1 ).isValid () )
1404
+ return QVariant ();
1403
1405
1404
- QgsExpression::Node* node;
1405
-
1406
- node = getNode ( values.at ( 0 ), parent );
1407
- ENSURE_NO_EVAL_ERROR;
1408
- QString str = node->eval ( parent, context ).toString ();
1409
-
1410
- node = getNode ( values.at ( 1 ), parent );
1411
- ENSURE_NO_EVAL_ERROR;
1412
- int from = node->eval ( parent, context ).toInt ();
1406
+ QString str = getStringValue ( values.at ( 0 ), parent );
1407
+ int from = getIntValue ( values.at ( 1 ), parent );
1413
1408
1414
- node = getNode ( values.at ( 2 ), parent );
1415
- QVariant value = node->eval ( parent, context );
1416
- int len;
1417
- if ( value.isValid () )
1418
- {
1419
- len = value.toInt ();
1420
- }
1409
+ int len = 0 ;
1410
+ if ( values.at ( 2 ).isValid () )
1411
+ len = getIntValue ( values.at ( 2 ), parent );
1421
1412
else
1422
- {
1423
1413
len = str.size ();
1424
- }
1425
1414
1426
1415
if ( from < 0 )
1427
1416
{
@@ -3847,7 +3836,8 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
3847
3836
<< new StaticFunction ( QStringLiteral ( " replace" ), -1 , fcnReplace, QStringLiteral ( " String" ) )
3848
3837
<< new StaticFunction ( QStringLiteral ( " regexp_replace" ), 3 , fcnRegexpReplace, QStringLiteral ( " String" ) )
3849
3838
<< new StaticFunction ( QStringLiteral ( " regexp_substr" ), 2 , fcnRegexpSubstr, QStringLiteral ( " String" ) )
3850
- << new StaticFunction ( QStringLiteral ( " substr" ), ParameterList () << Parameter ( QStringLiteral ( " string" ) ) << Parameter ( QStringLiteral ( " start " ) ) << Parameter ( QStringLiteral ( " length" ), true ), fcnSubstr, QStringLiteral ( " String" ), QString (), False, QSet<QString>(), true )
3839
+ << new StaticFunction ( QStringLiteral ( " substr" ), ParameterList () << Parameter ( QStringLiteral ( " string" ) ) << Parameter ( QStringLiteral ( " start " ) ) << Parameter ( QStringLiteral ( " length" ), true ), fcnSubstr, QStringLiteral ( " String" ), QString (),
3840
+ false , QSet< QString >(), false , QStringList (), true )
3851
3841
<< new StaticFunction ( QStringLiteral ( " concat" ), -1 , fcnConcat, QStringLiteral ( " String" ), QString (), false , QSet<QString>(), false , QStringList (), true )
3852
3842
<< new StaticFunction ( QStringLiteral ( " strpos" ), 2 , fcnStrpos, QStringLiteral ( " String" ) )
3853
3843
<< new StaticFunction ( QStringLiteral ( " left" ), 2 , fcnLeft, QStringLiteral ( " String" ) )
0 commit comments