diff --git a/AK/Utf16View.cpp b/AK/Utf16View.cpp index 232dde3e06..ea2234b9ff 100644 --- a/AK/Utf16View.cpp +++ b/AK/Utf16View.cpp @@ -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()); diff --git a/AK/Utf16View.h b/AK/Utf16View.h index 9be66ced81..26d80ee409 100644 --- a/AK/Utf16View.h +++ b/AK/Utf16View.h @@ -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;