Buffer: accept initial content in constructor

This commit is contained in:
Maxime Coste 2011-09-06 18:33:18 +00:00
parent 6668151c78
commit 3f51feaaef
3 changed files with 7 additions and 7 deletions

View File

@ -118,9 +118,11 @@ bool BufferIterator::is_end() const
return m_position == m_buffer->length();
}
Buffer::Buffer(const std::string& name)
: m_name(name)
Buffer::Buffer(const std::string& name, const BufferString& initial_content)
: m_name(name), m_history(1), m_history_cursor(m_history.begin()),
m_content(initial_content)
{
compute_lines();
}
void Buffer::erase(const BufferIterator& begin, const BufferIterator& end)

View File

@ -65,7 +65,8 @@ private:
class Buffer
{
public:
Buffer(const std::string& name);
Buffer(const std::string& name,
const BufferString& initial_content = "");
void erase(const BufferIterator& begin,
const BufferIterator& end);
@ -78,7 +79,6 @@ public:
BufferIterator begin() const;
BufferIterator end() const;
BufferSize length() const;
BufferIterator iterator_at(const BufferCoord& line_and_column) const;

View File

@ -32,9 +32,7 @@ Buffer* create_buffer_from_file(const std::string& filename)
content += std::string(buf, size);
}
close(fd);
Buffer* buffer = new Buffer(filename);
buffer->insert(buffer->begin(), content);
return buffer;
return new Buffer(filename, content);
}
void write_buffer_to_file(const Buffer& buffer, const std::string& filename)