From 3e6110dec6f4cb004b8594b9b798a9db5b08fe7a Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 7 Dec 2016 01:22:53 +0300 Subject: Add path::current(), path::parent() --- butl/path.txx | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'butl/path.txx') diff --git a/butl/path.txx b/butl/path.txx index 0cdaf5b..7c46dbe 100644 --- a/butl/path.txx +++ b/butl/path.txx @@ -193,10 +193,7 @@ namespace butl if (!tsep) { const string_type& l (ps.back ()); - size_type ln (l.size ()); - - if ((ln == 1 && l[0] == '.') || - (ln == 2 && l[0] == '.' && l[1] == '.')) + if (traits::current (l) || traits::parent (l)) tsep = true; } } @@ -208,30 +205,21 @@ namespace butl for (typename paths::iterator i (ps.begin ()), e (ps.end ()); i != e; ++i) { string_type& s (*i); - size_type n (s.size ()); - if (n == 1 && s[0] == '.') + if (traits::current (s)) continue; - if (n == 2 && s[0] == '.' && s[1] == '.') + // If '..' then pop the last directory from r unless it is '..'. + // + if (traits::parent (s) && !r.empty () && !traits::parent (r.back ())) { - // Pop the last directory from r unless it is '..'. + // Cannot go past the root directory. // - if (!r.empty ()) - { - string_type const& s1 (r.back ()); + if (abs && r.size () == 1) + throw invalid_basic_path (this->path_); - if (!(s1.size () == 2 && s1[0] == '.' && s1[1] == '.')) - { - // Cannot go past the root directory. - // - if (abs && r.size () == 1) - throw invalid_basic_path (this->path_); - - r.pop_back (); - continue; - } - } + r.pop_back (); + continue; } r.push_back (std::move (s)); @@ -286,7 +274,7 @@ namespace butl } else if (!cur_empty) // Collapse to canonical current directory. { - p = "."; + p.assign (1, '.'); ts = 1; // Canonical separator is always first. } else // Collapse to empty path. @@ -304,14 +292,14 @@ namespace butl template void basic_path:: - current (basic_path const& p) + current_directory (basic_path const& p) { const string_type& s (p.string ()); if (s.empty ()) throw invalid_basic_path (s); - traits::current (s); + traits::current_directory (s); } template -- cgit v1.1