From 85a9715ac3eef34f2eb19a89db02c2c74707f6b2 Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 15 Apr 2018 15:30:30 +0200 Subject: [PATCH] implement is_relative/is_absolute --- ostd/path.hh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ostd/path.hh b/ostd/path.hh index 8c41055..0e0e6f6 100644 --- a/ostd/path.hh +++ b/ostd/path.hh @@ -155,10 +155,7 @@ struct path { if (is_win()) { return ( (p_path.data()[0] == '\\') || - ( - (p_path.length() >= 3) && - (p_path[2] == '\\') && has_letter(p_path) - ) + (has_letter(p_path) && (p_path.data()[2] == '\\')) ); } return (p_path.data()[0] == '/'); @@ -248,6 +245,20 @@ struct path { return !stem().empty(); } + bool is_absolute() const { + if (is_win()) { + if (p_path.substr(0, 2) == "\\\\") { + return true; + } + return (has_letter(p_path) && (p_path.data()[2] == '\\')); + } + return (p_path.data()[0] == '/'); + } + + bool is_relative() const { + return !is_absolute(); + } + path relative_to(path other) const { if (other.p_path == ".") { return *this;