2018-10-10 11:53:07 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-09-06 15:34:26 +02:00
|
|
|
#include <AK/String.h>
|
|
|
|
#include <AK/Vector.h>
|
2019-06-14 06:43:56 +02:00
|
|
|
#include <stdarg.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
class StringBuilder {
|
|
|
|
public:
|
2019-08-07 21:28:07 +02:00
|
|
|
using OutputType = String;
|
|
|
|
|
2019-12-09 17:45:40 +01:00
|
|
|
explicit StringBuilder(size_t initial_capacity = 16);
|
2019-05-28 11:53:16 +02:00
|
|
|
~StringBuilder() {}
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-06-02 12:26:28 +02:00
|
|
|
void append(const StringView&);
|
2018-10-10 11:53:07 +02:00
|
|
|
void append(char);
|
2019-12-09 17:45:40 +01:00
|
|
|
void append(const char*, size_t);
|
2019-01-18 02:41:27 +01:00
|
|
|
void appendf(const char*, ...);
|
2019-01-30 16:28:51 +01:00
|
|
|
void appendvf(const char*, va_list);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-08-07 21:28:07 +02:00
|
|
|
String build() { return to_string(); }
|
|
|
|
|
2019-01-31 17:31:23 +01:00
|
|
|
String to_string();
|
2019-01-18 03:27:51 +01:00
|
|
|
ByteBuffer to_byte_buffer();
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-09-25 11:49:41 +03:00
|
|
|
StringView string_view() const;
|
|
|
|
void clear();
|
|
|
|
|
2019-12-09 17:45:40 +01:00
|
|
|
size_t length() const { return m_length; }
|
|
|
|
void trim(size_t count) { m_length -= count; }
|
2019-09-29 16:20:09 +02:00
|
|
|
|
2018-10-10 11:53:07 +02:00
|
|
|
private:
|
2019-12-09 17:45:40 +01:00
|
|
|
void will_append(size_t);
|
2019-01-18 03:27:51 +01:00
|
|
|
|
|
|
|
ByteBuffer m_buffer;
|
2019-12-09 17:45:40 +01:00
|
|
|
size_t m_length { 0 };
|
2018-10-10 11:53:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::StringBuilder;
|