Buffer: add is_valid(BufferCoord) method

This commit is contained in:
Maxime Coste 2013-04-23 18:46:18 +02:00
parent dd3a7f739d
commit 72ef210e1b
3 changed files with 10 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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)