Allow reflow of multiline text

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
wayvncctl-polishing
Jim Ramsay 2023-01-11 21:45:23 -05:00
parent 104040291b
commit 177ea507e3
2 changed files with 36 additions and 0 deletions

View File

@ -79,6 +79,9 @@ int table_printer_reflow_text(char* dst, int dst_size, const char* src,
assert(dst_len < dst_size); assert(dst_len < dst_size);
++line_len; ++line_len;
++i; ++i;
if (c == '\n')
line_len = 0;
} }
dst[dst_len] = '\0'; dst[dst_len] = '\0';

View File

@ -45,6 +45,38 @@ static int test_reflow_text(void)
return 0; return 0;
} }
static int test_reflow_multiline(void)
{
char buf[20];
const char* src = "one two\nthree four";
table_printer_reflow_text(buf, sizeof(buf), src, 20);
ASSERT_STR_EQ("one two\nthree four", buf);
table_printer_reflow_text(buf, sizeof(buf), src, 18);
ASSERT_STR_EQ("one two\nthree four", buf);
table_printer_reflow_text(buf, sizeof(buf), src, 17);
ASSERT_STR_EQ("one two\nthree four", buf);
table_printer_reflow_text(buf, sizeof(buf), src, 10);
ASSERT_STR_EQ("one two\nthree four", buf);
table_printer_reflow_text(buf, sizeof(buf), src, 9);
ASSERT_STR_EQ("one two\nthree\nfour", buf);
table_printer_reflow_text(buf, sizeof(buf), src, 7);
ASSERT_STR_EQ("one two\nthree\nfour", buf);
table_printer_reflow_text(buf, sizeof(buf), src, 6);
ASSERT_STR_EQ("one\ntwo\nthree\nfour", buf);
table_printer_reflow_text(buf, sizeof(buf), src, 5);
ASSERT_STR_EQ("one\ntwo\nthree\nfour", buf);
return 0;
}
static int test_indent_and_reflow(void) static int test_indent_and_reflow(void)
{ {
size_t len; size_t len;
@ -137,6 +169,7 @@ int main()
{ {
int r = 0; int r = 0;
RUN_TEST(test_reflow_text); RUN_TEST(test_reflow_text);
RUN_TEST(test_reflow_multiline);
RUN_TEST(test_indent_and_reflow); RUN_TEST(test_indent_and_reflow);
RUN_TEST(test_defaults); RUN_TEST(test_defaults);
RUN_TEST(test_print_line); RUN_TEST(test_print_line);