summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libformat/libformat/buildfile2
-rw-r--r--libformat/libformat/format.cxx26
-rw-r--r--libformat/libformat/format.hxx9
-rw-r--r--libformat/tests/test/driver.cxx5
-rw-r--r--libformat/tests/test/test.out2
5 files changed, 37 insertions, 7 deletions
diff --git a/libformat/libformat/buildfile b/libformat/libformat/buildfile
index 4f6f156..55c918a 100644
--- a/libformat/libformat/buildfile
+++ b/libformat/libformat/buildfile
@@ -18,4 +18,4 @@ libs{format}: cxx.export.poptions += -DLIBFORMAT_SHARED
# Install into the libformat/ subdirectory of, say, /usr/include/.
#
-install.include = $install.include/libformat/
+install.include = $install.include/$project/
diff --git a/libformat/libformat/format.cxx b/libformat/libformat/format.cxx
index 421f50d..53530a8 100644
--- a/libformat/libformat/format.cxx
+++ b/libformat/libformat/format.cxx
@@ -2,10 +2,30 @@
#include <libformat/format.hxx>
+#include <cctype> // to{upper,lower}()
+#include <algorithm> // transform()
+
using namespace std;
-string
-format (const string& g, const string& n)
+namespace format
{
- return g + ", " + n + '!';
+ 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 + '!';
+ }
}
diff --git a/libformat/libformat/format.hxx b/libformat/libformat/format.hxx
index 9c813ac..c711c16 100644
--- a/libformat/libformat/format.hxx
+++ b/libformat/libformat/format.hxx
@@ -6,5 +6,10 @@
#include <libformat/export.hxx>
-LIBFORMAT_EXPORT std::string
-format (const std::string& greeting, const std::string& name);
+namespace format
+{
+ enum class volume {quiet, normal, loud};
+
+ LIBFORMAT_EXPORT std::string
+ message (const std::string& greeting, const std::string& name, volume);
+}
diff --git a/libformat/tests/test/driver.cxx b/libformat/tests/test/driver.cxx
index fb2939d..1cf2959 100644
--- a/libformat/tests/test/driver.cxx
+++ b/libformat/tests/test/driver.cxx
@@ -8,6 +8,9 @@ int
main ()
{
using namespace std;
+ using namespace format;
- cout << format ("Hello", "World") << endl;
+ cout << message ("Hello", "World", volume::quiet) << endl;
+ cout << message ("Hello", "World", volume::normal) << endl;
+ cout << message ("Hello", "World", volume::loud) << endl;
}
diff --git a/libformat/tests/test/test.out b/libformat/tests/test/test.out
index 8ab686e..7ce133b 100644
--- a/libformat/tests/test/test.out
+++ b/libformat/tests/test/test.out
@@ -1 +1,3 @@
+hello, World!
Hello, World!
+HELLO, World!