diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.hpp b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.hpp index debdc5886def150cff76529384f92d15bc49e5cc..6b2de0e07bb146b9a059a5f96902ad4f0320a1d2 100644 --- a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.hpp +++ b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.hpp @@ -441,7 +441,7 @@ bool RegExpOptimize::Unbounded < SymbolType >::V1( UnboundedRegExpIteration < Sy * @return bool true if optimization applied else false */ template < class SymbolType > -bool RegExpOptimize::Unbounded < SymbolType >::V2( UnboundedRegExpAlternation < SymbolType > & /* node */ ) { +bool RegExpOptimize::Unbounded < SymbolType >::V2( UnboundedRegExpAlternation < SymbolType > & node ) { bool optimized = false; /* @@ -449,7 +449,7 @@ bool RegExpOptimize::Unbounded < SymbolType >::V2( UnboundedRegExpAlternation < * We need also to cover the cases like ( a + b + d )* + ( e )* + a + b + c + e = ( a + b + d )* + ( e )* + c */ - /*ext::vector < const UnboundedRegExpElement < SymbolType > * > iterElements; + ext::vector < const UnboundedRegExpElement < SymbolType > * > iterElements; // cache iter elements because of operator invalidation after erase for( const UnboundedRegExpElement < SymbolType > & n : node.getElements ( ) ) { const UnboundedRegExpIteration < SymbolType > * iter = dynamic_cast < const UnboundedRegExpIteration < SymbolType > * > ( & n ); @@ -469,13 +469,13 @@ bool RegExpOptimize::Unbounded < SymbolType >::V2( UnboundedRegExpAlternation < return a == *n; }); - if( it == node.getChildren().end() ) { + if( it == node.getChildren ( ).end ( ) ) { continue; } optimized = true; - node.getChildren ( ).erase( it ); - }*/ + node.erase( it ); + } return optimized; } diff --git a/alib2algo/test-src/regexp/simplify/RegExpOptimizeTest.cpp b/alib2algo/test-src/regexp/simplify/RegExpOptimizeTest.cpp index 723c4d1bb11c1b279b8bc4d150594a5800763edb..995cf7d070daa8c54de0fc0a45f2db28c36a86c5 100644 --- a/alib2algo/test-src/regexp/simplify/RegExpOptimizeTest.cpp +++ b/alib2algo/test-src/regexp/simplify/RegExpOptimizeTest.cpp @@ -20,7 +20,8 @@ TEST_CASE ( "RegExp Optimize", "[unit][algo][regexp][simplify]" ) { std::make_pair ( "(a*b*)*", "(a+b)*" ), std::make_pair ( "#0*+a*", "a*" ), std::make_pair ( "a+(a+a)", "a" ), - std::make_pair ( "(a+b*)(a+b*)*", "(a+b)*" ) // implemented but skipped because ( a + b* )* gets simplified to ( a + b )* FIXME + std::make_pair ( "(a+b*)(a+b*)*", "(a+b)*" ), + std::make_pair ( "(a+b+d)*+e*+a+b+c+e", "c+e*+(a+b+d)*" ) // std::make_pair ( "(x y)*x", "x(y x)*" ), );