mirror of
https://github.com/boostorg/filesystem.git
synced 2025-05-12 13:41:47 +00:00
Convert root dir to preferred separator in path::lexically_normal.
This is consistent with std::filesystem and behavior before 16bd89b7c0398d0dc5904148a865ef3fc3ece7ec. Closes https://github.com/boostorg/filesystem/issues/200.
This commit is contained in:
parent
9e5a3e231e
commit
d418858839
13
src/path.cpp
13
src/path.cpp
@ -525,8 +525,17 @@ BOOST_FILESYSTEM_DECL path path::lexically_relative(path const& base) const
|
|||||||
|
|
||||||
BOOST_FILESYSTEM_DECL path path::lexically_normal() const
|
BOOST_FILESYSTEM_DECL path path::lexically_normal() const
|
||||||
{
|
{
|
||||||
const size_type root_path_size = find_root_path_size();
|
size_type root_name_size = 0;
|
||||||
path normal(m_pathname.c_str(), m_pathname.c_str() + root_path_size);
|
size_type root_dir_pos = find_root_directory_start(m_pathname, m_pathname.size(), root_name_size);
|
||||||
|
path normal(m_pathname.c_str(), m_pathname.c_str() + root_name_size);
|
||||||
|
|
||||||
|
size_type root_path_size = root_name_size;
|
||||||
|
if (root_dir_pos < m_pathname.size())
|
||||||
|
{
|
||||||
|
root_path_size = root_dir_pos + 1;
|
||||||
|
normal.m_pathname.push_back(preferred_separator);
|
||||||
|
}
|
||||||
|
|
||||||
size_type i = root_path_size, n = m_pathname.size();
|
size_type i = root_path_size, n = m_pathname.size();
|
||||||
|
|
||||||
// Skip redundant directory separators after the root directory
|
// Skip redundant directory separators after the root directory
|
||||||
|
@ -2304,6 +2304,8 @@ void lexically_normal_tests()
|
|||||||
|
|
||||||
if (platform == "Windows")
|
if (platform == "Windows")
|
||||||
{
|
{
|
||||||
|
BOOST_TEST_EQ(path("c:/foo/bar").lexically_normal().string(), "c:\\foo\\bar");
|
||||||
|
|
||||||
PATH_TEST_EQ(path("c:foo").lexically_normal().generic_path(), "c:foo");
|
PATH_TEST_EQ(path("c:foo").lexically_normal().generic_path(), "c:foo");
|
||||||
PATH_TEST_EQ(path("c:..").lexically_normal().generic_path(), "c:..");
|
PATH_TEST_EQ(path("c:..").lexically_normal().generic_path(), "c:..");
|
||||||
PATH_TEST_EQ(path("c:foo/..").lexically_normal().generic_path(), "c:");
|
PATH_TEST_EQ(path("c:foo/..").lexically_normal().generic_path(), "c:");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user