code: @CheckForSigned
    protected static int findWrapPos (final String sText, final int nWidth, final int nStartPos)
    {
      // the line ends before the max wrap pos or a new line char found
      int pos = sText.indexOf ('\n', nStartPos);
      if (pos != -1 && pos <= nWidth)
      {
        return pos + 1;
      }
  
      pos = sText.indexOf ('\t', nStartPos);
      if (pos != -1 && pos <= nWidth)
      {
        return pos + 1;
      }
  
      if (nStartPos + nWidth >= sText.length ())
      {
        return -1;
      }
  
      // look for the last whitespace character before startPos+width
      for (pos = nStartPos + nWidth; pos >= nStartPos; --pos)
      {
        final char c = sText.charAt (pos);
        if (c == ' ' || c == '\n' || c == '\r')
        {
          break;
        }
      }
  
      // if we found it - just return
      if (pos > nStartPos)
      {
        return pos;
      }
  
      // if we didn't find one, simply chop at startPos+width
      pos = nStartPos + nWidth;
  
      return pos == sText.length () ? -1 : pos;
    }
docs: Finds the next text wrap position after <code>startPos</code> for the text
  in <code>text</code> with the column width <code>width</code>. The wrap
  point is the last position before startPos+width having a whitespace
  character (space, \n, \r). If there is no whitespace character before
  startPos+width, it will return startPos+width.
  
  @param sText
  The text being searched for the wrap position
  @param nWidth
  width of the wrapped text
  @param nStartPos
  position from which to start the lookup whitespace character
  @return position on which the text must be wrapped or -1 if the wrap
  position is at the end of the text