From d92ee726ce3b2fc2c249407d977433f0badcc918 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 Aug 2021 19:08:34 -0600 Subject: [PATCH] [util/hb-shape] Treat as single-paragraph text other than provided by a file Fixes https://github.com/harfbuzz/harfbuzz/issues/3129 --- util/hb-shape.cc | 4 ++-- util/hb-subset.cc | 4 ++-- util/main-font-text.hh | 4 ++-- util/text-options.hh | 39 +++++++++------------------------------ 4 files changed, 15 insertions(+), 36 deletions(-) diff --git a/util/hb-shape.cc b/util/hb-shape.cc index d9c727f55..b2d809cc8 100644 --- a/util/hb-shape.cc +++ b/util/hb-shape.cc @@ -187,11 +187,11 @@ main (int argc, char **argv) start_offset = argc == 2 && p[0] != '\0' && p[0] != ':' && p[1] == ':' && (p[2] == '\\' || p[2] == '/') ? 2 : 0; } - ret |= main_func (argc, args, EOF); + ret |= main_func (argc, args); fflush (stdout); } return ret; } - return main_func (argc, argv, '\n'); + return main_func (argc, argv); } diff --git a/util/hb-subset.cc b/util/hb-subset.cc index da808f901..e722379bf 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -155,7 +155,7 @@ main (int argc, char **argv) args[argc++] = p = e; } - int result = main_func (argc, args, EOF); + int result = main_func (argc, args); fprintf (stdout, result == 0 ? "success\n" : "failure\n"); fflush (stdout); ret |= result; @@ -163,5 +163,5 @@ main (int argc, char **argv) return ret; } - return main_func (argc, argv, '\n'); + return main_func (argc, argv); } diff --git a/util/main-font-text.hh b/util/main-font-text.hh index a3e8d42bc..b8c023a5b 100644 --- a/util/main-font-text.hh +++ b/util/main-font-text.hh @@ -33,7 +33,7 @@ template int -main_font_text (int argc, char **argv, int eol = '\n') +main_font_text (int argc, char **argv) { font_options_t font_opts; @@ -60,7 +60,7 @@ main_font_text (int argc, char **argv, int eol = '\n') unsigned int text_len; const char *text; - while ((text = input.get_line (&text_len, eol))) + while ((text = input.get_line (&text_len))) consumer.consume_line (text, text_len, input.text_before, input.text_after); consumer.finish (&font_opts); diff --git a/util/text-options.hh b/util/text-options.hh index ad72d7384..2ed239a07 100644 --- a/util/text-options.hh +++ b/util/text-options.hh @@ -23,7 +23,7 @@ struct text_options_t "Only one of text and text-file can be set"); } - const char *get_line (unsigned int *len, int eol = '\n'); + const char *get_line (unsigned int *len); char *text_before = nullptr; char *text_after = nullptr; @@ -35,8 +35,6 @@ struct text_options_t private: FILE *fp = nullptr; GString *gs = nullptr; - char *line = nullptr; - unsigned int line_len = UINT_MAX; }; @@ -118,41 +116,22 @@ parse_unicodes (const char *name G_GNUC_UNUSED, } const char * -text_options_t::get_line (unsigned int *len, int eol) +text_options_t::get_line (unsigned int *len) { if (text) { - if (!line) + if (text_len == -2) { - line = text; - line_len = text_len; - } - if (line_len == UINT_MAX) - line_len = strlen (line); - - if (!line_len) { *len = 0; return nullptr; } - const char *ret = line; - const char *p = (const char *) memchr (line, eol, line_len); - unsigned int ret_len; - if (!p) - { - ret_len = line_len; - line += ret_len; - line_len = 0; - } - else - { - ret_len = p - ret; - line += ret_len + 1; - line_len -= ret_len + 1; - } + if (text_len == -1) + text_len = strlen (text); - *len = ret_len; - return ret; + *len = text_len; + text_len = -2; + return text; } if (!fp) @@ -177,7 +156,7 @@ text_options_t::get_line (unsigned int *len, int eol) while (fgets (buf, sizeof (buf), fp)) { unsigned bytes = strlen (buf); - if (bytes && (int) (unsigned char) buf[bytes - 1] == eol) + if (bytes && buf[bytes - 1] == '\n') { bytes--; g_string_append_len (gs, buf, bytes);