Wraps lines longer than given width to multiple lines. Existing line breaks aren't modified, but are taken to account when determining line lengths. Lines are wrapped at word boundaries only, unless a word is longer than the given line width.
   80                                                                      {
   81 
   82    wxString wrapped;
   83    wxStringTokenizer lines(string, _T("\n"), wxTOKEN_RET_EMPTY);
   84 
   85    while (lines.HasMoreTokens()) {
   86    
   87    wxString line = lines.GetNextToken();
   88    wxStringTokenizer words(line, _T(" \t"), wxTOKEN_RET_DELIMS);
   89    wxString wrappedLine;
   90    int length = 0;
   91    while (words.HasMoreTokens()) {
   92        
   93        wxString word = words.GetNextToken();
   94        if (length + word.length() < lineWidth) {
   95        
   96        wrappedLine.Append(word);
   97        length = length + word.length();
   98        } else if (word.length() < lineWidth) {
   99        
  100        
  101        wrappedLine.Append(_(" \n"));
  102        wrappedLine.Append(word);
  103        length = word.length();
  104        } else {
  105        
  106        unsigned int i = 0;
  107        for (; i < word.length(); i = i + (lineWidth - 1)) {
  108            wrappedLine.Append(_T(" \n"));
  109            wrappedLine.Append(word.Mid(i, lineWidth - 1));
  110            length = word.length() - i;
  111        }
  112        }
  113    }
  114    wrappedLine.Append(_T("\n"));
  115    wrapped.Append(wrappedLine);
  116    }
  117 
  118    return wrapped;
  119}