1 // portability.cpp ---------------------------------------------------------//
3 // Copyright 2002-2005 Beman Dawes
4 // Use, modification, and distribution is subject to the Boost Software
5 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
6 // at http://www.boost.org/LICENSE_1_0.txt)
8 // See library home page at http://www.boost.org/libs/filesystem
10 //----------------------------------------------------------------------------//
12 // define BOOST_FILESYSTEM_SOURCE so that <boost/filesystem/config.hpp> knows
13 // the library is being built (possibly exporting rather than importing code)
14 #define BOOST_FILESYSTEM_SOURCE
16 #ifndef BOOST_SYSTEM_NO_DEPRECATED
17 # define BOOST_SYSTEM_NO_DEPRECATED
20 #include <boost/filesystem/v2/config.hpp>
21 #include <boost/filesystem/v2/path.hpp>
23 namespace fs
= boost::filesystem2
;
25 #include <cstring> // SGI MIPSpro compilers need this
27 # ifdef BOOST_NO_STDC_NAMESPACE
28 namespace std
{ using ::strerror
; }
31 //----------------------------------------------------------------------------//
35 const char invalid_chars
[] =
36 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
37 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
39 // note that the terminating '\0' is part of the string - thus the size below
40 // is sizeof(invalid_chars) rather than sizeof(invalid_chars)-1. I
41 const std::string
windows_invalid_chars( invalid_chars
, sizeof(invalid_chars
) );
43 const std::string
valid_posix(
44 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-" );
46 } // unnamed namespace
53 // name_check functions ----------------------------------------------//
56 BOOST_FILESYSTEM_DECL
bool native( const std::string
& name
)
58 return windows_name( name
);
61 BOOST_FILESYSTEM_DECL
bool native( const std::string
& name
)
63 return name
.size() != 0
65 && name
.find('/') == std::string::npos
;
69 BOOST_FILESYSTEM_DECL
bool portable_posix_name( const std::string
& name
)
71 return name
.size() != 0
72 && name
.find_first_not_of( valid_posix
) == std::string::npos
;
75 BOOST_FILESYSTEM_DECL
bool windows_name( const std::string
& name
)
77 return name
.size() != 0
79 && name
.find_first_of( windows_invalid_chars
) == std::string::npos
80 && *(name
.end()-1) != ' '
81 && (*(name
.end()-1) != '.'
82 || name
.length() == 1 || name
== "..");
85 BOOST_FILESYSTEM_DECL
bool portable_name( const std::string
& name
)
91 || (windows_name( name
)
92 && portable_posix_name( name
)
93 && name
[0] != '.' && name
[0] != '-'));
96 BOOST_FILESYSTEM_DECL
bool portable_directory_name( const std::string
& name
)
101 || (portable_name( name
)
102 && name
.find('.') == std::string::npos
);
105 BOOST_FILESYSTEM_DECL
bool portable_file_name( const std::string
& name
)
107 std::string::size_type pos
;
109 portable_name( name
)
112 && ( (pos
= name
.find( '.' )) == std::string::npos
113 || (name
.find( '.', pos
+1 ) == std::string::npos
114 && (pos
+ 5) > name
.length() ))
118 } // namespace filesystem2