2026-04-28 06:32:35 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2026-present, the Ladybird developers.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/FlyString.h>
|
2026-06-22 17:07:40 -03:00
|
|
|
#include <LibTextCodec/Decoder.h>
|
2026-04-28 06:32:35 -03:00
|
|
|
|
|
|
|
|
namespace Web::Encoding {
|
|
|
|
|
|
|
|
|
|
// https://encoding.spec.whatwg.org/#textdecodercommon
|
|
|
|
|
class TextDecoderCommonMixin {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~TextDecoderCommonMixin();
|
|
|
|
|
|
|
|
|
|
// https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
|
|
|
|
|
FlyString const& encoding() const { return m_encoding; }
|
|
|
|
|
|
|
|
|
|
// https://encoding.spec.whatwg.org/#dom-textdecoder-fatal
|
2026-06-22 17:07:40 -03:00
|
|
|
bool fatal() const { return m_error_mode == TextCodec::ErrorMode::Fatal; }
|
2026-04-28 06:32:35 -03:00
|
|
|
|
|
|
|
|
// https://encoding.spec.whatwg.org/#dom-textdecoder-ignorebom
|
|
|
|
|
bool ignore_bom() const { return m_ignore_bom; }
|
|
|
|
|
|
|
|
|
|
protected:
|
2026-06-22 17:07:40 -03:00
|
|
|
TextDecoderCommonMixin(TextCodec::Decoder& decoder, FlyString encoding, TextCodec::ErrorMode error_mode, bool ignore_bom);
|
2026-04-28 06:32:35 -03:00
|
|
|
|
|
|
|
|
// https://encoding.spec.whatwg.org/#textdecodercommon-decoder
|
|
|
|
|
TextCodec::Decoder& m_decoder;
|
|
|
|
|
|
|
|
|
|
// https://encoding.spec.whatwg.org/#textdecoder-encoding
|
|
|
|
|
FlyString m_encoding;
|
|
|
|
|
|
|
|
|
|
// https://encoding.spec.whatwg.org/#textdecoder-error-mode
|
2026-06-22 17:07:40 -03:00
|
|
|
TextCodec::ErrorMode m_error_mode { TextCodec::ErrorMode::Replacement };
|
2026-04-28 06:32:35 -03:00
|
|
|
|
|
|
|
|
// https://encoding.spec.whatwg.org/#textdecoder-ignore-bom-flag
|
|
|
|
|
bool m_ignore_bom { false };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|