From e5054cd174da50e07a3f8300cd5a11780af6d3e3 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Mon, 11 Mar 2019 09:55:28 +0100
Subject: [PATCH] allow another regexp optimization rule

---
 .../regexp/simplify/RegExpOptimizeUnboundedPart.hpp    | 10 +++++-----
 .../test-src/regexp/simplify/RegExpOptimizeTest.cpp    |  3 ++-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.hpp b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.hpp
index debdc5886d..6b2de0e07b 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 723c4d1bb1..995cf7d070 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)*" ),
 				);
 
-- 
GitLab