mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
AK: Add a Utf16View::is_code_unit_less_than helper
This seems like the natural place to put this since it is specific to UTF-16.
This commit is contained in:
parent
233022c473
commit
5cf87dcfdc
Notes:
github-actions[bot]
2025-05-17 12:02:09 +00:00
Author: https://github.com/shannonbooth
Commit: 5cf87dcfdc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4740
Reviewed-by: https://github.com/stelar7
Reviewed-by: https://github.com/trflynn89
2 changed files with 17 additions and 0 deletions
|
@ -300,6 +300,22 @@ bool Utf16View::starts_with(Utf16View const& needle) const
|
|||
return true;
|
||||
}
|
||||
|
||||
// https://infra.spec.whatwg.org/#code-unit-less-than
|
||||
bool Utf16View::is_code_unit_less_than(Utf16View const& other) const
|
||||
{
|
||||
auto a = m_code_units;
|
||||
auto b = other.m_code_units;
|
||||
|
||||
auto common_length = min(a.size(), b.size());
|
||||
|
||||
for (size_t position = 0; position < common_length; ++position) {
|
||||
if (a[position] != b[position])
|
||||
return a[position] < b[position];
|
||||
}
|
||||
|
||||
return a.size() < b.size();
|
||||
}
|
||||
|
||||
bool Utf16View::validate() const
|
||||
{
|
||||
return simdutf::validate_utf16(char_data(), length_in_code_units());
|
||||
|
|
|
@ -135,6 +135,7 @@ public:
|
|||
Utf16View unicode_substring_view(size_t code_point_offset) const { return unicode_substring_view(code_point_offset, length_in_code_points() - code_point_offset); }
|
||||
|
||||
bool starts_with(Utf16View const&) const;
|
||||
bool is_code_unit_less_than(Utf16View const& other) const;
|
||||
|
||||
bool validate() const;
|
||||
bool validate(size_t& valid_code_units) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue