Re: gtk_text_buffer_insert() problem character code transfer
- From: tomas tuxteam de
- To: æå <shahezzferry gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: gtk_text_buffer_insert() problem character code transfer
- Date: Sat, 3 Feb 2007 12:05:02 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Fri, Feb 02, 2007 at 05:03:20PM +0800, æå wrote:
hi everyone,
I have a GtkTextView to display the data in the buffer *buffer.
The buffer i received from a socket consists of English and Chinese
Characters.
How to display this Characters one by one using the API :
gtk_text_buffer_insert()?
I think I don't understand quite what you mean with "one by one".
Typically you'd add as much as you got from the socket -- like so:
/* at the beginning */
GtkTextBuffer *tb = gtk_text_buffer_new(NULL); /* or create a tag table */
/* everytime you get a load full of chars,
typically in a callback function */
int len;
char buf[1024];
if( (len=read(socket, buf, sizeof(buf))) > 0 ) {
GtkTextIter it;
gtk_text_buffer_get_end_iter(tb, &it); /* position it at end of text */
gtk_text_buffer_insert(tb, &it, buf, len); /* insert at end */
}
CAVEATS:
* this is totally untested code.
* you'll probably want a more intelligent function than read() to fetch
a bufferfull: the input will come in utf-8 (I assume), and read()
might brutally split multi-byte sequences; I'd expect
gtk_text_buffer_insert() to get upset about this: not what you want.
See g_io_channel_read_chars() & friends for a more robust soultion.
You'll find there also functions to use different encodings should
your input be other than utf-8.
HTH
- -- tomÃs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFFxHpuBcgs9XrR2kYRAlVNAJ98ALAMDC8XfPxEosj5yjsj/njggwCfUV6d
k8/IkimivncOo3o5H8uoDik=
=t9J7
-----END PGP SIGNATURE-----
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]