add a Line::length method
This commit is contained in:
parent
0ba7c7286d
commit
2e7cd2233c
|
@ -100,14 +100,14 @@ BufferIterator Buffer::end() const
|
||||||
{
|
{
|
||||||
if (m_lines.empty())
|
if (m_lines.empty())
|
||||||
return BufferIterator(*this, { 0, 0 });
|
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
|
BufferSize Buffer::length() const
|
||||||
{
|
{
|
||||||
if (m_lines.empty())
|
if (m_lines.empty())
|
||||||
return 0;
|
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
|
BufferSize Buffer::line_count() const
|
||||||
|
@ -190,7 +190,7 @@ void Buffer::check_invariant() const
|
||||||
for (auto& line : m_lines)
|
for (auto& line : m_lines)
|
||||||
{
|
{
|
||||||
assert(line.start == start);
|
assert(line.start == start);
|
||||||
start += line.content.length();
|
start += line.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,8 @@ private:
|
||||||
{
|
{
|
||||||
BufferPos start;
|
BufferPos start;
|
||||||
String content;
|
String content;
|
||||||
|
|
||||||
|
size_t length() const { return content.length(); }
|
||||||
};
|
};
|
||||||
std::vector<Line> m_lines;
|
std::vector<Line> m_lines;
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,10 @@ inline bool BufferIterator::is_valid() const
|
||||||
{
|
{
|
||||||
return m_buffer and
|
return m_buffer and
|
||||||
((line() < m_buffer->line_count() 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() and column() == 0)) or
|
||||||
(line() == m_buffer->line_count() - 1 and
|
(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)
|
inline BufferIterator& BufferIterator::operator=(const BufferIterator& iterator)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user