aboutsummaryrefslogtreecommitdiff
path: root/butl/path
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-07-19 12:06:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-07-19 12:06:57 +0200
commite5aae1bb97d5f73703287358f841c6d957101dfd (patch)
tree9f2d663e6360e8ac9c1e635a3f1e5d0577125bb1 /butl/path
parente187af6b40020053e3420a4c35a697f487308791 (diff)
Implement path iterator decrement operator
Diffstat (limited to 'butl/path')
-rw-r--r--butl/path25
1 files changed, 23 insertions, 2 deletions
diff --git a/butl/path b/butl/path
index db77563..c667378 100644
--- a/butl/path
+++ b/butl/path
@@ -388,9 +388,9 @@ namespace butl
{
typedef string_type value_type;
typedef string_type* pointer;
- typedef string_type& reference;
+ typedef string_type reference;
typedef std::ptrdiff_t difference_type;
- typedef std::forward_iterator_tag iterator_category;
+ typedef std::bidirectional_iterator_tag iterator_category;
typedef typename string_type::size_type size_type;
@@ -409,9 +409,30 @@ namespace butl
return *this;
}
+ iterator&
+ operator-- ()
+ {
+ e_ = b_;
+
+ if (e_ != 0)
+ {
+ b_ = e_ == string_type::npos ?
+ traits::rfind_separator (*p_) /* Rigtmost component */ :
+ --e_ > 0 ? traits::rfind_separator (*p_, e_ - 1) :
+ string_type::npos /* Leftmost empty component */;
+
+ b_ = b_ == string_type::npos ? 0 : b_ + 1;
+ }
+
+ return *this;
+ }
+
iterator
operator++ (int) {iterator r (*this); operator++ (); return r;}
+ iterator
+ operator-- (int) {iterator r (*this); operator-- (); return r;}
+
string_type operator* () const
{
return string_type (*p_, b_, (e_ != string_type::npos ? e_ - b_ : e_));