2016-05-25 00:52:53 -05:00
|
|
|
// 25 may 2016
|
2016-05-25 20:17:34 -05:00
|
|
|
#include "uipriv_unix.h"
|
2016-05-25 00:52:53 -05:00
|
|
|
|
2016-05-25 14:07:32 -05:00
|
|
|
ptrdiff_t *graphemes(const char *text, PangoContext *context)
|
2016-05-25 00:52:53 -05:00
|
|
|
{
|
2016-05-25 14:07:32 -05:00
|
|
|
size_t len, lenchars;
|
|
|
|
PangoLogAttr *logattrs;
|
|
|
|
ptrdiff_t *out;
|
|
|
|
ptrdiff_t *op;
|
|
|
|
size_t i;
|
2016-05-25 00:52:53 -05:00
|
|
|
|
|
|
|
len = strlen(text);
|
2016-05-25 14:07:32 -05:00
|
|
|
lenchars = g_utf8_strlen(text, -1);
|
|
|
|
logattrs = (PangoLogAttr *) uiAlloc((lenchars + 1) * sizeof (PangoLogAttr), "PangoLogAttr[]");
|
|
|
|
pango_get_log_attrs(text, len,
|
|
|
|
-1, NULL,
|
|
|
|
logattrs, lenchars + 1);
|
|
|
|
|
|
|
|
// should be more than enough
|
|
|
|
out = (ptrdiff_t *) uiAlloc((lenchars + 2) * sizeof (ptrdiff_t), "ptrdiff_t[]");
|
|
|
|
op = out;
|
|
|
|
for (i = 0; i < lenchars; i++)
|
|
|
|
if (logattrs[i].is_cursor_position != 0)
|
|
|
|
// TODO optimize this
|
|
|
|
*op++ = g_utf8_offset_to_pointer(text, i) - text;
|
|
|
|
// and do the last one
|
|
|
|
*op++ = len;
|
|
|
|
|
|
|
|
uiFree(logattrs);
|
|
|
|
return out;
|
2016-05-25 00:52:53 -05:00
|
|
|
}
|