Use auxbuffer for serialize_unicode_text

This commit is contained in:
Simon Cozens 2020-09-18 09:27:27 +01:00
parent 97308ddf33
commit 174de30855
1 changed files with 22 additions and 17 deletions

View File

@ -334,21 +334,26 @@ _hb_buffer_serialize_unicode_text (hb_buffer_t *buffer,
{ {
hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr); hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr);
*buf_consumed = 0; *buf_consumed = 0;
char *p = buf;
/* We can use a much simpler implementation for this and copy text
* directly into the output buffer. */
for (unsigned int i = start; i < end; i++) for (unsigned int i = start; i < end; i++)
{ {
if (i) { char b[1024];
*p++ = '|'; char *p = b;
}
p += hb_max (0, snprintf (p, buf_size - *buf_consumed, "U+%X", info[i].codepoint)); if (i)
*buf_consumed = p - buf; *p++ = '|';
if (*buf_consumed > buf_size)
p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "U+%04X", info[i].codepoint));
unsigned int l = p - b;
if (buf_size > l)
{
memcpy (buf, b, l);
buf += l;
buf_size -= l;
*buf_consumed += l;
*buf = '\0';
} else
return i - start; return i - start;
} }
*p = '\0';
return end - start; return end - start;
} }