private static int getLastSpace ( final CharSequence message , int width ) { final int length = message . length ( ) ; int stopPos = width ; int currPos = 0 ; int lastSpace = - 1 ; boolean inEscape = false ; while ( currPos < stopPos && currPos < length ) { final char c = message . charAt ( currPos ) ; if ( c == ESCAPE_CHAR ) { stopPos ++ ; inEscape = true ; } else if ( inEscape ) { stopPos ++ ; if ( Character . isLetter ( c ) ) inEscape = false ; } else if ( Character . isWhitespace ( c ) ) { lastSpace = currPos ; } currPos ++ ; } return lastSpace ; }
Returns the last whitespace location in string before width characters .