Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static int indexOfWrap(final CharSequence text, final int width, final in
}
// handle case of width > text.
// the line ends before the max wrap pos or a new line char found
final int limit = Math.min(startPos + width, text.length() - 1);
int limit = Math.min(startPos + width, text.length());
for (int idx = startPos; idx < limit; idx++) {
if (BREAK_CHAR_SET.contains(text.charAt(idx))) {
return idx;
Expand All @@ -87,6 +87,8 @@ public static int indexOfWrap(final CharSequence text, final int width, final in
if (startPos + width >= text.length()) {
return text.length();
}

limit = Math.min(startPos + width, text.length() - 1);
int pos;
// look for the last whitespace character before limit
for (pos = limit; pos >= startPos; --pos) {
Expand Down Expand Up @@ -311,15 +313,15 @@ protected Queue<String> makeColumnQueue(final CharSequence columnData, final Tex
final String indent = Util.repeatSpace(style.getIndent());
final Queue<String> result = new LinkedList<>();
int wrapPos = 0;
int nextPos;
int lastPos;
final int wrappedMaxWidth = style.getMaxWidth() - indent.length();
while (wrapPos < columnData.length()) {
final int workingWidth = wrapPos == 0 ? style.getMaxWidth() : wrappedMaxWidth;
nextPos = indexOfWrap(columnData, workingWidth, wrapPos);
final CharSequence working = columnData.subSequence(wrapPos, nextPos);
lastPos = indexOfWrap(columnData, workingWidth, wrapPos);
final CharSequence working = columnData.subSequence(wrapPos, lastPos);
result.add(lpad + style.pad(wrapPos > 0, working));
wrapPos = Util.indexOfNonWhitespace(columnData, nextPos);
wrapPos = wrapPos == -1 ? nextPos : wrapPos;
wrapPos = Util.indexOfNonWhitespace(columnData, lastPos);
wrapPos = wrapPos == -1 ? lastPos + 1 : wrapPos;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setUp() {
}

@Test
void tesstMakeColumnQueue() {
void testMakeColumnQueue() {
final String text = "The quick brown fox jumps over the lazy dog";
final TextStyle.Builder styleBuilder = TextStyle.builder().setMaxWidth(10).setIndent(0).setLeftPad(0);

Expand Down Expand Up @@ -98,6 +98,20 @@ void tesstMakeColumnQueue() {
assertEquals(expected, result, "right aligned failed");
}

@Test
void testMakeColumnQueueWithMultipleTrailingLineBreaks() {
// this test should work with any n>1 multiple trailing characters from TestHelpAppendable.BREAK_CHAR_SET.
final String text = "Header\t" + (char) Character.PARAGRAPH_SEPARATOR;
final TextStyle.Builder styleBuilder = TextStyle.builder().setMaxWidth(10).setIndent(0).setLeftPad(0);

Queue<String> expected = new LinkedList<>();
expected.add("Header ");
expected.add(" ");

Queue<String> result = underTest.makeColumnQueue(text, styleBuilder.get());
assertEquals(expected, result, "left aligned failed");
}

@Test
void testAdjustTableFormat() {
// test width smaller than header
Expand Down
Loading