Re: GtkTextBuffer: Q: offsets to indicies?



On Qui, 2002-08-01 at 17:41, Janus N. Tøndering wrote:
On Thu, 2002-08-01 at 18:28, Gustavo Carneiro wrote:
  This is what you want:

gtk_text_buffer_get_iter_at_offset(GtkTextBuffer *buffer,
                                   GtkTextIter *iter,
                                   gint char_offset);


No, this is what I am using now. I do not have the char_offset - I have
the byte index. The text below (from the GTK+ API ref.) explains it:

  You can use g_utf8_pointer_to_offset() to convert a byte index to
character offset. Example:
        gchar *str="some utf-8 string";
        int offset=g_utf8_pointer_to_offset(str, str+byte_index);

  Of course, in your case 'str' would be obtained from the text buffer
instead.
  Hope this helps.


"One of the important things to remember about text in GTK+ is that it's
in the UTF-8 encoding. This means that one character can be encoded as
multiple bytes. Character counts are usually referred to as offsets,
while byte counts are called indexes. If you confuse these two, things
will work fine with ASCII, but as soon as your buffer contains multibyte
characters, bad things will happen."

Regards,
Janus N. Tøndering

-- 
Gustavo João Alves Marques Carneiro
<gjc inescporto pt> <gustavo users sourceforge net>



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