charcode 0.1.5

Character encoding conversion implementing the WHATWG Encoding Standard, with no external dependencies.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
// @generated by tools/generate_tables.py from the WHATWG Encoding Standard indexes.
// https://encoding.spec.whatwg.org/indexes.json
// Do not edit by hand; re-run the generator instead.

//! The [`Encoding`] instances for every encoding compiled in.
//!
//! Each exists once as a private `const`, so that it can be named in other
//! constants such as the label table, and once as the `&'static` reference the
//! API hands out.  Both are gated on the feature that carries the encoding's
//! tables; see the crate documentation for what each feature covers.

use crate::Encoding;
#[cfg(feature = "single-byte")]
use crate::tables::single_byte as sb;
use crate::variant::VariantEncoding;

// The Encoding

pub(crate) const UTF_8_INIT: Encoding = Encoding::new("UTF-8", VariantEncoding::Utf8);
/// UTF-8, the encoding every new format should use.
pub static UTF_8: &Encoding = &UTF_8_INIT;

// Legacy single-byte encodings

#[cfg(feature = "single-byte")]
pub(crate) const IBM866_INIT: Encoding = Encoding::new(
    "IBM866",
    VariantEncoding::SingleByte(
        &sb::IBM866_DECODE,
        &sb::IBM866_ENCODE_CODE_POINTS,
        &sb::IBM866_ENCODE_BYTES,
    ),
);
/// IBM866.
#[cfg(feature = "single-byte")]
pub static IBM866: &Encoding = &IBM866_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_2_INIT: Encoding = Encoding::new(
    "ISO-8859-2",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_2_DECODE,
        &sb::ISO_8859_2_ENCODE_CODE_POINTS,
        &sb::ISO_8859_2_ENCODE_BYTES,
    ),
);
/// ISO-8859-2.
#[cfg(feature = "single-byte")]
pub static ISO_8859_2: &Encoding = &ISO_8859_2_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_3_INIT: Encoding = Encoding::new(
    "ISO-8859-3",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_3_DECODE,
        &sb::ISO_8859_3_ENCODE_CODE_POINTS,
        &sb::ISO_8859_3_ENCODE_BYTES,
    ),
);
/// ISO-8859-3.
#[cfg(feature = "single-byte")]
pub static ISO_8859_3: &Encoding = &ISO_8859_3_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_4_INIT: Encoding = Encoding::new(
    "ISO-8859-4",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_4_DECODE,
        &sb::ISO_8859_4_ENCODE_CODE_POINTS,
        &sb::ISO_8859_4_ENCODE_BYTES,
    ),
);
/// ISO-8859-4.
#[cfg(feature = "single-byte")]
pub static ISO_8859_4: &Encoding = &ISO_8859_4_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_5_INIT: Encoding = Encoding::new(
    "ISO-8859-5",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_5_DECODE,
        &sb::ISO_8859_5_ENCODE_CODE_POINTS,
        &sb::ISO_8859_5_ENCODE_BYTES,
    ),
);
/// ISO-8859-5.
#[cfg(feature = "single-byte")]
pub static ISO_8859_5: &Encoding = &ISO_8859_5_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_6_INIT: Encoding = Encoding::new(
    "ISO-8859-6",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_6_DECODE,
        &sb::ISO_8859_6_ENCODE_CODE_POINTS,
        &sb::ISO_8859_6_ENCODE_BYTES,
    ),
);
/// ISO-8859-6.
#[cfg(feature = "single-byte")]
pub static ISO_8859_6: &Encoding = &ISO_8859_6_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_7_INIT: Encoding = Encoding::new(
    "ISO-8859-7",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_7_DECODE,
        &sb::ISO_8859_7_ENCODE_CODE_POINTS,
        &sb::ISO_8859_7_ENCODE_BYTES,
    ),
);
/// ISO-8859-7.
#[cfg(feature = "single-byte")]
pub static ISO_8859_7: &Encoding = &ISO_8859_7_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_8_INIT: Encoding = Encoding::new(
    "ISO-8859-8",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_8_DECODE,
        &sb::ISO_8859_8_ENCODE_CODE_POINTS,
        &sb::ISO_8859_8_ENCODE_BYTES,
    ),
);
/// ISO-8859-8.
#[cfg(feature = "single-byte")]
pub static ISO_8859_8: &Encoding = &ISO_8859_8_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_8_I_INIT: Encoding = Encoding::new(
    "ISO-8859-8-I",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_8_DECODE,
        &sb::ISO_8859_8_ENCODE_CODE_POINTS,
        &sb::ISO_8859_8_ENCODE_BYTES,
    ),
);
/// ISO-8859-8-I, identical to [`ISO_8859_8`] except in its name and implied text direction.
#[cfg(feature = "single-byte")]
pub static ISO_8859_8_I: &Encoding = &ISO_8859_8_I_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_10_INIT: Encoding = Encoding::new(
    "ISO-8859-10",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_10_DECODE,
        &sb::ISO_8859_10_ENCODE_CODE_POINTS,
        &sb::ISO_8859_10_ENCODE_BYTES,
    ),
);
/// ISO-8859-10.
#[cfg(feature = "single-byte")]
pub static ISO_8859_10: &Encoding = &ISO_8859_10_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_13_INIT: Encoding = Encoding::new(
    "ISO-8859-13",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_13_DECODE,
        &sb::ISO_8859_13_ENCODE_CODE_POINTS,
        &sb::ISO_8859_13_ENCODE_BYTES,
    ),
);
/// ISO-8859-13.
#[cfg(feature = "single-byte")]
pub static ISO_8859_13: &Encoding = &ISO_8859_13_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_14_INIT: Encoding = Encoding::new(
    "ISO-8859-14",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_14_DECODE,
        &sb::ISO_8859_14_ENCODE_CODE_POINTS,
        &sb::ISO_8859_14_ENCODE_BYTES,
    ),
);
/// ISO-8859-14.
#[cfg(feature = "single-byte")]
pub static ISO_8859_14: &Encoding = &ISO_8859_14_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_15_INIT: Encoding = Encoding::new(
    "ISO-8859-15",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_15_DECODE,
        &sb::ISO_8859_15_ENCODE_CODE_POINTS,
        &sb::ISO_8859_15_ENCODE_BYTES,
    ),
);
/// ISO-8859-15.
#[cfg(feature = "single-byte")]
pub static ISO_8859_15: &Encoding = &ISO_8859_15_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const ISO_8859_16_INIT: Encoding = Encoding::new(
    "ISO-8859-16",
    VariantEncoding::SingleByte(
        &sb::ISO_8859_16_DECODE,
        &sb::ISO_8859_16_ENCODE_CODE_POINTS,
        &sb::ISO_8859_16_ENCODE_BYTES,
    ),
);
/// ISO-8859-16.
#[cfg(feature = "single-byte")]
pub static ISO_8859_16: &Encoding = &ISO_8859_16_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const KOI8_R_INIT: Encoding = Encoding::new(
    "KOI8-R",
    VariantEncoding::SingleByte(
        &sb::KOI8_R_DECODE,
        &sb::KOI8_R_ENCODE_CODE_POINTS,
        &sb::KOI8_R_ENCODE_BYTES,
    ),
);
/// KOI8-R.
#[cfg(feature = "single-byte")]
pub static KOI8_R: &Encoding = &KOI8_R_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const KOI8_U_INIT: Encoding = Encoding::new(
    "KOI8-U",
    VariantEncoding::SingleByte(
        &sb::KOI8_U_DECODE,
        &sb::KOI8_U_ENCODE_CODE_POINTS,
        &sb::KOI8_U_ENCODE_BYTES,
    ),
);
/// KOI8-U.
#[cfg(feature = "single-byte")]
pub static KOI8_U: &Encoding = &KOI8_U_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const MACINTOSH_INIT: Encoding = Encoding::new(
    "macintosh",
    VariantEncoding::SingleByte(
        &sb::MACINTOSH_DECODE,
        &sb::MACINTOSH_ENCODE_CODE_POINTS,
        &sb::MACINTOSH_ENCODE_BYTES,
    ),
);
/// macintosh.
#[cfg(feature = "single-byte")]
pub static MACINTOSH: &Encoding = &MACINTOSH_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_874_INIT: Encoding = Encoding::new(
    "windows-874",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_874_DECODE,
        &sb::WINDOWS_874_ENCODE_CODE_POINTS,
        &sb::WINDOWS_874_ENCODE_BYTES,
    ),
);
/// windows-874.
#[cfg(feature = "single-byte")]
pub static WINDOWS_874: &Encoding = &WINDOWS_874_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_1250_INIT: Encoding = Encoding::new(
    "windows-1250",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_1250_DECODE,
        &sb::WINDOWS_1250_ENCODE_CODE_POINTS,
        &sb::WINDOWS_1250_ENCODE_BYTES,
    ),
);
/// windows-1250.
#[cfg(feature = "single-byte")]
pub static WINDOWS_1250: &Encoding = &WINDOWS_1250_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_1251_INIT: Encoding = Encoding::new(
    "windows-1251",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_1251_DECODE,
        &sb::WINDOWS_1251_ENCODE_CODE_POINTS,
        &sb::WINDOWS_1251_ENCODE_BYTES,
    ),
);
/// windows-1251.
#[cfg(feature = "single-byte")]
pub static WINDOWS_1251: &Encoding = &WINDOWS_1251_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_1252_INIT: Encoding = Encoding::new(
    "windows-1252",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_1252_DECODE,
        &sb::WINDOWS_1252_ENCODE_CODE_POINTS,
        &sb::WINDOWS_1252_ENCODE_BYTES,
    ),
);
/// windows-1252.
#[cfg(feature = "single-byte")]
pub static WINDOWS_1252: &Encoding = &WINDOWS_1252_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_1253_INIT: Encoding = Encoding::new(
    "windows-1253",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_1253_DECODE,
        &sb::WINDOWS_1253_ENCODE_CODE_POINTS,
        &sb::WINDOWS_1253_ENCODE_BYTES,
    ),
);
/// windows-1253.
#[cfg(feature = "single-byte")]
pub static WINDOWS_1253: &Encoding = &WINDOWS_1253_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_1254_INIT: Encoding = Encoding::new(
    "windows-1254",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_1254_DECODE,
        &sb::WINDOWS_1254_ENCODE_CODE_POINTS,
        &sb::WINDOWS_1254_ENCODE_BYTES,
    ),
);
/// windows-1254.
#[cfg(feature = "single-byte")]
pub static WINDOWS_1254: &Encoding = &WINDOWS_1254_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_1255_INIT: Encoding = Encoding::new(
    "windows-1255",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_1255_DECODE,
        &sb::WINDOWS_1255_ENCODE_CODE_POINTS,
        &sb::WINDOWS_1255_ENCODE_BYTES,
    ),
);
/// windows-1255.
#[cfg(feature = "single-byte")]
pub static WINDOWS_1255: &Encoding = &WINDOWS_1255_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_1256_INIT: Encoding = Encoding::new(
    "windows-1256",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_1256_DECODE,
        &sb::WINDOWS_1256_ENCODE_CODE_POINTS,
        &sb::WINDOWS_1256_ENCODE_BYTES,
    ),
);
/// windows-1256.
#[cfg(feature = "single-byte")]
pub static WINDOWS_1256: &Encoding = &WINDOWS_1256_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_1257_INIT: Encoding = Encoding::new(
    "windows-1257",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_1257_DECODE,
        &sb::WINDOWS_1257_ENCODE_CODE_POINTS,
        &sb::WINDOWS_1257_ENCODE_BYTES,
    ),
);
/// windows-1257.
#[cfg(feature = "single-byte")]
pub static WINDOWS_1257: &Encoding = &WINDOWS_1257_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const WINDOWS_1258_INIT: Encoding = Encoding::new(
    "windows-1258",
    VariantEncoding::SingleByte(
        &sb::WINDOWS_1258_DECODE,
        &sb::WINDOWS_1258_ENCODE_CODE_POINTS,
        &sb::WINDOWS_1258_ENCODE_BYTES,
    ),
);
/// windows-1258.
#[cfg(feature = "single-byte")]
pub static WINDOWS_1258: &Encoding = &WINDOWS_1258_INIT;

