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