| 1 |
#ifndef PATH_HPP |
| 2 |
#define PATH_HPP |
| 3 |
|
| 4 |
#include "platform/platform.hpp" |
| 5 |
#include "utils/string_view.hpp" |
| 6 |
|
| 7 |
#include <string> |
| 8 |
#include <cctype> |
| 9 |
|
| 10 |
#if IS_WINDOWS |
| 11 |
#ifndef WIN32_LEAN_AND_MEAN |
| 12 |
#define WIN32_LEAN_AND_MEAN |
| 13 |
#endif |
| 14 |
#include <windows.h> |
| 15 |
#endif |
| 16 |
|
| 17 |
CPPTRACE_BEGIN_NAMESPACE |
| 18 |
namespace detail { |
| 19 |
#if IS_WINDOWS |
| 20 |
constexpr char PATH_SEP = '\\'; |
| 21 |
inline bool is_absolute(string_view path) { |
| 22 |
// I don't want to bring in shlwapi as a dependency just for PathIsRelativeA so I'm following the guidance of |
| 23 |
// https://stackoverflow.com/a/71941552/15675011 and |
| 24 |
// https://github.com/wine-mirror/wine/blob/b210a204137dec8d2126ca909d762454fd47e963/dlls/kernelbase/path.c#L982 |
| 25 |
if(path.empty() || IsDBCSLeadByte(path[0])) { |
| 26 |
return false; |
| 27 |
} |
| 28 |
if(path[0] == '\\') { |
| 29 |
return true; |
| 30 |
} |
| 31 |
if(path.size() >= 2 && std::isalpha(path[0]) && path[1] == ':') { |
| 32 |
return true; |
| 33 |
} |
| 34 |
return false; |
| 35 |
} |
| 36 |
#else |
| 37 |
constexpr char PATH_SEP = '/'; |
| 38 |
inline bool is_absolute(string_view path) { |
| 39 |
if(path.empty()) { |
| 40 |
return false; |
| 41 |
} |
| 42 |
return path[0] == '/'; |
| 43 |
} |
| 44 |
#endif |
| 45 |
} |
| 46 |
CPPTRACE_END_NAMESPACE |
| 47 |
|
| 48 |
#endif |