libiconv convert utf8 to gbk fialed when text contains ellipsis(……)
only in iOS17, and in Xcode 15 I update the libiconv
because it's old.
I have test libiconv.tbd
and libicon.2.tbd
the same result.
Condition:
- only iOS 17, iOS 16- is OK;
- Text contains
ellipsis(……)
such as……测试字符串
;- Convert to
gbk
orgb18030
is failed and return -1, butgb2312
return is OK。
int code_convert(const char *from_charset, const char *to_charset, char *inbuf, size_t inlen,
char *outbuf, size_t outlen) {
iconv_t cd;
char **pin = &inbuf;
char **pout = &outbuf;
cd = iconv_open(to_charset, from_charset);
if (cd == 0)
return -1;
memset(outbuf, 0, outlen);
if ((int)iconv(cd, pin, &inlen, pout, &outlen) == -1)
{
iconv_close(cd);
std::cout<< "转换失败" << std::endl;
return -1;
}
iconv_close(cd);
return 0;
}
int u2g(char *inbuf, size_t inlen, char *outbuf, size_t outlen) {
//gb18030 , gb2312
return code_convert("utf-8", "gb2312", inbuf, inlen, outbuf, outlen);
}
std::string UTFtoGBK(const char* utf8)
{
int length = strlen(utf8);
char *temp = (char*)malloc(sizeof(char)*length);
if(u2g((char*)utf8,length,temp,length) >= 0)
{
std::string str_result;
str_result.append(temp);
free(temp);
return str_result;
}else
{
free(temp);
return "";
}
}