Package org.codehaus.groovy.runtime
Class FormatHelper
java.lang.Object
org.codehaus.groovy.runtime.FormatHelper
Formatting methods
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappend(Appendable out, Object object) Appends an object to an Appendable using Groovy's default representation for the object.static StringescapeBackslashes(String orig) Escapes special characters in the given string, converting them to their escaped representations.static StringFormats the given object as a string with optional verbosity.static StringFormats the given object as a string with inspect and escape options.static StringFormats the given object as a string with multiple options.static StringFormats the given object as a string with full control over all options.static StringFormats the given object as a string with a maximum size constraint.static StringFormats the given object as a string with verbose and safe options.static StringReturns an inspectable string representation of the given object.static StringtoArrayString(Object[] arguments) A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".static StringtoArrayString(Object[] arguments, int maxSize, boolean safe) A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".static StringtoListString(Collection arg) A helper method to return the string representation of a list with bracket boundaries "[" and "]".static StringtoListString(Collection arg, int maxSize) A helper method to return the string representation of a list with bracket boundaries "[" and "]".static StringtoListString(Collection arg, int maxSize, boolean safe) A helper method to return the string representation of a list with bracket boundaries "[" and "]".static StringtoMapString(Map arg) A helper method to return the string representation of a map with bracket boundaries "[" and "]".static StringtoMapString(Map arg, int maxSize) A helper method to return the string representation of a map with bracket boundaries "[" and "]".static StringReturns a string representation of the given object.static StringOutput thetoStringfor the argument(s) with various options to configure.static StringtoTypeString(Object[] arguments) A helper method to format the arguments types as a comma-separated list.static StringtoTypeString(Object[] arguments, int maxSize) A helper method to format the arguments types as a comma-separated list.static voidWrites an object to a Writer using Groovy's default representation for the object.
-
Field Details
-
metaRegistry
-
-
Method Details
-
toString
Returns a string representation of the given object.- Parameters:
arguments- the object to convert to a string- Returns:
- a string representation
-
inspect
Returns an inspectable string representation of the given object.- Parameters:
self- the object to inspect- Returns:
- a detailed string representation
-
format
Formats the given object as a string with optional verbosity.- Parameters:
arguments- the object to formatverbose- if true, uses inspect mode with escaped backslashes- Returns:
- a formatted string representation
-
format
Formats the given object as a string with inspect and escape options.- Parameters:
arguments- the object to formatinspect- if true, uses inspect mode; if false, uses toStringescapeBackslashes- if true, escapes special characters like tabs and newlines- Returns:
- a formatted string representation
-
format
Formats the given object as a string with a maximum size constraint.- Parameters:
arguments- the object to formatverbose- if true, uses inspect mode with escaped backslashesmaxSize- maximum characters to include, or -1 for no limit- Returns:
- a formatted string representation
-
format
public static String format(Object arguments, boolean inspect, boolean escapeBackslashes, int maxSize) Formats the given object as a string with multiple options.- Parameters:
arguments- the object to formatinspect- if true, uses inspect mode; if false, uses toStringescapeBackslashes- if true, escapes special charactersmaxSize- maximum characters to include, or -1 for no limit- Returns:
- a formatted string representation
-
toString
public static String toString(@NamedParam(value="safe",type=java.lang.Boolean.class) @NamedParam(value="maxSize",type=java.lang.Integer.class) @NamedParam(value="verbose",type=java.lang.Boolean.class) @NamedParam(value="escapeBackslashes",type=java.lang.Boolean.class) @NamedParam(value="inspect",type=java.lang.Boolean.class) Map<String, Object> options, Object arguments) Output thetoStringfor the argument(s) with various options to configure. Configuration options:- safe
- provides protection if the
toStringthrows an exception, in which case the exception is swallowed and a dumber defaulttoStringis used - maxSize
- will attempt to truncate the output to fit approx the maxSize number of characters, -1 means don't truncate
- inspect
- if false, render a value by its
toString, otherwise use itsinspectvalue - escapeBackSlashes
- whether characters like tab, newline, etc. are converted to their escaped rendering ('\t', '\n', etc.)
- verbose
- shorthand to turn on both
inspectandescapeBackslashes
- Parameters:
options- a map of configuration optionsarguments- the argument(s) to calculate thetoStringfor- Returns:
- the string rendering of the argument(s)
- See Also:
-
format
Formats the given object as a string with verbose and safe options.- Parameters:
arguments- the object to formatverbose- if true, uses inspect mode with escaped backslashesmaxSize- maximum characters to include, or -1 for no limitsafe- if true, exceptions during formatting are caught and handled gracefully- Returns:
- a formatted string representation
-
format
public static String format(Object arguments, boolean inspect, boolean escapeBackslashes, int maxSize, boolean safe) Formats the given object as a string with full control over all options.- Parameters:
arguments- the object to formatinspect- if true, uses inspect mode; if false, uses toStringescapeBackslashes- if true, escapes special characters like tabs and newlinesmaxSize- maximum characters to include, or -1 for no limitsafe- if true, exceptions during formatting are caught and handled gracefully- Returns:
- a formatted string representation
-
escapeBackslashes
Escapes special characters in the given string, converting them to their escaped representations. Converts backslash, newline, carriage return, tab, and form feed characters.- Parameters:
orig- the string to escape- Returns:
- the string with special characters escaped
-
toTypeString
A helper method to format the arguments types as a comma-separated list.- Parameters:
arguments- the type to process- Returns:
- the string representation of the type
-
toTypeString
A helper method to format the arguments types as a comma-separated list.- Parameters:
arguments- the type to processmaxSize- stop after approximately this many characters and append '...', -1 means don't stop- Returns:
- the string representation of the type
-
toMapString
A helper method to return the string representation of a map with bracket boundaries "[" and "]".- Parameters:
arg- the map to process- Returns:
- the string representation of the map
-
toMapString
A helper method to return the string representation of a map with bracket boundaries "[" and "]".- Parameters:
arg- the map to processmaxSize- stop after approximately this many characters and append '...', -1 means don't stop- Returns:
- the string representation of the map
-
toListString
A helper method to return the string representation of a list with bracket boundaries "[" and "]".- Parameters:
arg- the collection to process- Returns:
- the string representation of the collection
-
toListString
A helper method to return the string representation of a list with bracket boundaries "[" and "]".- Parameters:
arg- the collection to processmaxSize- stop after approximately this many characters and append '...'- Returns:
- the string representation of the collection
-
toListString
A helper method to return the string representation of a list with bracket boundaries "[" and "]".- Parameters:
arg- the collection to processmaxSize- stop after approximately this many characters and append '...', -1 means don't stopsafe- whether to use a default object representation for any item in the collection if an exception occurs when generating its toString- Returns:
- the string representation of the collection
-
toArrayString
A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".- Parameters:
arguments- the array to process- Returns:
- the string representation of the array
-
toArrayString
A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".- Parameters:
arguments- the array to processmaxSize- stop after approximately this many characters and append '...'safe- whether to use a default object representation for any item in the array if an exception occurs when generating its toString- Returns:
- the string representation of the array
-
write
Writes an object to a Writer using Groovy's default representation for the object.- Parameters:
out- the writer to write toobject- the object to write- Throws:
IOException- if an I/O error occurs
-
append
Appends an object to an Appendable using Groovy's default representation for the object.- Parameters:
out- the appendable to write toobject- the object to append- Throws:
IOException- if an I/O error occurs
-