Move userspace to a templated StrFormat.
This commit is contained in:
parent
d9df1212b7
commit
26b61db021
25 changed files with 263 additions and 217 deletions
24
lib/glacier/string/string_builder.cpp
Normal file
24
lib/glacier/string/string_builder.cpp
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue