LibTextCodec: Delegate to process() in default validate() implementation

This commit is contained in:
Simon Wanner 2024-05-30 12:37:29 +02:00 committed by Andreas Kling
parent 88c2586f25
commit 9ed52504ab
Notes: sideshowbarker 2024-07-17 00:23:42 +09:00
2 changed files with 14 additions and 3 deletions

View file

@ -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)

View file

@ -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);