diff --git a/AK/String.cpp b/AK/String.cpp index c42b0891054..78fe2c3dd38 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -354,6 +354,12 @@ ErrorOr 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::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::substring_from_byte_offset_with_shared_superstring(size_t start, size_t byte_count) const { if (!byte_count) @@ -363,6 +369,12 @@ ErrorOr String::substring_from_byte_offset_with_shared_superstring(size_ return String { TRY(Detail::StringData::create_substring(*m_data, start, byte_count)) }; } +ErrorOr 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; diff --git a/AK/String.h b/AK/String.h index 05ceb42f868..ff72f4e35ee 100644 --- a/AK/String.h +++ b/AK/String.h @@ -107,9 +107,11 @@ public: // Creates a substring with a deep copy of the specified data window. ErrorOr substring_from_byte_offset(size_t start, size_t byte_count) const; + ErrorOr substring_from_byte_offset(size_t start) const; // Creates a substring that strongly references the origin superstring instead of making a deep copy of the data. ErrorOr substring_from_byte_offset_with_shared_superstring(size_t start, size_t byte_count) const; + ErrorOr substring_from_byte_offset_with_shared_superstring(size_t start) const; // Returns an iterable view over the Unicode code points. [[nodiscard]] Utf8View code_points() const;