diff --git a/alib/src/regexp/Alternation.cpp b/alib/src/regexp/Alternation.cpp index 1c557224ef201ca8c1e2ab5ee399b75924b13457..81ff4f56fafce9c54c6968c92b424c3abceb9b58 100644 --- a/alib/src/regexp/Alternation.cpp +++ b/alib/src/regexp/Alternation.cpp @@ -106,5 +106,13 @@ bool Alternation::containsEmptyString() const { return false; } +bool Alternation::isEmpty() const { + for(const auto& e : getElements()) + if(!e->isEmpty()) + return true; + + return false; +} + } /* namespace regexp */ diff --git a/alib/src/regexp/Alternation.h b/alib/src/regexp/Alternation.h index 52b8f8c184f0c2255d188bf0c8246e247d36ffb8..e01aac375cc983a62132e240ede84e8b4d06837f 100644 --- a/alib/src/regexp/Alternation.h +++ b/alib/src/regexp/Alternation.h @@ -55,6 +55,11 @@ public: * @copydoc RegExpElement::containsEmptyString() const */ bool containsEmptyString() const; + + /** + * @copydoc RegExpElement::isEmpty() const + */ + bool isEmpty() const; }; } /* namespace regexp */ diff --git a/alib/src/regexp/Concatenation.cpp b/alib/src/regexp/Concatenation.cpp index c43e767dfd52427ce0667880013b4cab96d6cf7b..602ebde3c8a4d2386d1e0151a8e82ce3d02a2807 100644 --- a/alib/src/regexp/Concatenation.cpp +++ b/alib/src/regexp/Concatenation.cpp @@ -95,11 +95,19 @@ bool Concatenation::operator==(const Concatenation& other) const { } bool Concatenation::containsEmptyString() const { - for( const auto& e : getElements()) + for(const auto& e : getElements()) if( ! e->containsEmptyString()) return false; return true; } +bool Concatenation::isEmpty() const { + for(const auto& e : getElements()) + if(!e->isEmpty()) + return false; + + return true; +} + } /* namespace regexp */ diff --git a/alib/src/regexp/Concatenation.h b/alib/src/regexp/Concatenation.h index 9fead277d3acba1db41b8d4352fd87f643af69dd..55b465ed9aa4837af53c33238ff1dd5b8d9b3625 100644 --- a/alib/src/regexp/Concatenation.h +++ b/alib/src/regexp/Concatenation.h @@ -54,6 +54,11 @@ public: * @copydoc RegExpElement::containsEmptyString() const */ bool containsEmptyString() const; + + /** + * @copydoc RegExpElement::isEmpty() const + */ + bool isEmpty() const; }; } /* namespace regexp */ diff --git a/alib/src/regexp/Iteration.cpp b/alib/src/regexp/Iteration.cpp index 85e68a102533aab7f0d9ea8d9b7c689710441ad6..3495f4a6bc7ce31427106dad88f49e1bce2cd91e 100644 --- a/alib/src/regexp/Iteration.cpp +++ b/alib/src/regexp/Iteration.cpp @@ -97,5 +97,9 @@ bool Iteration::containsEmptyString() const { return true; } +bool Iteration::isEmpty() const { + return false; +} + } /* namespace regexp */ diff --git a/alib/src/regexp/Iteration.h b/alib/src/regexp/Iteration.h index 7466b2aedc4d440e2cd69eb8eb0ae3c939eb014c..f7b755113cae3a193680cf9b318bedf561e0be5a 100644 --- a/alib/src/regexp/Iteration.h +++ b/alib/src/regexp/Iteration.h @@ -62,6 +62,11 @@ public: * @copydoc RegExpElement::containsEmptyString() const */ bool containsEmptyString() const; + + /** + * @copydoc RegExpElement::isEmpty() const + */ + bool isEmpty() const; }; } /* namespace regexp */ diff --git a/alib/src/regexp/RegExp.cpp b/alib/src/regexp/RegExp.cpp index 2200f3999faf593907834c41f67a985f834aa29a..246a5ee7ebe1b436ba90201d255cdc9bf26def24 100644 --- a/alib/src/regexp/RegExp.cpp +++ b/alib/src/regexp/RegExp.cpp @@ -71,7 +71,7 @@ void RegExp::setRegExp(RegExpElement* regExp) { } bool RegExp::isEmpty() const { - return regExp == NULL || dynamic_cast<const RegExpEmpty*>(regExp); + return regExp == NULL || regExp->isEmpty(); } bool RegExp::containsEmptyString() const { diff --git a/alib/src/regexp/RegExpElement.h b/alib/src/regexp/RegExpElement.h index 69421fde011bed11460fac27446cdcd19303d794..58fe62bab16fe67c00d314a66a95d326bd6a4651 100644 --- a/alib/src/regexp/RegExpElement.h +++ b/alib/src/regexp/RegExpElement.h @@ -59,6 +59,11 @@ public: * @return true if this subtree of regexp matches empty string (epsilon) */ virtual bool containsEmptyString() const = 0; + + /** + * @return true if this subtree describes empty language + */ + virtual bool isEmpty() const = 0; }; } /* namespace regexp */ diff --git a/alib/src/regexp/RegExpEmpty.cpp b/alib/src/regexp/RegExpEmpty.cpp index f7b5ad4f952c27f20a6cb189a6fbe15a3cc1dc5b..553cfd650f50ed8d2b73f1c34247ab9d07b72285 100644 --- a/alib/src/regexp/RegExpEmpty.cpp +++ b/alib/src/regexp/RegExpEmpty.cpp @@ -57,5 +57,9 @@ bool RegExpEmpty::containsEmptyString() const { return false; } +bool RegExpEmpty::isEmpty() const { + return true; +} + } /* namespace regexp */ diff --git a/alib/src/regexp/RegExpEmpty.h b/alib/src/regexp/RegExpEmpty.h index 7fb80a8935aa801a0fc928214b2b62b2e33d2fec..3578afa59f530be6fe5ee65ecdd18f526b7a4087 100644 --- a/alib/src/regexp/RegExpEmpty.h +++ b/alib/src/regexp/RegExpEmpty.h @@ -41,6 +41,11 @@ public: * @copydoc RegExpElement::containsEmptyString() const */ bool containsEmptyString() const; + + /** + * @copydoc RegExpElement::isEmpty() const + */ + bool isEmpty() const; }; } /* namespace regexp */ diff --git a/alib/src/regexp/RegExpEpsilon.cpp b/alib/src/regexp/RegExpEpsilon.cpp index ff8fbb4b1234c3555e751c8d270cc7331743c38a..e102539f5fe874fd45961b58c222f1c6a41bca35 100644 --- a/alib/src/regexp/RegExpEpsilon.cpp +++ b/alib/src/regexp/RegExpEpsilon.cpp @@ -53,5 +53,9 @@ bool RegExpEpsilon::containsEmptyString() const { return true; } +bool RegExpEpsilon::isEmpty() const { + return false; +} + } /* namespace regexp */ diff --git a/alib/src/regexp/RegExpEpsilon.h b/alib/src/regexp/RegExpEpsilon.h index a7dced2eafa80ee1764f7489e1c0f4b9a1264d28..28b8a6c0a432ac69fe0773f0c86200d814ac6109 100644 --- a/alib/src/regexp/RegExpEpsilon.h +++ b/alib/src/regexp/RegExpEpsilon.h @@ -42,6 +42,11 @@ public: * @copydoc RegExpElement::containsEmptyString() const */ bool containsEmptyString() const; + + /** + * @copydoc RegExpElement::isEmpty() const + */ + bool isEmpty() const; }; } /* namespace regexp */ diff --git a/alib/src/regexp/RegExpSymbol.cpp b/alib/src/regexp/RegExpSymbol.cpp index 66b85aed26ddaea6d1ef5f231ecce58150e1c989..f71609fc715cc47d51ebbd7cab0a53f148e8fa1a 100644 --- a/alib/src/regexp/RegExpSymbol.cpp +++ b/alib/src/regexp/RegExpSymbol.cpp @@ -58,6 +58,10 @@ bool RegExpSymbol::containsEmptyString() const { return false; } +bool RegExpSymbol::isEmpty() const { + return false; +} + const string& RegExpSymbol::getSymbol() const { return this->symbol; } diff --git a/alib/src/regexp/RegExpSymbol.h b/alib/src/regexp/RegExpSymbol.h index 77d24348e9a0c17946f14fccbffe96484e6a5329..54e1b618aaa423dad5f4a93ae69904ca5f0ab17a 100644 --- a/alib/src/regexp/RegExpSymbol.h +++ b/alib/src/regexp/RegExpSymbol.h @@ -46,8 +46,13 @@ public: * @copydoc RegExpElement::containsEmptyString() const */ bool containsEmptyString() const; - + const string& getSymbol() const; + + /** + * @copydoc RegExpElement::isEmpty() const + */ + bool isEmpty() const; }; } /* namespace regexp */