mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00
AK: Add a Utf16View::starts_with method
Based heavily on Utf8View::starts_with.
This commit is contained in:
parent
c46ba7e68d
commit
1b4a23095c
3 changed files with 47 additions and 0 deletions
|
@ -213,6 +213,25 @@ Utf16View Utf16View::unicode_substring_view(size_t code_point_offset, size_t cod
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool Utf16View::starts_with(Utf16View const& needle) const
|
||||
{
|
||||
if (needle.is_empty())
|
||||
return true;
|
||||
if (is_empty())
|
||||
return false;
|
||||
if (needle.length_in_code_units() > length_in_code_units())
|
||||
return false;
|
||||
if (begin_ptr() == needle.begin_ptr())
|
||||
return true;
|
||||
|
||||
for (auto this_it = begin(), needle_it = needle.begin(); needle_it != needle.end(); ++needle_it, ++this_it) {
|
||||
if (*this_it != *needle_it)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Utf16View::validate(size_t& valid_code_units) const
|
||||
{
|
||||
valid_code_units = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue