From 2e79c51d00f088c6ad778fe3d79e862492415920 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Dec 2018 21:51:52 +0100 Subject: [PATCH] fix overly long lines in NR. --- src/report.c | 7 ++++++- src/report.test.c | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/report.c b/src/report.c index 273e1ac91..f5023d6bb 100644 --- a/src/report.c +++ b/src/report.c @@ -1440,7 +1440,12 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) char *next = strchr(pos+1, ' '); if (next == NULL) { if (isfinal) { - swrite(begin, 1, sbp->end - begin, out); + swrite(begin, 1, pos - begin, out); + while (*pos && IS_UTF8_SPACE(pos)) { + ++pos; + } + newline(out); + swrite(pos, 1, sbp->end - pos, out); newline(out); } return; diff --git a/src/report.test.c b/src/report.test.c index 601df8eb0..67b0d602a 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -379,11 +379,32 @@ static void test_write_spell_syntax(CuTest *tc) { test_teardown(); } +static void test_pump_paragraph_toolong(CuTest *tc) { + const char *toolong = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin (93,-303)."; + const char *expect = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin\n(93,-303).\n"; + sbstring sbs; + char buf[256]; + stream out = { 0 }; + size_t len; + + mstream_init(&out); + + sbs_init(&sbs, buf, sizeof(buf)); + sbs_strcat(&sbs, toolong); + + pump_paragraph(&sbs, &out, 78, true); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + CuAssertStrEquals(tc, expect, buf); +} + CuSuite *get_report_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_write_spaces); SUITE_ADD_TEST(suite, test_write_many_spaces); + SUITE_ADD_TEST(suite, test_pump_paragraph_toolong); SUITE_ADD_TEST(suite, test_report_travelthru); SUITE_ADD_TEST(suite, test_report_region); SUITE_ADD_TEST(suite, test_report_allies);