[Glacier] Add the ability to remove a character from a StringBuilder.

This commit is contained in:
Drew Galbraith 2023-11-26 13:39:18 -08:00
parent 134185117d
commit c8e5441c7f
3 changed files with 33 additions and 0 deletions

View file

@ -19,6 +19,14 @@ void VariableStringBuilder::PushBack(const StringView& str) {
void VariableStringBuilder::PushBack(const char str) { data_.PushBack(str); }
void VariableStringBuilder::DeleteLast() {
if (data_.size() > 0) {
data_.PopBack();
}
}
void VariableStringBuilder::Reset() { data_ = glcr::Vector<char>(); }
String VariableStringBuilder::ToString() const {
return String(data_.RawPtr(), size());
}
@ -50,4 +58,12 @@ FixedStringBuilder::operator StringView() const {
return StringView(buffer_, size_);
}
void FixedStringBuilder::DeleteLast() {
if (size_ > 0) {
size_--;
}
}
void FixedStringBuilder::Reset() { size_ = 0; }
} // namespace glcr

View file

@ -12,6 +12,9 @@ class StringBuilder {
virtual void PushBack(const StringView& str) = 0;
virtual void PushBack(const char str) = 0;
virtual void DeleteLast() = 0;
virtual void Reset() = 0;
virtual String ToString() const = 0;
virtual operator StringView() const = 0;
@ -30,6 +33,9 @@ class VariableStringBuilder : public StringBuilder {
virtual void PushBack(const StringView& str) override;
virtual void PushBack(const char str) override;
virtual void DeleteLast() override;
virtual void Reset() override;
virtual String ToString() const override;
// Note that this could become invalidated
@ -56,6 +62,9 @@ class FixedStringBuilder : public StringBuilder {
virtual void PushBack(const StringView& str) override;
virtual void PushBack(const char str) override;
virtual void DeleteLast() override;
virtual void Reset() override;
virtual String ToString() const override;
virtual operator StringView() const override;