Repository navigation
Expand file tree
/
Copy pathcjkcodecs.rs
More file actions
55 lines (50 loc) · 1.51 KB
/
Copy pathcjkcodecs.rs
File metadata and controls
55 lines (50 loc) · 1.51 KB
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
//! The VM adapter for the CJK codec engines in `rustpython-common`.
//!
//! Laid out like `Modules/cjkcodecs/`: `multibytecodec` holds the codec objects
//! and the encode/decode drivers, and one `_codecs_*` module per region hands
//! out the codecs it registers.
pub(crate) mod multibytecodec;
/// Declares a `_codecs_*` module exposing `getcodec`, after
/// `cjkcodecs.h::I_AM_A_MODULE_FOR`.
macro_rules! codecs_module {
($module:ident, [$($name:literal),+ $(,)?]) => {
#[pymodule]
pub(crate) mod $module {
use crate::cjkcodecs::multibytecodec;
use crate::vm::{PyObjectRef, PyResult, VirtualMachine};
const CODECS: &[&'static str] = &[$($name),+];
#[pyfunction]
fn getcodec(object: PyObjectRef, vm: &VirtualMachine) -> PyResult {
multibytecodec::get_codec(CODECS, &object, vm)
}
}
};
}
codecs_module!(_codecs_cn, ["gb2312", "gbk", "gb18030", "hz"]);
codecs_module!(_codecs_hk, ["big5hkscs"]);
codecs_module!(
_codecs_iso2022,
[
"iso2022_kr",
"iso2022_jp",
"iso2022_jp_1",
"iso2022_jp_2",
"iso2022_jp_2004",
"iso2022_jp_3",
"iso2022_jp_ext",
]
);
codecs_module!(
_codecs_jp,
[
"shift_jis",
"cp932",
"euc_jp",
"shift_jis_2004",
"euc_jis_2004",
"euc_jisx0213",
"shift_jisx0213",
]
);
codecs_module!(_codecs_kr, ["euc_kr", "cp949", "johab"]);
codecs_module!(_codecs_tw, ["big5", "cp950"]);