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(); return m_position == m_buffer->length();
} }
Buffer::Buffer(const std::string& name) Buffer::Buffer(const std::string& name, const BufferString& initial_content)
: m_name(name) : 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) void Buffer::erase(const BufferIterator& begin, const BufferIterator& end)

View File

@ -65,7 +65,8 @@ private:
class Buffer class Buffer
{ {
public: public:
Buffer(const std::string& name); Buffer(const std::string& name,
const BufferString& initial_content = "");
void erase(const BufferIterator& begin, void erase(const BufferIterator& begin,
const BufferIterator& end); const BufferIterator& end);
@ -78,7 +79,6 @@ public:
BufferIterator begin() const; BufferIterator begin() const;
BufferIterator end() const; BufferIterator end() const;
BufferSize length() const; BufferSize length() const;
BufferIterator iterator_at(const BufferCoord& line_and_column) 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); content += std::string(buf, size);
} }
close(fd); close(fd);
Buffer* buffer = new Buffer(filename); return new Buffer(filename, content);
buffer->insert(buffer->begin(), content);
return buffer;
} }
void write_buffer_to_file(const Buffer& buffer, const std::string& filename) void write_buffer_to_file(const Buffer& buffer, const std::string& filename)