mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibTextCodec: Add replacement decoder
This commit is contained in:
parent
7f3b457e62
commit
11bb216912
Notes:
sideshowbarker
2024-07-17 07:35:03 +09:00
Author: https://github.com/skyrising Commit: https://github.com/SerenityOS/serenity/commit/11bb216912 Pull-request: https://github.com/SerenityOS/serenity/pull/24485 Reviewed-by: https://github.com/ADKaster
@ -34,6 +34,7 @@ EUCJPDecoder s_euc_jp_decoder;
|
||||
ISO2022JPDecoder s_iso_2022_jp_decoder;
|
||||
ShiftJISDecoder s_shift_jis_decoder;
|
||||
EUCKRDecoder s_euc_kr_decoder;
|
||||
ReplacementDecoder s_replacement_decoder;
|
||||
|
||||
// clang-format off
|
||||
// https://encoding.spec.whatwg.org/index-ibm866.txt
|
||||
@ -353,6 +354,8 @@ Optional<Decoder&> decoder_for(StringView a_encoding)
|
||||
return s_mac_roman_decoder;
|
||||
if (encoding.value().equals_ignoring_ascii_case("PDFDocEncoding"sv))
|
||||
return s_pdf_doc_encoding_decoder;
|
||||
if (encoding.value().equals_ignoring_ascii_case("replacement"sv))
|
||||
return s_replacement_decoder;
|
||||
if (encoding.value().equals_ignoring_ascii_case("shift_jis"sv))
|
||||
return s_shift_jis_decoder;
|
||||
if (encoding.value().equals_ignoring_ascii_case("windows-874"sv))
|
||||
@ -1777,4 +1780,18 @@ ErrorOr<void> EUCKRDecoder::process(StringView input, Function<ErrorOr<void>(u32
|
||||
}
|
||||
}
|
||||
|
||||
// https://encoding.spec.whatwg.org/#replacement-decoder
|
||||
ErrorOr<void> ReplacementDecoder::process(StringView input, Function<ErrorOr<void>(u32)> on_code_point)
|
||||
{
|
||||
// replacement’s decoder has an associated replacement error returned (initially false).
|
||||
// replacement’s decoder’s handler, given ioQueue and byte, runs these steps:
|
||||
// 1. If byte is end-of-queue, return finished.
|
||||
// 2. If replacement error returned is false, set replacement error returned to true and return error.
|
||||
// 3. Return finished.
|
||||
|
||||
if (!input.is_empty())
|
||||
return on_code_point(replacement_code_point);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -125,6 +125,12 @@ public:
|
||||
virtual ErrorOr<void> process(StringView, Function<ErrorOr<void>(u32)> on_code_point) override;
|
||||
};
|
||||
|
||||
class ReplacementDecoder final : public Decoder {
|
||||
public:
|
||||
virtual ErrorOr<void> process(StringView, Function<ErrorOr<void>(u32)> on_code_point) override;
|
||||
virtual bool validate(StringView input) override { return input.is_empty(); }
|
||||
};
|
||||
|
||||
Optional<Decoder&> decoder_for(StringView encoding);
|
||||
Optional<StringView> get_standardized_encoding(StringView encoding);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user