fullRuntime/src/sc/util/StringUtil.java
public static String insertLinebreaks(String text, int lineWidth) {
      if (text == null)
         return null;
      StringBuffer buf = new StringBuffer(text);
      int strLength = buf.length();
      int pos = 0;
      int nextNewline = buf.indexOf("\n");

      while ((pos + lineWidth) < strLength) {
        // if a newline already exists in this segment, advance our
        // position to the character immediately following it
        if (nextNewline != -1 && nextNewline <= (pos + lineWidth)) {
           pos = nextNewline + 1;
           nextNewline = buf.indexOf("\n", pos);
        } else {
            int nextBreak = buf.lastIndexOf(" ", pos + lineWidth);
            // if there are no spaces in this segment, just find the 
      	    // next space and put a newline there
      	    if (nextBreak <= pos) {
               nextBreak = buf.indexOf(" ", pos + lineWidth);
               if (nextBreak == -1)
                  break;
            }
      	    buf.setCharAt(nextBreak, '\n');
      	    pos = nextBreak + 1;
         }
      }

      return buf.toString();
   }
/**
    * Inserts linebreaks in the given text String.  The lineWidth specifies 
    * the maximum number of characters to allow in a single line.
    */
Inserts linebreaks in the given text String.  The lineWidth specifies
the maximum number of characters to allow in a single line.
Inserts linebreaks in the given text String . The lineWidth specifies the maximum number of characters to allow in a single line .
public static String insertLinebreaks(String text, int lineWidth) {
      if (text == null)
         return null;
      StringBuffer buf = new StringBuffer(text);
      int strLength = buf.length();
      int pos = 0;
      int nextNewline = buf.indexOf("\n");
      while ((pos + lineWidth) < strLength) {
        if (nextNewline != -1 && nextNewline <= (pos + lineWidth)) {
           pos = nextNewline + 1;
           nextNewline = buf.indexOf("\n", pos);
        } else {
            int nextBreak = buf.lastIndexOf(" ", pos + lineWidth);
      	    if (nextBreak <= pos) {
               nextBreak = buf.indexOf(" ", pos + lineWidth);
               if (nextBreak == -1)
                  break;
            }
      	    buf.setCharAt(nextBreak, '\n');
      	    pos = nextBreak + 1;
         }
      }
      return buf.toString();
   }
public static String insertLinebreaks ( String text , int lineWidth ) { if ( text == null ) return null ; StringBuffer buf = new StringBuffer ( text ) ; int strLength = buf . length ( ) ; int pos = 0 ; int nextNewline = buf . indexOf ( "\n" ) ; while ( ( pos + lineWidth ) < strLength ) { if ( nextNewline != - 1 && nextNewline <= ( pos + lineWidth ) ) { pos = nextNewline + 1 ; nextNewline = buf . indexOf ( "\n" , pos ) ; } else { int nextBreak = buf . lastIndexOf ( " " , pos + lineWidth ) ; if ( nextBreak <= pos ) { nextBreak = buf . indexOf ( " " , pos + lineWidth ) ; if ( nextBreak == - 1 ) break ; } buf . setCharAt ( nextBreak , '\n' ) ; pos = nextBreak + 1 ; } } return buf . toString ( ) ; }
Inserts linebreaks in the given text String.
Inserts linebreaks in the given text String .
// if a newline already exists in this segment, advance our // position to the character immediately following it // if there are no spaces in this segment, just find the  // next space and put a newline there