mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add String::repeated(StringView, size_t count)
This commit is contained in:
parent
be6e4b6f3c
commit
777c232e16
Notes:
sideshowbarker
2024-07-18 17:26:17 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/777c232e162 Pull-request: https://github.com/SerenityOS/serenity/pull/7436 Reviewed-by: https://github.com/alimpfard
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())
|
||||
|
|
|
@ -92,6 +92,7 @@ public:
|
|||
String(const FlyString&);
|
||||
|
||||
[[nodiscard]] static String repeated(char, size_t count);
|
||||
[[nodiscard]] static String repeated(const StringView&, size_t count);
|
||||
|
||||
[[nodiscard]] static String bijective_base_from(size_t value, unsigned base = 26, StringView map = {});
|
||||
|
||||
|
|
Loading…
Reference in a new issue