diff --git a/alib2/src/regexp/RegExp.cpp b/alib2/src/regexp/RegExp.cpp index 7f10b79b735cfd7e68644e798a2a77614235aa29..fdf21207752d588fc5705d53ad15f4fe611afd2e 100644 --- a/alib2/src/regexp/RegExp.cpp +++ b/alib2/src/regexp/RegExp.cpp @@ -64,7 +64,7 @@ RegExp& RegExp::operator=(const RegExp& other) { RegExp& RegExp::operator=(RegExp&& other) noexcept { std::swap(this->regExp, other.regExp); - + std::swap(this->alphabet, other.alphabet); return *this; } @@ -98,10 +98,8 @@ const std::set<alphabet::Symbol>& RegExp::getAlphabet() const { return alphabet; } -void RegExp::addSymbolToAlphabet(const alphabet::Symbol & symbol) { - std::pair<std::set<alphabet::Symbol>::iterator, bool> ret = alphabet.insert(symbol); - if (!ret.second) - throw alib::AlibException("Symbol \"" + (std::string) symbol + "\" is already in the alphabet."); +bool RegExp::addSymbolToAlphabet(const alphabet::Symbol & symbol) { + return alphabet.insert(symbol).second; } void RegExp::setAlphabet(const std::set<alphabet::Symbol> & symbols) { @@ -116,13 +114,11 @@ void RegExp::setAlphabet(const std::set<alphabet::Symbol> & symbols) { this->alphabet = symbols; } -void RegExp::removeSymbolFromAlphabet(const alphabet::Symbol & symbol) { +bool RegExp::removeSymbolFromAlphabet(const alphabet::Symbol & symbol) { if(this->regExp->testSymbol(symbol)) throw alib::AlibException("Input symbol \"" + (std::string) symbol + "\" is used."); - int removed = alphabet.erase(symbol); - if (!removed) - throw alib::AlibException("Input symbol \"" + (std::string) symbol + "\" doesn't exist."); + return alphabet.erase(symbol); } bool RegExp::isEmpty() const { diff --git a/alib2/src/regexp/RegExp.h b/alib2/src/regexp/RegExp.h index 99b900f099509f16025ca117ad89b20c7d8afcd1..f213e33c20f49a4e00b0b0f154a31ef64a5c8594 100644 --- a/alib2/src/regexp/RegExp.h +++ b/alib2/src/regexp/RegExp.h @@ -79,7 +79,7 @@ public: * Adds symbol to the alphabet available in the regular expression * @param symbol new symbol added to the alphabet */ - void addSymbolToAlphabet(const alphabet::Symbol & symbol); + bool addSymbolToAlphabet(const alphabet::Symbol & symbol); /** * Sets the alphabet of the regular expression @@ -91,7 +91,7 @@ public: * Removes symbol from the alphabet of symbol available in the regular expression * @param symbol removed symbol from the alphabet */ - void removeSymbolFromAlphabet(const alphabet::Symbol & symbol); + bool removeSymbolFromAlphabet(const alphabet::Symbol & symbol); /** * @return true if regexp represents empty language