| java.lang.Object jimm.util.StringUtils
StringUtils | public class StringUtils (Code) | | Globally available utility classes, mostly for string manipulation.
author: Jim Menard, jimm@io.com |
Method Summary | |
public static String | escapeHTML(String str) Returns a string with HTML special characters replaced by their entity
equivalents. | public static String | escapeXML(String str) Returns a string with XML special characters replaced by their entity
equivalents. | public static int | findBreakAfter(String line, int start) Returns the index of the first whitespace character or '-' in
line that is at or after start. | public static int | findBreakBefore(String line, int start) Returns the index of the first whitespace character or '-' in
line that is at or before start. | public static String | join(Collection c, String joinWith) Returns a string consisting of all members of a collection separated
by the specified string. | public static String | newlinesToXHTMLBreaks(String str) Returns a new string where all newlines ("\n", "\r",
or "\r\n") have been replaced by "\n" plus XHTML
break tags ("\n<br />"). | public static String | nullOrTrimmed(String str) Returns str with leading and trailing spaces trimmed or, if
str is null , returns null . | public static String | replaceDelimited(String start, String end, Replacer r, String s) Returns a new string with all strings delimited by start and
end replaced by whatever is generated by the
Replacer r. | public static String | replaceDelimited(String exceptAfter, String start, String end, Replacer r, String s) Returns a new string with all strings delimited by start and
end (but not immediately preceeded by exceptAfter)
replaced by whatever is generated by the Replacer
r. | public static List | split(String str, String delim) Returns a list of substrings created by splitting the given string at
the given delimiter. | public static List | splitIntoLines(String str) Returns an array of strings, one for each line in the string. | public static void | splitUp(StringBuffer buf, String str) Appends a string to a string buffer, adding extra newlines so the message
is not too wide. | public static void | splitUp(StringBuffer buf, String str, int maxWidth) Appends a string to a string buffer, adding extra newlines so the
message is not too wide. | public static String | unescapeXML(String str) Returns a string with XML entities replaced by their normal characters. | public static List | wrap(String str, FontMetrics fm, int maxWidth) Returns an array of strings, one for each line in the string after it
has been wrapped to fit lines of maxWidth. | public static void | wrapLineInto(String line, List list, FontMetrics fm, int maxWidth) Given a line of text and font metrics information, wrap the line and
add the new line(s) to list. |
DEFAULT_MAX_MESSAGE_WIDTH | final protected static int DEFAULT_MAX_MESSAGE_WIDTH(Code) | | |
escapeHTML | public static String escapeHTML(String str)(Code) | | Returns a string with HTML special characters replaced by their entity
equivalents.
Parameters: str - the string to escape a new string without HTML special characters |
escapeXML | public static String escapeXML(String str)(Code) | | Returns a string with XML special characters replaced by their entity
equivalents.
Parameters: str - the string to escape a new string without XML special characters |
findBreakAfter | public static int findBreakAfter(String line, int start)(Code) | | Returns the index of the first whitespace character or '-' in
line that is at or after start. Returns -1 if no
such character is found.
Parameters: line - a string Parameters: start - where to star looking |
findBreakBefore | public static int findBreakBefore(String line, int start)(Code) | | Returns the index of the first whitespace character or '-' in
line that is at or before start. Returns -1 if no
such character is found.
Parameters: line - a string Parameters: start - where to star looking |
join | public static String join(Collection c, String joinWith)(Code) | | Returns a string consisting of all members of a collection separated
by the specified string. The toString method of each
collection member is called to convert it to a string.
Parameters: c - a collection of objects Parameters: joinWith - the string that will separate each member of the collection |
newlinesToXHTMLBreaks | public static String newlinesToXHTMLBreaks(String str)(Code) | | Returns a new string where all newlines ("\n", "\r",
or "\r\n") have been replaced by "\n" plus XHTML
break tags ("\n<br />").
We don't call splitIntoLines because that method does not
tell us if the string ended with a newline or not.
Parameters: str - any string a new string with all newlines replaced by"\n<br />" |
nullOrTrimmed | public static String nullOrTrimmed(String str)(Code) | | Returns str with leading and trailing spaces trimmed or, if
str is null , returns null .
str trimmed or null |
replaceDelimited | public static String replaceDelimited(String start, String end, Replacer r, String s)(Code) | | Returns a new string with all strings delimited by start and
end replaced by whatever is generated by the
Replacer r. The delimiters themselves are
not part of the returned string.
If the Replacer ever returns null , we return
null .
Parameters: start - the delimiter start (for example, "{@") Parameters: end - the delimiter end (for example, "}") Parameters: r - the replacer; takes the text between start andend and returns the replacement text Parameters: s - the string we're munging a new string munged by the replacer, or null ifthe replacer ever returns null |
replaceDelimited | public static String replaceDelimited(String exceptAfter, String start, String end, Replacer r, String s)(Code) | | Returns a new string with all strings delimited by start and
end (but not immediately preceeded by exceptAfter)
replaced by whatever is generated by the Replacer
r. The delimiters themselves are not part of the returned
string.
If the Replacer ever returns null , we return
null .
Parameters: exceptAfter - ignore start if it appears immediatelyafter this string; may be null Parameters: start - the delimiter start (for example, "{@") Parameters: end - the delimiter end (for example, "}") Parameters: r - the replacer; takes the text between start andend and returns the replacement text Parameters: s - the string we're munging a new string munged by the replacer, or null ifthe replacer ever returns null |
split | public static List split(String str, String delim)(Code) | | Returns a list of substrings created by splitting the given string at
the given delimiter. The return value will be null if the
string is null , else it will be a non-empty list of strings.
If delim is null or is not found in the string,
the list will contain one element: the original string.
This isn't the same thing as using a tokenizer. delim is
a literal string, not a set of characters any of which may be a
delimiter.
Parameters: str - the string we're splitting Parameters: delim - the delimter string |
splitIntoLines | public static List splitIntoLines(String str)(Code) | | Returns an array of strings, one for each line in the string. Lines end
with any of cr, lf, or cr lf. A line ending at the end of the string
will not output a further, empty string.
This code assumes str is not null .
Parameters: str - the string to split a non-empty list of strings |
splitUp | public static void splitUp(StringBuffer buf, String str)(Code) | | Appends a string to a string buffer, adding extra newlines so the message
is not too wide. Max width is not guaranteed; if there is no space in a
line before DEFAULT_MAX_MESSAGE_WIDTH then the next one after
it will be used insetead. Each line will be trimmed before and after it's
added, so some whitespace may be goofed up. This is used for error message
wrapping, so it's not critical that whitespace be preserved.
TODO Looks for space, not all whitespace. This should probably change.
Parameters: buf - the string buffer Parameters: str - the string |
splitUp | public static void splitUp(StringBuffer buf, String str, int maxWidth)(Code) | | Appends a string to a string buffer, adding extra newlines so the
message is not too wide. Max width is not guaranteed; if there is no space
in a line before maxWidth then the next one after it will be
used instead. Each line will be trimmed before and after it's added,
so some whitespace may be goofed up. This is used for error message
wrapping, so it's not critical that whitespace be preserved.
TODO Looks for space, not all whitespace. This should probably change.
Parameters: buf - the string buffer Parameters: str - the string Parameters: maxWidth - maximum number of chars in each line |
unescapeXML | public static String unescapeXML(String str)(Code) | | Returns a string with XML entities replaced by their normal characters.
Parameters: str - the string to un-escape a new normal string |
wrap | public static List wrap(String str, FontMetrics fm, int maxWidth)(Code) | | Returns an array of strings, one for each line in the string after it
has been wrapped to fit lines of maxWidth. Lines end
with any of cr, lf, or cr lf. A line ending at the end of the string
will not output a further, empty string.
This code assumes str is not null .
Parameters: str - the string to split Parameters: fm - needed for string width calculations Parameters: maxWidth - the max line width, in points a non-empty list of strings |
wrapLineInto | public static void wrapLineInto(String line, List list, FontMetrics fm, int maxWidth)(Code) | | Given a line of text and font metrics information, wrap the line and
add the new line(s) to list.
Parameters: line - a line of text Parameters: list - an output list of strings Parameters: fm - font metrics Parameters: maxWidth - maximum width of the line(s) |
|
|