1 /**************************************************************************
2 * Copyright (C), AirM2M Tech. Co., Ltd.
4 * Name: gb2312_to_ucs2.c
11 **************************************************************************/
16 #include "gb2312_to_ucs2_table.h"
18 uint16_t gb2312_to_ucs(uint16_t gb2312
)
29 uint16_t offset
= ((gb2312
>> 8) - 0xA0) * 94 + ((gb2312
& 0x00ff) - 0xA1);
30 ucs
= gb2312_to_ucs2_table
[offset
];
36 size_t iconv_gb2312_to_ucs2_endian(char **_inbuf
, size_t *inbytesleft
, char **_outbuf
, size_t *outbytesleft
, int endian
)
38 uint16_t offset
,gb2312
;
39 char *gbbuf
= *_inbuf
;
40 uint16_t *ucs2buf
= (uint16_t*)*_outbuf
;
43 size_t inlen
= *inbytesleft
;
44 size_t outlen
= *outbytesleft
;
49 if(ucs2len
+2 > outlen
)
53 goto gb2312_to_ucs2_exit
;
65 gb2312
= (gb2312
<<8) + ((*gbbuf
++)&0x00ff);
68 offset
= ((gb2312
>>8) - 0xA0)*94/*(0xFE-0xA1+1)*/ + ((gb2312
&0x00ff) - 0xA1);
69 ucs2
= gb2312_to_ucs2_table
[offset
];
77 ucs2
= (ucs2
<<8)|(ucs2
>>8);
93 *outbytesleft
-= ucs2len
;
98 size_t iconv_gb2312_to_ucs2(char **_inbuf
, size_t *inbytesleft
, char **_outbuf
, size_t *outbytesleft
)
100 return iconv_gb2312_to_ucs2_endian(_inbuf
, inbytesleft
, _outbuf
, outbytesleft
, 0);
103 size_t iconv_gb2312_to_ucs2be(char **_inbuf
, size_t *inbytesleft
, char **_outbuf
, size_t *outbytesleft
)
105 return iconv_gb2312_to_ucs2_endian(_inbuf
, inbytesleft
, _outbuf
, outbytesleft
, 1);