Re: GtkTextBuffer: Q: offsets to indicies?



Hi,

I had the same problem. My current solution is to cache the offsets
already found. You could do something like this

int start = g_utf8_pointer_to_offset(data+last_index, data+t->start) +
last_offset;

where last_index is set to the byte index at the last call of
g_utf8_pointer_to_offset and last_offset is set to the char offset at
the last call of g_utf8_pointer_to_offset. This should make it a whole
lot faster.

Regards,
Janus N. Tøndering

On Wed, 2002-08-07 at 17:40, Olivier Sessink wrote:
On Tue, 06 Aug 2002 14:25:20 +0200 "Olivier Sessink"
<olivier lx student wau nl> wrote:


My problem is the handling of multibyte characters. I need to be able
to somehow convert an integer offset in the GtkTextBuffer into a index
(somthing a. la. gtk_text_buffer_get_iter_from_index). But I cannot
find such a function?

this is my function:

glong utf8_byteoffset_to_charsoffset(gchar *string, glong byteoffset) {
    return g_utf8_pointer_to_offset(string, &string[byteoffset]);
}

hmm today I was profiling my syntax highlighting, and I found that 90% of
the CPU time was spent on this function, is there a faster way of doing
this??

my syntax highlighting is based on regular expressions, so it returns
offsets in bytes, but to set a tag in the widget I currently use
gtk_text_buffer_get_iter_at_offset(doc->buffer, &itstart, istart);
which uses character offsets, and not byte-offsets.

regards,
      Olivier
-- 
Janus Nørgaard Tøndering        
email: janus bananus dk, j nus person dk or u011014 daimi au dk

"Would you buy a car with the hood welded shut?"
-Phil Hughes, Linux Journal Magazine





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