Skip to content
Snippets Groups Projects
Commit e6210290 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

do not throw when manipulating with sets in regexp

parent 250438ff
No related branches found
No related tags found
No related merge requests found
...@@ -64,7 +64,7 @@ RegExp& RegExp::operator=(const RegExp& other) { ...@@ -64,7 +64,7 @@ RegExp& RegExp::operator=(const RegExp& other) {
   
RegExp& RegExp::operator=(RegExp&& other) noexcept { RegExp& RegExp::operator=(RegExp&& other) noexcept {
std::swap(this->regExp, other.regExp); std::swap(this->regExp, other.regExp);
std::swap(this->alphabet, other.alphabet);
return *this; return *this;
} }
   
...@@ -98,10 +98,8 @@ const std::set<alphabet::Symbol>& RegExp::getAlphabet() const { ...@@ -98,10 +98,8 @@ const std::set<alphabet::Symbol>& RegExp::getAlphabet() const {
return alphabet; return alphabet;
} }
   
void RegExp::addSymbolToAlphabet(const alphabet::Symbol & symbol) { bool RegExp::addSymbolToAlphabet(const alphabet::Symbol & symbol) {
std::pair<std::set<alphabet::Symbol>::iterator, bool> ret = alphabet.insert(symbol); return alphabet.insert(symbol).second;
if (!ret.second)
throw alib::AlibException("Symbol \"" + (std::string) symbol + "\" is already in the alphabet.");
} }
   
void RegExp::setAlphabet(const std::set<alphabet::Symbol> & symbols) { void RegExp::setAlphabet(const std::set<alphabet::Symbol> & symbols) {
...@@ -116,13 +114,11 @@ 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; this->alphabet = symbols;
} }
   
void RegExp::removeSymbolFromAlphabet(const alphabet::Symbol & symbol) { bool RegExp::removeSymbolFromAlphabet(const alphabet::Symbol & symbol) {
if(this->regExp->testSymbol(symbol)) if(this->regExp->testSymbol(symbol))
throw alib::AlibException("Input symbol \"" + (std::string) symbol + "\" is used."); throw alib::AlibException("Input symbol \"" + (std::string) symbol + "\" is used.");
int removed = alphabet.erase(symbol); return alphabet.erase(symbol);
if (!removed)
throw alib::AlibException("Input symbol \"" + (std::string) symbol + "\" doesn't exist.");
} }
   
bool RegExp::isEmpty() const { bool RegExp::isEmpty() const {
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
* Adds symbol to the alphabet available in the regular expression * Adds symbol to the alphabet available in the regular expression
* @param symbol new symbol added to the alphabet * @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 * Sets the alphabet of the regular expression
...@@ -91,7 +91,7 @@ public: ...@@ -91,7 +91,7 @@ public:
* Removes symbol from the alphabet of symbol available in the regular expression * Removes symbol from the alphabet of symbol available in the regular expression
* @param symbol removed symbol from the alphabet * @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 * @return true if regexp represents empty language
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment