aboutsummaryrefslogtreecommitdiff
path: root/butl/path
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-11-30 17:34:37 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-30 17:34:37 +0200
commit5cbb86ab1d4d10371fb765f4e283af47298fec34 (patch)
treedda71d746a8a346a49da60e9b794b46e8dbb273f /butl/path
parentad6cee2e8bacebd876eb9171d0ea3f5e787746f9 (diff)
Implement path canonicalize()
Diffstat (limited to 'butl/path')
-rw-r--r--butl/path27
1 files changed, 26 insertions, 1 deletions
diff --git a/butl/path b/butl/path
index d60938f..2a32c70 100644
--- a/butl/path
+++ b/butl/path
@@ -254,6 +254,24 @@ namespace butl
return ln < rn ? -1 : (ln > rn ? 1 : 0);
}
+ static void
+ canonicalize (string_type& s)
+ {
+ //canonicalize (s.data (), s.size ()); // C++17
+
+ for (size_t i (0), n (s.size ()); i != n; ++i)
+ if (is_separator (s[i]) && s[i] != directory_separator)
+ s[i] = directory_separator;
+ }
+
+ static void
+ canonicalize (C* s, size_type n)
+ {
+ for (const C* e (s + n); s != e; ++s)
+ if (is_separator (*s) && *s != directory_separator)
+ *s = directory_separator;
+ }
+
// Get/set current working directory. Throw std::system_error to report
// the underlying OS errors.
//
@@ -780,7 +798,14 @@ namespace butl
reverse_iterator rend () const {return reverse_iterator (begin ());}
public:
- // Normalize the path and return*this. Normalization involves collapsing
+ // Canonicalize the path and return *this. Canonicalization involves
+ // converting all directory separators to the canonical form. Note that
+ // multiple directory separators are not collapsed.
+ //
+ basic_path&
+ canonicalize ();
+
+ // Normalize the path and return *this. Normalization involves collapsing
// the '.' and '..' directories if possible, collapsing multiple
// directory separators, and converting all directory separators to the
// canonical form.