libiconv convert utf8 to gbk fialed when text contains `ellipsis(……)` only in iOS17

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:

  1. only iOS 17, iOS 16- is OK;
  2. Text contains ellipsis(……) such as ……测试字符串;
  3. Convert to gbk or gb18030 is failed and return -1, but gb2312 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 "";
    }
}

Accepted Reply

We have also encountered similar issues, and our current solution is to compile the source code of IOS16's iconv into libiconv.a library to replace libiconv.tbd. Until Apple resolves this issue, it seems like there is no better alternative.

  • Hi shenbj,

    I have resolved the problem by using Objective-C interface kCFStringEncodingGB_18030_2000, and replace libiconv C library with Objective-C itself method.

Add a Comment

Replies

We have also encountered similar issues, and our current solution is to compile the source code of IOS16's iconv into libiconv.a library to replace libiconv.tbd. Until Apple resolves this issue, it seems like there is no better alternative.

  • Hi shenbj,

    I have resolved the problem by using Objective-C interface kCFStringEncodingGB_18030_2000, and replace libiconv C library with Objective-C itself method.

Add a Comment

Hi shenbj,

I have resolve the problem by using Objective-C interface kCFStringEncodingGB_18030_2000, and replace iconv C library with Objective-C itself method.