mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
AK: Add String::repeated(StringView, size_t count)
This commit is contained in:
parent
be6e4b6f3c
commit
777c232e16
2 changed files with 13 additions and 0 deletions
|
@ -234,6 +234,7 @@ bool String::ends_with(char ch) const
|
|||
return false;
|
||||
return characters()[length() - 1] == ch;
|
||||
}
|
||||
|
||||
String String::repeated(char ch, size_t count)
|
||||
{
|
||||
if (!count)
|
||||
|
@ -244,6 +245,17 @@ String String::repeated(char ch, size_t count)
|
|||
return *impl;
|
||||
}
|
||||
|
||||
String String::repeated(const StringView& string, size_t count)
|
||||
{
|
||||
if (!count || string.is_empty())
|
||||
return empty();
|
||||
char* buffer;
|
||||
auto impl = StringImpl::create_uninitialized(count * string.length(), buffer);
|
||||
for (size_t i = 0; i < count; i++)
|
||||
__builtin_memcpy(buffer + i * string.length(), string.characters_without_null_termination(), string.length());
|
||||
return *impl;
|
||||
}
|
||||
|
||||
String String::bijective_base_from(size_t value, unsigned base, StringView map)
|
||||
{
|
||||
if (map.is_null())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue