Skip to content

Commit

Permalink
Merge pull request #5979 from murraystevenson/setExpressionWhitespace
Browse files Browse the repository at this point in the history
SetAlgo : Treat set expressions containing only whitespace as empty
  • Loading branch information
johnhaddon authored Jul 31, 2024
2 parents d277178 + 9879d81 commit 9c929e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
1.4.x.x (relative to 1.4.10.0)
=======

Improvements
------------

- SetExpressions : Set Expressions containing only whitespace characters are now treated as empty rather than producing an error.

1.4.10.0 (relative to 1.4.9.0)
========
Expand Down
20 changes: 20 additions & 0 deletions python/GafferSceneTest/SetAlgoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,26 @@ def test( self ) :
expressionCheck( '(setA - ((setC /group/group/sphere2) & setB))', [ '/group/group/sphere1' ] )
expressionCheck( 'setA - (/group/group/sphere1 /group/group/sphere2) | (setA setB setC) & setC', [ '/group/sphere3' ] )

# Test a selection of the above expressions with tab and newline whitespace characters inserted
expressionCheck( 'setA\nsetC', [ '/group/group/sphere1', '/group/group/sphere2', '/group/sphere3' ] )
expressionCheck( '\n\nsetA\tsetC\n\n\t', [ '/group/group/sphere1', '/group/group/sphere2', '/group/sphere3' ] )
expressionCheck( 'setA\t-\tsetB\n|\nsetC', [ '/group/group/sphere1', '/group/sphere3' ] )
expressionCheck( 'setA\n| setB\n& setC', [ '/group/group/sphere1', '/group/group/sphere2' ] )
expressionCheck( '/group/light1\n/group/light2', [ '/group/light1', '/group/light2' ] )
expressionCheck( '/group/light1\t/group/light2\n', [ '/group/light1', '/group/light2' ] )
expressionCheck( '(\n\t/group/light1\n\t/group/light2\n)\n|\nsetA', [ '/group/light1', '/group/light2', '/group/group/sphere1', '/group/group/sphere2' ] )
expressionCheck( '(\nsetA - \n(\n\t(\n\t\tsetC /group/group/sphere2\n\t)\n & setB)\n)\n', [ '/group/group/sphere1' ] )

# Test expressions containing only whitespace are treated as empty
expressionCheck( '', [] )
expressionCheck( ' ', [] )
expressionCheck( '\n', [] )
expressionCheck( ' \n ', [] )
expressionCheck( '\t', [] )
expressionCheck( ' \t ', [] )
expressionCheck( '\n \t', [] )
expressionCheck( '\t\n\t \n \t\n', [] )

# Test if proper exception is thrown for invalid expression
with self.assertRaises( RuntimeError ) as e :
# note the missing )
Expand Down
2 changes: 1 addition & 1 deletion src/GafferScene/SetAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ struct ExpressionGrammar : qi::grammar<Iterator, ExpressionAst(), ascii::space_t

void expressionToAST( const std::string &setExpression, ExpressionAst &ast)
{
if( setExpression == "" )
if( std::all_of( setExpression.begin(), setExpression.end(), isspace ) )
{
return;
}
Expand Down

0 comments on commit 9c929e0

Please sign in to comment.