[util/hb-shape] Treat as single-paragraph text other than provided by a file

Fixes https://github.com/harfbuzz/harfbuzz/issues/3129
This commit is contained in:
Behdad Esfahbod 2021-08-09 19:08:34 -06:00
parent 8940409e3c
commit d92ee726ce
4 changed files with 15 additions and 36 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -33,7 +33,7 @@
template <typename consumer_t, typename font_options_t, typename text_options_t>
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);

View File

@ -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);