|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--edu.mit.ai.psg.strings.Prettify
Prettify: Reformats line breaks and indentation of strings with nested parens, braces, etc. such as those produced by toString() methods of collections and other complex objects.
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 force JavaDoc to preserve indentation):
. 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 to tailor parameters, rather than changing the static default values.
| Inner Class Summary | |
static class |
Prettify.ASCIISyntax
ASCII-only syntax |
static class |
Prettify.JavaSyntax
Uses Character predicates for Unicode syntax |
static class |
Prettify.JavaSyntaxNoEscapes
Ignores escape characters (e.g., for strings with pathnames using '\') |
static interface |
Prettify.Syntax
Syntax used by Prettify |
| Field Summary | |
static Prettify.Syntax |
defaultSyntax
default is Prettify.JavaSyntaxNoEscapes |
static int |
depthLimit
Max levels of nesting (count parens; -1 [default] means include everything to unbounded depth) |
static int |
lengthLimit
Max number of elements (count commas; -1 [default] means include everything to unbounded length) |
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; |
static int |
widthLimit
Max width of output string (count chars; default is 80, -1 for no limit). |
| Constructor Summary | |
Prettify()
|
|
| Method Summary | |
static String |
getCopyright()
|
static String |
getHomepage()
|
static String |
getNoWarranty()
|
static String |
getVersion()
|
static String |
string(int indent,
String uglyString)
Prettify string with additional indentation after first line. |
static String |
string(int indent,
String uglyString,
boolean doShorterNotFaster)
Prettify string, specifying indentation and choosing algorithm. |
static String |
string(int indent,
String uglyString,
int maxWidth)
Prettify string, specifying indentation and maximum width. |
static String |
string(int indent,
String uglyString,
int maxWidth,
int maxDepth,
int maxLength,
boolean doShorterNotFaster)
Deprecated. 1999.04, replaced by string(int, String, int, int, int, boolean, Prettify.Syntax) |
static String |
string(int indent,
String uglyString,
int maxWidth,
int maxDepth,
int maxLength,
boolean doShorterNotFaster,
Prettify.Syntax syntax)
Prettify string, specifying everything. |
static String |
string(String uglyString)
Prettify a string, reformatting indentation and line breaks. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
public static int depthLimit
public static int lengthLimit
public static int widthLimit
trimmed string will be returned.public static boolean shorterNotFaster
public static Prettify.Syntax defaultSyntax
Prettify.JavaSyntaxNoEscapesPrettify.Syntax| Constructor Detail |
public Prettify()
| Method Detail |
public static String getCopyright()
public static String getNoWarranty()
public static String getVersion()
public static String getHomepage()
public static String string(String uglyString)
uglyString - string to be reformatted
public static String string(int indent,
String uglyString)
. Food: Set(Apples, Oranges, Sandwiches, . Carrots, Raisins)(Note that spaces at beginning of uglyString will be removed.)
indent - Number of spaces to add to indentation of lines after firstuglyString - string to be reformatted
public static String string(int indent,
String uglyString,
boolean doShorterNotFaster)
indent - Number of spaces to add to indentation of lines after firstuglyString - String to be reformatteddoShorterNotFaster - Selects algorithm:
public static String string(int indent,
String uglyString,
int maxWidth)
indent - Number of spaces to add to indentation of lines after firstuglyString - String to be reformattedmaxWidth - Limit on number of chars per line (including indent,
-1 for no limit). If string cannot be formatted within maxWidth,
returns unformatted trimmed string.
public static String string(int indent,
String uglyString,
int maxWidth,
int maxDepth,
int maxLength,
boolean doShorterNotFaster)
string(int, String, int, int, int, boolean, Prettify.Syntax)
public static String string(int indent,
String uglyString,
int maxWidth,
int maxDepth,
int maxLength,
boolean doShorterNotFaster,
Prettify.Syntax syntax)
indent - Number of spaces to add to indentation of lines after firstuglyString - String to be reformattedmaxWidth - Limit on number of chars per line (including indent,
-1 for no limit). If string cannot be formatted within maxWidth,
returns unformatted trimmed string.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: syntax - Specifies what to treat as whitespace, unbreakable.words,
list and string delimiters, etc.
|
Copyright (c) 1996-1999 Massachusetts Institute of Technology Feedback: jeva-feedback@ai.mit.edu |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||