Re: GtkTextBuffer, Gnome VFS, and UTF8 encoding...
- From: "Gustavo J. A. M. Carneiro" <gjc inescporto pt>
- To: email micahcarrick com
- Cc: Gnome Devel List <gnome-devel-list gnome org>
- Subject: Re: GtkTextBuffer, Gnome VFS, and UTF8 encoding...
- Date: Fri, 16 Sep 2005 13:48:52 +0100
On Wed, 2005-09-14 at 16:55 -0700, Micah Carrick wrote:
> I'm still wet behind the ears hear so bare with me. I'm trying to load
> a text file into a GtkTextBuffer. When doing so with local text files,
> no problem. However, when I open a file that I created on my Windows
> system, the program crashes due to utf8 validation. So used
> g_utf8_validate() to catch this. However, I need to be able to read
> this type of file (it's a text file containing assembly code). I'm
> using something like the following to read the file (using gnome-vfs):
>
> do {
> result = gnome_vfs_read (handle,
> text_buffer,
> BUFFER_SIZE,
> &bytes_read);
> bytes_total += bytes_read;
> } while(result == GNOME_VFS_OK);
>
> if(result == GNOME_VFS_ERROR_EOF) {
> if (!g_utf8_validate (text_buffer, (gssize)file_info->size, NULL))
> {
> g_debug("editor.c:open_file() Cannot open file. UTF8
> validation failed.\n");
>
> /* clean up */
> text_buffer = NULL;
> g_free(text_buffer);
> gnome_vfs_close(handle);
>
> return FALSE;
> }
> bla bla bla....
>
>
> Is there some easy way to determine the character coding of the file I'm
> opening and make a conversion before trying to put it into a
> GtkTextBuffer? Does GnomeVFS have anything? I couldn't find anything
> in the documentation. I've been trying to figure out how gedit does it
> by looking through the souce but I'm afraid I'm still quite new to this.
I don't know, but I think gedit has this. Browsing gedit source
should give you some code you can copy, if your program is GPL.
Regards.
--
Gustavo J. A. M. Carneiro
<gjc inescporto pt> <gustavo users sourceforge net>
The universe is always one step beyond logic.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]