2023-11-03 02:48:21 -07:00
|
|
|
#include "glacier/string/string_builder.h"
|
|
|
|
|
|
|
|
namespace glcr {
|
|
|
|
|
2023-11-09 08:52:30 -08:00
|
|
|
uint64_t VariableStringBuilder::size() const { return data_.size(); }
|
|
|
|
|
|
|
|
void VariableStringBuilder::PushBack(const StringView& str) {
|
|
|
|
if (data_.capacity() < size() + str.size()) {
|
|
|
|
uint64_t new_capacity = data_.capacity() == 0 ? 1 : data_.capacity() * 2;
|
2023-11-03 02:48:21 -07:00
|
|
|
while (new_capacity < size() + str.size()) {
|
|
|
|
new_capacity *= 2;
|
|
|
|
}
|
2023-11-09 08:52:30 -08:00
|
|
|
data_.Resize(new_capacity);
|
2023-11-03 02:48:21 -07:00
|
|
|
}
|
|
|
|
for (uint64_t i = 0; i < str.size(); i++) {
|
2023-11-09 08:52:30 -08:00
|
|
|
data_.PushBack(str[i]);
|
2023-11-03 02:48:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:52:30 -08:00
|
|
|
void VariableStringBuilder::PushBack(const char str) { data_.PushBack(str); }
|
|
|
|
|
|
|
|
String VariableStringBuilder::ToString() const {
|
|
|
|
return String(data_.RawPtr(), size());
|
|
|
|
}
|
2023-11-03 02:48:21 -07:00
|
|
|
|
2023-11-09 08:52:30 -08:00
|
|
|
VariableStringBuilder::operator StringView() const {
|
|
|
|
return StringView(data_.RawPtr(), size());
|
2023-11-03 02:48:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace glcr
|