Skip to content

Commit e8ff65d

Browse files
author
Mariusz Pasinski
committed
refactor: remove unused path utils
I wanted to keep those a bit longer because they will be used in a different source file, but I can revive those functions from Git history, so farewell 👋
1 parent 7d82be1 commit e8ff65d

File tree

1 file changed

+0
-83
lines changed

1 file changed

+0
-83
lines changed

packages/host/cpp/CxxNodeApiHostModule.cpp

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -27,89 +27,6 @@ bool isModulePathLike(const std::string_view &path) {
2727
});
2828
}
2929

30-
// NOTE: behaves like `explode()` in PHP
31-
std::vector<std::string_view> explodePath(const std::string_view &path) {
32-
std::vector<std::string_view> parts;
33-
for (size_t pos = 0; std::string_view::npos != pos; /* no-op */) {
34-
if (const size_t nextPos = path.find('/', pos); std::string_view::npos != nextPos) {
35-
parts.emplace_back(path.substr(pos, nextPos - pos));
36-
pos = nextPos + 1;
37-
} else {
38-
if (std::string_view &&part = path.substr(pos); !part.empty()) {
39-
// Paths ending with `/` are as if there was a tailing dot `/.`
40-
// therefore the last `/` can be safely removed
41-
parts.emplace_back(part);
42-
}
43-
break;
44-
}
45-
}
46-
return parts;
47-
}
48-
49-
// NOTE: Absolute paths would have the first part empty, relative would have a name
50-
std::string implodePath(const std::vector<std::string_view> &parts) {
51-
std::string joinedPath;
52-
for (size_t i = 0; i < parts.size(); ++i) {
53-
if (i > 0) {
54-
joinedPath += '/';
55-
}
56-
joinedPath += parts[i];
57-
}
58-
return joinedPath;
59-
}
60-
61-
// NOTE: Returned path does not include the `/` at the end of the string
62-
// NOTE: For some cases this cannot be a view: `getParentPath("..")` => "../.."
63-
void makeParentPathInplace(std::vector<std::string_view> &parts) {
64-
if (!parts.empty() && ".." != parts.back()) {
65-
const bool wasDot = "." == parts.back();
66-
parts.pop_back();
67-
if (wasDot && parts.empty()) {
68-
parts.emplace_back("..");
69-
}
70-
} else {
71-
parts.emplace_back("..");
72-
}
73-
}
74-
75-
std::vector<std::string_view> makeParentPath(const std::string_view &path) {
76-
auto parts = explodePath(path);
77-
makeParentPathInplace(parts);
78-
return parts;
79-
}
80-
81-
std::vector<std::string_view> simplifyPath(const std::vector<std::string_view> &parts) {
82-
std::vector<std::string_view> result;
83-
if (!parts.empty()) {
84-
for (const auto &part : parts) {
85-
if ("." == part && !result.empty()) {
86-
continue; // We only allow for a single `./` at the beginning
87-
} else if (".." == part) {
88-
makeParentPathInplace(result);
89-
} else {
90-
result.emplace_back(part);
91-
}
92-
}
93-
} else {
94-
result.emplace_back("."); // Empty path is as if it was "."
95-
}
96-
return result;
97-
}
98-
99-
std::vector<std::string_view> joinPath(const std::vector<std::string_view> &baseDir,
100-
const std::vector<std::string_view> &rest) {
101-
auto pathComponents = simplifyPath(baseDir);
102-
auto restComponents = simplifyPath(rest);
103-
for (auto &&part : restComponents) {
104-
if (".." == part) {
105-
makeParentPathInplace(pathComponents);
106-
} else if (!part.empty() && "." != part) {
107-
pathComponents.emplace_back(part);
108-
}
109-
}
110-
return pathComponents;
111-
}
112-
11330
std::pair<std::string_view, std::string_view>
11431
rpartition(const std::string_view &input, char delimiter) {
11532
if (const size_t pos = input.find_last_of(delimiter); std::string_view::npos != pos) {

0 commit comments

Comments
 (0)