mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-19 15:32:31 +00:00
AK+LibTextCodec: Stop using Utf16View endianness override
This is preparation for removing the endianness override, since it was only used by a single client: LibTextCodec. While here, add helpers and make use of simdutf for fast conversion.
This commit is contained in:
parent
96f1f15ad6
commit
0e9480b944
Notes:
github-actions[bot]
2025-04-16 08:06:08 +00:00
Author: https://github.com/awesomekling
Commit: 0e9480b944
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4370
7 changed files with 56 additions and 53 deletions
|
@ -369,25 +369,9 @@ ErrorOr<String> UTF8Decoder::to_utf8(StringView input)
|
|||
return String::from_utf8_with_replacement_character(input);
|
||||
}
|
||||
|
||||
static Utf16View as_utf16(StringView view, AK::Endianness endianness)
|
||||
{
|
||||
return Utf16View {
|
||||
{ reinterpret_cast<u16 const*>(view.bytes().data()), view.length() / 2 },
|
||||
endianness
|
||||
};
|
||||
}
|
||||
|
||||
ErrorOr<void> UTF16BEDecoder::process(StringView input, Function<ErrorOr<void>(u32)> on_code_point)
|
||||
{
|
||||
for (auto code_point : as_utf16(input, AK::Endianness::Big))
|
||||
TRY(on_code_point(code_point));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool UTF16BEDecoder::validate(StringView input)
|
||||
{
|
||||
return as_utf16(input, AK::Endianness::Big).validate();
|
||||
return AK::validate_utf16_be(input.bytes());
|
||||
}
|
||||
|
||||
ErrorOr<String> UTF16BEDecoder::to_utf8(StringView input)
|
||||
|
@ -396,20 +380,12 @@ ErrorOr<String> UTF16BEDecoder::to_utf8(StringView input)
|
|||
if (auto bytes = input.bytes(); bytes.size() >= 2 && bytes[0] == 0xFE && bytes[1] == 0xFF)
|
||||
input = input.substring_view(2);
|
||||
|
||||
return String::from_utf16(as_utf16(input, AK::Endianness::Big));
|
||||
}
|
||||
|
||||
ErrorOr<void> UTF16LEDecoder::process(StringView input, Function<ErrorOr<void>(u32)> on_code_point)
|
||||
{
|
||||
for (auto code_point : as_utf16(input, AK::Endianness::Little))
|
||||
TRY(on_code_point(code_point));
|
||||
|
||||
return {};
|
||||
return String::from_utf16_be(input.bytes());
|
||||
}
|
||||
|
||||
bool UTF16LEDecoder::validate(StringView input)
|
||||
{
|
||||
return as_utf16(input, AK::Endianness::Little).validate();
|
||||
return AK::validate_utf16_le(input.bytes());
|
||||
}
|
||||
|
||||
ErrorOr<String> UTF16LEDecoder::to_utf8(StringView input)
|
||||
|
@ -418,7 +394,7 @@ ErrorOr<String> UTF16LEDecoder::to_utf8(StringView input)
|
|||
if (auto bytes = input.bytes(); bytes.size() >= 2 && bytes[0] == 0xFF && bytes[1] == 0xFE)
|
||||
input = input.substring_view(2);
|
||||
|
||||
return String::from_utf16(as_utf16(input, AK::Endianness::Little));
|
||||
return String::from_utf16_le(input.bytes());
|
||||
}
|
||||
|
||||
ErrorOr<void> Latin1Decoder::process(StringView input, Function<ErrorOr<void>(u32)> on_code_point)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue