[Glacier] Add the ability to remove a character from a StringBuilder.
This commit is contained in:
parent
134185117d
commit
c8e5441c7f
|
@ -45,6 +45,8 @@ class Vector {
|
|||
template <typename... Args>
|
||||
void EmplaceBack(Args&&... args);
|
||||
|
||||
T&& PopBack();
|
||||
|
||||
private:
|
||||
T* data_;
|
||||
uint64_t size_;
|
||||
|
@ -119,6 +121,12 @@ void Vector<T>::EmplaceBack(Args&&... args) {
|
|||
data_[size_++] = T(args...);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T&& Vector<T>::PopBack() {
|
||||
size_--;
|
||||
return glcr::Move(data_[size_]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Vector<T>::Expand() {
|
||||
uint64_t new_capacity = capacity_ == 0 ? 1 : capacity_ * 2;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue