From 2e7cd2233ce449a51756c180432635eb1aee20f3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 30 Mar 2012 12:00:40 +0000 Subject: [PATCH] add a Line::length method --- src/buffer.cc | 6 +++--- src/buffer.hh | 2 ++ src/buffer_iterator.inl.hh | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 754167125..1c37e2f24 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -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(); } } diff --git a/src/buffer.hh b/src/buffer.hh index 526110fd4..83e5ffc74 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -182,6 +182,8 @@ private: { BufferPos start; String content; + + size_t length() const { return content.length(); } }; std::vector m_lines; diff --git a/src/buffer_iterator.inl.hh b/src/buffer_iterator.inl.hh index fa9e8f672..1ad3e25f5 100644 --- a/src/buffer_iterator.inl.hh +++ b/src/buffer_iterator.inl.hh @@ -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)