aboutsummaryrefslogtreecommitdiff
path: root/libbutl/path.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-08-27 10:19:38 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-08-27 10:19:38 +0200
commit584e8fce074286cbf1a5bf0c79265f789c050c59 (patch)
tree1e1d774ea0f916d7e1880442bee9b7a270876eda /libbutl/path.ixx
parent5d7f4abad8b452490f19db16bed031392dc4d1fd (diff)
Add ability to pass alternative dir separator to path::canonicalize()
This, for example, can be used to make paths with forward slashes on Windows.
Diffstat (limited to 'libbutl/path.ixx')
-rw-r--r--libbutl/path.ixx16
1 files changed, 12 insertions, 4 deletions
diff --git a/libbutl/path.ixx b/libbutl/path.ixx
index 8512286..9c96cfc 100644
--- a/libbutl/path.ixx
+++ b/libbutl/path.ixx
@@ -396,12 +396,20 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
template <typename C, typename K>
inline basic_path<C, K>& basic_path<C, K>::
- canonicalize ()
+ canonicalize (char ds)
{
- traits_type::canonicalize (this->path_);
+ traits_type::canonicalize (this->path_, ds);
- if (this->tsep_ > 1) // Non-canonical trailing separator.
- this->tsep_ = 1;
+ // Canonicalize the trailing separator if any.
+ //
+ if (this->tsep_ > 0)
+ {
+ auto dss (traits_type::directory_separators);
+ difference_type i (ds == '\0' ? 1 : strchr (dss, ds) - dss + 1);
+
+ if (this->tsep_ != i)
+ this->tsep_ = i;
+ }
return *this;
}