From 31ccc33713e3ebd0fc0479d906f114ea33c5d616 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 13 Nov 2019 23:44:41 +0300 Subject: Add to_stream(ostream, path, bool) --- libbutl/path-io.mxx | 13 +++++++------ libbutl/path.ixx | 24 ++++++++++++++++++++++++ libbutl/path.mxx | 7 +++++++ 3 files changed, 38 insertions(+), 6 deletions(-) (limited to 'libbutl') diff --git a/libbutl/path-io.mxx b/libbutl/path-io.mxx index 5a91dac..a44d26b 100644 --- a/libbutl/path-io.mxx +++ b/libbutl/path-io.mxx @@ -31,16 +31,17 @@ import butl.path; LIBBUTL_MODEXPORT namespace butl { - // This is the default path IO implementation. It is separate to allo custom - // implementations. For example, we may want to print paths as relative to - // the working directory. Or we may want to print '~' for the home directory - // prefix. Or we may want to print dir_path with a trailing '/'. + // This is the default path IO implementation. It is separate to allow + // custom implementations. For example, we may want to print paths as + // relative to the working directory. Or we may want to print '~' for the + // home directory prefix. Or we may want to print dir_path with a trailing + // '/'. // template inline std::basic_ostream& operator<< (std::basic_ostream& os, const basic_path& p) { - return os << p.string (); + return to_stream (os, p, false /* representation */); } template @@ -49,6 +50,6 @@ LIBBUTL_MODEXPORT namespace butl { assert (!pn.empty ()); - return os << (pn.name ? *pn.name : pn.path->string ()); + return pn.name ? (os << *pn.name) : (os << *pn.path); } } diff --git a/libbutl/path.ixx b/libbutl/path.ixx index b91102a..165f06a 100644 --- a/libbutl/path.ixx +++ b/libbutl/path.ixx @@ -743,4 +743,28 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. return *this; } + + template + inline std::basic_ostream& + to_stream (std::basic_ostream& os, + const basic_path& p, + bool representation) + { + os << p.string (); + + if (representation) + { + C sep (p.separator ()); + +#ifndef _WIN32 + if (sep != 0 && !p.root ()) + os << sep; +#else + if (sep != 0) + os << sep; +#endif + } + + return os; + } } diff --git a/libbutl/path.mxx b/libbutl/path.mxx index 4ed6989..130419c 100644 --- a/libbutl/path.mxx +++ b/libbutl/path.mxx @@ -10,6 +10,7 @@ #ifndef __cpp_lib_modules_ts #include +#include #include // ptrdiff_t #include // uint16_t #include // move(), swap() @@ -1372,6 +1373,12 @@ LIBBUTL_MODEXPORT namespace butl empty () const {return path == nullptr && !name;} }; + template + std::basic_ostream& + to_stream (std::basic_ostream& os, + const basic_path& p, + bool representation); + // For operator<< (ostream) see the path-io header. template -- cgit v1.1