Repository navigation
Expand file tree
/
Copy pathpath.cc
More file actions
109 lines (85 loc) · 2.92 KB
/
Copy pathpath.cc
File metadata and controls
109 lines (85 loc) · 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <type_traits>
#include "../url.hh"
#include "../string.hh"
using namespace oro::runtime::string;
namespace oro::runtime::url {
PathComponents::PathComponents (const String& pathname) {
this->set(pathname);
}
void PathComponents::set (const String& pathname) {
const auto parts = split(pathname, "/");
for (const auto& part : parts) {
const auto value = trim(part);
if (value.size() > 0) {
this->parts.push_back(value);
}
}
}
const String PathComponents::operator[] (const size_t index) const {
return this->parts[index];
}
const String& PathComponents::operator[] (const size_t index) {
return this->parts[index];
}
const String& PathComponents:: at (const size_t index) const {
return this->parts.at(index);
}
const String PathComponents::str () const noexcept {
return "/" + join(this->parts, "/");
}
const PathComponents::Iterator PathComponents::begin () const noexcept {
return this->parts.begin();
}
const PathComponents::Iterator PathComponents::end () const noexcept {
return this->parts.end();
}
const size_t PathComponents::size () const noexcept {
return this->parts.size();
}
const bool PathComponents::empty () const noexcept {
return this->parts.empty();
}
template <typename T>
const T PathComponents::get (const size_t index) const {
if (std::is_same<T, uint64_t>::value) {
return std::stoull(this->at(index));
}
if (std::is_same<T, int64_t>::value) {
return std::stoll(this->at(index));
}
if (std::is_same<T, uint32_t>::value) {
return std::stoul(this->at(index));
}
if (std::is_same<T, int32_t>::value) {
return std::stol(this->at(index));
}
if (std::is_same<T, uint16_t>::value) {
return std::stoul(this->at(index));
}
if (std::is_same<T, int16_t>::value) {
return std::stol(this->at(index));
}
if (std::is_same<T, uint8_t>::value) {
return std::stoul(this->at(index));
}
if (std::is_same<T, int8_t>::value) {
return std::stod(this->at(index));
}
if (std::is_same<T, bool>::value) {
if (std::stod(this->at(index)) == 0) {
return false;
}
return true;
}
throw Error("unhandled type in PathComponents::get");
}
template const uint64_t PathComponents::get (const size_t index) const;
template const int64_t PathComponents::get (const size_t index) const;
template const uint32_t PathComponents::get (const size_t index) const;
template const int32_t PathComponents::get (const size_t index) const;
template const uint16_t PathComponents::get (const size_t index) const;
template const int16_t PathComponents::get (const size_t index) const;
template const uint8_t PathComponents::get (const size_t index) const;
template const int8_t PathComponents::get (const size_t index) const;
template const bool PathComponents::get (const size_t index) const;
}