All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class edu.mit.ai.psg.prettify.Prettify

java.lang.Object
   |
   +----edu.mit.ai.psg.prettify.Prettify

public class Prettify
extends Object
Prettify: Reformats multiline strings with nested parens, braces, etc.

A utility to take strings of the form
Set(Set(Array("Eucalyptus", "Mulberry", "Chestnut"), Array("Oak", "Maple", "Ironwood")), Set( "Apple", "Cherry", "Plum", "Peach"))
and format them into something more readable, such as the following (minus the dots, which are there to work around problem with preformatted text in JavaDoc comments):

.   Set(Set(Array("Eucalyptus", "Mulberry", "Chestnut"), 
.           Array("Oak", "Maple", "Ironwood")),
.       Set("Apple", "Cherry", "Plum", "Peach"))
Assumes result string will be displayed in a fixed width font, though still a great improvement even if the font is variable width.

Note that static parameters are "globally" shared, so in multithread code the verbose interface to string(..) should be called if to tailor parameters, rather than changing the static default values.

Author:
CarlManning, caroma@ai.mit.edu
Copyright (c) 1996, 1997 Massachusetts Institute of Technology

Variable Index

 o depthLimit
Max levels of nesting (count parens; -1 [default] means include everything to unbounded depth)
 o lengthLimit
Max number of elements (count commas; -1 [default] means include everything to unbounded length)
 o shorterNotFaster
shorterNotFaster controls which algorithm to use.
true = use slower algorithm that produces shorter strings [default];
false = use faster algorithm that produces longer strings;
 o widthLimit
Max width of output string (count chars; default is 80)

Method Index

 o string(int, String)
Prettify string with additional indentation after first line.
 o string(int, String, boolean)
Prettify string, specifying indentation and choosing algorithm.
 o string(int, String, int)
Prettify string, specifying indentation and maximum width.
 o string(int, String, int, int, int, boolean)
Prettify string, specifying everything.
 o string(String)
Prettify a string, reformatting indentation and line breaks.

Variables

 o depthLimit
 public static int depthLimit
Max levels of nesting (count parens; -1 [default] means include everything to unbounded depth)

 o lengthLimit
 public static int lengthLimit
Max number of elements (count commas; -1 [default] means include everything to unbounded length)

 o widthLimit
 public static int widthLimit
Max width of output string (count chars; default is 80)

 o shorterNotFaster
 public static boolean shorterNotFaster
shorterNotFaster controls which algorithm to use.
true = use slower algorithm that produces shorter strings [default];
false = use faster algorithm that produces longer strings;

Methods

 o string
 public static String string(String uglyString)
Prettify a string, reformatting indentation and line breaks.

Parameters:
uglyString - string to be reformatted
 o string
 public static String string(int indent,
                             String uglyString)
Prettify string with additional indentation after first line. Good for cases where the first line is after a title, e.g.,:
.        Food:   Set(Apples, Oranges, Sandwiches,
.                    Carrots, Raisins)
(Note that spaces at beginning of uglyString will be removed.)

Parameters:
indent - Number of spaces to add to indentation of lines after first
uglyString - string to be reformatted
 o string
 public static String string(int indent,
                             String uglyString,
                             boolean doShorterNotFaster)
Prettify string, specifying indentation and choosing algorithm.

Parameters:
indent - Number of spaces to add to indentation of lines after first
uglyString - String to be reformatted
doShorterNotFaster - Selects algorithm:
true = use slower algorithm that produces shorter strings;
false = use faster algorithm that produces longer strings.
 o string
 public static String string(int indent,
                             String uglyString,
                             int maxWidth)
Prettify string, specifying indentation and maximum width.

Parameters:
indent - Number of spaces to add to indentation of lines after first
uglyString - String to be reformatted
maxWidth - Limit on number of chars per line (including indent)
 o string
 public static String string(int indent,
                             String uglyString,
                             int maxWidth,
                             int maxDepth,
                             int maxLength,
                             boolean doShorterNotFaster)
Prettify string, specifying everything.

Parameters:
indent - Number of spaces to add to indentation of lines after first
uglyString - String to be reformatted
maxWidth - Limit on number of chars per line (including indent) (-1 for no limit)
maxDepth - Limit on number of levels of parentheses, braces, etc. shown (-1 for no limit). Omit with ellipses ... substrings nested in more than maxDepth levels of parentheses, brackets, or braces.
maxLength - Limit on number of terms at same level of parenthesization (-1 for no limit). Omit with ellipses ... substrings in lists after maxLength terms.
doShorterNotFaster - Selects: algorithm:
true = use slower algorithm that produces shorter strings;
false = use faster algorithm that produces longer strings.

All Packages  Class Hierarchy  This Package  Previous  Next  Index