diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-01 12:35:05 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-01 12:35:05 +0200 |
commit | 81c69fd1708e4326107e6a2716f0332a729136a8 (patch) | |
tree | 58cb6f8bc37fd5ade58575aba84d0c29a5b25262 /butl/path.txx | |
parent | ec5b8d561277b2a4b0ad02aa7f936d4d4b20c35f (diff) |
Add path::posix_string()&& overload, path::posix_representation()
Diffstat (limited to 'butl/path.txx')
-rw-r--r-- | butl/path.txx | 48 |
1 files changed, 41 insertions, 7 deletions
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 |