iconv

文字コードの変換。

linux のコマンド、あるいはライブラリ。

jagtalk ではこんな使い方をしている。

http://github.com/nishimotz/jagtalk/blob/master/util.c

# include <iconv.h>
# define ICONV_BUFSIZE 4096
//
        char orig_buf[ICONV_BUFSIZE];
        char buf[ICONV_BUFSIZE];
        // orig_buf に文字列をコピー
        iconv_t m_iconv = iconv_open("UTF-8", "EUC-JP"); // tocode, fromcode
        size_t in_size = (size_t)ICONV_BUFSIZE;
        size_t out_size = (size_t)ICONV_BUFSIZE;
        char *in = orig_buf;
        char *out = buf;
        iconv(m_iconv, &in, &in_size, &out, &out_size);
        iconv_close(m_iconv);
        fputs( buf, stdout );
	fflush( stdout );

http://github.com/nishimotz/jagtalk/blob/master/getline.c

        char read_buf[ICONV_BUFSIZE];
	fgets( read_buf, ICONV_BUFSIZE, stdin );
	if( read_buf == NULL) return -1;
        iconv_t m_iconv = iconv_open("EUC-JP", "UTF-8"); // tocode, fromcode
        size_t in_size = (size_t)ICONV_BUFSIZE;
        size_t out_size = (size_t)MAX_LENGTH;
        char *in = read_buf;
        char *out = buf;
        iconv(m_iconv, &in, &in_size, &out, &out_size);
        iconv_close(m_iconv);
	int p = strlen( buf ) - 1;
	if( buf[p] == '\n' )  buf[p] = '\0';
	return p;
iconv.txt · 最終更新: 2010/06/29 13:04 (外部編集)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0