#[cfg(feature = "single-byte")]
pub(crate) const X_MAC_CYRILLIC_INIT: Encoding = Encoding::new(
    "x-mac-cyrillic",
    VariantEncoding::SingleByte(
        &sb::X_MAC_CYRILLIC_DECODE,
        &sb::X_MAC_CYRILLIC_ENCODE_CODE_POINTS,
        &sb::X_MAC_CYRILLIC_ENCODE_BYTES,
    ),
);
/// x-mac-cyrillic.
#[cfg(feature = "single-byte")]
pub static X_MAC_CYRILLIC: &Encoding = &X_MAC_CYRILLIC_INIT;

// Legacy multi-byte Chinese (simplified) encodings

#[cfg(feature = "gb18030")]
pub(crate) const GBK_INIT: Encoding =
    Encoding::new("GBK", VariantEncoding::Gb18030 { is_gbk: true });
/// GBK, which decodes as [`GB18030`] but whose encoder emits only two-byte sequences.
#[cfg(feature = "gb18030")]
pub static GBK: &Encoding = &GBK_INIT;

#[cfg(feature = "gb18030")]
pub(crate) const GB18030_INIT: Encoding =
    Encoding::new("gb18030", VariantEncoding::Gb18030 { is_gbk: false });
/// gb18030, the Chinese national standard, which covers all of Unicode.
#[cfg(feature = "gb18030")]
pub static GB18030: &Encoding = &GB18030_INIT;

