AK: Define some UTF-16 helper methods

* contains
* escape_html_entities
* replace
* to_ascii_lowercase
* to_ascii_uppercase
* to_ascii_titlecase
* trim
* trim_whitespace
This commit is contained in:
Timothy Flynn 2025-06-27 12:30:25 -04:00 committed by Tim Flynn
commit 6e0290ecaa
Notes: github-actions[bot] 2025-07-18 16:47:12 +00:00
6 changed files with 345 additions and 1 deletions

View file

@ -43,6 +43,41 @@ public:
return Utf16String { move(copy) };
}
ALWAYS_INLINE Utf16FlyString to_ascii_lowercase() const
{
auto view = m_data.utf16_view();
if (view.has_ascii_storage()) {
if (!any_of(view.ascii_span(), is_ascii_upper_alpha))
return *this;
} else {
if (!any_of(view.utf16_span(), is_ascii_upper_alpha))
return *this;
}
return view.to_ascii_lowercase();
}
ALWAYS_INLINE Utf16FlyString to_ascii_uppercase() const
{
auto view = m_data.utf16_view();
if (view.has_ascii_storage()) {
if (!any_of(view.ascii_span(), is_ascii_lower_alpha))
return *this;
} else {
if (!any_of(view.utf16_span(), is_ascii_lower_alpha))
return *this;
}
return view.to_ascii_uppercase();
}
ALWAYS_INLINE Utf16FlyString to_ascii_titlecase() const
{
return view().to_ascii_titlecase();
}
ALWAYS_INLINE Utf16FlyString& operator=(Utf16String const& string)
{
*this = Utf16FlyString { string };