diff --git a/src/core/GapBuffer.cc b/src/core/GapBuffer.cc index 8dc29fc..a541b27 100644 --- a/src/core/GapBuffer.cc +++ b/src/core/GapBuffer.cc @@ -50,12 +50,24 @@ void GapBuffer::erase(size_t position, size_t length) } } +void GapBuffer::clear() +{ + m_size = 0u; + m_gap_position = 0u; +} + std::string GapBuffer::get_string() { compact(); return std::string((char *)m_buffer, m_size); } +void GapBuffer::set_string(std::string s) +{ + clear(); + insert(0u, (const uint8_t *)s.c_str(), s.size()); +} + void GapBuffer::ensure_free(size_t length) { if (gap_size() < length) diff --git a/src/core/GapBuffer.h b/src/core/GapBuffer.h index 3429dbd..a6017c1 100644 --- a/src/core/GapBuffer.h +++ b/src/core/GapBuffer.h @@ -56,6 +56,11 @@ public: */ void erase(size_t position, size_t length); + /** + * Erase all data from the gap buffer. + */ + void clear(); + /** * Get the contents of the gap buffer as a string. * @@ -64,6 +69,11 @@ public: */ std::string get_string(); + /** + * Replace the buffer contents with a string. + */ + void set_string(std::string s); + /** * Get the size of the data stored within the buffer. */