d05 ex03 handle weird request as long as they contains form name
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
*********************************************/
|
||||
|
||||
const t_formModel Intern::_chooseForm[] = {
|
||||
{"Shrubbery", Intern::makeShrubbery},
|
||||
{"Presidential", Intern::makePresidential},
|
||||
{"Robotomy", Intern::makeRobotomy}
|
||||
{"shrubbery", Intern::makeShrubbery},
|
||||
{"presidential", Intern::makePresidential},
|
||||
{"robotomy", Intern::makeRobotomy}
|
||||
};
|
||||
|
||||
/*********************************************
|
||||
@@ -44,18 +44,6 @@ Intern & Intern::operator=( Intern const & rhs __attribute__((unused))) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
//std::ostream & operator<<(std::ostream & o, Intern const & rhs)
|
||||
//{
|
||||
// o << rhs.getFoo();
|
||||
// return (o);
|
||||
//}
|
||||
|
||||
/*********************************************
|
||||
* ACCESSORS
|
||||
*********************************************/
|
||||
|
||||
//std::string Intern::getFoo() const {return _foo;}
|
||||
|
||||
/*********************************************
|
||||
* PRIVATE MEMBER FUNCTIONS
|
||||
*********************************************/
|
||||
@@ -64,7 +52,7 @@ AForm * Intern::makeForm(std::string formName, std::string formTarget) const {
|
||||
unsigned int len = sizeof _chooseForm / sizeof _chooseForm[0];
|
||||
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
if (!formName.compare(_chooseForm[i].name))
|
||||
if (isValidForm(formName, i))
|
||||
{
|
||||
std::cout << "Intern creates " << formName << "\n";
|
||||
return _chooseForm[i].create(formTarget);
|
||||
@@ -73,6 +61,16 @@ AForm * Intern::makeForm(std::string formName, std::string formTarget) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool Intern::isValidForm(std::string name, unsigned int i) const {
|
||||
// to lowercase :
|
||||
// https://stackoverflow.com/questions/313970/how-to-convert-an-instance-of-stdstring-to-lower-case
|
||||
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
|
||||
|
||||
if (name.find(_chooseForm[i].name) == std::string::npos)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*********************************************
|
||||
* PUBLIC MEMBER FUNCTIONS
|
||||
*********************************************/
|
||||
@@ -84,10 +82,3 @@ AForm * Intern::makePresidential(std::string const &target) {
|
||||
AForm * Intern::makeRobotomy(std::string const &target) {
|
||||
return new RobotomyRequestForm(target);}
|
||||
|
||||
/*********************************************
|
||||
* NESTED CLASS
|
||||
*********************************************/
|
||||
|
||||
//void Intern::Class::function() {}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user