mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +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: 9ebed7d8d5
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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue