summaryrefslogtreecommitdiff
path: root/src/ranges.hh
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-12-07 01:58:19 +0800
committerMaxime Coste <mawww@kakoune.org>2017-12-07 01:58:19 +0800
commitbedb98220cf45e328e6b1ce98b7c984e15ceeb62 (patch)
treea782bfbcd6793a81c58bf243bd71c6403de04ab1 /src/ranges.hh
parent2f48bbf6ff0c2bad4d06ce1189cd8e0e50d7a447 (diff)
Ranges: add unit test and fix corner case in split view
Diffstat (limited to 'src/ranges.hh')
-rw-r--r--src/ranges.hh12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/ranges.hh b/src/ranges.hh
index 9a4b1c8e..aebe6f50 100644
--- a/src/ranges.hh
+++ b/src/ranges.hh
@@ -173,13 +173,13 @@ struct SplitView
struct Iterator : std::iterator<std::forward_iterator_tag, ValueType>
{
- Iterator(RangeIt pos, RangeIt end, Element separator, Element escaper)
- : pos(pos), sep(pos), end(end), separator(separator), escaper(escaper)
+ Iterator(RangeIt pos, const RangeIt& end, Element separator, Element escaper)
+ : done{pos == end}, pos{pos}, sep{pos}, end(end), separator{std::move(separator)}, escaper{std::move(escaper)}
{
bool escaped = false;
while (sep != end and (escaped or *sep != separator))
{
- escaped = escape and *sep == escaper;
+ escaped = escape and not escaped and *sep == escaper;
++sep;
}
}
@@ -187,8 +187,8 @@ struct SplitView
Iterator& operator++() { advance(); return *this; }
Iterator operator++(int) { auto copy = *this; advance(); return copy; }
- bool operator==(const Iterator& other) const { return pos == other.pos; }
- bool operator!=(const Iterator& other) const { return pos != other.pos; }
+ bool operator==(const Iterator& other) const { return pos == other.pos and done == other.done; }
+ bool operator!=(const Iterator& other) const { return pos != other.pos or done != other.done; }
ValueType operator*() { return {pos, sep}; }
@@ -198,6 +198,7 @@ struct SplitView
if (sep == end)
{
pos = end;
+ done = true;
return;
}
@@ -211,6 +212,7 @@ struct SplitView
}
}
+ bool done;
RangeIt pos;
RangeIt sep;
RangeIt end;