1 /*
2  * Copyright (C) 2008, 2009
3  * Free Software Foundation, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * \author Yang Jianyu <xiaoyjy@hotmail.com>
11  */
12 
13 #ifndef _CCONV_H_
14 #define _CCONV_H_
15 
16 #include <iconv.h>
17 
18 #define CCONV_CODE_UTF  "UTF-8"
19 
20 // GBL means LARGEST of GB encoding.
21 #define CCONV_CODE_GBL  "GB18030"
22 #define CCONV_CODE_BIG  "BIG5"
23 
24 #define CCONV_CODE_UCN  "UTF8-CN"
25 #define CCONV_CODE_UTW  "UTF8-TW"
26 #define CCONV_CODE_UHK  "UTF8-HK"
27 
28 #define CCONV_CODE_UHS  "UTF8-HANS"
29 #define CCONV_CODE_UHT  "UTF8-HANT"
30 
31 #define CCONV_CODE_GHS  "GB-HANS"
32 #define CCONV_CODE_GHT  "GB-HANT"
33 
34 typedef enum cconv_type
35 {
36 	CCONV_ERROR = -1,
37 	CCONV_NULL  = 0 ,
38 	CCONV_GBL_TO_BIG = 1,
39 	CCONV_GBL_TO_UHS,
40 	CCONV_GBL_TO_UHT,
41 	CCONV_GBL_TO_GHS,
42 	CCONV_GBL_TO_GHT,
43 	CCONV_BIG_TO_GBL,
44 	CCONV_BIG_TO_UHS,
45 	CCONV_UTF_TO_UHT,
46 	CCONV_UTF_TO_UHS,
47 	CCONV_UTF_TO_GBL,
48 	CCONV_UTF_TO_BIG,
49 }
50 cconv_type;
51 
52 typedef void* cconv_t;
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 /* {{{ cconv_t cconv_open(const char* tocode, const char* fromcode) */
59 /**
60  * Open a cconv handle.
61  *
62  * @param   tocode	Convert to-code.
63  * @param   fromcode	Convert from-code.
64  * @retval  t_handle	Cconv handle,(-1: error).
65  */
66 extern cconv_t cconv_open(const char* tocode, const char* fromcode);
67 
68 
69 /**
70  * Convert character code.
71  *
72  * @param   t_handle    cconv handle.
73  * @param   inbuf       Input buffer.
74  * @param   inbytesleft Input buffer left.
75  * @retval  t_handle    cconv handle,(-1: error).
76  */
77 extern size_t cconv(cconv_t cd,
78 #ifdef FreeBSD
79 		const char** inbuf,
80 #else
81 		char** inbuf,
82 #endif
83 		size_t* inbytesleft,
84 		char**  outbuf,
85 		size_t* outbytesleft);
86 
87 
88 /* {{{ int cconv_close( cconv_t cd ) */
89 /**
90  * Close a cconv handle.
91  *
92  * @param   cd          cconv handle.
93  * @return              0: succ, -1: fail.
94  */
95 extern int cconv_close(cconv_t cd);
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif // _CCONV_H_
102 
103