encoding/
all.rs

1// This is a part of encoding-next.
2// Copyright (c) 2013, Kang Seonghoon.
3// See README.md and LICENSE.txt for details.
4
5//! A list of all supported encodings. Useful for encodings fixed in the compile time.
6
7use crate::codec;
8use crate::index_singlebyte as index;
9use crate::types::EncodingRef;
10
11macro_rules! unique(
12    ($(#[$attr:meta])* var=$var:ident, mod=$($module:ident)::+, val=$val:ident) => (
13        unique!($(#[$attr])* var=$var, mod=$($module)::+, ty=$val, val=$val);
14    );
15    ($(#[$attr:meta])* var=$var:ident, mod=$($module:ident)::+, ty=$ty:ident, val=$val:ident) => (
16        $(#[$attr])* pub const $var: &'static $($module)::+::$ty = &$($module)::+::$val;
17    );
18);
19
20macro_rules! singlebyte(
21    ($(#[$attr:meta])* var=$var:ident, mod=$($module:ident)::+, name=$name:expr) => (
22        singlebyte!($(#[$attr])* var=$var, mod=$($module)::+, name=$name, whatwg=None);
23    );
24    ($(#[$attr:meta])* var=$var:ident, mod=$($module:ident)::+, name|whatwg=$name:expr) => (
25        singlebyte!($(#[$attr])* var=$var, mod=$($module)::+, name=$name, whatwg=Some($name));
26    );
27    ($(#[$attr:meta])* var=$var:ident, mod=$($module:ident)::+,
28                       name=$name:expr, whatwg=$whatwg:expr) => (
29        $(#[$attr])* pub const $var: &'static codec::singlebyte::SingleByteEncoding =
30            &codec::singlebyte::SingleByteEncoding {
31                name: $name,
32                whatwg_name: $whatwg,
33                index_forward: $($module)::+::forward,
34                index_backward: $($module)::+::backward,
35            };
36    )
37);
38
39unique!(var=ERROR, mod=codec::error, val=ErrorEncoding);
40unique!(var=ASCII, mod=codec::ascii, val=ASCIIEncoding);
41singlebyte!(var=ARMSCII_8, mod=index::armscii_8, name="armscii-8");
42singlebyte!(var=CP437, mod=index::cp437, name="cp437");
43singlebyte!(var=IBM866, mod=index::ibm866, name|whatwg="ibm866");
44singlebyte!(var=ISO_8859_1, mod=codec::singlebyte::iso_8859_1, name="iso-8859-1");
45singlebyte!(var=ISO_8859_2, mod=index::iso_8859_2, name|whatwg="iso-8859-2");
46singlebyte!(var=ISO_8859_3, mod=index::iso_8859_3, name|whatwg="iso-8859-3");
47singlebyte!(var=ISO_8859_4, mod=index::iso_8859_4, name|whatwg="iso-8859-4");
48singlebyte!(var=ISO_8859_5, mod=index::iso_8859_5, name|whatwg="iso-8859-5");
49singlebyte!(var=ISO_8859_6, mod=index::iso_8859_6, name|whatwg="iso-8859-6");
50singlebyte!(var=ISO_8859_7, mod=index::iso_8859_7, name|whatwg="iso-8859-7");
51singlebyte!(var=ISO_8859_8, mod=index::iso_8859_8, name|whatwg="iso-8859-8");
52singlebyte!(var=ISO_8859_10, mod=index::iso_8859_10, name|whatwg="iso-8859-10");
53singlebyte!(var=ISO_8859_13, mod=index::iso_8859_13, name|whatwg="iso-8859-13");
54singlebyte!(var=ISO_8859_14, mod=index::iso_8859_14, name|whatwg="iso-8859-14");
55singlebyte!(var=ISO_8859_15, mod=index::iso_8859_15, name|whatwg="iso-8859-15");
56singlebyte!(var=ISO_8859_16, mod=index::iso_8859_16, name|whatwg="iso-8859-16");
57singlebyte!(var=KOI8_R, mod=index::koi8_r, name|whatwg="koi8-r");
58singlebyte!(var=KOI8_U, mod=index::koi8_u, name|whatwg="koi8-u");
59singlebyte!(var=MAC_ROMAN, mod=index::macintosh, name="mac-roman", whatwg=Some("macintosh"));
60singlebyte!(var=WINDOWS_874, mod=index::windows_874, name|whatwg="windows-874");
61singlebyte!(var=WINDOWS_1250, mod=index::windows_1250, name|whatwg="windows-1250");
62singlebyte!(var=WINDOWS_1251, mod=index::windows_1251, name|whatwg="windows-1251");
63singlebyte!(var=WINDOWS_1252, mod=index::windows_1252, name|whatwg="windows-1252");
64singlebyte!(var=WINDOWS_1253, mod=index::windows_1253, name|whatwg="windows-1253");
65singlebyte!(var=WINDOWS_1254, mod=index::windows_1254, name|whatwg="windows-1254");
66singlebyte!(var=WINDOWS_1255, mod=index::windows_1255, name|whatwg="windows-1255");
67singlebyte!(var=WINDOWS_1256, mod=index::windows_1256, name|whatwg="windows-1256");
68singlebyte!(var=WINDOWS_1257, mod=index::windows_1257, name|whatwg="windows-1257");
69singlebyte!(var=WINDOWS_1258, mod=index::windows_1258, name|whatwg="windows-1258");
70singlebyte!(var=MAC_CYRILLIC, mod=index::x_mac_cyrillic,
71            name="mac-cyrillic", whatwg=Some("x-mac-cyrillic"));
72unique!(var=UTF_8, mod=codec::utf_8, val=UTF8Encoding);
73unique!(var=UTF_16LE, mod=codec::utf_16, val=UTF16LEEncoding);
74unique!(var=UTF_16BE, mod=codec::utf_16, val=UTF16BEEncoding);
75unique!(var=WINDOWS_949, mod=codec::korean, val=Windows949Encoding);
76unique!(var=EUC_JP, mod=codec::japanese, val=EUCJPEncoding);
77unique!(var=WINDOWS_31J, mod=codec::japanese, val=Windows31JEncoding);
78unique!(var=ISO_2022_JP, mod=codec::japanese, val=ISO2022JPEncoding);
79unique!(var=GBK, mod=codec::simpchinese, val=GBKEncoding);
80unique!(var=GB18030, mod=codec::simpchinese, val=GB18030Encoding);
81unique!(var=HZ, mod=codec::simpchinese, val=HZEncoding);
82unique!(var=BIG5_2003, mod=codec::tradchinese, val=BigFive2003Encoding);
83
84pub mod whatwg {
85    use crate::codec;
86    use crate::index_singlebyte as index;
87
88    singlebyte!(var=X_USER_DEFINED, mod=codec::whatwg::x_user_defined,
89                name="pua-mapped-binary", whatwg=Some("x-user-defined"));
90    singlebyte!(var=ISO_8859_8_I, mod=index::iso_8859_8, name|whatwg="iso-8859-8-i");
91    unique!(var=REPLACEMENT, mod=codec::whatwg, val=EncoderOnlyUTF8Encoding);
92}
93
94/// Returns a list of references to the encodings available.
95pub fn encodings() -> &'static [EncodingRef] {
96    // TODO should be generated automatically
97    const ENCODINGS: &[EncodingRef] = &[
98        ERROR,
99        ASCII,
100        CP437,
101        ARMSCII_8,
102        IBM866,
103        ISO_8859_1,
104        ISO_8859_2,
105        ISO_8859_3,
106        ISO_8859_4,
107        ISO_8859_5,
108        ISO_8859_6,
109        ISO_8859_7,
110        ISO_8859_8,
111        ISO_8859_10,
112        ISO_8859_13,
113        ISO_8859_14,
114        ISO_8859_15,
115        ISO_8859_16,
116        KOI8_R,
117        KOI8_U,
118        MAC_ROMAN,
119        WINDOWS_874,
120        WINDOWS_1250,
121        WINDOWS_1251,
122        WINDOWS_1252,
123        WINDOWS_1253,
124        WINDOWS_1254,
125        WINDOWS_1255,
126        WINDOWS_1256,
127        WINDOWS_1257,
128        WINDOWS_1258,
129        MAC_CYRILLIC,
130        UTF_8,
131        UTF_16LE,
132        UTF_16BE,
133        WINDOWS_949,
134        EUC_JP,
135        WINDOWS_31J,
136        ISO_2022_JP,
137        GBK,
138        GB18030,
139        HZ,
140        BIG5_2003,
141        whatwg::X_USER_DEFINED,
142        whatwg::ISO_8859_8_I,
143        whatwg::REPLACEMENT,
144    ];
145    ENCODINGS
146}