aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/functions-builtin.cxx11
-rw-r--r--build2/name.hxx7
-rw-r--r--build2/name.ixx14
3 files changed, 30 insertions, 2 deletions
diff --git a/build2/functions-builtin.cxx b/build2/functions-builtin.cxx
index d6d9501..03f3592 100644
--- a/build2/functions-builtin.cxx
+++ b/build2/functions-builtin.cxx
@@ -11,13 +11,20 @@ using namespace std;
namespace build2
{
- // Return NULL value if an environment variable is not set.
+ // Return NULL value if an environment variable is not set, untyped value
+ // otherwise.
//
static inline value
getenv (const string& name)
{
const char* v (::getenv (name.c_str ()));
- return v != nullptr ? value (v) : value ();
+
+ if (v == nullptr)
+ return value ();
+
+ names r;
+ r.emplace_back (to_name (v));
+ return value (move (r));
}
void
diff --git a/build2/name.hxx b/build2/name.hxx
index c341cc9..388415b 100644
--- a/build2/name.hxx
+++ b/build2/name.hxx
@@ -104,6 +104,13 @@ namespace build2
string
to_string (const name&);
+ // Store a string in a name in a reversible way. If the string ends with a
+ // trailing directory separator then it is stored as a directory, otherwise
+ // as a simple name.
+ //
+ name
+ to_name (string);
+
// Serialize the name to the stream. If requested, the name components
// containing special characters are quoted. The special characters are:
//
diff --git a/build2/name.ixx b/build2/name.ixx
index c77846a..ef59442 100644
--- a/build2/name.ixx
+++ b/build2/name.ixx
@@ -23,4 +23,18 @@ namespace build2
return r;
}
+
+ inline name
+ to_name (string s)
+ {
+ if (!s.empty () && path::traits::is_separator (s.back ()))
+ {
+ dir_path d (move (s), dir_path::exact);
+
+ if (!d.empty ())
+ return name (move (d));
+ }
+
+ return name (move (s));
+ }
}