-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy path_codecs_cn.java
More file actions
29 lines (25 loc) · 902 Bytes
/
Copy path_codecs_cn.java
File metadata and controls
29 lines (25 loc) · 902 Bytes
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
package org.python.modules.cjkcodecs;
import org.python.core.Py;
import org.python.core.PyObject;
import org.python.expose.ExposedFunction;
import org.python.expose.ExposedModule;
import java.nio.charset.Charset;
@ExposedModule(name = "_codecs_cn")
public class _codecs_cn {
private static Charset GB2312 = Charset.forName("gb2312");
private static Charset GBK = Charset.forName("gbk");
private static Charset GB18030 = Charset.forName("gb18030");
@ExposedFunction
public static PyObject getcodec(String name) {
switch(name) {
case "gb2312":
return new PyMultibyteCodec(GB2312);
case "gb18030":
return new PyMultibyteCodec(GB18030);
case "gbk":
return new PyMultibyteCodec(GBK);
default:
throw Py.LookupError("no such codec is supported");
}
}
}