summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-01-23 18:52:42 +0100
committerMaxime Coste <frrrwww@gmail.com>2013-01-23 18:52:42 +0100
commit410067282af52c8d6ba17dcf5d3f96d1c644c511 (patch)
treed703cd014e915ac85a238f203b9f303e772399d2 /src
parent72cc61c987d29eb4fc41db1c3e2f2c92f9b3ebac (diff)
Buffer: end is either one past last character, or one past last line
Diffstat (limited to 'src')
-rw-r--r--src/buffer.cc6
-rw-r--r--src/buffer_iterator.inl.hh8
2 files changed, 9 insertions, 5 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index 266d4905..d94c5617 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -256,9 +256,9 @@ void Buffer::do_insert(const BufferIterator& pos, const String& content)
BufferIterator begin_it;
BufferIterator end_it;
- // if we inserted at the end of the buffer, we may have created a new
+ // if we inserted at the end of the buffer, we have created a new
// line without inserting a '\n'
- if (pos == end() and (pos == begin() or *(pos-1) == '\n'))
+ if (pos.is_end())
{
ByteCount start = 0;
for (ByteCount i = 0; i < content.length(); ++i)
@@ -361,7 +361,7 @@ void Buffer::apply_modification(const Modification& modification)
{
case Modification::Insert:
{
- do_insert(pos < end() ? pos : end(), content);
+ do_insert(pos, content);
break;
}
case Modification::Erase:
diff --git a/src/buffer_iterator.inl.hh b/src/buffer_iterator.inl.hh
index 201ea481..1e477561 100644
--- a/src/buffer_iterator.inl.hh
+++ b/src/buffer_iterator.inl.hh
@@ -116,8 +116,7 @@ inline char BufferIterator::operator*() const
inline ByteCount BufferIterator::offset() const
{
assert(m_buffer);
- return line() == 0 ? column()
- : m_buffer->m_lines[line()].start + column();
+ return m_buffer->m_lines[line()].start + column();
}
inline size_t BufferIterator::operator-(const BufferIterator& iterator) const
@@ -221,6 +220,11 @@ inline bool BufferIterator::is_begin() const
inline bool BufferIterator::is_end() const
{
assert(m_buffer);
+ if (m_coord.line == m_buffer->line_count())
+ {
+ assert(m_coord.column == 0);
+ return true;
+ }
return offset() == m_buffer->character_count();
}