2013-07-01 22:45:33 -04:00
|
|
|
#include "RegExState.h"
|
|
|
|
|
|
|
|
|
|
RegExState::RegExState(char inCharacter) {
|
|
|
|
|
character = inCharacter;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-02 13:14:40 -04:00
|
|
|
RegExState::RegExState() {
|
|
|
|
|
character = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-01 22:45:33 -04:00
|
|
|
RegExState::~RegExState() {
|
|
|
|
|
//No cleanup necessary
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RegExState::addNext(RegExState* nextState) {
|
|
|
|
|
nextStates.push_back(nextState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RegExState::characterIs(char inCharacter) {
|
|
|
|
|
return character == inCharacter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<RegExState*>* RegExState::advance(char advanceCharacter) {
|
|
|
|
|
std::vector<RegExState*>* advanceStates = new std::vector<RegExState*>();
|
|
|
|
|
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++) {
|
2015-06-08 21:47:02 -04:00
|
|
|
if (nextStates[i] != NULL && nextStates[i]->characterIs(advanceCharacter))
|
2013-07-01 22:45:33 -04:00
|
|
|
advanceStates->push_back(nextStates[i]);
|
|
|
|
|
}
|
|
|
|
|
return advanceStates;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 21:47:02 -04:00
|
|
|
std::vector<RegExState*> RegExState::getNextStates() {
|
|
|
|
|
return nextStates;
|
2013-07-07 02:13:05 -04:00
|
|
|
}
|
|
|
|
|
|
2013-07-01 22:45:33 -04:00
|
|
|
bool RegExState::isGoal() {
|
2013-07-03 23:40:36 -04:00
|
|
|
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++)
|
|
|
|
|
if (nextStates[i] == NULL)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
2013-07-01 22:45:33 -04:00
|
|
|
}
|
|
|
|
|
|
2013-07-02 01:47:42 -04:00
|
|
|
std::string RegExState::toString() {
|
2013-07-07 02:13:05 -04:00
|
|
|
std::vector<RegExState*> avoidList;
|
|
|
|
|
return toString(&avoidList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string RegExState::toString(RegExState* avoid) {
|
|
|
|
|
std::vector<RegExState*> avoidList;
|
|
|
|
|
avoidList.push_back(avoid);
|
|
|
|
|
return toString(&avoidList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string RegExState::toString(std::vector<RegExState*>* avoid) {
|
|
|
|
|
avoid->push_back(this);
|
2013-07-02 01:47:42 -04:00
|
|
|
std::string string = "";
|
2013-07-02 13:14:40 -04:00
|
|
|
string += std::string("\"") + character + "\"";
|
2013-07-07 02:13:05 -04:00
|
|
|
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++) {
|
|
|
|
|
bool inAvoid = false;
|
|
|
|
|
for (std::vector<RegExState*>::size_type j = 0; j < avoid->size(); j++) {
|
|
|
|
|
if (nextStates[i] == (*avoid)[j]) {
|
|
|
|
|
inAvoid = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (inAvoid) {
|
2013-07-10 23:50:53 -04:00
|
|
|
string += "->loop";
|
2013-07-07 02:13:05 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-03 23:40:36 -04:00
|
|
|
if (nextStates[i] != this && nextStates[i] != NULL)
|
2013-07-07 02:13:05 -04:00
|
|
|
string += "->" + nextStates[i]->toString(avoid) + " EC ";
|
2013-07-03 23:40:36 -04:00
|
|
|
else if (nextStates[i] == NULL)
|
|
|
|
|
string += "-> GOAL ";
|
|
|
|
|
else
|
|
|
|
|
string += "->this";
|
2013-07-07 02:13:05 -04:00
|
|
|
}
|
2013-07-02 01:47:42 -04:00
|
|
|
return string;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-07 02:13:05 -04:00
|
|
|
char RegExState::getCharacter() {
|
|
|
|
|
return character;
|
|
|
|
|
}
|