57 lines
949 B
C++
57 lines
949 B
C++
#include "bob.h"
|
|
|
|
#include <algorithm>
|
|
#include <locale>
|
|
#include <string>
|
|
|
|
namespace bob {
|
|
|
|
|
|
using namespace std;
|
|
|
|
namespace {
|
|
|
|
void trim_spaces(string &str)
|
|
{
|
|
str.erase(remove_if(str.begin(), str.end(),
|
|
[](char c){return isspace(static_cast<unsigned char>(c));}),
|
|
str.end());
|
|
}
|
|
|
|
string to_uppercase(const string &str)
|
|
{
|
|
string result = str;
|
|
for (auto & c: result)
|
|
c = toupper(c);
|
|
|
|
return result;
|
|
}
|
|
|
|
bool has_alpha(const string &str)
|
|
{
|
|
return find_if(str.begin(), str.end(),
|
|
[](char c){return isalpha(static_cast<unsigned char>(c));}) != str.end();
|
|
}
|
|
|
|
}
|
|
|
|
const char * hey(const char input[])
|
|
{
|
|
|
|
string str(input);
|
|
trim_spaces(str);
|
|
|
|
if (str.empty())
|
|
return "Fine. Be that way!";
|
|
|
|
if (has_alpha(str) && str == to_uppercase(str))
|
|
return "Whoa, chill out!";
|
|
|
|
if ('?' == str.back())
|
|
return "Sure.";
|
|
|
|
return "Whatever.";
|
|
}
|
|
|
|
}
|
|
|