mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:24:58 +00:00
StringBuilder: Add try_append_repeated() and append_repeated()
This two methods add the character as many times as specified by the second parameter.
This commit is contained in:
parent
d589898f5b
commit
62b8ccaffc
2 changed files with 15 additions and 0 deletions
|
@ -56,6 +56,14 @@ ErrorOr<void> StringBuilder::try_append(char ch)
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> StringBuilder::try_append_repeated(char ch, size_t n)
|
||||
{
|
||||
TRY(will_append(n));
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
TRY(try_append(ch));
|
||||
return {};
|
||||
}
|
||||
|
||||
void StringBuilder::append(StringView string)
|
||||
{
|
||||
MUST(try_append(string));
|
||||
|
@ -84,6 +92,11 @@ void StringBuilder::appendvf(char const* fmt, va_list ap)
|
|||
nullptr, fmt, ap);
|
||||
}
|
||||
|
||||
void StringBuilder::append_repeated(char ch, size_t n)
|
||||
{
|
||||
MUST(try_append_repeated(ch, n));
|
||||
}
|
||||
|
||||
ByteBuffer StringBuilder::to_byte_buffer() const
|
||||
{
|
||||
// FIXME: Handle OOM failure.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue