aboutsummaryrefslogtreecommitdiff
path: root/build2/name.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-11-30 17:32:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-30 17:32:43 +0200
commitbe14801929cf2a6caced87df034ae12a85f42aa6 (patch)
tree74670e0a746961424e50c09449d526e143c1abfc /build2/name.cxx
parent4b31ef06275ad423e48a75d15fb0ee21c3127e3c (diff)
Add support for typed/untyped concatenated expansion
Diffstat (limited to 'build2/name.cxx')
-rw-r--r--build2/name.cxx54
1 files changed, 50 insertions, 4 deletions
diff --git a/build2/name.cxx b/build2/name.cxx
index 5f6762d..1e5f5e4 100644
--- a/build2/name.cxx
+++ b/build2/name.cxx
@@ -12,6 +12,49 @@
namespace build2
{
+ string
+ to_string (const name& n)
+ {
+ string r;
+
+ // Note: similar to to_stream() below.
+ //
+ if (n.empty ())
+ return r;
+
+ if (n.proj != nullptr)
+ {
+ r += *n.proj;
+ r += '%';
+ }
+
+ // If the value is empty, then we want to put the directory inside {},
+ // e.g., dir{bar/}, not bar/dir{}.
+ //
+ bool d (!n.dir.empty ());
+ bool v (!n.value.empty ());
+ bool t (!n.type.empty ());
+
+ if (v && d)
+ r += n.dir.representation ();
+
+ if (t)
+ {
+ r += n.type;
+ r += '{';
+ }
+
+ if (v)
+ r += n.value;
+ else
+ r += n.dir.representation ();
+
+ if (t)
+ r += '}';
+
+ return r;
+ }
+
ostream&
to_stream (ostream& os, const name& n, bool quote, char pair)
{
@@ -62,9 +105,12 @@ namespace build2
os << d;
};
+ // Note: similar to to_string() below.
+ //
+
// If quoted then print empty name as '' rather than {}.
//
- if (quote && n.empty () && n.proj == nullptr)
+ if (quote && n.empty ())
return os << "''";
if (n.proj != nullptr)
@@ -73,9 +119,9 @@ namespace build2
os << '%';
}
- // If the value is empty, then we want to print the directory
- // inside {}, e.g., dir{bar/}, not bar/dir{}. We also want to
- // print {} for an empty name (unless quoted).
+ // If the value is empty, then we want to print the directory inside {},
+ // e.g., dir{bar/}, not bar/dir{}. We also want to print {} for an empty
+ // name (unless quoted).
//
bool d (!n.dir.empty ());
bool v (!n.value.empty ());