add Buffer::clear() and Buffer::set_string()

This commit is contained in:
Josh Holtrop 2017-01-18 22:36:41 -05:00
parent 22b2cd426e
commit 47d15ca858
3 changed files with 4 additions and 2 deletions

View File

@ -119,7 +119,9 @@ public:
m_cursors.push_back(iterator); m_cursors.push_back(iterator);
return iterator; return iterator;
} }
void clear() { m_gap_buffer->clear(); }
auto get_string() { return m_gap_buffer->get_string(); } auto get_string() { return m_gap_buffer->get_string(); }
void set_string(const std::string & s) { m_gap_buffer->set_string(s); }
size_t size() const { return m_gap_buffer->size(); } size_t size() const { return m_gap_buffer->size(); }
uint8_t * address(size_t offset) const { return m_gap_buffer->address(offset); } uint8_t * address(size_t offset) const { return m_gap_buffer->address(offset); }
Encoding::Type encoding() const { return m_encoding; } Encoding::Type encoding() const { return m_encoding; }

View File

@ -62,7 +62,7 @@ std::string GapBuffer::get_string()
return std::string((char *)m_buffer, m_size); return std::string((char *)m_buffer, m_size);
} }
void GapBuffer::set_string(std::string s) void GapBuffer::set_string(const std::string & s)
{ {
clear(); clear();
insert(0u, (const uint8_t *)s.c_str(), s.size()); insert(0u, (const uint8_t *)s.c_str(), s.size());

View File

@ -72,7 +72,7 @@ public:
/** /**
* Replace the buffer contents with a string. * Replace the buffer contents with a string.
*/ */
void set_string(std::string s); void set_string(const std::string & s);
/** /**
* Get the size of the data stored within the buffer. * Get the size of the data stored within the buffer.