From d6ba871fb31062c8eff9ca530d6cc062c56fb85d Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 31 Mar 2014 12:01:17 +0200 Subject: [PATCH] fix for issue 12 --- aconversions/src/re2fa/Brzozowski.cpp | 14 +++++--------- alib/src/regexp/Alternation.cpp | 9 +++++---- alib/src/regexp/Concatenation.cpp | 9 +++++---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/aconversions/src/re2fa/Brzozowski.cpp b/aconversions/src/re2fa/Brzozowski.cpp index f1fb9f587e..42beed5d6e 100644 --- a/aconversions/src/re2fa/Brzozowski.cpp +++ b/aconversions/src/re2fa/Brzozowski.cpp @@ -6,6 +6,7 @@ */ #include "Brzozowski.h" +#include <iostream> using namespace alib; using namespace automaton; @@ -68,10 +69,7 @@ FSM Brzozowski::convert( void ) } } - // FIXME sometimes crashes upon regexp comparsion - ?? issue #22 - // Q.insert( Qi.at( i ).begin( ), Qi.at( i ).end( ) ); - for( const auto & r : Qi.at( i ) ) - Q.insert( r ); + Q.insert( Qi.at( i ).begin( ), Qi.at( i ).end( ) ); i += 1; } @@ -129,11 +127,9 @@ Brzozowski::StateBuilder::StateBuilder( const set<RegExp> & Q ) const State & Brzozowski::StateBuilder::getState( const RegExp & re ) const { - // FIXME map::find() does not work! see gitlab issue #12 - for( const auto & kv : m_states ) - if( kv.first == re ) - return kv.second; - + auto state = m_states.find( re ); + if( state != m_states.end() ) return state->second; + throw AlibException( "Brzozowski::StateBuilder - Regular expression not found!" ); } diff --git a/alib/src/regexp/Alternation.cpp b/alib/src/regexp/Alternation.cpp index 180d2413f4..aac9219f55 100644 --- a/alib/src/regexp/Alternation.cpp +++ b/alib/src/regexp/Alternation.cpp @@ -80,10 +80,11 @@ bool Alternation::operator<(const Alternation& other) const { auto thisIter = this->elements.begin(); auto otherIter = other.elements.begin(); for(; thisIter != this->elements.end(); thisIter++, otherIter++) { - if(**thisIter < **otherIter) return true; + if(**thisIter != **otherIter) break; } + if(thisIter == this->elements.end()) return false; - return false; + return **thisIter < **otherIter; } bool Alternation::operator==(const Alternation& other) const { @@ -103,7 +104,7 @@ bool Alternation::containsEmptyString() const { if(e->containsEmptyString()) return true; - return false; + return false; // alternation of zero regexps is empty } bool Alternation::isEmpty() const { @@ -111,7 +112,7 @@ bool Alternation::isEmpty() const { if(!e->isEmpty()) return false; - return true; + return true; // alternation of zero regexps is empty } } /* namespace regexp */ diff --git a/alib/src/regexp/Concatenation.cpp b/alib/src/regexp/Concatenation.cpp index d06806fcf2..087f14074e 100644 --- a/alib/src/regexp/Concatenation.cpp +++ b/alib/src/regexp/Concatenation.cpp @@ -76,10 +76,11 @@ bool Concatenation::operator<(const Concatenation& other) const { auto thisIter = this->elements.begin(); auto otherIter = other.elements.begin(); for(; thisIter != this->elements.end(); thisIter++, otherIter++) { - if(**thisIter < **otherIter) return true; + if(**thisIter != **otherIter) break; } + if(thisIter == this->elements.end()) return false; - return false; + return **thisIter < **otherIter; } bool Concatenation::operator==(const Concatenation& other) const { @@ -99,7 +100,7 @@ bool Concatenation::containsEmptyString() const { if( ! e->containsEmptyString()) return false; - return true; + return true; // concatenation of zero regexps is epsilon } bool Concatenation::isEmpty() const { @@ -107,7 +108,7 @@ bool Concatenation::isEmpty() const { if(e->isEmpty()) return true; - return false; + return false; // concatenation of zero regexps is epsilon } } /* namespace regexp */ -- GitLab