$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r50639 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/src libs/filesystem/test
From: bdawes_at_[hidden]
Date: 2009-01-16 13:40:10
Author: bemandawes
Date: 2009-01-16 13:40:10 EST (Fri, 16 Jan 2009)
New Revision: 50639
URL: http://svn.boost.org/trac/boost/changeset/50639
Log:
Filesystem.v2: work-in-progress; POSIX implementation showing signs of life
Text files modified: 
   sandbox/filesystem-v3/boost/filesystem/path.hpp               |    24 +++++-----                              
   sandbox/filesystem-v3/libs/filesystem/src/path.cpp            |    43 ++++++++++++--------                    
   sandbox/filesystem-v3/libs/filesystem/src/portability.cpp     |    25 ++++++-----                             
   sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp      |    84 ++++++++++++++++++++++++++++++++++++++++
   sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp |    10 ++--                                    
   5 files changed, 140 insertions(+), 46 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-01-16 13:40:10 EST (Fri, 16 Jan 2009)
@@ -161,7 +161,7 @@
   inline void append( const charT * begin,   // requires: null termination
     string_type & target, system::error_code & ec )
   {
-    path_traits::append<charT>( begin, 0, target, ec );
+    path_traits::append<charT>( begin, static_cast<const charT *>(0), target, ec );
   }
 
   template< class charT >   // specialization required
