BAN: String add operator=(StringView)

This commit is contained in:
Bananymous 2023-01-13 00:55:58 +02:00
parent c33c6c5785
commit 53d1d12c12
2 changed files with 7 additions and 2 deletions

View File

@ -48,6 +48,12 @@ namespace BAN
return *this; return *this;
} }
String& String::operator=(StringView other)
{
MUST(copy_impl(other));
return *this;
}
ErrorOr<void> String::PushBack(char ch) ErrorOr<void> String::PushBack(char ch)
{ {
TRY(EnsureCapasity(m_size + 2)); TRY(EnsureCapasity(m_size + 2));
@ -70,8 +76,6 @@ namespace BAN
ErrorOr<void> String::Insert(StringView other, size_type index) ErrorOr<void> String::Insert(StringView other, size_type index)
{ {
dprintln("insert '{}' to '{}' at index {}", other, *this, index);
ASSERT(index <= m_size); ASSERT(index <= m_size);
TRY(EnsureCapasity(m_size + other.Size() + 1)); TRY(EnsureCapasity(m_size + other.Size() + 1));
memmove(m_data + index + other.Size(), m_data + index, m_size - index); memmove(m_data + index + other.Size(), m_data + index, m_size - index);

View File

@ -24,6 +24,7 @@ namespace BAN
String& operator=(const String&); String& operator=(const String&);
String& operator=(String&&); String& operator=(String&&);
String& operator=(StringView);
[[nodiscard]] ErrorOr<void> PushBack(char); [[nodiscard]] ErrorOr<void> PushBack(char);
[[nodiscard]] ErrorOr<void> Insert(char, size_type); [[nodiscard]] ErrorOr<void> Insert(char, size_type);