mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
08d9883306
The former allows you to inspect the string while it's being built. It's an explicit method rather than `operator StringView()` because you must remember you can only look at it in between modifications; appending to the StringBuilder invalidates the StringView. The latter lets you clear the state of a StringBuilder explicitly, to start from an empty string again.
40 lines
686 B
C++
40 lines
686 B
C++
#pragma once
|
|
|
|
#include <AK/String.h>
|
|
#include <AK/Vector.h>
|
|
#include <stdarg.h>
|
|
|
|
namespace AK {
|
|
|
|
class StringBuilder {
|
|
public:
|
|
using OutputType = String;
|
|
|
|
explicit StringBuilder(int initial_capacity = 16);
|
|
~StringBuilder() {}
|
|
|
|
void append(const StringView&);
|
|
void append(char);
|
|
void append(const char*, int);
|
|
void appendf(const char*, ...);
|
|
void appendvf(const char*, va_list);
|
|
|
|
String build() { return to_string(); }
|
|
|
|
String to_string();
|
|
ByteBuffer to_byte_buffer();
|
|
|
|
StringView string_view() const;
|
|
void clear();
|
|
|
|
private:
|
|
void will_append(int);
|
|
|
|
ByteBuffer m_buffer;
|
|
int m_length { 0 };
|
|
};
|
|
|
|
}
|
|
|
|
using AK::StringBuilder;
|