Sha256: ee9f848cd587f7fb2637871f31a6f5d6281400ffd0294d60054f8adec29dd237

Contents?: true

Size: 1.06 KB

Versions: 396

Compression:

Stored size: 1.06 KB

Contents

#include "bob.h"
#include <boost/algorithm/string/trim.hpp>
#include <algorithm>
#include <cctype>
#include <iterator>

using namespace std;

namespace bob
{
namespace
{

bool is_upper(string const& text)
{
    auto last = end(text);
    auto it = find_if_not(begin(text), last,
        [](char c) { return c == toupper(c); });
    return it == last;
}

bool has_alpha(string const& text)
{
    auto last = end(text);
    auto it = find_if(begin(text), last, [](char c) { return isalpha(c) != 0; });
    return it != last;
}

bool is_shouting(string const &text)
{
    return is_upper(text) && has_alpha(text);
}

bool is_question(string const &text)
{
    return boost::algorithm::trim_copy(text).back() == '?';
}

bool is_silence(string const& text)
{
    return boost::algorithm::trim_copy(text).length() == 0;
}

}

string hey(string const& text)
{
    if (is_silence(text)) {
        return "Fine. Be that way!";
    }
    if (is_shouting(text)) {
        return "Whoa, chill out!";
    }
    if (is_question(text)) {
        return "Sure.";
    }
    return "Whatever.";
}

}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.179 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.178 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.177 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.176 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.175 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.174 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.173 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.172 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.171 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.170 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.169 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.167 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.166 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.165 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.164 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.163 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.162 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.161 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.160 tracks/cpp/exercises/bob/example.cpp