add GapBuffer::clear() and GapBuffer::set_string()

This commit is contained in:
josh committed 2017-01-18 22:20:36 -05:00
1 parent 211ce0185c
commit 22b2cd426e
2 files changed
+22

No files matched your search

+12
View File
@@ -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)
+10
View File
@@ -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.
*/