add GapBuffer::clear() and GapBuffer::set_string()
This commit is contained in:
1 parent
211ce0185c
commit
22b2cd426e
2 files changed
+22
No files matched your search
@@ -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()
|
std::string GapBuffer::get_string()
|
||||||
{
|
{
|
||||||
compact();
|
compact();
|
||||||
return std::string((char *)m_buffer, m_size);
|
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)
|
void GapBuffer::ensure_free(size_t length)
|
||||||
{
|
{
|
||||||
if (gap_size() < length)
|
if (gap_size() < length)
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void erase(size_t position, size_t length);
|
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.
|
* Get the contents of the gap buffer as a string.
|
||||||
*
|
*
|
||||||
@@ -64,6 +69,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
std::string get_string();
|
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.
|
* Get the size of the data stored within the buffer.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user