add a Line::length method

This commit is contained in:
Maxime Coste 2012-03-30 12:00:40 +00:00
parent 0ba7c7286d
commit 2e7cd2233c
3 changed files with 7 additions and 5 deletions

View File

@ -100,14 +100,14 @@ BufferIterator Buffer::end() const
{
if (m_lines.empty())
return BufferIterator(*this, { 0, 0 });
return BufferIterator(*this, { (int)line_count()-1, (int)m_lines.back().content.length() });
return BufferIterator(*this, { (int)line_count()-1, (int)m_lines.back().length() });
}
BufferSize Buffer::length() const
{
if (m_lines.empty())
return 0;
return m_lines.back().start + m_lines.back().content.length();
return m_lines.back().start + m_lines.back().length();
}
BufferSize Buffer::line_count() const
@ -190,7 +190,7 @@ void Buffer::check_invariant() const
for (auto& line : m_lines)
{
assert(line.start == start);
start += line.content.length();
start += line.length();
}
}

View File

@ -182,6 +182,8 @@ private:
{
BufferPos start;
String content;
size_t length() const { return content.length(); }
};
std::vector<Line> m_lines;

View File

@ -22,10 +22,10 @@ inline bool BufferIterator::is_valid() const
{
return m_buffer and
((line() < m_buffer->line_count() and
column() < m_buffer->m_lines[line()].content.length()) or
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().content.length()));
column() == m_buffer->m_lines.back().length()));
}
inline BufferIterator& BufferIterator::operator=(const BufferIterator& iterator)