|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sourceforge.pmd.util.StringUtil
public final class StringUtil
A number of String-specific utility methods for use by PMD or its IDE plugins.
| Field Summary | |
|---|---|
static java.lang.String[] |
EMPTY_STRINGS
|
| Method Summary | |
|---|---|
static void |
appendXmlEscaped(java.lang.StringBuilder buf,
java.lang.String src)
Appends to a StringBuilder the String src where non-ASCII and XML special chars are escaped. |
static void |
appendXmlEscaped(java.lang.StringBuilder buf,
java.lang.String src,
boolean supportUTF8)
|
static boolean |
areSemanticEquals(java.lang.String a,
java.lang.String b)
Returns true if both strings are effectively null or whitespace, returns false otherwise if they have actual text that differs. |
static java.lang.String |
asString(java.lang.Object[] items,
java.lang.String separator)
Formats all items onto a string with separators if more than one exists, return an empty string if the items are null or empty. |
static void |
asStringOn(java.lang.StringBuffer sb,
java.util.Iterator<?> iter,
java.lang.String separator)
Copies the elements returned by the iterator onto the string buffer each delimited by the separator. |
static void |
asStringOn(java.lang.StringBuilder sb,
java.lang.Object[] items,
java.lang.String separator)
Copies the array items onto the string builder each delimited by the separator. |
static java.lang.String |
escapeWhitespace(java.lang.Object o)
Replace some whitespace characters so they are visually apparent. |
static java.lang.String |
htmlEncode(java.lang.String string)
|
static boolean |
isAnyOf(java.lang.String text,
java.lang.String... tests)
Returns whether the non-null text arg matches any of the test values. |
static boolean |
isEmpty(java.lang.String value)
Returns true if the value arg is either null, empty, or full of whitespace characters. |
static boolean |
isNotEmpty(java.lang.String value)
|
static boolean |
isSame(java.lang.String s1,
java.lang.String s2,
boolean trim,
boolean ignoreCase,
boolean standardizeWhitespace)
Are the two String values the same. |
static int |
lengthOfShortestIn(java.lang.String[] strings)
Return the length of the shortest string in the array. |
static java.lang.String |
lpad(java.lang.String s,
int length)
Left pads a string. |
static int |
maxCommonLeadingWhitespaceForAll(java.lang.String[] strings)
Determine the maximum number of common leading whitespace characters the strings share in the same sequence. |
static java.lang.String |
replaceString(java.lang.String original,
char oldChar,
java.lang.String newString)
|
static java.lang.String |
replaceString(java.lang.String original,
java.lang.String oldString,
java.lang.String newString)
|
static boolean |
startsWithAny(java.lang.String text,
java.lang.String... prefixes)
Return whether the non-null text arg starts with any of the prefix values. |
static java.lang.String[] |
substringsOf(java.lang.String source,
char delimiter)
Parses the input source using the delimiter specified. |
static java.lang.String[] |
substringsOf(java.lang.String str,
java.lang.String separator)
Much more efficient than StringTokenizer. |
static java.lang.String[] |
trimStartOn(java.lang.String[] strings,
int trimDepth)
Trims off the leading characters off the strings up to the trimDepth specified. |
static java.lang.String |
withoutPrefixes(java.lang.String text,
java.lang.String... prefixes)
Checks for the existence of any of the listed prefixes on the non-null text and removes them. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String[] EMPTY_STRINGS
| Method Detail |
|---|
public static boolean startsWithAny(java.lang.String text,
java.lang.String... prefixes)
text - prefixes -
public static boolean isAnyOf(java.lang.String text,
java.lang.String... tests)
text - tests -
public static java.lang.String withoutPrefixes(java.lang.String text,
java.lang.String... prefixes)
text - prefixes -
public static boolean isEmpty(java.lang.String value)
value -
true if the value is empty, false
otherwise.public static boolean isNotEmpty(java.lang.String value)
value - String
public static boolean areSemanticEquals(java.lang.String a,
java.lang.String b)
a - b -
public static java.lang.String replaceString(java.lang.String original,
char oldChar,
java.lang.String newString)
original - StringoldChar - charnewString - String
public static java.lang.String replaceString(java.lang.String original,
java.lang.String oldString,
java.lang.String newString)
original - StringoldString - StringnewString - String
public static void appendXmlEscaped(java.lang.StringBuilder buf,
java.lang.String src)
buf - The destination XML streamsrc - The String to append to the streampublic static java.lang.String escapeWhitespace(java.lang.Object o)
o -
public static java.lang.String htmlEncode(java.lang.String string)
string - String
public static void appendXmlEscaped(java.lang.StringBuilder buf,
java.lang.String src,
boolean supportUTF8)
buf - src - supportUTF8 - override the default setting, whether special
characters should be replaced with entities (
false) or should be included as is (
true).TODO - unify the method above with the one below
public to support unit testing - make this package private, once the
unit test classes are in the same package.
public static java.lang.String[] substringsOf(java.lang.String source,
char delimiter)
source - Stringdelimiter - char
public static java.lang.String[] substringsOf(java.lang.String str,
java.lang.String separator)
str - Stringseparator - char
public static void asStringOn(java.lang.StringBuffer sb,
java.util.Iterator<?> iter,
java.lang.String separator)
sb - StringBufferiter - Iteratorseparator - String
public static void asStringOn(java.lang.StringBuilder sb,
java.lang.Object[] items,
java.lang.String separator)
sb - StringBuilderitems - Object[]separator - Stringpublic static int lengthOfShortestIn(java.lang.String[] strings)
strings - String[]
public static int maxCommonLeadingWhitespaceForAll(java.lang.String[] strings)
strings - String[]
public static java.lang.String[] trimStartOn(java.lang.String[] strings,
int trimDepth)
strings - trimDepth -
public static java.lang.String lpad(java.lang.String s,
int length)
s - The String to padlength - The desired minimum length of the resulting padded String
public static boolean isSame(java.lang.String s1,
java.lang.String s2,
boolean trim,
boolean ignoreCase,
boolean standardizeWhitespace)
s1 - The first String.s2 - The second String.trim - Indicates if the Strings should be trimmed before comparison.ignoreCase - Indicates if the case of the Strings should ignored
during comparison.standardizeWhitespace - Indicates if the embedded whitespace should
be standardized before comparison.
true if the Strings are the same, false
otherwise.
public static java.lang.String asString(java.lang.Object[] items,
java.lang.String separator)
items - Object[]separator - String
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||