免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: 还不错
打印 上一主题 下一主题

[函数] 关于iconv转换不常见字符失败的问题 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2009-05-22 17:30 |只看该作者
原帖由 blackuhlan 于 2009-5-22 17:10 发表
或者你的界面显示不出来,或者你没有编码转换表,或者你的编码转换表是错的


iconv用的是系统的转换表吧?怎么看?

论坛徽章:
0
12 [报告]
发表于 2009-05-22 20:51 |只看该作者
void *UTB_GBK(const char* p1, const char*p2)
{
    iconv_t h;
    size_t n;
    if ((h = iconv_open("GBK", "UTF-8")) == (iconv_t) - 1)
    {
        printf("error iconv1!\n");
        return;
    }
    size_t size_from = strlen(p1);
    size_t size_to = 1000;
    if ((n = iconv(h, (char**) & p1, &size_from, (char**) & p2, &size_to)) == -1)
    {
        perror("error iconv doing\n");
        return;
    }
    iconv_close(h);
};

以前写的一个应用,不知道对你有没有帮组!

论坛徽章:
0
13 [报告]
发表于 2009-05-23 09:13 |只看该作者
谢谢楼上这位老兄,我代码差不多就是这样的


int DecodeUCS2(char *v_strdest,const unsigned char *v_strsrc,int v_len)
{
        iconv_t cd;
        int outlen=255;
        int inlen=v_len;
        char **pin = (char **)&v_strsrc;
        char **pout = &v_strdest;
       
        memset(v_strdest,0x0,255);
        if((cd=iconv_open("gb2312","UCS-2BE"))==(iconv_t)-1)
        {
                return -1;
        }
        if(iconv(cd,pin,&inlen,pout,&outlen)==-1)
        {
                iconv_close(cd);
                return -1;
        }
        iconv_close(cd);
        return 255-outlen;
}

[ 本帖最后由 还不错 于 2009-5-23 09:17 编辑 ]

论坛徽章:
0
14 [报告]
发表于 2009-05-23 10:34 |只看该作者
如果你的是windows的话,一般转换表(汉字对应的)都很全,傻瓜型操作系统的特点嘛。
如果你的是unix的话,man iconv能找到相应的转换表所在目录,例如我的是hp,man iconv后有这么一段话:

      The fromcode and tocode names can be any of the base and alias names
      listed in the iconv configuration file,
      /usr/lib/nls/iconv/config.iconv.  See iconv(3C) for details and the
      configuration file for a list of supported code set names.
所以我知道他的转换表有那些

论坛徽章:
0
15 [报告]
发表于 2009-05-23 10:59 |只看该作者
linux下man iconv没有发现转换表目录,我find了一下好像也没有找到,我怀疑还是转换表不如windows下全造成的。是否可以更新linux下的转换表了?让他更完整

论坛徽章:
0
16 [报告]
发表于 2009-05-23 11:32 |只看该作者
理论上是可以的,你找下/usr/lang/nls看看,linux不熟哈。应该是在nls目录下。例如我的转换表在/usr/lib/nls/iconv/tables目录.仔细阅读man iconv出来的东西,至少aix和hp我都是通过man iconv找到他的转换表的。

论坛徽章:
0
17 [报告]
发表于 2009-05-23 14:02 |只看该作者
谢谢楼上这位兄弟了。我man的全部内容如下:
ICONV(1)                                                              ICONV(1)

NAME
       iconv - Convert encoding of given files from one encoding to another

SYNOPSIS
       iconv -f encoding -t encoding inputfile

DESCRIPTION
       The iconv program converts the encoding of characters in inputfile from
       one coded character set to another. The result is written to standard
       output unless otherwise specified by the --output option.

       --from-code, -f encoding

       Convert characters from encoding

       --to-code, -t encoding

       Convert characters to encoding

       --list

       List known coded character sets

       --output, -o file

       Specify output file (instead of stdout)

       --verbose

       Print progress information.

AUTHOR
       iconv is written by Ulrich Drepper as part of the GNU C Library.

       This man page is written by Joel Klecker <espy@debian.org>, for the
       Debian GNU/Linux system.

3rd Berkeley Distribution         March 2001                          ICONV(1)

论坛徽章:
0
18 [报告]
发表于 2009-05-25 09:04 |只看该作者
还有哪位能来帮看看吗?

论坛徽章:
0
19 [报告]
发表于 2009-05-25 11:07 |只看该作者
你转成UTF16BE看看

论坛徽章:
0
20 [报告]
发表于 2011-04-18 12:01 |只看该作者
MARK
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP