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.0.0.5 tracks/cpp/bob/example.cpp
trackler-2.0.0.4 tracks/cpp/bob/example.cpp
trackler-2.0.0.3 tracks/cpp/bob/example.cpp
trackler-2.0.0.2 tracks/cpp/bob/example.cpp
trackler-2.0.0.1 tracks/cpp/bob/example.cpp
trackler-2.0.0.0 tracks/cpp/bob/example.cpp
trackler-1.0.4.1 tracks/cpp/bob/example.cpp
trackler-1.0.4.0 tracks/cpp/bob/example.cpp
trackler-1.0.3.0 tracks/cpp/bob/example.cpp
trackler-1.0.2.1 tracks/cpp/bob/example.cpp
trackler-1.0.2.0 tracks/cpp/bob/example.cpp
trackler-1.0.1.2 tracks/cpp/bob/example.cpp
trackler-1.0.1.1 tracks/cpp/bob/example.cpp
trackler-1.0.1.0 tracks/cpp/bob/example.cpp
trackler-1.0.0.1 tracks/cpp/bob/example.cpp
trackler-1.0.0 tracks/cpp/bob/example.cpp