aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--butl/path39
-rw-r--r--butl/path.ixx44
-rw-r--r--butl/path.txx30
3 files changed, 57 insertions, 56 deletions
diff --git a/butl/path b/butl/path
index 8e1eb1a..967afe7 100644
--- a/butl/path
+++ b/butl/path
@@ -321,52 +321,53 @@ namespace butl
// is, "/" for the root directory and "/tmp" (no trailing slash) for the
// rest. This means we can return/store references to path_.
//
- // Then we have diff_ which is the size difference between path_ and its
- // "pure" part, that is, without any trailing slashes, even for "/". So:
+ // Then we have tsep_ ("trailing separator") which is the size difference
+ // between path_ and its "pure" part, that is, without any trailing
+ // slashes, even for "/". So:
//
- // diff_ == -1 -- trailing slash in path_ (the "/" case)
- // diff_ == 0 -- no trailing slash
+ // tsep_ == -1 -- trailing slash in path_ (the "/" case)
+ // tsep_ == 0 -- no trailing slash
//
// Finally, to represent non-root ("/") trailing slashes we use positive
- // diff_ values. In this case diff_ is interpreted as a 1-based index in
+ // tsep_ values. In this case tsep_ is interpreted as a 1-based index in
// the path_traits::directory_separators string.
//
// Notes:
- // - If path_ is empty, then diff_ can only be 0.
- // - We could have used a much narrower integer for diff_.
+ // - If path_ is empty, then tsep_ can only be 0.
+ // - We could have used a much narrower integer for tsep_.
//
string_type path_;
- difference_type diff_;
+ difference_type tsep_;
size_type
- _size () const {return path_.size () + (diff_ < 0 ? -1 : 0);}
+ _size () const {return path_.size () + (tsep_ < 0 ? -1 : 0);}
void
- _swap (path_data& d) {path_.swap (d.path_); std::swap (diff_, d.diff_);}
+ _swap (path_data& d) {path_.swap (d.path_); std::swap (tsep_, d.tsep_);}
void
- _clear () {path_.clear (); diff_ = 0;}
+ _clear () {path_.clear (); tsep_ = 0;}
// Constructors.
//
- path_data (): diff_ (0) {}
+ path_data (): tsep_ (0) {}
- path_data (string_type&& p, difference_type d)
- : path_ (std::move (p)), diff_ (path_.empty () ? 0 : d) {}
+ 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)), diff_ (0)
+ : path_ (std::move (p)), tsep_ (0)
{
size_type n (path_.size ()), i;
if (n != 0 && (i = path_traits<C>::separator_index (path_[n - 1])) != 0)
{
if (n == 1) // The "/" case.
- diff_ = -1;
+ tsep_ = -1;
else
{
- diff_ = i;
+ tsep_ = i;
path_.pop_back ();
}
}
@@ -702,8 +703,8 @@ namespace butl
{
return e_ != string_type::npos
? p_->path_[e_]
- : (p_->diff_ > 0
- ? path_traits<C>::directory_separators[p_->diff_ - 1]
+ : (p_->tsep_ > 0
+ ? path_traits<C>::directory_separators[p_->tsep_ - 1]
: 0);
}
diff --git a/butl/path.ixx b/butl/path.ixx
index d1fa34c..169f05d 100644
--- a/butl/path.ixx
+++ b/butl/path.ixx
@@ -43,7 +43,7 @@ namespace butl
path_cast_impl (const basic_path<C, K2>& p, basic_path<C, K1>*)
{
typename basic_path<C, K1>::data_type d (
- typename basic_path<C, K1>::string_type (p.path_), p.diff_);
+ typename basic_path<C, K1>::string_type (p.path_), p.tsep_);
K1::cast (d);
return basic_path<C, K1> (std::move (d));
}
@@ -52,7 +52,7 @@ namespace butl
inline basic_path<C, K1>
path_cast_impl (basic_path<C, K2>&& p, basic_path<C, K1>*)
{
- typename basic_path<C, K1>::data_type d (std::move (p.path_), p.diff_);
+ typename basic_path<C, K1>::data_type d (std::move (p.path_), p.tsep_);
K1::cast (d);
return basic_path<C, K1> (std::move (d));
}
@@ -166,7 +166,7 @@ namespace butl
: string_type::npos);
return p != string_type::npos
- ? basic_path (data_type (string_type (s, p + 1), this->diff_))
+ ? basic_path (data_type (string_type (s, p + 1), this->tsep_))
: *this;
}
@@ -216,7 +216,7 @@ namespace butl
//
: (e.b_ != string_type::npos
? data_type (string_type (b.p_->path_, b.b_, e.b_ - b.b_))
- : data_type (string_type (b.p_->path_, b.b_), b.p_->diff_)))
+ : data_type (string_type (b.p_->path_, b.b_), b.p_->tsep_)))
{
//assert (b.p_ == e.p_);
}
@@ -261,7 +261,7 @@ namespace butl
? dir_type (
s.size () > 2
? data_type (string_type (s, 0, 3))
- : data_type (string_type (s), this->diff_ != 0 ? this->diff_ : 1))
+ : data_type (string_type (s), this->tsep_ != 0 ? this->tsep_ : 1))
: dir_type ();
#else
return absolute ()
@@ -279,7 +279,7 @@ namespace butl
size_type p (traits::find_extension (s));
return p != string_type::npos
- ? basic_path (data_type (string_type (s, 0, p), this->diff_))
+ ? basic_path (data_type (string_type (s, 0, p), this->tsep_))
: *this;
}
@@ -324,24 +324,24 @@ namespace butl
template <typename C, typename K>
inline void basic_path<C, K>::
- combine (const C* r, size_type rn, difference_type rd)
+ combine (const C* r, size_type rn, difference_type rts)
{
//assert (rn != 0);
string_type& l (this->path_);
- difference_type& d (this->diff_);
+ difference_type& ts (this->tsep_);
// Handle the separator. LHS should be empty or already have one.
//
- switch (d)
+ switch (ts)
{
case 0: if (!l.empty ()) throw invalid_basic_path<C> (l); break;
case -1: break; // Already in the string.
- default: l += path_traits<C>::directory_separators[d - 1];
+ default: l += path_traits<C>::directory_separators[ts - 1];
}
l.append (r, rn);
- d = rd; // New trailing separator from RHS.
+ ts = rts; // New trailing separator from RHS.
}
template <typename C, typename K>
@@ -372,7 +372,7 @@ namespace butl
throw invalid_basic_path<C> (r.path_);
if (!r.empty ())
- combine (r.path_.c_str (), r.path_.size (), r.diff_);
+ combine (r.path_.c_str (), r.path_.size (), r.tsep_);
return *this;
}
@@ -401,7 +401,7 @@ namespace butl
inline void basic_path<C, K>::
append (const C* r, size_type rn)
{
- //assert (this->diff_ != -1); // Append to root?
+ //assert (this->tsep_ != -1); // Append to root?
this->path_.append (r, rn);
}
@@ -435,8 +435,8 @@ namespace butl
{
string_type r (this->path_);
- if (this->diff_ > 0)
- r += path_traits<C>::directory_separators[this->diff_ - 1];
+ if (this->tsep_ > 0)
+ r += path_traits<C>::directory_separators[this->tsep_ - 1];
return r;
}
@@ -448,8 +448,8 @@ namespace butl
string_type r;
r.swap (this->path_);
- if (this->diff_ > 0)
- r += path_traits<C>::directory_separators[this->diff_ - 1];
+ if (this->tsep_ > 0)
+ r += path_traits<C>::directory_separators[this->tsep_ - 1];
return r;
}
@@ -458,9 +458,9 @@ namespace butl
inline C basic_path<C, K>::
separator () const
{
- return (this->diff_ == 0 ? 0 :
- this->diff_ == -1 ? this->path_[0] :
- path_traits<C>::directory_separators[this->diff_ - 1]);
+ return (this->tsep_ == 0 ? 0 :
+ this->tsep_ == -1 ? this->path_[0] :
+ path_traits<C>::directory_separators[this->tsep_ - 1]);
}
template <typename C, typename K>
@@ -477,7 +477,7 @@ namespace butl
{
// Add trailing slash if one isn't already there.
//
- if (!d.path_.empty () && d.diff_ == 0)
- d.diff_ = 1; // Canonical separator is always first.
+ if (!d.path_.empty () && d.tsep_ == 0)
+ d.tsep_ = 1; // Canonical separator is always first.
}
}
diff --git a/butl/path.txx b/butl/path.txx
index 1653dc0..5bcaea0 100644
--- a/butl/path.txx
+++ b/butl/path.txx
@@ -28,13 +28,13 @@ namespace butl
// If there is implied trailing slash, add it to count. Unless it is
// "matched" by the implied slash on the other side.
//
- if (d.diff_ > 0 && dn < s.size ())
+ if (d.tsep_ > 0 && dn < s.size ())
dn++;
// Preserve trailing slash.
//
return basic_path (data_type (string_type (s, dn, s.size () - dn),
- this->diff_));
+ this->tsep_));
}
template <typename C, typename K>
@@ -47,10 +47,10 @@ namespace butl
if (ln == 0)
{
- if (this->diff_ == 0) // Must be a directory.
+ if (this->tsep_ == 0) // Must be a directory.
throw invalid_basic_path<C> (s);
- return dir_type (data_type (string_type (s), this->diff_));
+ return dir_type (data_type (string_type (s), this->tsep_));
}
if (!sup (l))
@@ -156,12 +156,12 @@ namespace butl
assert (!actual || abs); // Only absolue can be actualized.
string_type& s (this->path_);
- difference_type& d (this->diff_);
+ difference_type& ts (this->tsep_);
typedef std::vector<string_type> paths;
paths ps;
- bool tsep (d != 0); // Trailing directory separator.
+ bool tsep (ts != 0); // Trailing directory separator.
{
size_type n (_size ());
@@ -278,13 +278,13 @@ namespace butl
if (p.empty ())
{
p += traits::directory_separator;
- d = -1;
+ ts = -1;
}
else
- d = 1; // Canonical separator is always first.
+ ts = 1; // Canonical separator is always first.
}
else
- d = 0;
+ ts = 0;
s.swap (p);
return *this;
@@ -333,7 +333,7 @@ namespace butl
m != 0 && (i = path_traits<C>::separator_index (s[m - 1])) != 0;
--m) di = i;
- difference_type d (0);
+ difference_type ts (0);
if (size_t k = n - m)
{
// We can only accomodate one trailing slash in the exact mode.
@@ -344,15 +344,15 @@ namespace butl
if (m == 0) // The "/" case.
{
++m; // Keep one slash in the string.
- d = -1;
+ ts = -1;
}
else
- d = di;
+ ts = di;
s.resize (m);
}
- return data_type (std::move (s), d);
+ return data_type (std::move (s), ts);
}
template <typename C>
@@ -369,8 +369,8 @@ namespace butl
// Unless the result is empty, make sure we have the trailing slash.
//
- if (!r.path_.empty () && r.diff_ == 0)
- r.diff_ = 1; // Canonical separator is always first.
+ if (!r.path_.empty () && r.tsep_ == 0)
+ r.tsep_ = 1; // Canonical separator is always first.
return r;
}