mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-26 18:59:35 +00:00
AK+LibJS: Extract some UTF-16 helpers for use in an outside class
An upcoming Utf16String will need access to these helpers. Let's make them publicly available.
This commit is contained in:
parent
b6dc5050d2
commit
66006d3812
Notes:
github-actions[bot]
2025-07-03 13:54:12 +00:00
Author: https://github.com/trflynn89
Commit: 66006d3812
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5228
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/shannonbooth
10 changed files with 121 additions and 86 deletions
|
@ -184,11 +184,11 @@ Optional<u32> TextEncoderStream::convert_code_unit_to_scalar_value(u32 item, Utf
|
|||
|
||||
// 3. If item is a trailing surrogate, then return a scalar value from surrogates given leadingSurrogate
|
||||
// and item.
|
||||
if (Utf16View::is_low_surrogate(item)) {
|
||||
if (AK::UnicodeUtils::is_utf16_low_surrogate(item)) {
|
||||
// https://encoding.spec.whatwg.org/#scalar-value-from-surrogates
|
||||
// To obtain a scalar value from surrogates, given a leading surrogate leading and a trailing surrogate
|
||||
// trailing, return 0x10000 + ((leading − 0xD800) << 10) + (trailing − 0xDC00).
|
||||
return Utf16View::decode_surrogate_pair(leading_surrogate, item);
|
||||
return AK::UnicodeUtils::decode_utf16_surrogate_pair(leading_surrogate, item);
|
||||
}
|
||||
|
||||
// 4. Restore item to input.
|
||||
|
@ -199,13 +199,13 @@ Optional<u32> TextEncoderStream::convert_code_unit_to_scalar_value(u32 item, Utf
|
|||
}
|
||||
|
||||
// 2. If item is a leading surrogate, then set encoder’s leading surrogate to item and return continue.
|
||||
if (Utf16View::is_high_surrogate(item)) {
|
||||
if (AK::UnicodeUtils::is_utf16_high_surrogate(item)) {
|
||||
m_leading_surrogate = item;
|
||||
return OptionalNone {};
|
||||
}
|
||||
|
||||
// 3. If item is a trailing surrogate, then return U+FFFD.
|
||||
if (Utf16View::is_low_surrogate(item))
|
||||
if (AK::UnicodeUtils::is_utf16_low_surrogate(item))
|
||||
return 0xFFFD;
|
||||
|
||||
// 4. Return item.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue