aboutsummaryrefslogtreecommitdiff
path: root/libbutl/path.mxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-01-19 09:05:51 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-01-19 09:05:51 +0200
commit89bc63fb386f0e4d6e2b21c0d806da1e8de0a34d (patch)
tree94e95a3a79e73e6d076f5f19fe7a5ac0e0841506 /libbutl/path.mxx
parente3bf8b04654d4131be6ea4be670e66827b489d2e (diff)
Add path::make_{directory,leaf,base}()
Diffstat (limited to 'libbutl/path.mxx')
-rw-r--r--libbutl/path.mxx24
1 files changed, 22 insertions, 2 deletions
diff --git a/libbutl/path.mxx b/libbutl/path.mxx
index 520453a..01fa0fc 100644
--- a/libbutl/path.mxx
+++ b/libbutl/path.mxx
@@ -510,14 +510,18 @@ LIBBUTL_MODEXPORT namespace butl
// Constructors.
//
- path_data (): tsep_ (0) {}
+ path_data ()
+ : tsep_ (0) {}
path_data (string_type&& p, difference_type ts)
: path_ (std::move (p)), tsep_ (path_.empty () ? 0 : ts) {}
explicit
path_data (string_type&& p)
- : path_ (std::move (p)), tsep_ (0)
+ : path_ (std::move (p)) { _init (); }
+
+ void
+ _init ()
{
size_type n (path_.size ()), i;
@@ -531,6 +535,8 @@ LIBBUTL_MODEXPORT namespace butl
path_.pop_back ();
}
}
+ else
+ tsep_ = 0;
}
};
@@ -764,6 +770,11 @@ LIBBUTL_MODEXPORT namespace butl
basic_path
leaf () const;
+ // As above but make the instance itself the leaf. Return *this.
+ //
+ basic_path&
+ make_leaf ();
+
// Return the path without the specified directory part. Throws
// invalid_path if the directory is not a prefix of *this. Expects both
// paths to be normalized.
@@ -777,6 +788,11 @@ LIBBUTL_MODEXPORT namespace butl
dir_type
directory () const;
+ // As above but make the instance itself the directory. Return *this.
+ //
+ basic_path&
+ make_directory ();
+
// Return the directory part of the path without the specified leaf part.
// Throws invalid_path if the leaf is not a suffix of *this. Expects both
// paths to be normalized.
@@ -795,6 +811,9 @@ LIBBUTL_MODEXPORT namespace butl
basic_path
base () const;
+ basic_path&
+ make_base ();
+
// Return the extension or empty string if not present. If not empty, then
// the result starts with the character past the dot.
//
@@ -1081,6 +1100,7 @@ LIBBUTL_MODEXPORT namespace butl
basic_path (data_type&& d): base_type (std::move (d)) {}
using base_type::_size;
+ using base_type::_init;
// Common implementation for operator/= and operator+=.
//