1 | // portability.cpp -------------------------------------------------------------------// |
---|---|
2 | |
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) |
7 | |
8 | // See library home page at http://www.boost.org/libs/filesystem |
9 | |
10 | //--------------------------------------------------------------------------------------// |
11 | |
12 | #include "platform_config.hpp" |
13 | |
14 | #include <boost/filesystem/config.hpp> |
15 | #include <boost/filesystem/path.hpp> |
16 | |
17 | #include <cstring> // SGI MIPSpro compilers need this |
18 | #include <string> |
19 | |
20 | #include <boost/filesystem/detail/header.hpp> // must be the last #include |
21 | |
22 | namespace boost { |
23 | namespace filesystem { |
24 | |
25 | namespace { |
26 | |
27 | BOOST_CONSTEXPR_OR_CONST char windows_invalid_chars[] = |
28 | "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" |
29 | "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" |
30 | "<>:\"/\\|"; |
31 | |
32 | BOOST_CONSTEXPR_OR_CONST char posix_valid_chars[] = |
33 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"; |
34 | |
35 | } // unnamed namespace |
36 | |
37 | // name_check functions ----------------------------------------------// |
38 | |
39 | #ifdef BOOST_WINDOWS |
40 | BOOST_FILESYSTEM_DECL bool native(std::string const& name) |
41 | { |
42 | return windows_name(name); |
43 | } |
44 | #else |
45 | BOOST_FILESYSTEM_DECL bool native(std::string const& name) |
46 | { |
47 | return !name.empty() && name[0] != ' ' && name.find(c: '/') == std::string::npos; |
48 | } |
49 | #endif |
50 | |
51 | BOOST_FILESYSTEM_DECL bool portable_posix_name(std::string const& name) |
52 | { |
53 | return !name.empty() && name.find_first_not_of(s: posix_valid_chars, pos: 0, n: sizeof(posix_valid_chars) - 1) == std::string::npos; |
54 | } |
55 | |
56 | BOOST_FILESYSTEM_DECL bool windows_name(std::string const& name) |
57 | { |
58 | // note that the terminating '\0' is part of the string - thus the size below |
59 | // is sizeof(windows_invalid_chars) rather than sizeof(windows_invalid_chars)-1. |
60 | return !name.empty() && name[0] != ' ' && name.find_first_of(s: windows_invalid_chars, pos: 0, n: sizeof(windows_invalid_chars)) == std::string::npos |
61 | && *(name.end() - 1) != ' ' && (*(name.end() - 1) != '.' || name.size() == 1 || name == ".."); |
62 | } |
63 | |
64 | BOOST_FILESYSTEM_DECL bool portable_name(std::string const& name) |
65 | { |
66 | return !name.empty() && (name == "."|| name == ".."|| (windows_name(name) && portable_posix_name(name) && name[0] != '.' && name[0] != '-')); |
67 | } |
68 | |
69 | BOOST_FILESYSTEM_DECL bool portable_directory_name(std::string const& name) |
70 | { |
71 | return name == "."|| name == ".."|| (portable_name(name) && name.find(c: '.') == std::string::npos); |
72 | } |
73 | |
74 | BOOST_FILESYSTEM_DECL bool portable_file_name(std::string const& name) |
75 | { |
76 | std::string::size_type pos; |
77 | return portable_name(name) && name != "."&& name != ".."&& ((pos = name.find(c: '.')) == std::string::npos || (name.find(c: '.', pos: pos + 1) == std::string::npos && (pos + 5) > name.size())); |
78 | } |
79 | |
80 | } // namespace filesystem |
81 | } // namespace boost |
82 | |
83 | #include <boost/filesystem/detail/footer.hpp> |
84 |