Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77571 - in trunk/libs/filesystem: doc doc/src src test
From: bdawes_at_[hidden]
Date: 2012-03-26 17:19:37


Author: bemandawes
Date: 2012-03-26 17:19:36 EDT (Mon, 26 Mar 2012)
New Revision: 77571
URL: http://svn.boost.org/trac/boost/changeset/77571

Log:
Fix #5118, replace_extension doesn't work as specified in documentation
Text files modified:
   trunk/libs/filesystem/doc/reference.html | 19 +++++++++++++------
   trunk/libs/filesystem/doc/release_history.html | 14 ++++++++++++--
   trunk/libs/filesystem/doc/src/source.html | 15 ++++++++++-----
   trunk/libs/filesystem/src/path.cpp | 21 +++++++++++----------
   trunk/libs/filesystem/test/path_test.cpp | 18 +++++++++++-------
   5 files changed, 57 insertions(+), 30 deletions(-)

Modified: trunk/libs/filesystem/doc/reference.html
==============================================================================
--- trunk/libs/filesystem/doc/reference.html (original)
+++ trunk/libs/filesystem/doc/reference.html 2012-03-26 17:19:36 EDT (Mon, 26 Mar 2012)
@@ -1,5 +1,7 @@
 <html>
-
+<!-- © Copyright Beman Dawes, 2002, 2006, 2007, 2009, 2010, 2011 -->
+<!-- Distributed under the Boost Software License, Version 1.0. -->
+<!-- See http://www.boost.org/LICENSE_1_0.txt -->
 <head>
 <meta http-equiv="Content-Language" content="en-us">
 <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
@@ -1010,11 +1012,16 @@
 </blockquote>
 <pre>path&amp; <a name="path-replace_extension">replace_extension</a>(const path&amp; new_extension = path());</pre>
 <blockquote>
- <p><i>Postcondition: </i> <code>extension() == <i>replacement</i></code>,
- where <code><i>replacement</i></code> is <code>new_extension</code> if <code>
- new_extension.empty() || new_extension[0] ==</code> the dot character,
- otherwise <code><i>replacement</i></code> is the dot character followed by
- <code>new_extension</code>.</p>
+ <p><i>Effects:</i></p>
+ <ul>
+ <li>Any existing <code>extension()</code> is removed from the stored path,
+ then</li>
+ <li>iff
+ <code>new_extension</code> is not empty and does not begin with a dot
+ character, a dot character is appended to the stored path, then</li>
+ <li>
+ <code>new_extension</code> is appended to the stored path.</li>
+ </ul>
   <p><i>Returns:</i> <code>*this</code></p>
 </blockquote>
 <pre><code>void <a name="path-swap">swap</a>(path&amp; rhs) noexcept;</code></pre>

Modified: trunk/libs/filesystem/doc/release_history.html
==============================================================================
--- trunk/libs/filesystem/doc/release_history.html (original)
+++ trunk/libs/filesystem/doc/release_history.html 2012-03-26 17:19:36 EDT (Mon, 26 Mar 2012)
@@ -38,7 +38,17 @@
 
 <h2>1.50.0</h2>
 <ul>
- <li>Add constexpr value_type preferred_separator to class path.</li>
+ <li>Remove Filesystem Version 2 from the distribution. Version 3 is now the
+ only distributed version. Those still using V2 are urged to migrate to V3 as
+ soon as possible.</li>
+ <li>Add <code>constexpr value_type preferred_separator</code> to class path.</li>
+ <li>Fix #5118,
+ <code>replace_extension</code> doesn't work as specified in documentation. The
+ documentation, implementation, and test cases have all had fixes applied. The
+ documentation had failed to mention that any existing extension is removed.
+ The behavior for simple cases has been reverted to the Version 2 behavior, but
+ with corrections so that complex replacements now work. Two test cases from
+ #5118 have been added.</li>
 </ul>
 
 <h2>1.49.0</h2>
@@ -123,7 +133,7 @@
 </ul>
 <hr>
 <p>Revised
-<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->20 March, 2012<!--webbot bot="Timestamp" endspan i-checksum="28814" --></p>
+<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->26 March, 2012<!--webbot bot="Timestamp" endspan i-checksum="28826" --></p>
 <p>© Copyright Beman Dawes, 2011</p>
 <p> Use, modification, and distribution are subject to the Boost Software
 License, Version 1.0. See <a href="http://www.boost.org/LICENSE_1_0.txt">

Modified: trunk/libs/filesystem/doc/src/source.html
==============================================================================
--- trunk/libs/filesystem/doc/src/source.html (original)
+++ trunk/libs/filesystem/doc/src/source.html 2012-03-26 17:19:36 EDT (Mon, 26 Mar 2012)
@@ -967,11 +967,16 @@
 </blockquote>
 <pre>path&amp; <a name="path-replace_extension">replace_extension</a>(const path&amp; new_extension = path());</pre>
 <blockquote>
