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.159 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.158 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.157 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.156 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.155 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.154 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.153 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.152 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.151 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.150 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.149 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.148 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.147 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.146 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.145 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.144 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.143 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.142 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.141 tracks/cpp/exercises/bob/example.cpp
trackler-2.2.1.140 tracks/cpp/exercises/bob/example.cpp