Decoder.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <AK/Function.h>
  9. namespace TextCodec {
  10. class Decoder {
  11. public:
  12. virtual void process(StringView, Function<void(u32)> on_code_point) = 0;
  13. virtual String to_utf8(StringView);
  14. protected:
  15. virtual ~Decoder() = default;
  16. };
  17. class UTF8Decoder final : public Decoder {
  18. public:
  19. virtual void process(StringView, Function<void(u32)> on_code_point) override;
  20. virtual String to_utf8(StringView) override;
  21. };
  22. class UTF16BEDecoder final : public Decoder {
  23. public:
  24. virtual void process(StringView, Function<void(u32)> on_code_point) override;
  25. virtual String to_utf8(StringView) override;
  26. };
  27. class Latin1Decoder final : public Decoder {
  28. public:
  29. virtual void process(StringView, Function<void(u32)> on_code_point) override;
  30. };
  31. class Latin2Decoder final : public Decoder {
  32. public:
  33. virtual void process(StringView, Function<void(u32)> on_code_point) override;
  34. };
  35. class HebrewDecoder final : public Decoder {
  36. public:
  37. virtual void process(StringView, Function<void(u32)> on_code_point) override;
  38. };
  39. class CyrillicDecoder final : public Decoder {
  40. public:
  41. virtual void process(StringView, Function<void(u32)> on_code_point) override;
  42. };
  43. class Koi8RDecoder final : public Decoder {
  44. public:
  45. virtual void process(StringView, Function<void(u32)> on_code_point) override;
  46. };
  47. class Latin9Decoder final : public Decoder {
  48. public:
  49. virtual void process(StringView, Function<void(u32)> on_code_point) override;
  50. };
  51. class TurkishDecoder final : public Decoder {
  52. public:
  53. virtual void process(StringView, Function<void(u32)> on_code_point) override;
  54. };
  55. Decoder* decoder_for(String const& encoding);
  56. Optional<String> get_standardized_encoding(const String& encoding);
  57. }