Move userspace to a templated StrFormat.

This commit is contained in:
Drew Galbraith 2023-11-03 02:48:21 -07:00
parent d9df1212b7
commit 26b61db021
25 changed files with 263 additions and 217 deletions

View file

@ -0,0 +1,24 @@
#include "glacier/string/string_builder.h"
namespace glcr {
void StringBuilder::PushBack(const StringView& str) {
if (capacity() < size() + str.size()) {
uint64_t new_capacity = capacity() == 0 ? 1 : capacity() * 2;
while (new_capacity < size() + str.size()) {
new_capacity *= 2;
}
Resize(new_capacity);
}
for (uint64_t i = 0; i < str.size(); i++) {
Vector<char>::PushBack(str[i]);
}
}
String StringBuilder::ToString() const { return String(RawPtr(), size()); }
StringBuilder::operator StringView() const {
return StringView(RawPtr(), size());
}
} // namespace glcr