Character set encoding conversion through stream

original
2014/08/19 09:37
Reading number 207
 //Initialize file input stream tb_stream_ref_t istream = tb_stream_init_from_url("/home/utf8.txt"); //Initialize file output stream tb_stream_ref_t ostream = tb_stream_init_from_file("/home/gbk.txt",  TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_BINARY | TB_FILE_MODE_TRUNC); /*Initialize the character set encoding stream with istream as the input, utf8=>gbk * *All currently supported character set encoding formats: * * TB_CHARSET_TYPE_ASCII * TB_CHARSET_TYPE_GB2312 * TB_CHARSET_TYPE_GBK  * TB_CHARSET_TYPE_ISO8859  * TB_CHARSET_TYPE_UCS2  * TB_CHARSET_TYPE_UCS4  * TB_CHARSET_TYPE_UTF16  * TB_CHARSET_TYPE_UTF32  * TB_CHARSET_TYPE_UTF8  * *Note: For multi byte encoding formats, such as usc4, utf16,.. The default conversion uses the big end format *If you want to support data in small end format and local end format, you can pass in: *  *Small end format data: TB_CHARSET_TYPE_GBK | TB_CHARSET_TYPE_LE * *Local side format data: TB_CHARSET_TYPE_UTF32 | TB_CHARSET_TYPE_NE */ tb_stream_ref_t fstream = tb_stream_init_filter_from_charset(istream,  TB_CHARSET_TYPE_UTF8, TB_CHARSET_TYPE_GBK); //Stream coding if (istream && ostream && fstream)  { tb_hong_t save = tb_transfer_done(fstream,  ostream, 0, tb_null, tb_null); } //Release stream data if (fstream) tb_stream_exit(fstream); if (istream) tb_stream_exit(istream); if (ostream) tb_stream_exit(ostream);

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
zero Collection
zero fabulous
 Back to top
Top