aboutsummaryrefslogtreecommitdiff
path: root/butl/path.txx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-11-30 11:47:27 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-12-05 14:04:01 +0300
commite7b033d7b38bc55f934521b5f35060b43a8b0526 (patch)
tree52a99420086e7e86ac99ef4b2b96bd210504cf01 /butl/path.txx
parentcf8f3b830789a6bcc538d2f4d0e8a1425a110c47 (diff)
Make path::normalize() to preserve ./, invalidate paths starting with \, / on Windows
Diffstat (limited to 'butl/path.txx')
-rw-r--r--butl/path.txx26
1 files changed, 19 insertions, 7 deletions
diff --git a/butl/path.txx b/butl/path.txx
index 5bcaea0..0cdaf5b 100644
--- a/butl/path.txx
+++ b/butl/path.txx
@@ -147,7 +147,7 @@ namespace butl
template <typename C, typename K>
basic_path<C, K>& basic_path<C, K>::
- normalize (bool actual)
+ normalize (bool actual, bool cur_empty)
{
if (empty ())
return *this;
@@ -273,12 +273,24 @@ namespace butl
p += traits::directory_separator;
}
- if (tsep && (!p.empty () || abs)) // Distinguish "/"-empty and "."-empty.
+ if (tsep)
{
if (p.empty ())
{
- p += traits::directory_separator;
- ts = -1;
+ // Distinguish "/"-empty and "."-empty.
+ //
+ if (abs)
+ {
+ p += traits::directory_separator;
+ ts = -1;
+ }
+ else if (!cur_empty) // Collapse to canonical current directory.
+ {
+ p = ".";
+ ts = 1; // Canonical separator is always first.
+ }
+ else // Collapse to empty path.
+ ts = 0;
}
else
ts = 1; // Canonical separator is always first.
@@ -313,11 +325,11 @@ namespace butl
#ifdef _WIN32
// We do not support any special Windows path name notations like in C:abc,
- // \\?\c:\abc, \\server\abc and \\?\UNC\server\abc (more about them at
- // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx).
+ // /, \, /abc, \abc, \\?\c:\abc, \\server\abc and \\?\UNC\server\abc (more
+ // about them in "Naming Files, Paths, and Namespaces" MSDN article).
//
if ((n > 2 && s[1] == ':' && s[2] != '\\' && s[2] != '/') ||
- (n > 1 && s[0] == '\\' && s[1] == '\\'))
+ (n > 0 && (s[0] == '\\' || s[0] == '/')))
{
if (exact)
return data_type ();