From de04a602514d3d141fc1822cc71c53049e63c548 Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 15 Apr 2018 18:00:20 +0200 Subject: [PATCH] better implementation of parent/has_parent --- ostd/path.hh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ostd/path.hh b/ostd/path.hh index 5b0a04d..efff944 100644 --- a/ostd/path.hh +++ b/ostd/path.hh @@ -174,17 +174,17 @@ struct path { } path parent() const { - path rel = relative_to(anchor()); - if (rel.p_path == ".") { + string_range sep = ostd::find_last( + relative_to_str(anchor()), separator() + ); + if (sep.empty()) { return *this; } - return ostd::string_range{ - p_path.data(), strrchr(p_path.data(), separator()) - }; + return ostd::string_range{p_path.data(), sep.data()}; } bool has_parent() const noexcept { - return (parent().p_path != p_path); + return !ostd::find(relative_to_str(anchor()), separator()).empty(); } path relative() const {