2023-11-03 02:48:21 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "glacier/container/vector.h"
|
|
|
|
#include "glacier/string/string.h"
|
|
|
|
#include "glacier/string/string_view.h"
|
|
|
|
|
|
|
|
namespace glcr {
|
|
|
|
|
2023-11-09 08:52:30 -08:00
|
|
|
class StringBuilder {
|
2023-11-03 02:48:21 -07:00
|
|
|
public:
|
2023-11-09 08:52:30 -08:00
|
|
|
virtual uint64_t size() const = 0;
|
|
|
|
virtual void PushBack(const StringView& str) = 0;
|
|
|
|
virtual void PushBack(const char str) = 0;
|
2023-11-03 02:48:21 -07:00
|
|
|
|
2023-11-09 08:52:30 -08:00
|
|
|
virtual String ToString() const = 0;
|
2023-11-03 02:48:21 -07:00
|
|
|
|
2023-11-09 08:52:30 -08:00
|
|
|
virtual operator StringView() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class VariableStringBuilder : public StringBuilder {
|
|
|
|
public:
|
|
|
|
VariableStringBuilder() = default;
|
|
|
|
VariableStringBuilder(const VariableStringBuilder&) = delete;
|
|
|
|
VariableStringBuilder(VariableStringBuilder&&) = default;
|
|
|
|
|
|
|
|
~VariableStringBuilder() = default;
|
|
|
|
|
|
|
|
virtual uint64_t size() const override;
|
|
|
|
|
|
|
|
virtual void PushBack(const StringView& str) override;
|
|
|
|
virtual void PushBack(const char str) override;
|
|
|
|
|
|
|
|
virtual String ToString() const override;
|
2023-11-03 02:48:21 -07:00
|
|
|
|
|
|
|
// Note that this could become invalidated
|
|
|
|
// at any time if more characters are pushed
|
|
|
|
// onto the builder.
|
2023-11-09 08:52:30 -08:00
|
|
|
virtual operator StringView() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Vector<char> data_;
|
2023-11-03 02:48:21 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace glcr
|