// Legacy multi-byte Chinese (traditional) encodings

#[cfg(feature = "big5")]
pub(crate) const BIG5_HKSCS_INIT: Encoding = Encoding::new("Big5-HKSCS", VariantEncoding::Big5);
/// The standard's Big5: Big5 plus the Hong Kong Supplementary Character Set and other common extensions.  For Big5 itself see [`BIG5`](crate::BIG5).
#[cfg(feature = "big5")]
pub static BIG5_HKSCS: &Encoding = &BIG5_HKSCS_INIT;

// Legacy multi-byte Japanese encodings

#[cfg(feature = "euc-jp")]
pub(crate) const X_WHATWG_EUC_JP_INIT: Encoding =
    Encoding::new("x-whatwg-euc-jp", VariantEncoding::EucJp);
/// The standard's EUC-JP, which folds the NEC and IBM extension rows into the JIS X 0208 plane and remaps six of its pointers.  Its decoder accepts JIS X 0212 via the 0x8F prefix; its encoder never writes one.  For EUC-JP itself see [`EUC_JP`](crate::EUC_JP).
#[cfg(feature = "euc-jp")]
pub static X_WHATWG_EUC_JP: &Encoding = &X_WHATWG_EUC_JP_INIT;

#[cfg(feature = "iso-2022-jp")]
pub(crate) const X_WHATWG_ISO_2022_JP_INIT: Encoding =
    Encoding::new("x-whatwg-iso-2022-jp", VariantEncoding::Iso2022Jp);
