Debian Codegraph @

io/path.h

raw symbols SCIP
1 #cxx . . $ `<file>/io/path.h`/ifndef IOUTILITIES_PATHHELPER_H
2 #define IOUTILITIES_PATHHELPER_Hcxx . . $ `io/path.h:2:9`!
3
4 #include "../global.h"cxx . . $ `<file>/global.h`/
5
6 #ifdef PLATFORM_WINDOWS
7 #include "../conversion/stringconversion.h"
8 #endif
9
10 #include <string>
11 #include <string_view>
12 #ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEMcxx . . $ `<built-in>:484:9`!
13 #include <filesystem>
14 #endif
15
16 #ifdef PLATFORM_WINDOWS
17 #define PATH_SEP_CHAR '\\'
18 #define SEARCH_PATH_SEP_CHAR ';'
19 #define PATH_SEP_STR "\\"
20 #define SEARCH_PATH_SEP_STR ";"
21 #else
22 #define PATH_SEP_CHARcxx . . $ `io/path.h:22:9`! '/'
23 #define SEARCH_PATH_SEP_CHARcxx . . $ `io/path.h:23:9`! ':'
24 #define PATH_SEP_STRcxx . . $ `io/path.h:24:9`! "/"
25 #define SEARCH_PATH_SEP_STRcxx . . $ `io/path.h:25:9`! ":"
26 #endif
27
28 namespace CppUtilitiescxx . . $ CppUtilities/ {
29
30 CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::stringcxx . . $ std/string# fileNamecxx . . $ CppUtilities/fileName(fd626fc03107dd24).(const stdcxx . . $ std/::stringcxx . . $ std/string# &path);
31 CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::stringcxx . . $ std/string# directorycxx . . $ CppUtilities/directory(fd626fc03107dd24).(const stdcxx . . $ std/::stringcxx . . $ std/string# &path);
32 #ifdef CPP_UTILITIES_PATHHELPER_STRING_VIEWcxx . . $ `io/path.cpp:1:9`!
33 CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::string_viewcxx . . $ std/string_view# fileNamecxx . . $ CppUtilities/fileName(59d317b252f70f25).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# path);
34 CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::string_viewcxx . . $ std/string_view# directorycxx . . $ CppUtilities/directory(59d317b252f70f25).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# path);
35 #endif
36 CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! void removeInvalidCharscxx . . $ CppUtilities/removeInvalidChars(80d0450aec2fd74).(stdcxx . . $ std/::stringcxx . . $ std/string# &fileName);
37
38 /// \brief The native type used by std::filesystem:path.
39 /// \remarks The current implementation requires this to be always wchar_t on Windows and char otherwise.
40 using PathValueTypecxx . . $ CppUtilities/PathValueType# =
41 #ifdef PLATFORM_WINDOWS
42 wchar_t
43 #else
44 char
45 #endif
46 ;
47 #ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEMcxx . . $ `<built-in>:484:9`!
48 static_assert(stdcxx . . $ std/::is_same_v<typename stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#::value_typecxx . . $ std/filesystem/__cxx11/path#value_type#, PathValueTypecxx . . $ CppUtilities/PathValueType#>);
49 #endif
50
51 /// \brief The string type used to store paths in the native encoding.
52 /// \remarks This type is used to store paths when interfacing with native APIs.
53 using NativePathStringcxx . . $ CppUtilities/NativePathString# = stdcxx . . $ std/::basic_stringcxx . . $ std/__cxx11/basic_string#<PathValueTypecxx . . $ CppUtilities/PathValueType#>;
54 /// \brief The string view type used to pass paths in the native encoding.
55 /// \remarks This type is used to pass paths when interfacing with native APIs.
56 using NativePathStringViewcxx . . $ CppUtilities/NativePathStringView# = stdcxx . . $ std/::basic_string_viewcxx . . $ std/basic_string_view#<PathValueTypecxx . . $ CppUtilities/PathValueType#>;
57 /// \brief The string type used to store paths UTF-8 encoded.
58 /// \remarks This type is used to store paths everywhere except when interfacing directly with native APIs.
59 using PathStringcxx . . $ CppUtilities/PathString# = stdcxx . . $ std/::stringcxx . . $ std/string#;
60 /// \brief The string view type used to pass paths UTF-8 encoded.
61 /// \remarks This type is used to pass paths everywhere except when interfacing directly with native APIs.
62 using PathStringViewcxx . . $ CppUtilities/PathStringView# = stdcxx . . $ std/::string_viewcxx . . $ std/string_view#;
63
64 /*!
65 * \brief Returns \a path in the platform's native encoding.
66 * \remarks
67 * - On Windows we store paths internally as UTF-8 strings. So it is assumed that \a path is UTF-8 and a UTF-16
68 * std::wstring is returned.
69 * - On any other platforms we store paths internally using the native format (usually UTF-8). So it is assumed
70 * that \a path is already encoded as intended and passed as-is.
71 * - This function does basically the same as libstdc++'s `std::filesystem::u8path` implementation. However, the
72 * C++ standard actually imposes a conversion to UTF-8 when a non-UTF-8 narrow encoding is used. That's not
73 * wanted here. Besides, that function is deprecated in C++ 20.
74 */
75 inline
76 #ifdef PLATFORM_WINDOWS
77 NativePathString
78 #else
79 NativePathStringViewcxx . . $ CppUtilities/NativePathStringView#
80 #endif
81 makeNativePathcxx . . $ CppUtilities/makeNativePath(59d317b252f70f25).(PathStringViewcxx . . $ CppUtilities/PathStringView# path)
82 {
83 #ifdef PLATFORM_WINDOWS
84 auto ec = std::error_code();
85 return convertMultiByteToWide(ec, path);
86 #else
87 return pathcxx . . $ std/basic_string_view#basic_string_view(b419d9def655ef02).;
88 #endif
89 }
90
91 #if !defined(CPP_UTILITIES_NO_ICONV) || !defined(PLATFORM_WINDOWS)
92 /*!
93 * \brief Returns \a path as UTF-8 string or string view.
94 * \sa This is the opposite of makeNativePath() so check out remarks of that function for details.
95 */
96 inline
97 #ifdef PLATFORM_WINDOWS
98 PathString
99 #else
100 PathStringViewcxx . . $ CppUtilities/PathStringView#
101 #endif
102 extractNativePathcxx . . $ CppUtilities/extractNativePath(59d317b252f70f25).(NativePathStringViewcxx . . $ CppUtilities/NativePathStringView# path)
103 {
104 #ifdef PLATFORM_WINDOWS
105 auto res = convertUtf16LEToUtf8(reinterpret_cast<const char *>(path.data()), path.size() * 2);
106 return std::string(res.first.get(), res.second);
107 #else
108 return pathcxx . . $ std/basic_string_view#basic_string_view(b419d9def655ef02).;
109 #endif
110 }
111 #endif
112
113 } // namespace CppUtilities
114
115 #endif // IOUTILITIES_PATHHELPER_H