mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 11:31:49 +00:00
add io::path.normalized()
This commit is contained in:
parent
1ec8f89599
commit
59f46ad530
5 changed files with 39 additions and 35 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#include "path.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <stack>
|
||||
|
||||
using namespace io;
|
||||
|
||||
|
|
@ -9,3 +9,30 @@ void path::checkValid() const {
|
|||
throw std::runtime_error("path entry point is not specified: " + str);
|
||||
}
|
||||
}
|
||||
|
||||
path path::normalized() const {
|
||||
io::path path = pathPart();
|
||||
|
||||
std::stack<std::string> parts;
|
||||
do {
|
||||
parts.push(path.name());
|
||||
path.str = path.parent().string();
|
||||
} while (!path.empty());
|
||||
|
||||
while (!parts.empty()) {
|
||||
const std::string part = parts.top();
|
||||
parts.pop();
|
||||
if (part == ".") {
|
||||
continue;
|
||||
}
|
||||
if (part == "..") {
|
||||
throw access_error("entry point reached");
|
||||
}
|
||||
|
||||
path = path / part;
|
||||
}
|
||||
if (path.colonPos != std::string::npos) {
|
||||
path = path.entryPoint() + ":" + path.string();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue