mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 15:10:19 +00:00
AK: Add StringBuilder::append_repeated(StringView, size_t)
By analogy with append_repeated(char, size_t)
This commit is contained in:
parent
e6749eb6b7
commit
9ebed7d8d5
Notes:
github-actions[bot]
2024-11-09 19:43:44 +00:00
Author: https://github.com/stasoid Commit: https://github.com/LadybirdBrowser/ladybird/commit/9ebed7d8d56 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1918 Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 17 additions and 0 deletions
|
@ -105,6 +105,16 @@ ErrorOr<void> StringBuilder::try_append_repeated(char ch, size_t n)
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> StringBuilder::try_append_repeated(StringView string, size_t n)
|
||||
{
|
||||
if (string.is_empty())
|
||||
return {};
|
||||
TRY(will_append(string.length() * n));
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
TRY(try_append(string));
|
||||
return {};
|
||||
}
|
||||
|
||||
void StringBuilder::append(StringView string)
|
||||
{
|
||||
MUST(try_append(string));
|
||||
|
@ -130,6 +140,11 @@ void StringBuilder::append_repeated(char ch, size_t n)
|
|||
MUST(try_append_repeated(ch, n));
|
||||
}
|
||||
|
||||
void StringBuilder::append_repeated(StringView string, size_t n)
|
||||
{
|
||||
MUST(try_append_repeated(string, n));
|
||||
}
|
||||
|
||||
ErrorOr<ByteBuffer> StringBuilder::to_byte_buffer() const
|
||||
{
|
||||
return ByteBuffer::copy(data(), length());
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
}
|
||||
ErrorOr<void> try_append(char const*, size_t);
|
||||
ErrorOr<void> try_append_repeated(char, size_t);
|
||||
ErrorOr<void> try_append_repeated(StringView, size_t);
|
||||
ErrorOr<void> try_append_escaped_for_json(StringView);
|
||||
|
||||
void append(StringView);
|
||||
|
@ -49,6 +50,7 @@ public:
|
|||
void append(char const*, size_t);
|
||||
void appendvf(char const*, va_list);
|
||||
void append_repeated(char, size_t);
|
||||
void append_repeated(StringView, size_t);
|
||||
|
||||
void append_as_lowercase(char);
|
||||
void append_escaped_for_json(StringView);
|
||||
|
|
Loading…
Reference in a new issue