@@ -180,20 +180,20 @@
 namespace detail
 {
 #ifdef BOOST_WINDOWS_API
-  typedef std::string   extern_string_type; 
+  typedef std::string   interface_string_type; 
 #else 
-  typedef std::wstring  extern_string_type; 
+  typedef std::wstring  interface_string_type; 
 #endif
 
-  typedef extern_string_type::value_type  extern_value_type;
+  typedef interface_string_type::value_type  interface_value_type;
 
   BOOST_FILESYSTEM_DECL
-  void append( const extern_value_type * begin,
-               const extern_value_type * end,      // 0 for null terminated MBCS
+  void append( const interface_value_type * begin,
+               const interface_value_type * end,      // 0 for null terminated MBCS
                path_traits::string_type & target, system::error_code & ec );
 
   BOOST_FILESYSTEM_DECL
-  extern_string_type convert_to_string( const path_traits::string_type & src,
+  interface_string_type convert_to_string( const path_traits::string_type & src,
                                  system::error_code & ec ); 
 
 }  // namespace detail
@@ -240,22 +240,22 @@
   }
 
   template<>
-  inline void append<char>( const detail::extern_value_type * begin,
-    const detail::extern_value_type * end,
+  inline void append<detail::interface_value_type>( const detail::interface_value_type * begin,
+    const detail::interface_value_type * end,
     string_type & target, system::error_code & ec )
   {
     detail::append( begin, end, target, ec );
   }
 
   template<>
-  inline void append<char>( const detail::extern_value_type * begin,
+  inline void append<detail::interface_value_type>( const detail::interface_value_type * begin,
     string_type & target, system::error_code & ec )
   { 
     detail::append( begin, 0, target, ec );
   }
 
   template<>
-  inline detail::extern_string_type convert<std::string>( const string_type & s,
+  inline detail::interface_string_type convert<detail::interface_string_type>( const string_type & s,
     system::error_code & ec )
   {
     return detail::convert_to_string( s, ec );
@@ -508,7 +508,7 @@
     //  return formatted "as input"
 
     operator const string_type&() const  { return m_path; }
-    operator const detail::extern_string_type() const
+    operator const detail::interface_string_type() const
     { 
       return detail::convert_to_string( m_path, system::throws );
     }
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-01-16 13:40:10 EST (Fri, 16 Jan 2009)
@@ -17,7 +17,10 @@
 #include <cstddef>
 #include <cstring>
 #include <cassert>
-#include <windows.h>
+
+#ifdef BOOST_WINDOWS_PATH
+#  include <windows.h>
+#endif
 
 namespace fs = boost::filesystem;
 
@@ -678,7 +681,7 @@
     return loc;
 # else
     // ISO C calls this "the locale-specific native environment":
-    return std::locale loc("");
+    return std::locale("");
 # endif
   }
 
@@ -757,12 +760,12 @@
   //  actual append done here to factor it out from messy buffer management code;
   //  this function just assumes the buffer is large enough.
   inline void do_append(
-                   const extern_value_type * from, const extern_value_type * from_end,
+                   const interface_value_type * from, const interface_value_type * from_end,
                    value_type * to, value_type * to_end,
                    string_type & target, error_code & ec )
   {
     std::mbstate_t state  = std::mbstate_t();  // perhaps unneeded, but cuts bug reports
-    const extern_value_type * from_next;
+    const interface_value_type * from_next;
     value_type * to_next;
 
     if ( wchar_t_codecvt_facet()->APPEND_DIRECTION( state, from, from_end, from_next,
@@ -776,11 +779,15 @@
   }
 
   BOOST_FILESYSTEM_DECL
-  void append( const extern_value_type * begin, const extern_value_type * end,
+  void append( const interface_value_type * begin, const interface_value_type * end,
   string_type & target, error_code & ec )
   {
-    if ( !end ) 
-      end = begin + std::strlen(begin);
+    if ( !end )
+    {
+      // compute strlen by hand since interface_value_type may not be char
+      end = begin;
+      while (*end) ++end;
+    }
 
     if ( begin == end )
     {
@@ -793,7 +800,7 @@
     //  dynamically allocate a buffer only if source is unusually large
     if ( buf_size > default_codecvt_buf_size )
     {
-      boost::scoped_array< wchar_t > buf( new wchar_t [buf_size] );
+      boost::scoped_array< value_type > buf( new value_type [buf_size] );
       do_append( begin, end, buf.get(), buf.get()+buf_size, target, ec );
     }
     else
@@ -809,12 +816,14 @@
 
   //  actual convert done here to factor it out from messy buffer management code;
   //  this function just assumes the buffer is large enough.
-  inline string  do_convert( const wchar_t * from, const wchar_t * from_end,
-                            char * to, char * to_end, error_code & ec )
+  inline interface_string_type  do_convert(
+    const value_type * from, const value_type * from_end,
+    interface_value_type * to, interface_value_type * to_end,
+    error_code & ec )
   {
     std::mbstate_t state  = std::mbstate_t();  // perhaps unneeded, but cuts bug reports
-    const wchar_t * from_next;
-    char * to_next;
+    const value_type * from_next;
+    interface_value_type * to_next;
 
     if ( wchar_t_codecvt_facet()->CONVERT_DIRECTION( state, from, from_end,
           from_next, to, to_end, to_next ) != std::codecvt_base::ok )
@@ -823,16 +832,16 @@
       throw "convert error handling not implemented yet";
     }
     if ( &ec != &system::throws ) ec.clear();
-    return string( to, to_next ); 
+    return interface_string_type( to, to_next ); 
   }
 
   BOOST_FILESYSTEM_DECL
-  extern_string_type convert_to_string( const string_type & src, error_code & ec )
+  interface_string_type convert_to_string( const string_type & src, error_code & ec )
   {
     if ( src.empty() )
     {
       if ( &ec != &system::throws ) ec.clear();
-      return std::string();
+      return interface_string_type();
     }
 
     //  The codecvt length functions may not be implemented, and I don't reall
@@ -845,13 +854,13 @@
     //  dynamically allocate a buffer only if source is unusually large
     if ( buf_size > default_codecvt_buf_size )
     {
-      boost::scoped_array< char > buf( new extern_value_type [buf_size] );
+      boost::scoped_array< interface_value_type > buf( new interface_value_type [buf_size] );
       return do_convert( src.c_str(), src.c_str()+src.size(),
         buf.get(), buf.get()+buf_size, ec );
     }
     else
     {
-      extern_value_type buf[default_codecvt_buf_size];
+      interface_value_type buf[default_codecvt_buf_size];
       return do_convert( src.c_str(), src.c_str()+src.size(), buf, buf+buf_size, ec );
     }
   }
Modified: sandbox/filesystem-v3/libs/filesystem/src/portability.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/src/portability.cpp	(original)
+++ sandbox/filesystem-v3/libs/filesystem/src/portability.cpp	2009-01-16 13:40:10 EST (Fri, 16 Jan 2009)
@@ -69,6 +69,7 @@
     BOOST_FILESYSTEM_DECL bool windows_name( const std::string & name )
     {
       return name.size() != 0
+        && name[0] != ' '
         && name.find_first_of( windows_invalid_chars ) == std::string::npos
         && *(name.end()-1) != ' '
         && (*(name.end()-1) != '.'
@@ -78,12 +79,12 @@
     BOOST_FILESYSTEM_DECL bool portable_name( const std::string & name )
     {
       return
-        name.size() == 0
-        || name == "."
-        || name == ".."
-        || (windows_name( name )
-        && portable_posix_name( name )
-        && name[0] != '.' && name[0] != '-');
+        name.size() != 0
+        && ( name == "."
+          || name == ".."
+          || (windows_name( name )
+            && portable_posix_name( name )
+            && name[0] != '.' && name[0] != '-'));
     }
 
     BOOST_FILESYSTEM_DECL bool portable_directory_name( const std::string & name )
@@ -99,12 +100,12 @@
     {
       std::string::size_type pos;
       return
-         name == "."
-        || name == ".."
-        || (portable_name( name )
-          && ( (pos = name.find( '.' )) == std::string::npos
-            || (name.find( '.', pos+1 )== std::string::npos
-              && (pos + 5) > name.length() )))
+         portable_name( name )
+         && name != "."
+         && name != ".."
+         && ( (pos = name.find( '.' )) == std::string::npos
+             || (name.find( '.', pos+1 ) == std::string::npos
+               && (pos + 5) > name.length() ))
         ;
     }
 
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-01-16 13:40:10 EST (Fri, 16 Jan 2009)
@@ -1188,6 +1188,89 @@
     PATH_CHECK( ".././.", ".././." );
   }
 
+  //  name_function_tests  ---------------------------------------------------//
+
+  void name_function_tests()
+  {
+    std::cout << "name_function_tests..." << std::endl;
+
+    BOOST_CHECK( fs::portable_posix_name( std::string( "x" ) ) );
+    BOOST_CHECK( fs::windows_name( std::string( "x" ) ) );
+    BOOST_CHECK( fs::portable_name( std::string( "x" ) ) );
+    BOOST_CHECK( fs::portable_directory_name( std::string( "x" ) ) );
+    BOOST_CHECK( fs::portable_file_name( std::string( "x" ) ) );
+
+    BOOST_CHECK( fs::portable_posix_name( std::string( "." ) ) );
+    BOOST_CHECK( fs::windows_name( std::string( "." ) ) );
+    BOOST_CHECK( fs::portable_name( std::string( "." ) ) );
+    BOOST_CHECK( fs::portable_directory_name( std::string( "." ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( "." ) ) );
+
+    BOOST_CHECK( fs::portable_posix_name( std::string( ".." ) ) );
+    BOOST_CHECK( fs::windows_name( std::string( ".." ) ) );
+    BOOST_CHECK( fs::portable_name( std::string( ".." ) ) );
+    BOOST_CHECK( fs::portable_directory_name( std::string( ".." ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( ".." ) ) );
+
+    BOOST_CHECK( !fs::native( std::string( "" ) ) );
+    BOOST_CHECK( !fs::portable_posix_name( std::string( "" ) ) );
+    BOOST_CHECK( !fs::windows_name( std::string( "" ) ) );
+    BOOST_CHECK( !fs::portable_name( std::string( "" ) ) );
+    BOOST_CHECK( !fs::portable_directory_name( std::string( "" ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( "" ) ) );
+
+    BOOST_CHECK( !fs::native( std::string( " " ) ) );
+    BOOST_CHECK( !fs::portable_posix_name( std::string( " " ) ) );
+    BOOST_CHECK( !fs::windows_name( std::string( " " ) ) );
+    BOOST_CHECK( !fs::portable_name( std::string( " " ) ) );
+    BOOST_CHECK( !fs::portable_directory_name( std::string( " " ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( " " ) ) );
+
+    BOOST_CHECK( !fs::portable_posix_name( std::string( ":" ) ) );
+    BOOST_CHECK( !fs::windows_name( std::string( ":" ) ) );
+    BOOST_CHECK( !fs::portable_name( std::string( ":" ) ) );
+    BOOST_CHECK( !fs::portable_directory_name( std::string( ":" ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( ":" ) ) );
+
+    BOOST_CHECK( fs::portable_posix_name( std::string( "-" ) ) );
+    BOOST_CHECK( fs::windows_name( std::string( "-" ) ) );
+    BOOST_CHECK( !fs::portable_name( std::string( "-" ) ) );
+    BOOST_CHECK( !fs::portable_directory_name( std::string( "-" ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( "-" ) ) );
+
+    BOOST_CHECK( !fs::portable_posix_name( std::string( "foo bar" ) ) );
+    BOOST_CHECK( fs::windows_name( std::string( "foo bar" ) ) );
+    BOOST_CHECK( !fs::windows_name( std::string( " bar" ) ) );
+    BOOST_CHECK( !fs::windows_name( std::string( "foo " ) ) );
+    BOOST_CHECK( !fs::portable_name( std::string( "foo bar" ) ) );
+    BOOST_CHECK( !fs::portable_directory_name( std::string( "foo bar" ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( "foo bar" ) ) );
+
+    BOOST_CHECK( fs::portable_posix_name( std::string( "foo.bar" ) ) );
+    BOOST_CHECK( fs::windows_name( std::string( "foo.bar" ) ) );
+    BOOST_CHECK( fs::portable_name( std::string( "foo.bar" ) ) );
+    BOOST_CHECK( !fs::portable_directory_name( std::string( "foo.bar" ) ) );
+    BOOST_CHECK( fs::portable_file_name( std::string( "foo.bar" ) ) );
+
+    BOOST_CHECK( fs::portable_posix_name( std::string( "foo.barf" ) ) );
+    BOOST_CHECK( fs::windows_name( std::string( "foo.barf" ) ) );
+    BOOST_CHECK( fs::portable_name( std::string( "foo.barf" ) ) );
+    BOOST_CHECK( !fs::portable_directory_name( std::string( "foo.barf" ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( "foo.barf" ) ) );
+
+    BOOST_CHECK( fs::portable_posix_name( std::string( ".foo" ) ) );
+    BOOST_CHECK( fs::windows_name( std::string( ".foo" ) ) );
+    BOOST_CHECK( !fs::portable_name( std::string( ".foo" ) ) );
+    BOOST_CHECK( !fs::portable_directory_name( std::string( ".foo" ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( ".foo" ) ) );
+
+    BOOST_CHECK( fs::portable_posix_name( std::string( "foo." ) ) );
+    BOOST_CHECK( !fs::windows_name( std::string( "foo." ) ) );
+    BOOST_CHECK( !fs::portable_name( std::string( "foo." ) ) );
+    BOOST_CHECK( !fs::portable_directory_name( std::string( "foo." ) ) );
+    BOOST_CHECK( !fs::portable_file_name( std::string( "foo." ) ) );
+  }
+
 } // unnamed namespace
 
   //------------------------------------------------------------------------------------//
@@ -1221,6 +1304,7 @@
   iterator_tests();
   non_member_tests();
   exception_tests();
+  name_function_tests();
 
   // verify deprecated names still available
 
Modified: sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp	(original)
+++ sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp	2009-01-16 13:40:10 EST (Fri, 16 Jan 2009)
@@ -604,11 +604,11 @@
     user_string::value_type usr_c_str[] = { 'a', 'b', 'c', 0 };
     user_string usr( usr_c_str );
 
-    path p1( usr_c_str );
-    CHECK( p1 == path("bcd") );
-    CHECK( p1 == "bcd" );
-    user_string s1( p1.string<user_string>() );
-    CHECK( s1 == usr );
+    //path p1( usr_c_str );
+    //CHECK( p1 == path("bcd") );
+    //CHECK( p1 == "bcd" );
+    //user_string s1( p1.string<user_string>() );
+    //CHECK( s1 == usr );
   }
 
 }  // unnamed namespace