in src/main/java/org/apache/commons/cli/HelpFormatter.java [558:585]
protected int findWrapPos(final String text, final int width, final int startPos) {
// the line ends before the max wrap pos or a new line char found
int pos = text.indexOf(Char.LF, startPos);
if (pos != -1 && pos <= width) {
return pos + 1;
}
pos = text.indexOf(Char.TAB, startPos);
if (pos != -1 && pos <= width) {
return pos + 1;
}
if (startPos + width >= text.length()) {
return -1;
}
// look for the last whitespace character before startPos+width
for (pos = startPos + width; pos >= startPos; --pos) {
final char c = text.charAt(pos);
if (c == Char.SP || c == Char.LF || c == Char.CR) {
break;
}
}
// if we found it - just return
if (pos > startPos) {
return pos;
}
// if we didn't find one, simply chop at startPos+width
pos = startPos + width;
return pos == text.length() ? -1 : pos;
}