12#ifndef ROC_CORE_STRING_BUFFER_H_
13#define ROC_CORE_STRING_BUFFER_H_
44 return data_.
size() - 1;
63 return assign(str, str + strlen(str));
68 bool assign(
const char* str_begin,
const char* str_end) {
72 const size_t str_sz = size_t(str_end - str_begin);
74 if (!data_.
resize(str_sz + 1)) {
80 memcpy(data_.
data(), str_begin, str_sz);
94 const size_t orig_sz = data_.
size();
96 if (!data_.
resize(orig_sz + n_chars)) {
101 return data_.
data() + orig_sz - 1;
106 bool grow(
size_t desired_len) {
107 return data_.
grow(desired_len + 1);
113 return data_.
grow_exp(desired_len + 1);
bool grow_exp(size_t min_size)
Increase array capacity exponentially.
T * data()
Get pointer to first element.
bool grow(size_t max_sz)
Increase array capacity.
bool resize(size_t sz)
Set array size.
size_t size() const
Get number of elements.
Memory allocator interface.
Base class for non-copyable objects.
void clear()
Set buffer to empty string.
bool grow_exp(size_t desired_len)
Grow capacity to be able to hold desired number of characters. Capacity is increased exponentionally.
StringBuffer(IAllocator &allocator)
Initialize empty buffer.
bool grow(size_t desired_len)
Grow capacity to be able to hold desired number of characters. Capacity is increased linearly.
bool assign(const char *str_begin, const char *str_end)
Copy given range into buffer. Buffer will be automatically zero-terminated.
const char * c_str() const
Get zero-terminated string.
char * extend(size_t n_chars)
Extend buffer by requested number of characters.
size_t len() const
Get string length, excluding terminating zero.
bool is_empty() const
Check if buffer is empty.
bool assign(const char *str)
Copy given string into buffer. str should be zero-terminated.
Memory allocator interface.
#define roc_panic_if_not(x)
Panic if condition is false.