#pragma once
#include "TextCodec.h"
#include <wtf/Optional.h>
namespace WebCore {
class TextCodecCJK final : public TextCodec {
public:
static void registerEncodingNames(EncodingNameRegistrar);
static void registerCodecs(TextCodecRegistrar);
enum class Encoding : uint8_t;
explicit TextCodecCJK(Encoding);
private:
String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError) final;
Vector<uint8_t> encode(StringView, UnencodableHandling) const final;
enum class SawError : bool { No, Yes };
String decodeCommon(const uint8_t*, size_t, bool, bool, bool&, const Function<SawError(uint8_t, StringBuilder&)>&);
String eucJPDecode(const uint8_t*, size_t, bool, bool, bool&);
String iso2022JPDecode(const uint8_t*, size_t, bool, bool, bool&);
String shiftJISDecode(const uint8_t*, size_t, bool, bool, bool&);
String eucKRDecode(const uint8_t*, size_t, bool, bool, bool&);
String big5Decode(const uint8_t*, size_t, bool, bool, bool&);
String gbkDecode(const uint8_t*, size_t, bool, bool, bool&);
String gb18030Decode(const uint8_t*, size_t, bool, bool, bool&);
const Encoding m_encoding;
bool m_jis0212 { false };
enum class ISO2022JPDecoderState : uint8_t { ASCII, Roman, Katakana, LeadByte, TrailByte, EscapeStart, Escape };
ISO2022JPDecoderState m_iso2022JPDecoderState { ISO2022JPDecoderState::ASCII };
ISO2022JPDecoderState m_iso2022JPDecoderOutputState { ISO2022JPDecoderState::ASCII };
bool m_iso2022JPOutput { false };
Optional<uint8_t> m_iso2022JPSecondPrependedByte;
uint8_t m_gb18030First { 0x00 };
uint8_t m_gb18030Second { 0x00 };
uint8_t m_gb18030Third { 0x00 };
uint8_t m_lead { 0x00 };
Optional<uint8_t> m_prependedByte;
};
}