code cleanups in buffer

This commit is contained in:
Maxime Coste 2012-06-25 19:05:32 +02:00
parent d1c4a655b9
commit ccec35f88c
3 changed files with 13 additions and 8 deletions

View File

@ -69,7 +69,7 @@ BufferSize Buffer::line_length(BufferPos line) const
{
assert(line < line_count());
BufferPos end = (line < m_lines.size() - 1) ?
m_lines[line + 1].start : length();
m_lines[line + 1].start : character_count();
return end - m_lines[line].start;
}
@ -108,7 +108,7 @@ BufferIterator Buffer::end() const
return BufferIterator(*this, { (int)line_count()-1, (int)m_lines.back().length() });
}
BufferSize Buffer::length() const
BufferSize Buffer::character_count() const
{
if (m_lines.empty())
return 0;

View File

@ -123,11 +123,13 @@ public:
Buffer& operator= (const Buffer&) = delete;
~Buffer();
void begin_undo_group();
void end_undo_group();
Type type() const { return m_type; }
// apply given modification to buffer.
void modify(Modification&& modification);
void begin_undo_group();
void end_undo_group();
bool undo();
bool redo();
@ -136,7 +138,7 @@ public:
BufferIterator begin() const;
BufferIterator end() const;
BufferSize length() const;
BufferSize character_count() const;
BufferSize line_count() const;
BufferIterator iterator_at(const BufferCoord& line_and_column) const;
@ -150,8 +152,11 @@ public:
Window* get_or_create_window();
void delete_window(Window* window);
// returns true if the buffer is in a different state than
// the last time it was saved
bool is_modified() const;
Type type() const { return m_type; }
// notify the buffer that it was saved in the current state
void notify_saved();
void add_iterator_to_update(BufferIterator& iterator);

View File

@ -133,7 +133,7 @@ inline BufferIterator BufferIterator::operator+(BufferSize size) const
assert(m_buffer);
if (size >= 0)
{
BufferSize o = std::min(m_buffer->length(), offset() + size);
BufferSize o = std::min(m_buffer->character_count(), offset() + size);
for (int i = line() + 1; i < m_buffer->line_count(); ++i)
{
if (m_buffer->m_lines[i].start > o)
@ -209,7 +209,7 @@ inline bool BufferIterator::is_begin() const
inline bool BufferIterator::is_end() const
{
assert(m_buffer);
return offset() == m_buffer->length();
return offset() == m_buffer->character_count();
}
}