1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
2
3 #include "ef_zh_cn_map.h"
4
5 #include "ef_iso2022_intern.h"
6 #include "ef_ucs4_map.h"
7 #include "ef_ucs4_gb2312.h"
8 #include "ef_ucs4_gbk.h"
9
10 /* --- static variables --- */
11
12 static ef_map_ucs4_to_func_t map_ucs4_to_funcs[] = {
13 ef_map_ucs4_to_gb2312_80, ef_map_ucs4_to_gbk,
14 };
15
16 /* --- global functions --- */
17
ef_map_ucs4_to_zh_cn(ef_char_t * zhcn,ef_char_t * ucs4)18 int ef_map_ucs4_to_zh_cn(ef_char_t *zhcn, ef_char_t *ucs4) {
19 return ef_map_ucs4_to_with_funcs(zhcn, ucs4, map_ucs4_to_funcs,
20 sizeof(map_ucs4_to_funcs) / sizeof(map_ucs4_to_funcs[0]));
21 }
22
ef_map_gbk_to_gb2312_80(ef_char_t * gb2312,ef_char_t * gbk)23 int ef_map_gbk_to_gb2312_80(ef_char_t *gb2312, ef_char_t *gbk) {
24 if (0xa1 <= gbk->ch[0] && gbk->ch[0] <= 0xfe && 0xa1 <= gbk->ch[1] && gbk->ch[1] <= 0xfe) {
25 gb2312->ch[0] = UNMAP_FROM_GR(gbk->ch[0]);
26 gb2312->ch[1] = UNMAP_FROM_GR(gbk->ch[1]);
27 gb2312->size = 2;
28 gb2312->cs = GB2312_80;
29
30 return 1;
31 } else {
32 return 0;
33 }
34 }
35
ef_map_gb2312_80_to_gbk(ef_char_t * gbk,ef_char_t * gb2312)36 int ef_map_gb2312_80_to_gbk(ef_char_t *gbk, ef_char_t *gb2312) {
37 gbk->ch[0] = MAP_TO_GR(gb2312->ch[0]);
38 gbk->ch[1] = MAP_TO_GR(gb2312->ch[1]);
39 gbk->size = 2;
40 gbk->cs = GBK;
41
42 return 1;
43 }
44