Package com.globalmentor.text
Class TextFormatter
- java.lang.Object
-
- com.globalmentor.text.TextFormatter
-
public class TextFormatter extends java.lang.Object
Utilities for formatting text.- Author:
- Garret Wilson
-
-
Constructor Summary
Constructors Constructor Description TextFormatter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <A extends java.lang.Appendable>
AformatAttribute(A appendable, NameValuePair<?,?> attribute)
static <A extends java.lang.Appendable>
AformatAttribute(A appendable, NameValuePair<?,?> attribute, char quote)
Formats a single name-value attribute using 61 for assignment.static <A extends java.lang.Appendable>
AformatAttribute(A appendable, NameValuePair<?,?> attribute, char assignment, char quote)
Formats a single name-value attribute.static <A extends java.lang.Appendable>
AformatAttribute(A appendable, java.lang.Object name, java.lang.Object value)
static <A extends java.lang.Appendable>
AformatAttribute(A appendable, java.lang.Object name, java.lang.Object value, char quote)
Formats a single name-value attribute using 61 for assignment.static <A extends java.lang.Appendable>
AformatAttribute(A appendable, java.lang.Object name, java.lang.Object value, char assignment, char quote)
Formats a single name-value attribute.static <A extends java.lang.Appendable>
AformatAttribute(A appendable, java.util.Map.Entry<?,?> attribute)
static <A extends java.lang.Appendable>
AformatAttribute(A appendable, java.util.Map.Entry<?,?> attribute, char quote)
Formats a single name-value attribute using 61 for assignment.static <A extends java.lang.Appendable>
AformatAttribute(A appendable, java.util.Map.Entry<?,?> attribute, char assignment, char quote)
Formats a single name-value attribute.static <A extends java.lang.Appendable>
AformatAttributes(A appendable, char separator, char assignment, char quote, java.util.Set<?> unquotedNames, NameValuePair<?,?>... attributes)
Formats a series of name-value pairs.static <A extends java.lang.Appendable>
AformatAttributes(A appendable, NameValuePair<?,?>... attributes)
Formats a series of name-value pairs using the format: name="value", name="value"static java.lang.String
formatHex(byte[] bytes)
Formats an array of bytes into a sequence of hex characters, with each character pair representing the hexadecimal value of the byte.static <A extends java.lang.Appendable>
AformatHex(A appendable, byte[] bytes)
Formats an array of bytes into a sequence of hex characters, with each character pair representing the hexadecimal value of the byte.static <T> java.lang.String
formatList(char separator, java.lang.Iterable<T> items)
Appends the string representations of the given items separated by a separator character.static java.lang.String
formatList(char separator, java.lang.Object... items)
Appends the string representations of the given items separated by a separator character.static <A extends java.lang.Appendable,T>
AformatList(A appendable, char separator, java.lang.Iterable<T> items)
Appends the string representations of the given items separated by a separator character.static <A extends java.lang.Appendable>
AformatList(A appendable, char separator, java.lang.Object... items)
Appends the string representations of the given items separated by a separator character.static <A extends java.lang.Appendable,T>
AformatList(A appendable, java.lang.Iterable<T> items)
Appends the string representations of the given items separated by a 44.static <A extends java.lang.Appendable>
AformatList(A appendable, java.lang.Object... items)
Appends the string representations of the given items separated by a 44.static <A extends java.lang.Appendable,T>
AformatList(A appendable, java.lang.String separator, java.lang.Iterable<T> items)
Appends the string representations of the given items separated by a separator string.static <A extends java.lang.Appendable>
AformatList(A appendable, java.lang.String separator, java.lang.Object... items)
Appends the string representations of the given items separated by a separator string.static <A extends java.lang.Appendable,T>
AformatList(A appendable, T[] items, char separator, T ignoreItem)
Appends the string representations of the given items separated by a separator character.static <A extends java.lang.Appendable,T>
AformatList(A appendable, T[] items, java.lang.String separator, T ignoreItem)
Appends the string representations of the given items separated by a separator string.static <T> java.lang.String
formatList(java.lang.Iterable<T> items)
Appends the string representations of the given items separated by a 44.static <T> java.lang.String
formatList(java.lang.String separator, java.lang.Iterable<T> items)
Appends the string representations of the given items separated by a separator string.static java.lang.String
formatList(java.lang.String separator, java.lang.Object... items)
Appends the string representations of the given items separated by a separator string.static <T> java.lang.String
formatList(T[] items, char separator, T ignoreItem)
Appends the string representations of the given items separated by a separator character.
-
-
-
Method Detail
-
formatHex
public static <A extends java.lang.Appendable> A formatHex(A appendable, byte[] bytes) throws java.io.IOException
Formats an array of bytes into a sequence of hex characters, with each character pair representing the hexadecimal value of the byte.- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.bytes
- The values to convert.- Returns:
- A lowercase string with hexadecimal digits, each pair representing a byte in the byte array.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatHex
public static java.lang.String formatHex(byte[] bytes)
Formats an array of bytes into a sequence of hex characters, with each character pair representing the hexadecimal value of the byte.- Parameters:
bytes
- The values to convert.- Returns:
- A lowercase string with hexadecimal digits, each pair representing a byte in the byte array.
-
formatList
public static <A extends java.lang.Appendable,T> A formatList(A appendable, java.lang.Iterable<T> items) throws java.io.IOException
Appends the string representations of the given items separated by a 44.null
objects are represented by "null".- Type Parameters:
A
- The type of the appendable.T
- The type of item being formatted.- Parameters:
appendable
- The formatting destination.items
- The items to be formatted.- Returns:
- The appendable containing the new information.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.- See Also:
Object.toString()
,Characters.COMMA_CHAR
-
formatList
public static <T> java.lang.String formatList(java.lang.Iterable<T> items)
Appends the string representations of the given items separated by a 44.null
objects are represented by "null".- Type Parameters:
T
- The type of item being formatted.- Parameters:
items
- The items to be formatted.- Returns:
- The string containing the formatted list.
- See Also:
Object.toString()
,Characters.COMMA_CHAR
-
formatList
public static <A extends java.lang.Appendable,T> A formatList(A appendable, char separator, java.lang.Iterable<T> items) throws java.io.IOException
Appends the string representations of the given items separated by a separator character.null
objects are represented by "null".- Type Parameters:
A
- The type of the appendable.T
- The type of item being formatted.- Parameters:
appendable
- The formatting destination.separator
- The separator character to be inserted between the item strings, orCharacters.UNDEFINED_CHAR
if there should be no separator.items
- The items to be formatted.- Returns:
- The appendable containing the new information.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.- See Also:
Object.toString()
-
formatList
public static <T> java.lang.String formatList(char separator, java.lang.Iterable<T> items)
Appends the string representations of the given items separated by a separator character.null
objects are represented by "null".- Type Parameters:
T
- The type of item being formatted.- Parameters:
separator
- The separator character to be inserted between the item strings, orCharacters.UNDEFINED_CHAR
if there should be no separator.items
- The items to be formatted.- Returns:
- The string containing the formatted list.
- See Also:
Object.toString()
-
formatList
public static <A extends java.lang.Appendable,T> A formatList(A appendable, java.lang.String separator, java.lang.Iterable<T> items) throws java.io.IOException
Appends the string representations of the given items separated by a separator string.null
objects are represented by "null".- Type Parameters:
A
- The type of the appendable.T
- The type of item being formatted.- Parameters:
appendable
- The formatting destination.separator
- The separator to be inserted between the item strings, ornull
if there should be no separator.items
- The items to be formatted.- Returns:
- The appendable containing the new information.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.- See Also:
Object.toString()
-
formatList
public static <T> java.lang.String formatList(java.lang.String separator, java.lang.Iterable<T> items)
Appends the string representations of the given items separated by a separator string.null
objects are represented by "null".- Type Parameters:
T
- The type of item being formatted.- Parameters:
separator
- The separator to be inserted between the item strings, ornull
if there should be no separator.items
- The items to be formatted.- Returns:
- The string containing the formatted list.
- See Also:
Object.toString()
-
formatList
public static <A extends java.lang.Appendable> A formatList(A appendable, char separator, java.lang.Object... items) throws java.io.IOException
Appends the string representations of the given items separated by a separator character.null
objects are represented by "null".- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.separator
- The separator character to be inserted between the object strings, orCharacters.UNDEFINED_CHAR
if there should be no separator.items
- The items to be formatted.- Returns:
- The appendable containing the new information.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.- See Also:
Object.toString()
-
formatList
public static <A extends java.lang.Appendable> A formatList(A appendable, java.lang.Object... items) throws java.io.IOException
Appends the string representations of the given items separated by a 44.null
objects are represented by "null".- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.items
- The items to be formatted.- Returns:
- The appendable containing the new information.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.- See Also:
Object.toString()
,Characters.COMMA_CHAR
-
formatList
public static java.lang.String formatList(char separator, java.lang.Object... items)
Appends the string representations of the given items separated by a separator character.null
objects are represented by "null".- Parameters:
separator
- The separator character to be inserted between the object strings, orCharacters.UNDEFINED_CHAR
if there should be no separator.items
- The items to be formatted.- Returns:
- The string containing the formatted list.
- See Also:
Object.toString()
-
formatList
public static <A extends java.lang.Appendable,T> A formatList(A appendable, T[] items, char separator, T ignoreItem) throws java.io.IOException
Appends the string representations of the given items separated by a separator character.null
objects are represented by "null".- Type Parameters:
A
- The type of the appendable.T
- The type of item being formatted.- Parameters:
appendable
- The formatting destination.items
- The items to be formatted.separator
- The separator character to be inserted between the object strings, orCharacters.UNDEFINED_CHAR
if there should be no separator.ignoreItem
- The item to ignore, ornull
if no items should be ignored.- Returns:
- The appendable containing the new information.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.- See Also:
Object.toString()
-
formatList
public static <T> java.lang.String formatList(T[] items, char separator, T ignoreItem)
Appends the string representations of the given items separated by a separator character.null
objects are represented by "null".- Type Parameters:
T
- The type of item being formatted.- Parameters:
items
- The items to be formatted.separator
- The separator character to be inserted between the object strings, orCharacters.UNDEFINED_CHAR
if there should be no separator.ignoreItem
- The item to ignore, ornull
if no items should be ignored.- Returns:
- The string containing the new information.
- See Also:
Object.toString()
-
formatList
public static <A extends java.lang.Appendable> A formatList(A appendable, java.lang.String separator, java.lang.Object... items) throws java.io.IOException
Appends the string representations of the given items separated by a separator string.null
objects are represented by "null".- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.separator
- The separator string to be inserted between the object strings, ornull
if there should be no separator.items
- The items to be formatted.- Returns:
- The appendable containing the new information.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.- See Also:
Object.toString()
-
formatList
public static java.lang.String formatList(java.lang.String separator, java.lang.Object... items)
Appends the string representations of the given items separated by a separator string.null
objects are represented by "null".- Parameters:
separator
- The separator string to be inserted between the object strings, ornull
if there should be no separator.items
- The items to be formatted.- Returns:
- The string containing the formatted list.
- See Also:
Object.toString()
-
formatList
public static <A extends java.lang.Appendable,T> A formatList(A appendable, T[] items, java.lang.String separator, T ignoreItem) throws java.io.IOException
Appends the string representations of the given items separated by a separator string.null
objects are represented by "null".- Type Parameters:
A
- The type of the appendable.T
- The type of item being formatted.- Parameters:
appendable
- The formatting destination.items
- The items to be formatted.separator
- The separator string to be inserted between the object strings, ornull
if there should be no separator.ignoreItem
- The item to ignore, ornull
if no items should be ignored.- Returns:
- The appendable containing the new information.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.- See Also:
Object.toString()
-
formatAttribute
public static <A extends java.lang.Appendable> A formatAttribute(A appendable, java.util.Map.Entry<?,?> attribute) throws java.io.IOException
- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.attribute
- The attribute to format.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttribute
public static <A extends java.lang.Appendable> A formatAttribute(A appendable, java.util.Map.Entry<?,?> attribute, char quote) throws java.io.IOException
Formats a single name-value attribute using 61 for assignment.- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.attribute
- The attribute to format.quote
- The quote character to use for the value, orCharacters.UNDEFINED_CHAR
if the value should not be quoted.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttribute
public static <A extends java.lang.Appendable> A formatAttribute(A appendable, java.util.Map.Entry<?,?> attribute, char assignment, char quote) throws java.io.IOException
Formats a single name-value attribute.- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.attribute
- The attribute to format.assignment
- The character for assigning the value to the attribute.quote
- The quote character to use for the value, orCharacters.UNDEFINED_CHAR
if the value should not be quoted.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttribute
public static <A extends java.lang.Appendable> A formatAttribute(A appendable, NameValuePair<?,?> attribute) throws java.io.IOException
- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.attribute
- The attribute to format.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttribute
public static <A extends java.lang.Appendable> A formatAttribute(A appendable, NameValuePair<?,?> attribute, char quote) throws java.io.IOException
Formats a single name-value attribute using 61 for assignment.- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.attribute
- The attribute to format.quote
- The quote character to use for the value, orCharacters.UNDEFINED_CHAR
if the value should not be quoted.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttribute
public static <A extends java.lang.Appendable> A formatAttribute(A appendable, NameValuePair<?,?> attribute, char assignment, char quote) throws java.io.IOException
Formats a single name-value attribute.- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.attribute
- The attribute to format.assignment
- The character for assigning the value to the attribute.quote
- The quote character to use for the value, orCharacters.UNDEFINED_CHAR
if the value should not be quoted.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttribute
public static <A extends java.lang.Appendable> A formatAttribute(A appendable, java.lang.Object name, java.lang.Object value) throws java.io.IOException
- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.name
- The name to format.value
- The value to format.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttribute
public static <A extends java.lang.Appendable> A formatAttribute(A appendable, java.lang.Object name, java.lang.Object value, char quote) throws java.io.IOException
Formats a single name-value attribute using 61 for assignment.- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.name
- The name to format.value
- The value to format.quote
- The quote character to use for the value, orCharacters.UNDEFINED_CHAR
if the value should not be quoted.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttribute
public static <A extends java.lang.Appendable> A formatAttribute(A appendable, java.lang.Object name, java.lang.Object value, char assignment, char quote) throws java.io.IOException
Formats a single name-value attribute.- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.name
- The name to format.value
- The value to format.assignment
- The character for assigning the value to the attribute.quote
- The quote character to use for the value, orCharacters.UNDEFINED_CHAR
if the value should not be quoted.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttributes
public static <A extends java.lang.Appendable> A formatAttributes(A appendable, NameValuePair<?,?>... attributes) throws java.io.IOException
Formats a series of name-value pairs using the format: name="value", name="value"- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.attributes
- The attributes to format.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
formatAttributes
public static <A extends java.lang.Appendable> A formatAttributes(A appendable, char separator, char assignment, char quote, java.util.Set<?> unquotedNames, NameValuePair<?,?>... attributes) throws java.io.IOException
Formats a series of name-value pairs.- Type Parameters:
A
- The type of the appendable.- Parameters:
appendable
- The formatting destination.separator
- The character for separating the attribute, orCharacters.UNDEFINED_CHAR
if there should be no separator.assignment
- The character for assigning the value to the attribute.quote
- The quote character to use for the value, orCharacters.UNDEFINED_CHAR
if no values should be quoted.unquotedNames
- The set of names that should not be quoted.attributes
- The attributes to format.- Returns:
- The appendable used for formatting.
- Throws:
java.io.IOException
- if there is an error writing to the appendable.
-
-