Re: Displaying a UTF-8 file in a text view

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Nečas writes:> So if we leave out all the redundant things (and add at> least basic sanity checks), this will remain:> >     GtkTextBuffer *textbuffer;>     gchar *buf;>     const gchar *errpos;>     GError *err = NULL;>     gsize n;> >     if (g_file_get_contents(filename, &buf, &n, &err)) {>         if (g_utf8_validate(buf, n, &errpos)) {>             textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textarea));>             gtk_text_buffer_set_text(textbuffer, buf, n);>         }>         else>             g_printerr("Invalid byte at position %d\n", (gint)(errpos - buf));>         g_free(buf);>     }>     else {>         g_printerr("Cannot read %s: %s\n", filename, err->message);>         g_clear_error(&err);>     }> > This works, and if it doesn't it will tell you what's wrong.
Thanks for bearing with me, but I just discovered that the documents aren'tUTF-8,  but actually ISO-10646-UCS-2 (opening from Kedit). Now, I am againstruggling to get that to show up.
Thanks.
Kumar


_______________________________________________gtk-list mailing listgtk-list@xxxxxxxxxxxxx://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux