libwordring
whatwg/encoding/encoding_defs.hpp
1 #pragma once
2 
3 // https://encoding.spec.whatwg.org/
4 // https://triple-underscore.github.io/Encoding-ja.html
5 
6 #include <array>
7 #include <cstdint>
8 #include <variant>
9 
11 {
12  // 4.1. Encoders and decoders ---------------------------------------------
13 
14  class encoder {};
15  class decoder {};
16 
17  class result_finished {};
18  class result_continue {};
19 
20  using result_code_point = uint32_t;
21  using result_code_points_2 = std::array<uint32_t, 2>;
22 
23  using result_byte = uint8_t;
24  using result_bytes_2 = std::array<uint8_t, 2>;
25  using result_bytes_3 = std::array<uint8_t, 3>;
26  using result_bytes_4 = std::array<uint8_t, 4>;
27 
28  struct result_error
29  {
30  result_error() : code_point{ 0xFFFFFFFFu } {}
31  result_error(uint32_t cp) : code_point{ cp } {}
32  uint32_t code_point;
33  };
34 
35  using result_value = std::variant<
36  result_finished, // 0.
37  result_continue, // 1.
38  result_code_point, // 2.
39  result_code_points_2, // 3.
40  result_byte, // 4.
41  result_bytes_2, // 5.
42  result_bytes_3, // 6.
43  result_bytes_4, // 7.
44  result_error // 8.
45  >;
46 
47  enum class error_mode_name : uint32_t
48  {
49  None = 0,
50  Replacement = 1,
51  Fatal = 2,
52  Html = 3
53  };
54 
55  // 4.2. Names and labels --------------------------------------------------
56 
57  enum class encoding_name : uint32_t
58  {
59  UTF_8 = 1,
60 
61  // Legacy single - byte encodings
62  IBM866,
63  ISO_8859_2,
64  ISO_8859_3,
65  ISO_8859_4,
66  ISO_8859_5,
67  ISO_8859_6,
68  ISO_8859_7,
69  ISO_8859_8,
70  ISO_8859_8_I,
71  ISO_8859_10,
72  ISO_8859_13,
73  ISO_8859_14,
74  ISO_8859_15,
75  ISO_8859_16,
76  KOI8_R,
77  KOI8_U,
78  macintosh,
79  windows_874,
80  windows_1250,
81  windows_1251,
82  windows_1252,
83  windows_1253,
84  windows_1254,
85  windows_1255,
86  windows_1256,
87  windows_1257,
88  windows_1258,
89  x_mac_cyrillic,
90 
91  // Legacy multi - byte Chinese(simplified) encodings
92  GBK,
93  gb18030,
94 
95  // Legacy multi - byte Chinese(traditional) encodings
96  Big5,
97 
98  // Legacy multi - byte Japanese encodings
99  EUC_JP,
100  ISO_2022_JP,
101  Shift_JIS,
102 
103  // Legacy multi - byte Korean encodings
104  EUC_KR,
105 
106  // Legacy miscellaneous encodings
107  replacement,
108  UTF_16BE,
109  UTF_16LE,
110  x_user_defined,
111  };
112 }
113 
114 namespace wordring::whatwg
115 {
116  using encoding_name = encoding::encoding_name;
117 }
wordring::whatwg::encoding
wordring::whatwg
wordring::whatwg::encoding::encoder
Definition: whatwg/encoding/encoding_defs.hpp:14
wordring::whatwg::encoding::decoder
Definition: whatwg/encoding/encoding_defs.hpp:15
wordring::whatwg::encoding::result_finished
Definition: whatwg/encoding/encoding_defs.hpp:17
wordring::whatwg::encoding::result_error
Definition: whatwg/encoding/encoding_defs.hpp:28
wordring::whatwg::encoding::result_continue
Definition: whatwg/encoding/encoding_defs.hpp:18