blob: 6414d8409044d0a8b9d0ad23eb240599f3ab6398 (
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
|
#include "StringBuilder.h"
namespace AK {
void StringBuilder::append(String&& str)
{
m_strings.append(move(str));
}
void StringBuilder::append(char ch)
{
m_strings.append(StringImpl::create(&ch, 1));
}
String StringBuilder::build()
{
auto strings = move(m_strings);
if (strings.isEmpty())
return String::empty();
size_t sizeNeeded = 0;
for (auto& string : strings)
sizeNeeded += string.length();
char* buffer;
auto impl = StringImpl::createUninitialized(sizeNeeded, buffer);
if (!impl)
return String();
for (auto& string : strings) {
memcpy(buffer, string.characters(), string.length());
buffer += string.length();
}
*buffer = '\0';
return String(move(impl));
}
}
|