|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.xmlmind.util.StringUtil
public final class StringUtil
A collection of utility functions (static methods) operating on Strings.
| Field Summary | |
|---|---|
static java.lang.String[] |
EMPTY_LIST
A ready-to-use empty list of Strings. |
| Method Summary | |
|---|---|
static java.lang.String |
capitalize(java.lang.String string)
Returns the specified string with its first character converted to upper case. |
static java.lang.String |
escape(char c)
Returns the \\uXXXX Java escape sequence corresponding to specified character. |
static void |
escape(char c,
java.lang.StringBuilder buffer)
Same as escape(char) expect that the \\uXXXX
Java escape sequence is appended to specified buffer. |
static java.lang.String |
escape(java.lang.String string)
Returns the specified string with all non-ASCII characters and non-printable ASCII characters replaced by the corresponding Java escape sequences (that is '\n', 'é', etc). |
static void |
escape(java.lang.String string,
java.lang.StringBuilder buffer)
Same as escape(String) except that the escaped string is
appended to specified buffer. |
static java.lang.String |
join(char separatorChar,
java.lang.String... strings)
Equivalent to join(Character.toString(separatorChar), strings). |
static java.lang.String |
join(java.lang.String separator,
java.lang.String... strings)
Joins the items of the specified list of Strings using specified separator. |
static java.lang.String |
joinArguments(java.lang.String... args)
Inverse operation of splitArguments(java.lang.String). |
static java.lang.String |
quote(java.lang.String string)
Like escape(java.lang.String) but puts a double quote character ('\"')
around the escaped string. |
static java.lang.String |
quoteArgument(java.lang.String arg)
Quotes specified string using '\"' if needed to. |
static java.lang.String |
replaceAll(java.lang.String string,
java.lang.String oldSub,
java.lang.String newSub)
Replaces substring oldSub by substring newSub
inside String string. |
static java.lang.String[] |
split(java.lang.String s)
Splits specified string at whitespace character boundaries. |
static java.lang.String[] |
split(java.lang.String string,
char separatorChar)
Splits String string at occurrences of char separatorChar. |
static java.lang.String[] |
splitArguments(java.lang.String string)
Splits specified string in a manner which is similar to what is done for command line arguments. |
static java.lang.String |
substituteVars(java.lang.String text,
char[] names,
java.lang.Object[] values)
Equivalent to substituteVars(text, names, values, null, null, false). |
static java.lang.String |
substituteVars(java.lang.String text,
char[] names,
java.lang.Object[] values,
java.lang.String[] args,
java.lang.String allArgs)
Equivalent to substituteVars(text, names, values, args, allArgs, false). |
static java.lang.String |
substituteVars(java.lang.String text,
char[] names,
java.lang.Object[] values,
java.lang.String[] args,
java.lang.String allArgs,
boolean allowForeignVars)
Returns specified text where %0, %1, ..., %9, %* and %X, %Y, etc, variables have been subsituted by specified values. |
static java.lang.String |
uncapitalize(java.lang.String string)
Returns the specified string with its first character converted to lower case. |
static java.lang.String |
unescape(java.lang.String string)
Returns the specified string with Java escape sequences (that is '\n', 'é', etc) replaced by the corresponding character. |
static java.lang.String |
unquote(java.lang.String string)
Like unescape(java.lang.String) but removes the double quote characters
('\"'), if any, before unescaping the string. |
static java.lang.String[] |
wordWrap(java.lang.String text,
int maxLineLength)
Splits specified string at word boundaries, returning an array of lines having at most specified number of characters. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String[] EMPTY_LIST
| Method Detail |
|---|
public static java.lang.String[] split(java.lang.String s)
s - string to be split
public static java.lang.String[] split(java.lang.String string,
char separatorChar)
string - the String to be splitseparatorChar - the char where to split
Note that each occurrence of separatorChar specifies the end of a substring. Therefore, the returned list may contain empty substrings if consecutive separatorChars are found in String string.
However, for consistency with all the other split methods, this method returns an empty array for the empty string.
public static java.lang.String join(char separatorChar,
java.lang.String... strings)
join(Character.toString(separatorChar), strings).
public static java.lang.String join(java.lang.String separator,
java.lang.String... strings)
separator - the string used to join itemsstrings - the list where items are to be joined
public static final java.lang.String[] wordWrap(java.lang.String text,
int maxLineLength)
text - string to be split at word boundariesmaxLineLength - the number of characters contained in a line
should not exceed this value
public static java.lang.String[] splitArguments(java.lang.String string)
Example: returns {"one", "two", "three", " \"four\" ", "
'five' "} for input string:
one "two" 'three' " \"four\" " " 'five' "
Note that escaped sequences such as "\n" and "\t" contained in specified string are left as is. The reason for this is that specified string may contain any whitespace character including '\n' and '\t', provided that these characters are contained in a quoted argument.
public static java.lang.String joinArguments(java.lang.String... args)
splitArguments(java.lang.String). Returns ``command line''.
quoteArgument(java.lang.String)public static java.lang.String quoteArgument(java.lang.String arg)
Note that whitespace characters such as '\n' and '\t' are not escaped as "\n" and "\t". Instead, the whole string is quoted. This is sufficient to allow it to contain any whitespace character.
joinArguments(java.lang.String...)
public static java.lang.String substituteVars(java.lang.String text,
char[] names,
java.lang.Object[] values)
substituteVars(text, names, values, null, null, false).
public static java.lang.String substituteVars(java.lang.String text,
char[] names,
java.lang.Object[] values,
java.lang.String[] args,
java.lang.String allArgs)
substituteVars(text, names, values, args, allArgs, false).
public static java.lang.String substituteVars(java.lang.String text,
char[] names,
java.lang.Object[] values,
java.lang.String[] args,
java.lang.String allArgs,
boolean allowForeignVars)
"%%" may be used to escape character "%".
A variable, whether named or not, %X may also be specified as %{X} etc.
text - text containing variablesnames - the one-character long name of named variables %X,
%Y, etc.
May be null.
values - the values of named variables %X, %Y, etc.
These objects are converted to strings using the
toString() method.
When there are no enough values, the corresponding variables are not replaced.
May be null if names is also null.
args - the values of %0, %1, ...,
%9 variables.
When there are no enough values, the corresponding variables are replaced by the empty string.
May be null.
allArgs - the values of %* variable.
May be null, in which case, args are joined
using joinArguments(java.lang.String...) to form allArgs.
allowForeignVars - if true, unknown variables
specified as %{var_name} are assumed to be system properties or
environment variables and are subsituted as such.
public static java.lang.String replaceAll(java.lang.String string,
java.lang.String oldSub,
java.lang.String newSub)
oldSub by substring newSub
inside String string.
string - the String where replacements are to be performedoldSub - the substring to replacenewSub - the replacement substring
String.replace(char, char)public static java.lang.String capitalize(java.lang.String string)
string - the String to be processed
public static java.lang.String uncapitalize(java.lang.String string)
string - the String to be processed
public static java.lang.String quote(java.lang.String string)
escape(java.lang.String) but puts a double quote character ('\"')
around the escaped string.
public static java.lang.String escape(java.lang.String string)
string - the String to be escaped
public static void escape(java.lang.String string,
java.lang.StringBuilder buffer)
escape(String) except that the escaped string is
appended to specified buffer.
public static java.lang.String escape(char c)
c - the character to be escaped
public static void escape(char c,
java.lang.StringBuilder buffer)
escape(char) expect that the \\uXXXX
Java escape sequence is appended to specified buffer.
public static java.lang.String unquote(java.lang.String string)
unescape(java.lang.String) but removes the double quote characters
('\"'), if any, before unescaping the string.
public static java.lang.String unescape(java.lang.String string)
string - the String to be unescaped
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||