summaryrefslogtreecommitdiff
path: root/libformat/libformat/format.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libformat/libformat/format.cxx')
-rw-r--r--libformat/libformat/format.cxx11
1 files changed, 8 insertions, 3 deletions
diff --git a/libformat/libformat/format.cxx b/libformat/libformat/format.cxx
index de8a782..6450093 100644
--- a/libformat/libformat/format.cxx
+++ b/libformat/libformat/format.cxx
@@ -2,6 +2,7 @@
#include <cctype> // to{upper,lower}()
#include <algorithm> // transform()
+#include <stdexcept>
using namespace std;
@@ -10,9 +11,13 @@ namespace format
string
format_hello (const string& g, const string& n, volume v)
{
- string r (g);
+ if (const char* w = (g.empty () ? "empty greeting" :
+ n.empty () ? "empty name" : nullptr))
+ throw invalid_argument (w);
- transform (r.begin (), r.end (), r.begin (),
+ string h (g);
+
+ transform (h.begin (), h.end (), h.begin (),
[v] (char c) -> char
{
switch (v)
@@ -24,6 +29,6 @@ namespace format
return c;
});
- return r += ", " + n + '!';
+ return h += ", " + n + '!';
}
}