@@ -78,7 +78,7 @@ public static int indexOfWrap(final CharSequence text, final int width, final in
7878 }
7979 // handle case of width > text.
8080 // the line ends before the max wrap pos or a new line char found
81- final int limit = Math .min (startPos + width , text .length () - 1 );
81+ int limit = Math .min (startPos + width , text .length ());
8282 for (int idx = startPos ; idx < limit ; idx ++) {
8383 if (BREAK_CHAR_SET .contains (text .charAt (idx ))) {
8484 return idx ;
@@ -87,6 +87,8 @@ public static int indexOfWrap(final CharSequence text, final int width, final in
8787 if (startPos + width >= text .length ()) {
8888 return text .length ();
8989 }
90+
91+ limit = Math .min (startPos + width , text .length () - 1 );
9092 int pos ;
9193 // look for the last whitespace character before limit
9294 for (pos = limit ; pos >= startPos ; --pos ) {
@@ -311,15 +313,15 @@ protected Queue<String> makeColumnQueue(final CharSequence columnData, final Tex
311313 final String indent = Util .repeatSpace (style .getIndent ());
312314 final Queue <String > result = new LinkedList <>();
313315 int wrapPos = 0 ;
314- int nextPos ;
316+ int lastPos ;
315317 final int wrappedMaxWidth = style .getMaxWidth () - indent .length ();
316318 while (wrapPos < columnData .length ()) {
317319 final int workingWidth = wrapPos == 0 ? style .getMaxWidth () : wrappedMaxWidth ;
318- nextPos = indexOfWrap (columnData , workingWidth , wrapPos );
319- final CharSequence working = columnData .subSequence (wrapPos , nextPos );
320+ lastPos = indexOfWrap (columnData , workingWidth , wrapPos );
321+ final CharSequence working = columnData .subSequence (wrapPos , lastPos );
320322 result .add (lpad + style .pad (wrapPos > 0 , working ));
321- wrapPos = Util .indexOfNonWhitespace (columnData , nextPos );
322- wrapPos = wrapPos == -1 ? nextPos : wrapPos ;
323+ wrapPos = Util .indexOfNonWhitespace (columnData , lastPos );
324+ wrapPos = wrapPos == -1 ? lastPos + 1 : wrapPos ;
323325 }
324326 return result ;
325327 }
0 commit comments