C++ Utilities 5.18.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
path.h
Go to the documentation of this file.
1#ifndef IOUTILITIES_PATHHELPER_H
2#define IOUTILITIES_PATHHELPER_H
3
4#include "../global.h"
5
6#ifdef PLATFORM_WINDOWS
7#include "../conversion/stringconversion.h"
8#endif
9
10#include <list>
11#include <string>
12#include <string_view>
13
14#ifdef PLATFORM_WINDOWS
15#define PATH_SEP_CHAR '\\'
16#define SEARCH_PATH_SEP_CHAR ';'
17#define PATH_SEP_STR "\\"
18#define SEARCH_PATH_SEP_STR ";"
19#else
20#define PATH_SEP_CHAR '/'
21#define SEARCH_PATH_SEP_CHAR ':'
22#define PATH_SEP_STR "/"
23#define SEARCH_PATH_SEP_STR ":"
24#endif
25
26namespace CppUtilities {
27
28CPP_UTILITIES_EXPORT std::string fileName(const std::string &path);
29CPP_UTILITIES_EXPORT std::string directory(const std::string &path);
30#ifdef CPP_UTILITIES_PATHHELPER_STRING_VIEW
31CPP_UTILITIES_EXPORT std::string_view fileName(std::string_view path);
32CPP_UTILITIES_EXPORT std::string_view directory(std::string_view path);
33#endif
35
47inline
48#ifdef PLATFORM_WINDOWS
49 std::wstring
50#else
51 std::string_view
52#endif
53 makeNativePath(std::string_view path)
54{
55#ifdef PLATFORM_WINDOWS
56 auto ec = std::error_code();
57 return convertMultiByteToWide(ec, path);
58#else
59 return path;
60#endif
61}
62
63} // namespace CppUtilities
64
65#endif // IOUTILITIES_PATHHELPER_H
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Contains all utilities provides by the c++utilities library.
std::string_view makeNativePath(std::string_view path)
Returns path in the platform's native encoding.
Definition: path.h:53
CPP_UTILITIES_EXPORT void removeInvalidChars(std::string &fileName)
Removes invalid characters from the specified fileName.
Definition: path.cpp:75
CPP_UTILITIES_EXPORT std::string fileName(const std::string &path)
Returns the file name and extension of the specified path string.
Definition: path.cpp:17
CPP_UTILITIES_EXPORT std::string directory(const std::string &path)
Returns the directory of the specified path string (including trailing slash).
Definition: path.cpp:25