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.

-

path inserters - and extractors

-
std::ostream& operator<<(std::ostream & os, const path& p);
+

path inserter + and extractor

+

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

diff --git a/v3/test/msvc/filesystem-v3.sln b/v3/test/msvc/filesystem-v3.sln index 77e3e0e..33d5980 100644 --- a/v3/test/msvc/filesystem-v3.sln +++ b/v3/test/msvc/filesystem-v3.sln @@ -86,6 +86,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tut4", "tut4\tut4.vcproj", {FFD738F7-96F0-445C-81EA-551665EF53D1} = {FFD738F7-96F0-445C-81EA-551665EF53D1} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hebrew_example", "hebrew_example\hebrew_example.vcproj", "{F9F236A2-8B57-415A-8397-7145144400F5}" + ProjectSection(ProjectDependencies) = postProject + {F94CCADD-A90B-480C-A304-C19D015D36B1} = {F94CCADD-A90B-480C-A304-C19D015D36B1} + {FFD738F7-96F0-445C-81EA-551665EF53D1} = {FFD738F7-96F0-445C-81EA-551665EF53D1} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -152,6 +158,10 @@ Global {256EA89A-E073-4CE8-B675-BE2FBC6B2691}.Debug|Win32.Build.0 = Debug|Win32 {256EA89A-E073-4CE8-B675-BE2FBC6B2691}.Release|Win32.ActiveCfg = Release|Win32 {256EA89A-E073-4CE8-B675-BE2FBC6B2691}.Release|Win32.Build.0 = Release|Win32 + {F9F236A2-8B57-415A-8397-7145144400F5}.Debug|Win32.ActiveCfg = Debug|Win32 + {F9F236A2-8B57-415A-8397-7145144400F5}.Debug|Win32.Build.0 = Debug|Win32 + {F9F236A2-8B57-415A-8397-7145144400F5}.Release|Win32.ActiveCfg = Release|Win32 + {F9F236A2-8B57-415A-8397-7145144400F5}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/v3/test/path_unit_test.cpp b/v3/test/path_unit_test.cpp index 75be2b8..0df8311 100644 --- a/v3/test/path_unit_test.cpp +++ b/v3/test/path_unit_test.cpp @@ -398,6 +398,16 @@ namespace ss << p1; ss >> p2; CHECK(p1 == p2); + + path wp1(L"foo bar"); + path wp2; + + std::wstringstream wss; + + CHECK(wp1 != wp2); + wss << wp1; + wss >> wp2; + CHECK(wp1 == wp2); } // test_other_non_members ----------------------------------------------------------//