/// The standard's ISO-2022-JP, which adds a half-width katakana mode behind `ESC ( I`, folds the NEC and IBM extension rows into the JIS X 0208 plane, and remaps six of its pointers.  For ISO-2022-JP itself see [`ISO_2022_JP`](crate::ISO_2022_JP).
#[cfg(feature = "iso-2022-jp")]
pub static X_WHATWG_ISO_2022_JP: &Encoding = &X_WHATWG_ISO_2022_JP_INIT;

#[cfg(feature = "shift-jis")]
pub(crate) const WINDOWS_31J_INIT: Encoding =
    Encoding::new("windows-31j", VariantEncoding::ShiftJis);
/// The standard's Shift_JIS, which is Windows codepage 932: the NEC and IBM extension rows, the end-user defined area, and seven of JIS X 0208's pointers remapped.  For Shift_JIS itself see [`SHIFT_JIS`](crate::SHIFT_JIS).
#[cfg(feature = "shift-jis")]
pub static WINDOWS_31J: &Encoding = &WINDOWS_31J_INIT;

// Legacy multi-byte Korean encodings

#[cfg(feature = "euc-kr")]
pub(crate) const EUC_KR_INIT: Encoding = Encoding::new("EUC-KR", VariantEncoding::EucKr);
/// EUC-KR, in practice the Unified Hangul Code (Windows codepage 949).
#[cfg(feature = "euc-kr")]
pub static EUC_KR: &Encoding = &EUC_KR_INIT;

// Legacy miscellaneous encodings

pub(crate) const REPLACEMENT_INIT: Encoding =
    Encoding::new("replacement", VariantEncoding::Replacement);
/// The `replacement` encoding, which decodes any non-empty input to a single U+FFFD.
pub static REPLACEMENT: &Encoding = &REPLACEMENT_INIT;

pub(crate) const UTF_16BE_INIT: Encoding = Encoding::new("UTF-16BE", VariantEncoding::Utf16Be);
/// UTF-16BE.  Decode only; encoding to it yields UTF-8, per `get an output encoding`.
pub static UTF_16BE: &Encoding = &UTF_16BE_INIT;

pub(crate) const UTF_16LE_INIT: Encoding = Encoding::new("UTF-16LE", VariantEncoding::Utf16Le);
/// UTF-16LE.  Decode only; encoding to it yields UTF-8, per `get an output encoding`.
pub static UTF_16LE: &Encoding = &UTF_16LE_INIT;

pub(crate) const X_USER_DEFINED_INIT: Encoding =
    Encoding::new("x-user-defined", VariantEncoding::XUserDefined);
/// x-user-defined, which maps bytes 0x80 to 0xFF into the private use area.
pub static X_USER_DEFINED: &Encoding = &X_USER_DEFINED_INIT;