Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50952 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/doc libs/filesystem/src libs/filesystem/test
From: bdawes_at_[hidden]
Date: 2009-02-01 11:35:02


Author: bemandawes
Date: 2009-02-01 11:35:01 EST (Sun, 01 Feb 2009)
New Revision: 50952
URL: http://svn.boost.org/trac/boost/changeset/50952

Log:
Filesystem.v3: path::replace_extension. Fix Window copy_symlink boo boo.
Text files modified:
   sandbox/filesystem-v3/boost/filesystem/path.hpp | 50 +++++++++-----------
   sandbox/filesystem-v3/libs/filesystem/doc/v3_design.html | 8 +-
   sandbox/filesystem-v3/libs/filesystem/src/operations.cpp | 2
   sandbox/filesystem-v3/libs/filesystem/src/path.cpp | 15 ++++++
   sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp | 95 ++++++++++++++++++++++++---------------
   5 files changed, 101 insertions(+), 69 deletions(-)

Modified: sandbox/filesystem-v3/boost/filesystem/path.hpp
==============================================================================
--- sandbox/filesystem-v3/boost/filesystem/path.hpp (original)
+++ sandbox/filesystem-v3/boost/filesystem/path.hpp 2009-02-01 11:35:01 EST (Sun, 01 Feb 2009)
@@ -16,6 +16,7 @@
 /*
                               TO DO
 
+ * Document breaking changes, provide workarounds where possible.
    * Windows, POSIX, conversions for char16_t, char32_t for supporting compilers.
    * Need an error category for codecvt errors. Seed path.cpp detail::append, etc.
    * Add Alternate Data Stream test cases. See http://en.wikipedia.org/wiki/NTFS Features.
@@ -25,8 +26,8 @@
      Make sure current trunk has passing tests for those cases, all decompositions.
      See test_decompositions() in path_unit_test.cpp
    * Get the deprecated names working.
- * path_test ~line 1200 replace_extension() tests commented out
    * Document leading //: no longer treated specially.
+ * Document behavior of path::replace_extension has change WRT argument w/o a dot.
    * reference.html: operator /= is underspecified as to when a "/" is appended, and
      whether a '/' or '\' is appended.
    * path.cpp: locale and detail append/convert need error handling.
@@ -130,16 +131,16 @@
     String m_source;
   };
 
- //------------------------------------------------------------------------------------//
- // //
- // path_traits //
- // //
- // Specializations are provided for char, wchar_t, char16_t, and char32_t value //
- // types and their related string and iterator types. //
- // //
- // Users are permitted to add specializations for additional types. //
- // //
- //------------------------------------------------------------------------------------//
+//--------------------------------------------------------------------------------------//
+// //
+// path_traits //
+// //
+// Specializations are provided for char, wchar_t, char16_t, and char32_t value //
+// types and their related string and iterator types . //
+// //
+// Users are permitted to add specializations for additional types. //
+// //
+//--------------------------------------------------------------------------------------//
 
 namespace path_traits
 {
@@ -492,17 +493,10 @@
 
     // ----- modifiers -----
 
- void clear() { m_path.clear(); }
-
- void swap( path & rhs )
- {
- m_path.swap( rhs.m_path );
-# ifdef BOOST_CYGWIN_PATH
- std::swap( m_cygwin_root, rhs.m_cygwin_root );
-# endif
- }
-
- path & remove_filename();
+ void clear() { m_path.clear(); }
+ void swap( path & rhs ) { m_path.swap( rhs.m_path ); }
+ path & remove_filename();
+ path & replace_extension( const path & source = path() );
 
     // ----- observers -----
   
@@ -568,14 +562,14 @@
     // ----- decomposition -----
 
     path root_path() const;
- path root_name() const; // returns 0 or 1 element path
- // even on POSIX, root_name() is non-empty() for network paths
- path root_directory() const; // returns 0 or 1 element path
+ path root_name() const; // returns 0 or 1 element path
+ // even on POSIX, root_name() is non-empty() for network paths
+ path root_directory() const; // returns 0 or 1 element path
     path relative_path() const;
     path parent_path() const;
- path filename() const; // returns 0 or 1 element path
- path stem() const; // returns 0 or 1 element path
- path extension() const; // returns 0 or 1 element path
+ path filename() const; // returns 0 or 1 element path
+ path stem() const; // returns 0 or 1 element path
+ path extension() const; // returns 0 or 1 element path
 
     // ----- query -----
 

Modified: sandbox/filesystem-v3/libs/filesystem/doc/v3_design.html
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/doc/v3_design.html (original)
+++ sandbox/filesystem-v3/libs/filesystem/doc/v3_design.html 2009-02-01 11:35:01 EST (Sun, 01 Feb 2009)
@@ -43,7 +43,7 @@
     <a href="#Details">Details</a><br>
     <a href="#Other-changes">Other changes</a><br>
     <a href="#Prototype">Prototype</a><br>
- Trying the prototype<br>
+ Using the prototype<br>
     <a href="#Acknowledgements">Acknowledgements</a></td>
   </tr>
   <tr>
@@ -195,12 +195,12 @@
 <a href="http://svn.boost.org/svn/boost/sandbox/filesystem-v3/boost/filesystem/path.hpp">
 http://svn.boost.org/svn/boost/sandbox/filesystem-v3/boost/filesystem/path.hpp></p>
 
-<h2><a name="Trying-the-prototype">Trying the prototype</a></h2>
+<h2><a name="Trying-the-prototype">Using the prototype</a></h2>
 
 <blockquote>
   <pre>svn export
http://svn.boost.org/svn/boost/trunk filesystem-v3
-rmdir /s /q filesystem-v3/boost/filesystem
-rmdir /s /q filesystem-v3/libs/filesystem
+rmdir /s /q filesystem-v3\boost\filesystem
+rmdir /s /q filesystem-v3\libs\filesystem
 svn --force co http://svn.boost.org/svn/boost/sandbox/filesystem-v3 filesystem-v3</pre>
 </blockquote>
 <h2><a name="Acknowledgements">Acknowledgements</a></h2>

Modified: sandbox/filesystem-v3/libs/filesystem/src/operations.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/src/operations.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/src/operations.cpp 2009-02-01 11:35:01 EST (Sun, 01 Feb 2009)
@@ -604,7 +604,7 @@
       return;
 
         // preconditions met, so attempt the copy
- error( !::CopyFileEx( from.c_str(), to.c_str(), 0, 0, 0,
+ error( !::CopyFileExW( from.c_str(), to.c_str(), 0, 0, 0,
                 COPY_FILE_COPY_SYMLINK | COPY_FILE_FAIL_IF_EXISTS ), to, from, ec,
                 "boost::filesystem::copy_symlink" );
 

Modified: sandbox/filesystem-v3/libs/filesystem/src/path.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/src/path.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/src/path.cpp 2009-02-01 11:35:01 EST (Sun, 01 Feb 2009)
@@ -279,6 +279,21 @@
     return *this;
   }
 
+ path & path::replace_extension( const path & source )
+ {
+ // erase existing extension if any
+ size_type pos( m_path.rfind( dot ) );
+ if ( pos != string_type::npos )
+ m_path.erase( pos );
+
+ // append source extension if any
+ pos = source.m_path.rfind( dot );
+ if ( pos != string_type::npos )
+ m_path += source.c_str() + pos;
+
+ return *this;
+ }
+
 } // namespace filesystem
 } // namespace boost
   

Modified: sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp 2009-02-01 11:35:01 EST (Sun, 01 Feb 2009)
@@ -1,6 +1,6 @@
 // path_test program -----------------------------------------------------------------//
 
-// Copyright Beman Dawes 2002
+// Copyright Beman Dawes 2002, 2008
 // Copyright Vladimir Prus 2002
 
 // Use, modification, and distribution is subject to the Boost Software
@@ -1270,6 +1270,61 @@
     BOOST_CHECK( !fs::portable_directory_name( std::string( "foo." ) ) );
     BOOST_CHECK( !fs::portable_file_name( std::string( "foo." ) ) );
   }
+
+ // stem_tests ---------------------------------------------------//
+
+ void stem_tests()
+ {
+ std::cout << "stem_tests..." << std::endl;
+
+ BOOST_CHECK( path("b").stem() == "b" );
+ BOOST_CHECK( path("a/b.txt").stem() == "b" );
+ BOOST_CHECK( path("a/b.").stem() == "b" );
+ BOOST_CHECK( path("a.b.c").stem() == "a.b" );
+ BOOST_CHECK( path("a.b.c.").stem() == "a.b.c" );
+ BOOST_CHECK( path("").stem() == "" );
+ }
+
+ // extension_tests ---------------------------------------------------//
+
+ void extension_tests()
+ {
+ std::cout << "extension_tests..." << std::endl;
+
+ BOOST_CHECK( path("a/b").extension() == "" );
+ BOOST_CHECK( path("a/b.txt").extension() == ".txt" );
+ BOOST_CHECK( path("a/b.").extension() == "." );
+ BOOST_CHECK( path("a.b.c").extension() == ".c" );
+ BOOST_CHECK( path("a.b.c.").extension() == "." );
+ BOOST_CHECK( path("").extension() == "" );
+ BOOST_CHECK( path("a/").extension() == "." );
+ }
+
+ // replace_extension_tests ---------------------------------------------------//
+
+ void replace_extension_tests()
+ {
+ std::cout << "replace_extension_tests..." << std::endl;
+
+ BOOST_CHECK( path().replace_extension().empty() );
+ BOOST_CHECK( path().replace_extension("a").empty() );
+ BOOST_CHECK( path().replace_extension("a.") == "." );
+ BOOST_CHECK( path().replace_extension("a.txt") == ".txt" );
+ // see the rationale in html docs for explanation why this works:
+ BOOST_CHECK( path().replace_extension(".txt") == ".txt" );
+
+ BOOST_CHECK( path("a.txt").replace_extension() == "a" );
+ BOOST_CHECK( path("a.txt").replace_extension("") == "a" );
+ BOOST_CHECK( path("a.txt").replace_extension(".") == "a." );
+ BOOST_CHECK( path("a.txt").replace_extension(".tex") == "a.tex" );
+ BOOST_CHECK( path("a.txt").replace_extension("tex") == "a" );
+ BOOST_CHECK( path("a.").replace_extension(".tex") == "a.tex" );
+ BOOST_CHECK( path("a.").replace_extension("tex") == "a" );
+ BOOST_CHECK( path("a").replace_extension(".txt") == "a.txt" );
+ BOOST_CHECK( path("a").replace_extension("txt") == "a" );
+ BOOST_CHECK( path("a.b.txt" ).replace_extension(".tex") == "a.b.tex" );
+ BOOST_CHECK( path("a.b.txt" ).replace_extension("tex") == "a.b" );
+ }
 
 } // unnamed namespace
 
@@ -1305,6 +1360,9 @@
   non_member_tests();
   exception_tests();
   name_function_tests();
+ stem_tests();
+ extension_tests();
+ replace_extension_tests();
 
   // verify deprecated names still available
 
@@ -1368,41 +1426,6 @@
   BOOST_CHECK( path( "" ).empty() == true );
   BOOST_CHECK( path( "foo" ).empty() == false );
 
-
-// extension() tests
-
- BOOST_CHECK( path("a/b").extension() == "" );
- BOOST_CHECK( path("a/b.txt").extension() == ".txt" );
- BOOST_CHECK( path("a/b.").extension() == "." );
- BOOST_CHECK( path("a.b.c").extension() == ".c" );
- BOOST_CHECK( path("a.b.c.").extension() == "." );
- BOOST_CHECK( path("").extension() == "" );
- BOOST_CHECK( path("a/").extension() == "." );
-
-// stem() tests
-
- BOOST_CHECK( path("b").stem() == "b" );
- BOOST_CHECK( path("a/b.txt").stem() == "b" );
- BOOST_CHECK( path("a/b.").stem() == "b" );
- BOOST_CHECK( path("a.b.c").stem() == "a.b" );
- BOOST_CHECK( path("a.b.c.").stem() == "a.b.c" );
- BOOST_CHECK( path("").stem() == "" );
-
-//// replace_extension() tests
-//
-// BOOST_CHECK( path("a.txt").replace_extension("").string() == "a" );
-// BOOST_CHECK( path("a.txt").replace_extension(".").string() == "a." );
-// BOOST_CHECK( path("a.txt").replace_extension(".tex").string() == "a.tex" );
-// BOOST_CHECK( path("a.txt").replace_extension("tex").string() == "a.tex" );
-// BOOST_CHECK( path("a.").replace_extension(".tex").string() == "a.tex" );
-// BOOST_CHECK( path("a.").replace_extension("tex").string() == "a.tex" );
-// BOOST_CHECK( path("a").replace_extension(".txt").string() == "a.txt" );
-// BOOST_CHECK( path("a").replace_extension("txt").string() == "a.txt" );
-// BOOST_CHECK( path("a.b.txt" ).replace_extension(".tex").string() == "a.b.tex" );
-// BOOST_CHECK( path("a.b.txt" ).replace_extension("tex").string() == "a.b.tex" );
-// // see the rationale in html docs for explanation why this works
-// BOOST_CHECK( path("").replace_extension(".png").string() == ".png" );
-
   // inserter and extractor tests
 # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300 // bypass VC++ 7.0 and earlier
   std::cout << "\nInserter and extractor test...";


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