Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2020-11-19 15:48:43 +0300
committerNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2020-11-19 15:48:43 +0300
commit3eff6aeefaa8b44040c1bab5daaa1fedb43f27dd (patch)
tree261b3ee4926e62476926e41ba6144c4b64317396
parent231ba8be57b4a7450566a15aacc1acb5871c71eb (diff)
Add path_view::without_trailing_separator().
-rw-r--r--include/llfio/v2.0/detail/impl/posix/fs_handle.ipp2
-rw-r--r--include/llfio/v2.0/path_view.hpp15
-rw-r--r--test/tests/path_view.cpp3
3 files changed, 19 insertions, 1 deletions
diff --git a/include/llfio/v2.0/detail/impl/posix/fs_handle.ipp b/include/llfio/v2.0/detail/impl/posix/fs_handle.ipp
index f13ade7d..016e096b 100644
--- a/include/llfio/v2.0/detail/impl/posix/fs_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/posix/fs_handle.ipp
@@ -110,7 +110,7 @@ namespace detail
// Split the path into root and leafname
path_view currentpath(_currentpath);
path_view filename = currentpath.filename();
- currentpath = currentpath.remove_filename();
+ currentpath = currentpath.remove_filename().without_trailing_separator();
// Zero terminate the root path so it doesn't get copied later
const_cast<filesystem::path::string_type &>(_currentpath.native())[currentpath.native_size()] = 0;
auto currentdirh_ = path_handle::path(currentpath);
diff --git a/include/llfio/v2.0/path_view.hpp b/include/llfio/v2.0/path_view.hpp
index 19d37cd3..b82a88aa 100644
--- a/include/llfio/v2.0/path_view.hpp
+++ b/include/llfio/v2.0/path_view.hpp
@@ -1953,6 +1953,21 @@ public:
}
//! Returns a view of the filename part of this view.
LLFIO_PATH_VIEW_CONSTEXPR path_view filename() const noexcept { return this->_filename(); }
+ //! Returns a view of this view without a trailing separator, if there is one
+ LLFIO_PATH_VIEW_CONSTEXPR path_view without_trailing_separator() const noexcept
+ {
+ auto sep_idx = this->_find_last_sep();
+ return this->_invoke([this, sep_idx](const auto &v) {
+ if(v.size() - 1 == sep_idx)
+ {
+ return path_view(v.data(), sep_idx, not_zero_terminated, formatting());
+ }
+ else
+ {
+ return *this;
+ }
+ });
+ }
/*! Compares the two path views for equivalence or ordering using `T`
as the destination encoding, if necessary.
diff --git a/test/tests/path_view.cpp b/test/tests/path_view.cpp
index 98224c2b..74f0e098 100644
--- a/test/tests/path_view.cpp
+++ b/test/tests/path_view.cpp
@@ -117,6 +117,9 @@ static inline void TestPathView()
e = e.remove_filename();
BOOST_CHECK(0 == e.compare<>("/mnt/c/Users/ned/Documents/boostish/afio/programs/build_posix/testdir/"));
BOOST_CHECK(0 == f.compare<>("0"));
+ // Trailing
+ BOOST_CHECK(0 == llfio::path_view("/a/b/").without_trailing_separator().compare<>("/a/b"));
+ BOOST_CHECK(0 == llfio::path_view("/a/b").without_trailing_separator().compare<>("/a/b"));
#ifndef _WIN32
// cstr
llfio::path_view::c_str<> g(e, llfio::path_view::zero_terminated);