From 5b30f13249690c96894efc34eba0af45b1151d98 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Fri, 18 Sep 2020 10:31:28 +0100 Subject: [PATCH] Move delimiter addition into hb-buffer-serialize --- src/hb-buffer-serialize.cc | 23 ++++++++++++++++++++++- util/options.cc | 8 -------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc index b36f39191..253af7d7d 100644 --- a/src/hb-buffer-serialize.cc +++ b/src/hb-buffer-serialize.cc @@ -125,6 +125,8 @@ _hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer, if (i) *p++ = ','; + else + *p++ = '['; *p++ = '{'; @@ -174,6 +176,8 @@ _hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer, } *p++ = '}'; + if (i == end-1) + *p++ = ']'; unsigned int l = p - b; if (buf_size > l) @@ -213,9 +217,14 @@ _hb_buffer_serialize_unicode_json (hb_buffer_t *buffer, char *p = b; if (i) *p++ = ','; + else + *p++ = '['; p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint)); + if (i == end-1) + *p++ = ']'; + unsigned int l = p - b; if (buf_size > l) { @@ -257,6 +266,8 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer, if (i) *p++ = '|'; + else + *p++ = '['; if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES)) { @@ -297,6 +308,10 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer, p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "<%d,%d,%d,%d>", extents.x_bearing, extents.y_bearing, extents.width, extents.height)); } + if (i == end-1) { + *p++ = ']'; + } + unsigned int l = p - b; if (buf_size > l) { @@ -336,8 +351,14 @@ _hb_buffer_serialize_unicode_text (hb_buffer_t *buffer, if (i) *p++ = '|'; + else + *p++ = '<'; p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "U+%04X", info[i].codepoint)); + + if (i == end-1) + *p++ = '>'; + unsigned int l = p - b; if (buf_size > l) { @@ -487,7 +508,7 @@ hb_buffer_serialize_glyphs (hb_buffer_t *buffer, * The serialized codepoints will look something like: * * ``` - * U+0651|U+0628 + * * ``` * - Glyphs are separated with `|` * - Unicode codepoints are expressed as zero-padded four (or more) diff --git a/util/options.cc b/util/options.cc index 653e2019c..caf8233f7 100644 --- a/util/options.cc +++ b/util/options.cc @@ -916,10 +916,6 @@ format_options_t::serialize (hb_buffer_t *buffer, hb_buffer_serialize_flags_t flags, GString *gs) { - if (hb_buffer_get_content_type(buffer) == HB_BUFFER_CONTENT_TYPE_UNICODE) - g_string_append_c (gs, '<'); - else - g_string_append_c (gs, '['); unsigned int num_glyphs = hb_buffer_get_length (buffer); unsigned int start = 0; @@ -934,10 +930,6 @@ format_options_t::serialize (hb_buffer_t *buffer, break; g_string_append (gs, buf); } - if (hb_buffer_get_content_type(buffer) == HB_BUFFER_CONTENT_TYPE_UNICODE) - g_string_append_c (gs, '>'); - else - g_string_append_c (gs, ']'); } void