usr/src/java/util/org/opensolaris/os/vp/util/TextUtil.java
changeset 78 6336fcea8db0
parent 17 b82508ab9887
--- a/usr/src/java/util/org/opensolaris/os/vp/util/TextUtil.java	Tue Sep 16 13:32:03 2008 -0400
+++ b/usr/src/java/util/org/opensolaris/os/vp/util/TextUtil.java	Thu Sep 18 17:18:30 2008 -0400
@@ -130,6 +130,12 @@
      * @param	    width
      *		    the maximum width of each line
      *
+     * @param	    indent1
+     *		    the indent to put on the first line
+     *
+     * @param	    indent2
+     *		    the indent to put on the second and remaining lines
+     *
      * @param	    forceBreak
      *		    whether to force a break in the middle of a word
      *		    if the length of the word is greater than
@@ -137,7 +143,9 @@
      *
      * @return	    a wrapped string separated by newlines
      */
-    public static String format(String text, int width, boolean forceBreak) {
+    public static String format(String text, int width,
+	String indent1, String indent2, boolean forceBreak) {
+
 	if (text == null) {
 	    return text;
 	}
@@ -147,7 +155,8 @@
 
 	StringBuffer buffer = new StringBuffer();
 
-	int w = width;
+	String indent = indent1;
+	int w = width - indent.length();
 	if (w < 1) {
 	    w = 1;
 	}
@@ -173,11 +182,12 @@
 		buffer.append("\n");
 	    }
 
-	    buffer.append(groups[1].trim());
+	    buffer.append(indent).append(groups[1].trim());
 	    text = groups[2];
 
 	    if (i == 0) {
-		w = width;
+		indent = indent2;
+		w = width - indent.length();
 		if (w < 1) {
 		    w = 1;
 		}
@@ -187,6 +197,19 @@
 	return buffer.toString();
     }
 
+    /**
+     * Shortcut for:
+     * <p>
+     *	 <code>
+     *	   {@link #format(String,int,String,String,boolean) format}
+     *	   (text, width, "", "", forceBreak);
+     *	 </code>
+     * </p>
+     */
+    public static String format(String text, int width, boolean forceBreak) {
+	return format(text, width, "", "", forceBreak);
+    }
+
     public static boolean isPrintable(char c) {
 	return c >= 32 && c <= 126;
     }