mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:07:35 +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 false;
|
||||||
return characters()[length() - 1] == ch;
|
return characters()[length() - 1] == ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::repeated(char ch, size_t count)
|
String String::repeated(char ch, size_t count)
|
||||||
{
|
{
|
||||||
if (!count)
|
if (!count)
|
||||||
|
@ -244,6 +245,17 @@ String String::repeated(char ch, size_t count)
|
||||||
return *impl;
|
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)
|
String String::bijective_base_from(size_t value, unsigned base, StringView map)
|
||||||
{
|
{
|
||||||
if (map.is_null())
|
if (map.is_null())
|
||||||
|
|
|
@ -92,6 +92,7 @@ public:
|
||||||
String(const FlyString&);
|
String(const FlyString&);
|
||||||
|
|
||||||
[[nodiscard]] static String repeated(char, size_t count);
|
[[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 = {});
|
[[nodiscard]] static String bijective_base_from(size_t value, unsigned base = 26, StringView map = {});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue