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 #include <boost/config.hpp>
13 #if !defined( BOOST_NO_STD_WSTRING )
14 // Boost.Filesystem V3 and later requires std::wstring support.
15 // During the transition to V3, libraries are compiled with both V2 and V3 sources.
16 // On old compilers that don't support V3 anyhow, we just skip everything so the compile
17 // will succeed and the library can be built.
19 // define BOOST_FILESYSTEM_SOURCE so that <boost/filesystem/config.hpp> knows
20 // the library is being built (possibly exporting rather than importing code)
21 #define BOOST_FILESYSTEM_SOURCE
23 #ifndef BOOST_SYSTEM_NO_DEPRECATED
24 # define BOOST_SYSTEM_NO_DEPRECATED
27 #include <boost/filesystem/v3/config.hpp>
28 #include <boost/filesystem/v3/path.hpp>
30 namespace fs
= boost::filesystem3
;
32 #include <cstring> // SGI MIPSpro compilers need this
34 # ifdef BOOST_NO_STDC_NAMESPACE
35 namespace std
{ using ::strerror
; }
38 //--------------------------------------------------------------------------------------//
42 const char invalid_chars
[] =
43 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
44 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
46 // note that the terminating '\0' is part of the string - thus the size below
47 // is sizeof(invalid_chars) rather than sizeof(invalid_chars)-1. I
48 const std::string
windows_invalid_chars(invalid_chars
, sizeof(invalid_chars
));
50 const std::string
valid_posix(
51 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
53 } // unnamed namespace
60 // name_check functions ----------------------------------------------//
63 BOOST_FILESYSTEM_DECL
bool native(const std::string
& name
)
65 return windows_name(name
);
68 BOOST_FILESYSTEM_DECL
bool native(const std::string
& name
)
70 return name
.size() != 0
72 && name
.find('/') == std::string::npos
;
76 BOOST_FILESYSTEM_DECL
bool portable_posix_name(const std::string
& name
)
78 return name
.size() != 0
79 && name
.find_first_not_of(valid_posix
) == std::string::npos
;
82 BOOST_FILESYSTEM_DECL
bool windows_name(const std::string
& name
)
84 return name
.size() != 0
86 && name
.find_first_of(windows_invalid_chars
) == std::string::npos
87 && *(name
.end()-1) != ' '
88 && (*(name
.end()-1) != '.'
89 || name
.length() == 1 || name
== "..");
92 BOOST_FILESYSTEM_DECL
bool portable_name(const std::string
& name
)
98 || (windows_name(name
)
99 && portable_posix_name(name
)
100 && name
[0] != '.' && name
[0] != '-'));
103 BOOST_FILESYSTEM_DECL
bool portable_directory_name(const std::string
& name
)
108 || (portable_name(name
)
109 && name
.find('.') == std::string::npos
);
112 BOOST_FILESYSTEM_DECL
bool portable_file_name(const std::string
& name
)
114 std::string::size_type pos
;
119 && ((pos
= name
.find('.')) == std::string::npos
120 || (name
.find('.', pos
+1) == std::string::npos
121 && (pos
+ 5) > name
.length()))
125 } // namespace filesystem3
128 #endif // no wide character support