summaryrefslogtreecommitdiff
path: root/libmformat/libmformat
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-07-20 08:55:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-07-20 08:55:31 +0200
commit0c71feb0363b337152f11e301303f85f9621c148 (patch)
treec87351ae473f43fff599061b9d1389f42357e0fd /libmformat/libmformat
parent28b92b59909030424420fefbca5a3f5df22337b5 (diff)
Add modularized version
Diffstat (limited to 'libmformat/libmformat')
-rw-r--r--libmformat/libmformat/buildfile15
-rw-r--r--libmformat/libmformat/format.cxx31
-rw-r--r--libmformat/libmformat/format.mxx13
3 files changed, 59 insertions, 0 deletions
diff --git a/libmformat/libmformat/buildfile b/libmformat/libmformat/buildfile
new file mode 100644
index 0000000..24acee5
--- /dev/null
+++ b/libmformat/libmformat/buildfile
@@ -0,0 +1,15 @@
+import libs = libstd-modules%liba{std-modules}
+
+lib{mformat}: {mxx cxx}{format} $libs
+
+# For pre-releases use the complete version to make sure they cannot be used
+# in place of another pre-release or the final version.
+#
+if $version.pre_release
+ lib{mformat}: bin.lib.version = @"-$version.project_id"
+else
+ lib{mformat}: bin.lib.version = @"-$version.major.$version.minor"
+
+# Install into the libmformat/ subdirectory of, say, /usr/include/.
+#
+install.include = $install.include/$project/
diff --git a/libmformat/libmformat/format.cxx b/libmformat/libmformat/format.cxx
new file mode 100644
index 0000000..fe6ad15
--- /dev/null
+++ b/libmformat/libmformat/format.cxx
@@ -0,0 +1,31 @@
+// file: libmformat/format.cxx -*- C++ -*-
+
+module format;
+
+import std.core; // transform()
+import std.io; // to{upper,lower}()
+
+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 + '!';
+ }
+}
diff --git a/libmformat/libmformat/format.mxx b/libmformat/libmformat/format.mxx
new file mode 100644
index 0000000..c1e69ee
--- /dev/null
+++ b/libmformat/libmformat/format.mxx
@@ -0,0 +1,13 @@
+// file: libmformat/format.mxx -*- C++ -*-
+
+export module format;
+
+import std.core;
+
+export namespace format
+{
+ enum class volume {quiet, normal, loud};
+
+ __symexport std::string
+ message (const std::string& greeting, const std::string& name, volume);
+}