1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:44:58 +00:00

AK: Add convenience substring wrappers to String to exclude a length

These overloads exist on other string classes and are used throughout
the code base.
This commit is contained in:
Timothy Flynn 2023-01-22 11:40:57 -05:00 committed by Tim Flynn
parent 427b82065c
commit 76fd5f2756
2 changed files with 14 additions and 0 deletions

View file

@ -354,6 +354,12 @@ ErrorOr<String> String::substring_from_byte_offset(size_t start, size_t byte_cou
return String::from_utf8(bytes_as_string_view().substring_view(start, byte_count));
}
ErrorOr<String> String::substring_from_byte_offset(size_t start) const
{
VERIFY(start <= bytes_as_string_view().length());
return substring_from_byte_offset(start, bytes_as_string_view().length() - start);
}
ErrorOr<String> String::substring_from_byte_offset_with_shared_superstring(size_t start, size_t byte_count) const
{
if (!byte_count)
@ -363,6 +369,12 @@ ErrorOr<String> String::substring_from_byte_offset_with_shared_superstring(size_
return String { TRY(Detail::StringData::create_substring(*m_data, start, byte_count)) };
}
ErrorOr<String> String::substring_from_byte_offset_with_shared_superstring(size_t start) const
{
VERIFY(start <= bytes_as_string_view().length());
return substring_from_byte_offset_with_shared_superstring(start, bytes_as_string_view().length() - start);
}
bool String::operator==(char const* c_string) const
{
return bytes_as_string_view() == c_string;