Skip to content
Permalink
Browse files

Allow + for string concat in QgsExpression

  • Loading branch information
NathanW2 committed Aug 18, 2014
1 parent 0b213b6 commit 978642addbd8fc1c87d6fc0bba10ff34fc9c6172
Showing with 7 additions and 0 deletions.
  1. +6 −0 src/core/qgsexpression.cpp
  2. +1 −0 tests/src/core/testqgsexpression.cpp
@@ -2081,6 +2081,12 @@ QVariant QgsExpression::NodeBinaryOperator::eval( QgsExpression* parent, const Q
switch ( mOp )
{
case boPlus:
if ( vL.type() == QVariant::String && vR.type() == QVariant::String )
{
QString sL = getStringValue( vL, parent ); ENSURE_NO_EVAL_ERROR;
QString sR = getStringValue( vR, parent ); ENSURE_NO_EVAL_ERROR;
return QVariant( sL + sR );
}
case boMinus:
case boMul:
case boDiv:
@@ -223,6 +223,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "regexp 3" ) << "'hello' ~ 'llo$'" << false << QVariant( 1 );

// concatenation
QTest::newRow( "concat with plus" ) << "'a' + 'b'" << false << QVariant( "ab" );
QTest::newRow( "concat" ) << "'a' || 'b'" << false << QVariant( "ab" );
QTest::newRow( "concat with int" ) << "'a' || 1" << false << QVariant( "a1" );
QTest::newRow( "concat with int" ) << "2 || 'b'" << false << QVariant( "2b" );

0 comments on commit 978642a

Please sign in to comment.
You can’t perform that action at this time.