From b58afe586f6d100df94cc3a9b716befc68d8abec Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 25 Nov 2021 11:34:24 -0700 Subject: [PATCH] [util] Undo treat as single-paragraph text provided on cmdline Reverts d92ee726ce3b2fc2c249407d977433f0badcc918 except that it does so even in batch mode. Am going to add a --single-par mode that will affect all input modes. Part of https://github.com/harfbuzz/harfbuzz/issues/3129 Fixes https://github.com/harfbuzz/harfbuzz/issues/3298 --- util/text-options.hh | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/util/text-options.hh b/util/text-options.hh index 82ca6c0bd..d55c066b6 100644 --- a/util/text-options.hh +++ b/util/text-options.hh @@ -82,6 +82,8 @@ struct text_options_t private: FILE *in_fp = nullptr; GString *gs = nullptr; + char *line = nullptr; + unsigned line_len = UINT_MAX; }; struct shape_text_options_t : text_options_t @@ -273,18 +275,38 @@ text_options_t::get_line (unsigned int *len) { if (text) { - if (text_len == -2) + if (!line) + { + line = text; + line_len = text_len; + } + if (line_len == UINT_MAX) + line_len = strlen (line); + + if (!line_len) { *len = 0; return nullptr; } - if (text_len == -1) - text_len = strlen (text); + const char *ret = line; + const char *p = (const char *) memchr (line, '\n', 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; + } - *len = text_len; - text_len = -2; - return text; + *len = ret_len; + return ret; } g_string_set_size (gs, 0);