Replace offset_to_bytes() implementation

We should re-use the offset_to_bytes() implementation from ClutterEntry
as it guaranteed some behaviour and sanity checks that we want to keep
inside ClutterText.
This commit is contained in:
Emmanuele Bassi 2008-12-11 11:47:06 +00:00
parent 94789e3cc3
commit 7fa93ebe9e

View File

@ -182,15 +182,47 @@ enum
static guint text_signals[LAST_SIGNAL] = { 0, }; static guint text_signals[LAST_SIGNAL] = { 0, };
#define offset_real(text, pos) \ #define offset_real(t,p) \
(pos == -1 ? g_utf8_strlen (text, -1) : pos) ((p) == -1 ? g_utf8_strlen ((t), -1) : (p))
#define offset_to_bytes(text,pos) \ static gint
(pos == -1 ? strlen (text) \ offset_to_bytes (const gchar *text,
: ((gint) (g_utf8_offset_to_pointer (text, pos) - text))) gint pos)
{
gchar *c = NULL;
gint i, j, len;
#define bytes_to_offset(text, pos) \ if (pos < 0)
(g_utf8_pointer_to_offset (text, text + pos)) return strlen (text);
#if 0
if (pos < 1)
return pos;
#endif
c = g_utf8_next_char (text);
j = 1;
len = strlen (text);
for (i = 0; i < len; i++)
{
if (&text[i] == c)
{
if (j == pos)
break;
else
{
c = g_utf8_next_char (c);
j++;
}
}
}
return i;
}
#define bytes_to_offset(t,p) \
(g_utf8_pointer_to_offset ((t), (t) + (p)))
typedef struct TextCommand { typedef struct TextCommand {