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