PathUtils.h
2.92 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include "il2cpp-config.h"
#include <string>
#include "StringViewUtils.h"
namespace il2cpp
{
namespace utils
{
namespace PathUtils
{
std::string BasenameNoExtension(const std::string& path);
std::string PathNoExtension(const std::string& path);
template<typename CharType>
std::basic_string<CharType> Basename(const utils::StringView<CharType>& path)
{
if (path.IsEmpty())
return std::basic_string<CharType>(1, static_cast<CharType>('.'));
const size_t pos = path.RFind(IL2CPP_DIR_SEPARATOR);
// No seperators. Path is filename
if (pos == utils::StringView<CharType>::NPos())
return std::basic_string<CharType>(path.Str(), path.Length());
return std::basic_string<CharType>(path.Str() + pos + 1, path.Length() - pos - 1);
}
template<typename CharType>
std::basic_string<CharType> Basename(const std::basic_string<CharType>& path)
{
return Basename(STRING_TO_STRINGVIEW(path));
}
template<typename CharType>
std::basic_string<CharType> DirectoryName(const utils::StringView<CharType>& path)
{
if (path.IsEmpty())
return std::basic_string<CharType>();
const size_t pos = path.RFind(IL2CPP_DIR_SEPARATOR);
if (pos == utils::StringView<CharType>::NPos())
return std::basic_string<CharType>(1, static_cast<CharType>('.'));
if (pos == 0)
return std::basic_string<CharType>(1, static_cast<CharType>('/'));
return std::basic_string<CharType>(path.Str(), pos);
}
template<typename CharType>
std::basic_string<CharType> Combine(const utils::StringView<CharType>& path1, const utils::StringView<CharType>& path2)
{
std::basic_string<CharType> result;
result.reserve(path1.Length() + path2.Length() + 1);
result.append(path1.Str(), path1.Length());
result.append(1, static_cast<CharType>(IL2CPP_DIR_SEPARATOR));
result.append(path2.Str(), path2.Length());
return result;
}
template<typename CharType>
std::basic_string<CharType> DirectoryName(const std::basic_string<CharType>& path)
{
return DirectoryName(STRING_TO_STRINGVIEW(path));
}
template<typename CharType>
std::basic_string<CharType> Combine(const std::basic_string<CharType>& path1, const std::basic_string<CharType>& path2)
{
return Combine(STRING_TO_STRINGVIEW(path1), STRING_TO_STRINGVIEW(path2));
}
template<typename CharType>
std::basic_string<CharType> Combine(const std::basic_string<CharType>& path1, const utils::StringView<CharType>& path2)
{
return Combine(STRING_TO_STRINGVIEW(path1), path2);
}
template<typename CharType>
std::basic_string<CharType> Combine(const utils::StringView<CharType>& path1, const std::basic_string<CharType>& path2)
{
return Combine(path1, STRING_TO_STRINGVIEW(path2));
}
}
} /* utils */
} /* il2cpp */