mirror of
https://github.com/boostorg/filesystem.git
synced 2026-01-29 07:32:12 +00:00
Use boost::io::quoted I/O manipulator as a better solution to embedded spaces. See #3863
[SVN r63136]
This commit is contained in:
@@ -21,11 +21,12 @@
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/io/detail/quoted_manip.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <cstring>
|
||||
#include <iosfwd> // needed by basic_path inserter and extractor
|
||||
#include <iosfwd>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
#include <locale>
|
||||
@@ -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 <class Char, class Traits>
|
||||
inline std::basic_ostream<Char, Traits>&
|
||||
operator<<(std::basic_ostream<Char, Traits>& os, const path& p)
|
||||
{
|
||||
os << p.string();
|
||||
return os;
|
||||
return os
|
||||
<< boost::io::quoted(p.string<std::basic_string<Char> >(), static_cast<Char>('&'));
|
||||
}
|
||||
|
||||
inline std::wostream& operator<<(std::wostream & os, const path& p)
|
||||
template <class Char, class Traits>
|
||||
inline std::basic_istream<Char, Traits>&
|
||||
operator>>(std::basic_istream<Char, Traits>& 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<Char> str;
|
||||
is >> boost::io::quoted(str, static_cast<Char>('&'));
|
||||
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);
|
||||
|
||||
@@ -1177,36 +1177,30 @@ const string_type external_directory_string() const { return native(); }</pre>
|
||||
<blockquote>
|
||||
<p><i>Returns:</i> <code>path(lhs) /= rhs</code>.</p>
|
||||
</blockquote>
|
||||
<h3> <a name="path-non-member-operators"><code><font size="4">path</font></code></a><a name="path-inserter-extractor"><span style="background-color: #FFFFFF"> inserters
|
||||
and extractor</span></a><span style="background-color: #FFFFFF">s</span></h3>
|
||||
<pre>std::ostream& operator<<(std::ostream & os, const path& p);</pre>
|
||||
<h3> <a name="path-non-member-operators"><code><font size="4">path</font></code></a><a name="path-inserter-extractor"><span style="background-color: #FFFFFF"> inserter
|
||||
and extractor</span></a></h3>
|
||||
<p> The inserter and extractor delimit the string with double-quotes (<code>"</code>)
|
||||
to ensure that paths with embedded spaces will round trip correctly. Ampersand (<code>&</code>)
|
||||
is used as an escape character, so the path can itself contain double quotes.</p>
|
||||
<pre>template <class Char, class Traits>
|
||||
std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const path& p)
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p><i><span style="background-color: #FFFFFF">Effects:</span></i><span style="background-color: #FFFFFF">
|
||||
<code>os << p.string();</code></span></p>
|
||||
<code>os << <a href="../../../io/doc/quoted_manip.html">
|
||||
boost::io::quoted</a>(p.string<std::basic_string<Char>>(), static_cast<Char>('&'));</code></span></p>
|
||||
<p><i><span style="background-color: #FFFFFF">Returns:</span></i><span style="background-color: #FFFFFF">
|
||||
</span> <code><span style="background-color: #FFFFFF">os</span></code></p>
|
||||
</blockquote>
|
||||
<pre>std::wostream& operator<<(std::wostream & os, const path& p);</pre>
|
||||
<blockquote style="font-size: 10pt">
|
||||
<p style="font-size: 10pt"><i><span style="background-color: #FFFFFF">Effects:</span></i><span style="background-color: #FFFFFF">
|
||||
<code>os << p.wstring();</code></span></p>
|
||||
<p style="font-size: 10pt"><i><span style="background-color: #FFFFFF">Returns:</span></i><span style="background-color: #FFFFFF">
|
||||
</span><code><span style="background-color: #FFFFFF">os</span></code></p>
|
||||
</blockquote>
|
||||
<pre>std::istream& operator>>(std::istream & is, path& p);</pre>
|
||||
<pre>template <class Char, class Traits>
|
||||
inline std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is, path& p)
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p><span style="background-color: #FFFFFF"><i>Effects: </i>
|
||||
<code> std::string str;<br>
|
||||
is >> str;<br>
|
||||
p = str;</code></span></p>
|
||||
<p><i><span style="background-color: #FFFFFF">Returns:</span></i><span style="background-color: #FFFFFF">
|
||||
</span> <code><span style="background-color: #FFFFFF">is</span></code></p>
|
||||
</blockquote>
|
||||
<pre>std::wistream& operator>>(std::wistream & is, path& p);</pre>
|
||||
<blockquote>
|
||||
<p><span style="background-color: #FFFFFF"><i>Effects: </i>
|
||||
<code> std::wstring str;<br>
|
||||
is >> str;<br>
|
||||
<p><span style="background-color: #FFFFFF"><i>Effects: </i>
|
||||
<code> std::basic_string<Char> str;<br>
|
||||
is >>
|
||||
<a href="../../../io/doc/quoted_manip.html">boost::io::quoted</a>(str,
|
||||
static_cast<Char>('&'));<br>
|
||||
p = str;</code></span></p>
|
||||
<p><i><span style="background-color: #FFFFFF">Returns:</span></i><span style="background-color: #FFFFFF">
|
||||
</span> <code><span style="background-color: #FFFFFF">is</span></code></p>
|
||||
@@ -3074,7 +3068,7 @@ multiple string types. His idea became the basis for the version 3 path design.<
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->04 June 2010<!--webbot bot="Timestamp" endspan i-checksum="17550" --></p>
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->20 June 2010<!--webbot bot="Timestamp" endspan i-checksum="17544" --></p>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ----------------------------------------------------------//
|
||||
|
||||
Reference in New Issue
Block a user