summaryrefslogtreecommitdiff
path: root/AK/StringBuilder.h
blob: fc2a25dbfa0ff59b68bffc2c4bf7a8e828f15035 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include <AK/String.h>
#include <AK/Vector.h>
#include <stdarg.h>

namespace AK {

class StringBuilder {
public:
    using OutputType = String;

    explicit StringBuilder(size_t initial_capacity = 16);
    ~StringBuilder() {}

    void append(const StringView&);
    void append(char);
    void append(const char*, size_t);
    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();

    size_t length() const { return m_length; }
    void trim(size_t count) { m_length -= count; }

private:
    void will_append(size_t);

    ByteBuffer m_buffer;
    size_t m_length { 0 };
};

}

using AK::StringBuilder;