- <p><i>Postcondition: </i> <code>extension() == <i>replacement</i></code>,
- where <code><i>replacement</i></code> is <code>new_extension</code> if <code>
- new_extension.empty() || new_extension[0] ==</code> the dot character,
- otherwise <code><i>replacement</i></code> is the dot character followed by
- <code>new_extension</code>.</p>
+ <p><i>Effects:</i></p>
+ <ul>
+ <li>Any existing <code>extension()</code> is removed from the stored path,
+ then</li>
+ <li>iff
+ <code>new_extension</code> is not empty and does not begin with a dot
+ character, a dot character is appended to the stored path, then</li>
+ <li>
+ <code>new_extension</code> is appended to the stored path.</li>
+ </ul>
   <p><i>Returns:</i> <code>*this</code></p>
 </blockquote>
 <pre><code>void <a name="path-swap">swap</a>(path&amp; rhs) noexcept;</code></pre>

Modified: trunk/libs/filesystem/src/path.cpp
==============================================================================
--- trunk/libs/filesystem/src/path.cpp (original)
+++ trunk/libs/filesystem/src/path.cpp 2012-03-26 17:19:36 EDT (Mon, 26 Mar 2012)
@@ -247,17 +247,18 @@
     return *this;
   }
 
- path & path::replace_extension(const path & source)
+ path& path::replace_extension(const path& new_extension)
   {
- // erase existing extension if any
- size_type pos(m_pathname.rfind(dot));
- if (pos != string_type::npos && pos >= filename_pos(m_pathname, m_pathname.size()))
- m_pathname.erase(pos);
-
- // append source extension if any
- pos = source.m_pathname.rfind(dot);
- if (pos != string_type::npos)
- m_pathname += source.c_str() + pos;
+ // erase existing extension, including the dot, if any
+ m_pathname.erase(m_pathname.size()-extension().m_pathname.size());
+
+ if (!new_extension.empty())
+ {
+ // append new_extension, adding the dot if necessary
+ if (new_extension.m_pathname[0] != dot)
+ m_pathname.push_back(dot);
+ m_pathname.append(new_extension.m_pathname);
+ }
 
     return *this;
   }

Modified: trunk/libs/filesystem/test/path_test.cpp
==============================================================================
--- trunk/libs/filesystem/test/path_test.cpp (original)
+++ trunk/libs/filesystem/test/path_test.cpp 2012-03-26 17:19:36 EDT (Mon, 26 Mar 2012)
@@ -1675,9 +1675,10 @@
     std::cout << "replace_extension_tests..." << std::endl;
 
     BOOST_TEST(path().replace_extension().empty());
- BOOST_TEST(path().replace_extension("a").empty());
- BOOST_TEST(path().replace_extension("a.") == ".");
- BOOST_TEST(path().replace_extension("a.txt") == ".txt");
+ BOOST_TEST(path().replace_extension("a") == ".a");
+ BOOST_TEST(path().replace_extension("a.") == ".a.");
+ BOOST_TEST(path().replace_extension(".a") == ".a");
+ BOOST_TEST(path().replace_extension("a.txt") == ".a.txt");
     // see the rationale in html docs for explanation why this works:
     BOOST_TEST(path().replace_extension(".txt") == ".txt");
 
@@ -1685,15 +1686,18 @@
     BOOST_TEST(path("a.txt").replace_extension("") == "a");
     BOOST_TEST(path("a.txt").replace_extension(".") == "a.");
     BOOST_TEST(path("a.txt").replace_extension(".tex") == "a.tex");
- BOOST_TEST(path("a.txt").replace_extension("tex") == "a");
+ BOOST_TEST(path("a.txt").replace_extension("tex") == "a.tex");
     BOOST_TEST(path("a.").replace_extension(".tex") == "a.tex");
- BOOST_TEST(path("a.").replace_extension("tex") == "a");
+ BOOST_TEST(path("a.").replace_extension("tex") == "a.tex");
     BOOST_TEST(path("a").replace_extension(".txt") == "a.txt");
- BOOST_TEST(path("a").replace_extension("txt") == "a");
+ BOOST_TEST(path("a").replace_extension("txt") == "a.txt");
     BOOST_TEST(path("a.b.txt").replace_extension(".tex") == "a.b.tex");
- BOOST_TEST(path("a.b.txt").replace_extension("tex") == "a.b");
+ BOOST_TEST(path("a.b.txt").replace_extension("tex") == "a.b.tex");
     BOOST_TEST(path("a/b").replace_extension(".c") == "a/b.c");
     PATH_TEST_EQ(path("a.txt/b").replace_extension(".c"), "a.txt/b.c"); // ticket 4702
+ BOOST_TEST(path("foo.txt").replace_extension("exe") == "foo.exe"); // ticket 5118
+ BOOST_TEST(path("foo.txt").replace_extension(".tar.bz2")
+ == "foo.tar.bz2"); // ticket 5118
   }
   
   // make_preferred_tests ------------------------------------------------------------//


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk