From 998233d7675c19df232f61d1a20d8a276073507f Mon Sep 17 00:00:00 2001
From: Beman Dawes
Date: Sun, 20 Jun 2010 13:41:26 +0000
Subject: [PATCH] Use boost::io::quoted I/O manipulator as a better solution to
embedded spaces. See #3863
[SVN r63136]
---
include/boost/filesystem/v3/path.hpp | 35 +++++++++-------------
v3/doc/reference.html | 44 ++++++++++++----------------
v3/test/msvc/filesystem-v3.sln | 10 +++++++
v3/test/path_unit_test.cpp | 10 +++++++
4 files changed, 53 insertions(+), 46 deletions(-)
diff --git a/include/boost/filesystem/v3/path.hpp b/include/boost/filesystem/v3/path.hpp
index b0c8519..9ff2869 100644
--- a/include/boost/filesystem/v3/path.hpp
+++ b/include/boost/filesystem/v3/path.hpp
@@ -21,11 +21,12 @@
#include
#include
#include
+#include
#include
#include
#include
#include
-#include // needed by basic_path inserter and extractor
+#include
#include
#include
#include
@@ -542,35 +543,27 @@ namespace filesystem3
inline path operator/(const path& lhs, const path& rhs) { return path(lhs) /= rhs; }
// inserters and extractors
+ // use boost::io::quoted() to handle spaces in paths
+ // use '&' as escape character to ease use for Windows paths
- inline std::ostream& operator<<(std::ostream & os, const path& p)
+ template
+ inline std::basic_ostream&
+ operator<<(std::basic_ostream& os, const path& p)
{
- os << p.string();
- return os;
+ return os
+ << boost::io::quoted(p.string >(), static_cast('&'));
}
- inline std::wostream& operator<<(std::wostream & os, const path& p)
+ template
+ inline std::basic_istream&
+ operator>>(std::basic_istream& is, path& p)
{
- os << p.wstring();
- return os;
- }
-
- inline std::istream& operator>>(std::istream & is, path& p)
- {
- std::string str;
- std::getline(is, str); // See ticket #3863
+ std::basic_string str;
+ is >> boost::io::quoted(str, static_cast('&'));
p = str;
return is;
}
- inline std::wistream& operator>>(std::wistream & is, path& p)
- {
- std::wstring str;
- std::getline(is, str); // See ticket #3863
- p = str;
- return is;
- }
-
// name_checks
BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string & name);
diff --git a/v3/doc/reference.html b/v3/doc/reference.html
index ff6b8f1..b30468b 100644
--- a/v3/doc/reference.html
+++ b/v3/doc/reference.html
@@ -1177,36 +1177,30 @@ const string_type external_directory_string() const { return native(); }
Returns: path(lhs) /= rhs.
-
-std::ostream& operator<<(std::ostream & os, const path& p);
+
+ The inserter and extractor delimit the string with double-quotes (")
+to ensure that paths with embedded spaces will round trip correctly. Ampersand (&)
+is used as an escape character, so the path can itself contain double quotes.
+template <class Char, class Traits>
+std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const path& p)
+
Effects:
- os << p.string();
+ os <<
+ boost::io::quoted(p.string<std::basic_string<Char>>(), static_cast<Char>('&'));
Returns:
os
-std::wostream& operator<<(std::wostream & os, const path& p);
-
- Effects:
- os << p.wstring();
- Returns:
- os
-
-std::istream& operator>>(std::istream & is, path& p);
+template <class Char, class Traits>
+inline std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is, path& p)
+
- Effects:
- std::string str;
- is >> str;
- p = str;
- Returns:
- is
-
-std::wistream& operator>>(std::wistream & is, path& p);
-
- Effects:
- std::wstring str;
- is >> str;
+ Effects:
+ std::basic_string<Char> str;
+ is >>
+ boost::io::quoted(str,
+ static_cast<Char>('&'));
p = str;
Returns:
is
@@ -3074,7 +3068,7 @@ multiple string types. His idea became the basis for the version 3 path design.<
Distributed under the Boost Software License, Version 1.0. See
www.boost.org/LICENSE_1_0.txt
Revised
-04 June 2010
+20 June 2010