mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibTextCodec: Delegate to process() in default validate() implementation
This commit is contained in:
parent
88c2586f25
commit
9ed52504ab
Notes:
sideshowbarker
2024-07-17 00:23:42 +09:00
Author: https://github.com/skyrising Commit: https://github.com/SerenityOS/serenity/commit/9ed52504ab Pull-request: https://github.com/SerenityOS/serenity/pull/24485 Reviewed-by: https://github.com/ADKaster
2 changed files with 14 additions and 3 deletions
|
@ -531,10 +531,15 @@ StringView get_output_encoding(StringView encoding)
|
|||
return encoding;
|
||||
}
|
||||
|
||||
bool Decoder::validate(StringView)
|
||||
bool Decoder::validate(StringView input)
|
||||
{
|
||||
// By-default we assume that any input sequence is valid, character encodings that do not accept all inputs may override this
|
||||
return true;
|
||||
auto result = this->process(input, [](auto code_point) -> ErrorOr<void> {
|
||||
if (code_point == replacement_code_point)
|
||||
return Error::from_errno(EINVAL);
|
||||
return {};
|
||||
});
|
||||
|
||||
return !result.is_error();
|
||||
}
|
||||
|
||||
ErrorOr<String> Decoder::to_utf8(StringView input)
|
||||
|
|
|
@ -62,31 +62,37 @@ private:
|
|||
class Latin1Decoder final : public Decoder {
|
||||
public:
|
||||
virtual ErrorOr<void> process(StringView, Function<ErrorOr<void>(u32)> on_code_point) override;
|
||||
virtual bool validate(StringView) override { return true; }
|
||||
};
|
||||
|
||||
class Latin2Decoder final : public Decoder {
|
||||
public:
|
||||
virtual ErrorOr<void> process(StringView, Function<ErrorOr<void>(u32)> on_code_point) override;
|
||||
virtual bool validate(StringView) override { return true; }
|
||||
};
|
||||
|
||||
class Latin9Decoder final : public Decoder {
|
||||
public:
|
||||
virtual ErrorOr<void> process(StringView, Function<ErrorOr<void>(u32)> on_code_point) override;
|
||||
virtual bool validate(StringView) override { return true; }
|
||||
};
|
||||
|
||||
class PDFDocEncodingDecoder final : public Decoder {
|
||||
public:
|
||||
virtual ErrorOr<void> process(StringView, Function<ErrorOr<void>(u32)> on_code_point) override;
|
||||
virtual bool validate(StringView) override { return true; }
|
||||
};
|
||||
|
||||
class TurkishDecoder final : public Decoder {
|
||||
public:
|
||||
virtual ErrorOr<void> process(StringView, Function<ErrorOr<void>(u32)> on_code_point) override;
|
||||
virtual bool validate(StringView) override { return true; }
|
||||
};
|
||||
|
||||
class XUserDefinedDecoder final : public Decoder {
|
||||
public:
|
||||
virtual ErrorOr<void> process(StringView, Function<ErrorOr<void>(u32)> on_code_point) override;
|
||||
virtual bool validate(StringView) override { return true; }
|
||||
};
|
||||
|
||||
Optional<Decoder&> decoder_for(StringView encoding);
|
||||
|
|
Loading…
Add table
Reference in a new issue