summaryrefslogtreecommitdiff
path: root/libformat/libformat/format.cxx
blob: 53530a850655798dfa18bd271573635ac36decf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// file: libformat/format.cxx -*- C++ -*-

#include <libformat/format.hxx>

#include <cctype>     // to{upper,lower}()
#include <algorithm>  // transform()

using namespace std;

namespace format
{
  string
  message (const string& g, const string& n, volume v)
  {
    string r (g);

    auto tr = [&r] (char (*t) (char))
    {
      transform (r.begin (), r.end (), r.begin (), t);
    };

    switch (v)
    {
    case volume::quiet:  tr ([](char c) -> char {return tolower (c);}); break;
    case volume::normal:                                                break;
    case volume::loud:   tr ([](char c) -> char {return toupper (c);}); break;
    }

    return r += ", " + n + '!';
  }
}