LineBreaker removes multiple line breaks

This commit is contained in:
hneemann 2017-04-30 09:24:41 +02:00
parent 7d7f2630f2
commit 4b9b437dc1
2 changed files with 11 additions and 7 deletions

View File

@ -70,7 +70,6 @@ public class LineBreaker {
if (preserveLineBreaks) { if (preserveLineBreaks) {
addWord(word); addWord(word);
lineBreak(); lineBreak();
isFirst = true;
break; break;
} }
case '\r': case '\r':
@ -108,11 +107,14 @@ public class LineBreaker {
} }
private void lineBreak() { private void lineBreak() {
if (!isFirst) {
outText.append('\n'); outText.append('\n');
for (int j = 0; j < indent; j++) for (int j = 0; j < indent; j++)
outText.append(" "); outText.append(" ");
pos = indent; pos = indent;
containsLineBreak = true; containsLineBreak = true;
isFirst = true;
}
} }
/** /**

View File

@ -25,6 +25,8 @@ public class LineBreakerTest extends TestCase {
public void testBreakLinesPreserve() throws Exception { public void testBreakLinesPreserve() throws Exception {
assertEquals("this is a\ntest string", new LineBreaker(60).preserveContainedLineBreaks().breakLines("this is a\ntest string")); assertEquals("this is a\ntest string", new LineBreaker(60).preserveContainedLineBreaks().breakLines("this is a\ntest string"));
assertEquals("this is a\ntest string", new LineBreaker(60).preserveContainedLineBreaks().breakLines("this is a \n test string"));
assertEquals("this is a\ntest string\n", new LineBreaker(60).preserveContainedLineBreaks().breakLines("\n\nthis is a\n\ntest string\n\n\n"));
assertEquals("this is a\ntest string. This is\na test string.", new LineBreaker(20).preserveContainedLineBreaks().breakLines("this is a\n test string. This is a test string.")); assertEquals("this is a\ntest string. This is\na test string.", new LineBreaker(20).preserveContainedLineBreaks().breakLines("this is a\n test string. This is a test string."));
} }