Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56139 - in trunk: boost/filesystem libs/filesystem/test
From: bdawes_at_[hidden]
Date: 2009-09-10 13:25:21


Author: bemandawes
Date: 2009-09-10 13:25:20 EDT (Thu, 10 Sep 2009)
New Revision: 56139
URL: http://svn.boost.org/trac/boost/changeset/56139

Log:
Fix #3385, add test cases
Text files modified:
   trunk/boost/filesystem/path.hpp | 45 ++++++++++++++++++++++++++-------------
   trunk/libs/filesystem/test/path_test.cpp | 21 ++++++++++++++++++
   2 files changed, 51 insertions(+), 15 deletions(-)

Modified: trunk/boost/filesystem/path.hpp
==============================================================================
--- trunk/boost/filesystem/path.hpp (original)
+++ trunk/boost/filesystem/path.hpp 2009-09-10 13:25:20 EDT (Thu, 10 Sep 2009)
@@ -399,42 +399,57 @@
         lhs.begin(), lhs.end(), tmp.begin(), tmp.end() );
     }
 
- // operator == uses string compare rather than !(lhs < rhs) && !(rhs < lhs) because
- // the result is the same yet the direct string compare is much more efficient that
- // lexicographical_compare, and lexicographical_compare used twice at that.
+ // operator == uses hand-written compare rather than !(lhs < rhs) && !(rhs < lhs)
+ // because the result is the same yet the direct compare is much more efficient
+ // than lexicographical_compare, which would also be called twice.
 
     template< class String, class Traits >
- inline bool operator==( const basic_path<String, Traits> & lhs, const basic_path<String, Traits> & rhs )
+ inline bool operator==( const basic_path<String, Traits> & lhs,
+ const typename basic_path<String, Traits>::string_type::value_type * rhs )
+ {
+ typedef typename
+ boost::BOOST_FILESYSTEM_NAMESPACE::basic_path<String, Traits> path_type;
+ const typename path_type::string_type::value_type * l (lhs.string().c_str());
+ while ( (*l == *rhs
+# ifdef BOOST_WINDOWS_PATH
+ || (*l == path_alt_separator<path_type>::value && *rhs == slash<path_type>::value)
+ || (*l == slash<path_type>::value && *rhs == path_alt_separator<path_type>::value)
+# endif
+ ) && *l ) { ++l; ++rhs; }
+ return *l == *rhs
+# ifdef BOOST_WINDOWS_PATH
+ || (*l == path_alt_separator<path_type>::value && *rhs == slash<path_type>::value)
+ || (*l == slash<path_type>::value && *rhs == path_alt_separator<path_type>::value)
+# endif
+ ;
+ }
+
+ template< class String, class Traits >
+ inline bool operator==( const basic_path<String, Traits> & lhs,
+ const basic_path<String, Traits> & rhs )
     {
- return lhs.string() == rhs.string();
+ return lhs == rhs.string().c_str();
     }
 
     template< class String, class Traits >
     inline bool operator==( const typename basic_path<String, Traits>::string_type::value_type * lhs,
                     const basic_path<String, Traits> & rhs )
     {
- return lhs == rhs.string();
+ return rhs == lhs;
     }
 
     template< class String, class Traits >
     inline bool operator==( const typename basic_path<String, Traits>::string_type & lhs,
                     const basic_path<String, Traits> & rhs )
     {
- return lhs == rhs.string();
- }
-
- template< class String, class Traits >
- inline bool operator==( const basic_path<String, Traits> & lhs,
- const typename basic_path<String, Traits>::string_type::value_type * rhs )
- {
- return lhs.string() == rhs;
+ return rhs == lhs.c_str();
     }
 
     template< class String, class Traits >
     inline bool operator==( const basic_path<String, Traits> & lhs,
                     const typename basic_path<String, Traits>::string_type & rhs )
     {
- return lhs.string() == rhs;
+ return lhs == rhs.c_str();
     }
 
     template< class String, class Traits >

Modified: trunk/libs/filesystem/test/path_test.cpp
==============================================================================
--- trunk/libs/filesystem/test/path_test.cpp (original)
+++ trunk/libs/filesystem/test/path_test.cpp 2009-09-10 13:25:20 EDT (Thu, 10 Sep 2009)
@@ -226,6 +226,27 @@
   p4 = p4; // self-assignment
   BOOST_TEST( p4.string() == "foobar" );
 
+ if ( platform == "Windows" )
+ {
+ path p10 ("c:\\file");
+ path p11 ("c:/file");
+ // check each overload
+ BOOST_TEST( p10.string() == p11.string() );
+ BOOST_TEST( p10 == p11 );
+ BOOST_TEST( p10 == p11.string() );
+ BOOST_TEST( p10 == p11.string().c_str() );
+ BOOST_TEST( p10.string() == p11 );
+ BOOST_TEST( p10.string().c_str() == p11 );
+ BOOST_TEST( p10 == "c:\\file" );
+ BOOST_TEST( p10 == "c:/file" );
+ BOOST_TEST( p11 == "c:\\file" );
+ BOOST_TEST( p11 == "c:/file" );
+ BOOST_TEST( "c:\\file" == p10 );
+ BOOST_TEST( "c:/file" == p10 );
+ BOOST_TEST( "c:\\file" == p11 );
+ BOOST_TEST( "c:/file" == p11 );
+ }
+
   exception_tests();
   name_function_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