
This commit adds a new process method to all Decoder subclasses which do what to_utf8 used to do, and allows callers to customize the handling of individiual UTF-8 code points through a callback. Decoder::to_utf8 now uses this API to generate a string via StringBuilder, preserving the original behavior.
68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Forward.h>
|
|
#include <AK/Function.h>
|
|
|
|
namespace TextCodec {
|
|
|
|
class Decoder {
|
|
public:
|
|
virtual void process(StringView const&, Function<void(u32)> on_code_point) = 0;
|
|
virtual String to_utf8(StringView const&);
|
|
|
|
protected:
|
|
virtual ~Decoder() = default;
|
|
};
|
|
|
|
class UTF8Decoder final : public Decoder {
|
|
public:
|
|
virtual void process(StringView const&, Function<void(u32)> on_code_point) override;
|
|
virtual String to_utf8(StringView const&) override;
|
|
};
|
|
|
|
class UTF16BEDecoder final : public Decoder {
|
|
public:
|
|
virtual void process(StringView const&, Function<void(u32)> on_code_point) override;
|
|
virtual String to_utf8(StringView const&) override;
|
|
};
|
|
|
|
class Latin1Decoder final : public Decoder {
|
|
public:
|
|
virtual void process(StringView const&, Function<void(u32)> on_code_point) override;
|
|
};
|
|
|
|
class Latin2Decoder final : public Decoder {
|
|
public:
|
|
virtual void process(StringView const&, Function<void(u32)> on_code_point) override;
|
|
};
|
|
|
|
class HebrewDecoder final : public Decoder {
|
|
public:
|
|
virtual void process(StringView const&, Function<void(u32)> on_code_point) override;
|
|
};
|
|
|
|
class CyrillicDecoder final : public Decoder {
|
|
public:
|
|
virtual void process(StringView const&, Function<void(u32)> on_code_point) override;
|
|
};
|
|
|
|
class Latin9Decoder final : public Decoder {
|
|
public:
|
|
virtual void process(StringView const&, Function<void(u32)> on_code_point) override;
|
|
};
|
|
|
|
class TurkishDecoder final : public Decoder {
|
|
public:
|
|
virtual void process(StringView const&, Function<void(u32)> on_code_point) override;
|
|
};
|
|
|
|
Decoder* decoder_for(String const& encoding);
|
|
Optional<String> get_standardized_encoding(const String& encoding);
|
|
|
|
}
|