Re: g_utf8_offset_to_pointer() optimization
- From: Behdad Esfahbod <behdad cs toronto edu>
- To: Luis Menina <liberforce fr st>
- Cc: performance-list gnome org
- Subject: Re: g_utf8_offset_to_pointer() optimization
- Date: Wed, 2 Nov 2005 21:00:14 -0500 (EST)
On Wed, 2 Nov 2005, Luis Menina wrote:
> Can you give me more info about what is wrong with my function ?
> I don't understand what you mean by "it doesn't pass over the tail of
> the last characters"
Your code fails if the last character to skipped is a multibyte
one. Suppose this is the input:
str = "\xC2\xA0"
offset = 1
which is the U+00A0 NO-BREAK SPACE. The output should be str +
2, but your code returns str + 1.
behdad
> >>gchar * g_utf8_offset_to_pointer1 ( const gchar *str,
> >> glong offset)
> >>{
> >> while (offset)
> >> {
> >> if ((*++str & 0xC0) != 0x80)
> >> --offset ;
> >> }
> >>
> >> return (gchar *)str;
> >>}
--behdad
http://behdad.org/
"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
-- Dan Bern, "New American Language"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]