AK: Bring some missing DeprecatedString API over to String

Specifically, case sensitivity parameters for starts/ends with,
and the equals_ignoring_ascii_case() helper.
This commit is contained in:
Andreas Kling 2023-11-04 10:07:01 +01:00
parent f052823f5f
commit 0902f552a3
Notes: sideshowbarker 2024-07-16 20:08:14 +09:00
2 changed files with 13 additions and 6 deletions

View file

@ -513,9 +513,9 @@ bool String::starts_with(u32 code_point) const
return *code_points().begin() == code_point;
}
bool String::starts_with_bytes(StringView bytes) const
bool String::starts_with_bytes(StringView bytes, CaseSensitivity case_sensitivity) const
{
return bytes_as_string_view().starts_with(bytes);
return bytes_as_string_view().starts_with(bytes, case_sensitivity);
}
bool String::ends_with(u32 code_point) const
@ -530,9 +530,9 @@ bool String::ends_with(u32 code_point) const
return last_code_point == code_point;
}
bool String::ends_with_bytes(StringView bytes) const
bool String::ends_with_bytes(StringView bytes, CaseSensitivity case_sensitivity) const
{
return bytes_as_string_view().ends_with(bytes);
return bytes_as_string_view().ends_with(bytes, case_sensitivity);
}
bool String::is_short_string() const
@ -626,4 +626,9 @@ ErrorOr<String> String::from_deprecated_string(DeprecatedString const& deprecate
return String::from_utf8(deprecated_string.view());
}
bool String::equals_ignoring_ascii_case(StringView other) const
{
return StringUtils::equals_ignoring_ascii_case(bytes_as_string_view(), other);
}
}

View file

@ -101,11 +101,13 @@ public:
// Compare this String against another string with caseless matching. Using this method requires linking LibUnicode into your application.
[[nodiscard]] bool equals_ignoring_case(String const&) const;
[[nodiscard]] bool equals_ignoring_ascii_case(StringView) const;
[[nodiscard]] bool starts_with(u32 code_point) const;
[[nodiscard]] bool starts_with_bytes(StringView) const;
[[nodiscard]] bool starts_with_bytes(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
[[nodiscard]] bool ends_with(u32 code_point) const;
[[nodiscard]] bool ends_with_bytes(StringView) const;
[[nodiscard]] bool ends_with_bytes(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
// Creates a substring with a deep copy of the specified data window.
ErrorOr<String> substring_from_byte_offset(size_t start, size_t byte_count) const;