All pastes #27349 Raw Edit

Untitled

public text v1 · immutable
#27349 ·published 2005-11-01 22:34 UTC
rendered paste body
gchar *
g_utf8_offset_to_pointer  (const gchar *str,
                           glong        offset)
{
  const gchar *s = str;

#define FOUR_SINGLEBYTE_CHARS(p) (*(guint32 *)(p) & 0xc0c0c0c0) == 0

  while (offset)
    {
      if (offset > 4 && FOUR_SINGLEBYTE_CHARS (s))
        {
          s += 4;
          offset -= 4;
        }
      else
        {
          --offset;
          s = g_utf8_next_char (s);
        }
    }

  return (gchar *)s;
}