aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-01 12:35:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-01 12:35:05 +0200
commit81c69fd1708e4326107e6a2716f0332a729136a8 (patch)
tree58cb6f8bc37fd5ade58575aba84d0c29a5b25262
parentec5b8d561277b2a4b0ad02aa7f936d4d4b20c35f (diff)
Add path::posix_string()&& overload, path::posix_representation()
-rw-r--r--butl/path13
-rw-r--r--butl/path.ixx23
-rw-r--r--butl/path.txx48
3 files changed, 73 insertions, 11 deletions
diff --git a/butl/path b/butl/path
index d5b4407..d2d33b8 100644
--- a/butl/path
+++ b/butl/path
@@ -18,8 +18,6 @@ namespace butl
{
// Wish list/ideas for improvements.
//
- // - posix_representation() in addition to posix_string()
- //
// - Ability to convert to directory/leaf/base in-place, without dynamic
// allocation. One idea is something like this:
//
@@ -822,7 +820,16 @@ namespace butl
// c:\foo), this function will throw the invalid_path exception.
//
string_type
- posix_string () const;
+ posix_string () const&;
+
+ string_type
+ posix_representation () const&;
+
+ string_type
+ posix_string () &&;
+
+ string_type
+ posix_representation () &&;
// Implementation details.
//
diff --git a/butl/path.ixx b/butl/path.ixx
index a90922a..26a9b3d 100644
--- a/butl/path.ixx
+++ b/butl/path.ixx
@@ -296,10 +296,31 @@ namespace butl
#ifndef _WIN32
template <typename C, typename K>
inline typename basic_path<C, K>::string_type basic_path<C, K>::
- posix_string () const
+ posix_string () const&
{
return string ();
}
+
+ template <typename C, typename K>
+ inline typename basic_path<C, K>::string_type basic_path<C, K>::
+ posix_string () &&
+ {
+ return std::move (*this).string ();
+ }
+
+ template <typename C, typename K>
+ inline typename basic_path<C, K>::string_type basic_path<C, K>::
+ posix_representation () const&
+ {
+ return representation ();
+ }
+
+ template <typename C, typename K>
+ inline typename basic_path<C, K>::string_type basic_path<C, K>::
+ posix_representation () &&
+ {
+ return std::move (*this).representation ();
+ }
#endif
template <typename C, typename K>
diff --git a/butl/path.txx b/butl/path.txx
index 44c03c3..1653dc0 100644
--- a/butl/path.txx
+++ b/butl/path.txx
@@ -5,6 +5,10 @@
#include <vector>
#include <cassert>
+#ifdef _WIN32
+# include <algorithm> // replace()
+#endif
+
namespace butl
{
template <typename C, typename K>
@@ -59,19 +63,49 @@ namespace butl
#ifdef _WIN32
template <typename C, typename K>
typename basic_path<C, K>::string_type basic_path<C, K>::
- posix_string () const
+ posix_string () const&
{
if (absolute ())
throw invalid_basic_path<C> (this->path_);
- string_type r (this->path_);
+ string_type r (string ());
+ replace (r.begin (), r.end (), '\\', '/');
+ return r;
+ }
- // Translate Windows-style separators to the POSIX ones.
- //
- for (size_type i (0), n (r.size ()); i != n; ++i)
- if (r[i] == '\\')
- r[i] = '/';
+ template <typename C, typename K>
+ typename basic_path<C, K>::string_type basic_path<C, K>::
+ posix_string () &&
+ {
+ if (absolute ())
+ throw invalid_basic_path<C> (this->path_);
+
+ string_type r (std::move (*this).string ());
+ replace (r.begin (), r.end (), '\\', '/');
+ return r;
+ }
+
+ template <typename C, typename K>
+ typename basic_path<C, K>::string_type basic_path<C, K>::
+ posix_representation () const&
+ {
+ if (absolute ())
+ throw invalid_basic_path<C> (this->path_);
+
+ string_type r (representation ());
+ replace (r.begin (), r.end (), '\\', '/');
+ return r;
+ }
+
+ template <typename C, typename K>
+ typename basic_path<C, K>::string_type basic_path<C, K>::
+ posix_representation () &&
+ {
+ if (absolute ())
+ throw invalid_basic_path<C> (this->path_);
+ string_type r (std::move (*this).representation ());
+ replace (r.begin (), r.end (), '\\', '/');
return r;
}
#endif