forked from OctaForge/libostd
better implementation of parent/has_parent
This commit is contained in:
parent
567a3e0b85
commit
de04a60251
12
ostd/path.hh
12
ostd/path.hh
|
@ -174,17 +174,17 @@ struct path {
|
||||||
}
|
}
|
||||||
|
|
||||||
path parent() const {
|
path parent() const {
|
||||||
path rel = relative_to(anchor());
|
string_range sep = ostd::find_last(
|
||||||
if (rel.p_path == ".") {
|
relative_to_str(anchor()), separator()
|
||||||
|
);
|
||||||
|
if (sep.empty()) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
return ostd::string_range{
|
return ostd::string_range{p_path.data(), sep.data()};
|
||||||
p_path.data(), strrchr(p_path.data(), separator())
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_parent() const noexcept {
|
bool has_parent() const noexcept {
|
||||||
return (parent().p_path != p_path);
|
return !ostd::find(relative_to_str(anchor()), separator()).empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
path relative() const {
|
path relative() const {
|
||||||
|
|
Loading…
Reference in a new issue