encoding/
all.rs

1// This is a part of rust-encoding.
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 index_singlebyte as index;
8use codec;
9use 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=IBM866, mod=index::ibm866, name|whatwg="ibm866");
42singlebyte!(var=ISO_8859_1, mod=codec::singlebyte::iso_8859_1, name="iso-8859-1");
43singlebyte!(var=ISO_8859_2, mod=index::iso_8859_2, name|whatwg="iso-8859-2");
44singlebyte!(var=ISO_8859_3, mod=index::iso_8859_3, name|whatwg="iso-8859-3");
45singlebyte!(var=ISO_8859_4, mod=index::iso_8859_4, name|whatwg="iso-8859-4");
46singlebyte!(var=ISO_8859_5, mod=index::iso_8859_5, name|whatwg="iso-8859-5");
47singlebyte!(var=ISO_8859_6, mod=index::iso_8859_6, name|whatwg="iso-8859-6");
48singlebyte!(var=ISO_8859_7, mod=index::iso_8859_7, name|whatwg="iso-8859-7");
49singlebyte!(var=ISO_8859_8, mod=index::iso_8859_8, name|whatwg="iso-8859-8");
50singlebyte!(var=ISO_8859_10, mod=index::iso_8859_10, name|whatwg="iso-8859-10");
51singlebyte!(var=ISO_8859_13, mod=index::iso_8859_13, name|whatwg="iso-8859-13");
52singlebyte!(var=ISO_8859_14, mod=index::iso_8859_14, name|whatwg="iso-8859-14");
53singlebyte!(var=ISO_8859_15, mod=index::iso_8859_15, name|whatwg="iso-8859-15");
54singlebyte!(var=ISO_8859_16, mod=index::iso_8859_16, name|whatwg="iso-8859-16");
55singlebyte!(var=KOI8_R, mod=index::koi8_r, name|whatwg="koi8-r");
56singlebyte!(var=KOI8_U, mod=index::koi8_u, name|whatwg="koi8-u");
57singlebyte!(var=MAC_ROMAN, mod=index::macintosh, name="mac-roman", whatwg=Some("macintosh"));
58singlebyte!(var=WINDOWS_874, mod=index::windows_874, name|whatwg="windows-874");
59singlebyte!(var=WINDOWS_1250, mod=index::windows_1250, name|whatwg="windows-1250");
60singlebyte!(var=WINDOWS_1251, mod=index::windows_1251, name|whatwg="windows-1251");
61singlebyte!(var=WINDOWS_1252, mod=index::windows_1252, name|whatwg="windows-1252");
62singlebyte!(var=WINDOWS_1253, mod=index::windows_1253, name|whatwg="windows-1253");
63singlebyte!(var=WINDOWS_1254, mod=index::windows_1254, name|whatwg="windows-1254");
64singlebyte!(var=WINDOWS_1255, mod=index::windows_1255, name|whatwg="windows-1255");
65singlebyte!(var=WINDOWS_1256, mod=index::windows_1256, name|whatwg="windows-1256");
66singlebyte!(var=WINDOWS_1257, mod=index::windows_1257, name|whatwg="windows-1257");
67singlebyte!(var=WINDOWS_1258, mod=index::windows_1258, name|whatwg="windows-1258");
68singlebyte!(var=MAC_CYRILLIC, mod=index::x_mac_cyrillic,
69            name="mac-cyrillic", whatwg=Some("x-mac-cyrillic"));
70unique!(var=UTF_8, mod=codec::utf_8, val=UTF8Encoding);
71unique!(var=UTF_16LE, mod=codec::utf_16, ty=UTF16LEEncoding, val=UTF_16LE_ENCODING);
72unique!(var=UTF_16BE, mod=codec::utf_16, ty=UTF16BEEncoding, val=UTF_16BE_ENCODING);
73unique!(var=WINDOWS_949, mod=codec::korean, val=Windows949Encoding);
74unique!(var=EUC_JP, mod=codec::japanese, val=EUCJPEncoding);
75unique!(var=WINDOWS_31J, mod=codec::japanese, val=Windows31JEncoding);
76unique!(var=ISO_2022_JP, mod=codec::japanese, val=ISO2022JPEncoding);
77unique!(var=GBK, mod=codec::simpchinese, ty=GBKEncoding, val=GBK_ENCODING);
78unique!(var=GB18030, mod=codec::simpchinese, ty=GB18030Encoding, val=GB18030_ENCODING);
79unique!(var=HZ, mod=codec::simpchinese, val=HZEncoding);
80unique!(var=BIG5_2003, mod=codec::tradchinese, val=BigFive2003Encoding);
81
82pub mod whatwg {
83    use index_singlebyte as index;
84    use codec;
85
86    singlebyte!(var=X_USER_DEFINED, mod=codec::whatwg::x_user_defined,
87                name="pua-mapped-binary", whatwg=Some("x-user-defined"));
88    singlebyte!(var=ISO_8859_8_I, mod=index::iso_8859_8, name|whatwg="iso-8859-8-i");
89    unique!(var=REPLACEMENT, mod=codec::whatwg, val=EncoderOnlyUTF8Encoding);
90}
91
92/// Returns a list of references to the encodings available.
93pub fn encodings() -> &'static [EncodingRef] {
94    // TODO should be generated automatically
95    const ENCODINGS: &'static [EncodingRef] = &[
96        ERROR,
97        ASCII,
98        IBM866,
99        ISO_8859_1,
100        ISO_8859_2,
101        ISO_8859_3,
102        ISO_8859_4,
103        ISO_8859_5,
104        ISO_8859_6,
105        ISO_8859_7,
106        ISO_8859_8,
107        ISO_8859_10,
108        ISO_8859_13,
109        ISO_8859_14,
110        ISO_8859_15,
111        ISO_8859_16,
112        KOI8_R,
113        KOI8_U,
114        MAC_ROMAN,
115        WINDOWS_874,
116        WINDOWS_1250,
117        WINDOWS_1251,
118        WINDOWS_1252,
119        WINDOWS_1253,
120        WINDOWS_1254,
121        WINDOWS_1255,
122        WINDOWS_1256,
123        WINDOWS_1257,
124        WINDOWS_1258,
125        MAC_CYRILLIC,
126        UTF_8,
127        UTF_16LE,
128        UTF_16BE,
129        WINDOWS_949,
130        EUC_JP,
131        WINDOWS_31J,
132        ISO_2022_JP,
133        GBK,
134        GB18030,
135        HZ,
136        BIG5_2003,
137        whatwg::X_USER_DEFINED,
138        whatwg::ISO_8859_8_I,
139        whatwg::REPLACEMENT,
140    ];
141    ENCODINGS
142}
143