diff --git a/src/buffer.cc b/src/buffer.cc index 932b5532..93360b74 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -446,4 +446,11 @@ void Buffer::notify_saved() } } +bool Buffer::is_valid(const BufferCoord& c) const +{ + return (c.line < line_count() and c.column < m_lines[c.line].length()) or + (c.line == line_count() - 1 and c.column == m_lines.back().length()) or + (c.line == line_count() and c.column == 0); +} + } diff --git a/src/buffer.hh b/src/buffer.hh index b1482294..bca30078 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -123,6 +123,8 @@ public: String string(const BufferIterator& begin, const BufferIterator& end) const; + bool is_valid(const BufferCoord& c) const; + BufferIterator begin() const; BufferIterator end() const; ByteCount character_count() const; diff --git a/src/buffer_iterator.inl.hh b/src/buffer_iterator.inl.hh index e5b7c95a..ac455482 100644 --- a/src/buffer_iterator.inl.hh +++ b/src/buffer_iterator.inl.hh @@ -20,12 +20,7 @@ inline const Buffer& BufferIterator::buffer() const inline bool BufferIterator::is_valid() const { - return m_buffer and - ((line() < m_buffer->line_count() and - column() < m_buffer->m_lines[line()].length()) or - ((line() == m_buffer->line_count() and column() == 0)) or - (line() == m_buffer->line_count() - 1 and - column() == m_buffer->m_lines.back().length())); + return m_buffer and m_buffer->is_valid(m_coord); } inline void BufferIterator::clamp(bool avoid_eol)