public final class StringUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String[] |
EMPTY_STRINGS |
Modifier and Type | Method and Description |
---|---|
static void |
appendXmlEscaped(StringBuilder buf,
String src)
Deprecated.
use
appendXmlEscaped(StringBuilder, String, boolean) instead |
static void |
appendXmlEscaped(StringBuilder buf,
String src,
boolean supportUTF8) |
static boolean |
areSemanticEquals(String a,
String b)
Returns true if both strings are effectively null or whitespace, returns
false otherwise if they have actual text that differs.
|
static String |
asString(Object[] items,
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(StringBuffer sb,
Iterator<?> iter,
String separator)
Copies the elements returned by the iterator onto the string buffer each
delimited by the separator.
|
static void |
asStringOn(StringBuilder sb,
Object[] items,
String separator)
Copies the array items onto the string builder each delimited by the
separator.
|
static String |
escapeWhitespace(Object o)
Replace some whitespace characters so they are visually apparent.
|
static String |
htmlEncode(String string) |
static boolean |
isAnyOf(String text,
String... tests)
Returns whether the non-null text arg matches any of the test values.
|
static boolean |
isEmpty(String value)
Returns true if the value arg is either null, empty, or full of
whitespace characters.
|
static boolean |
isNotEmpty(String value) |
static boolean |
isSame(String s1,
String s2,
boolean trim,
boolean ignoreCase,
boolean standardizeWhitespace)
Are the two String values the same.
|
static int |
lengthOfShortestIn(String[] strings)
Return the length of the shortest string in the array.
|
static String |
lpad(String s,
int length)
Left pads a string.
|
static int |
maxCommonLeadingWhitespaceForAll(String[] strings)
Determine the maximum number of common leading whitespace characters the
strings share in the same sequence.
|
static String |
replaceString(String original,
char oldChar,
String newString) |
static String |
replaceString(String original,
String oldString,
String newString) |
static boolean |
startsWithAny(String text,
String... prefixes)
Return whether the non-null text arg starts with any of the prefix
values.
|
static String[] |
substringsOf(String source,
char delimiter)
Parses the input source using the delimiter specified.
|
static String[] |
substringsOf(String str,
String separator)
Much more efficient than StringTokenizer.
|
static String[] |
trimStartOn(String[] strings,
int trimDepth)
Trims off the leading characters off the strings up to the trimDepth
specified.
|
static String |
withoutPrefixes(String text,
String... prefixes)
Checks for the existence of any of the listed prefixes on the non-null
text and removes them.
|
public static final String[] EMPTY_STRINGS
public static boolean startsWithAny(String text, String... prefixes)
text
- prefixes
- public static boolean isAnyOf(String text, String... tests)
text
- tests
- public static String withoutPrefixes(String text, String... prefixes)
text
- prefixes
- public static boolean isEmpty(String value)
value
- true
if the value is empty, false
otherwise.public static boolean isNotEmpty(String value)
value
- Stringpublic static boolean areSemanticEquals(String a, String b)
a
- b
- public static String replaceString(String original, char oldChar, String newString)
original
- StringoldChar
- charnewString
- Stringpublic static String replaceString(String original, String oldString, String newString)
original
- StringoldString
- StringnewString
- String@Deprecated public static void appendXmlEscaped(StringBuilder buf, String src)
appendXmlEscaped(StringBuilder, String, boolean)
insteadbuf
- The destination XML streamsrc
- The String to append to the streampublic static String escapeWhitespace(Object o)
o
- public static void appendXmlEscaped(StringBuilder buf, 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 String[] substringsOf(String source, char delimiter)
source
- Stringdelimiter
- charpublic static String[] substringsOf(String str, String separator)
str
- Stringseparator
- charpublic static void asStringOn(StringBuffer sb, Iterator<?> iter, String separator)
sb
- StringBufferiter
- Iteratorseparator
- Stringpublic static void asStringOn(StringBuilder sb, Object[] items, String separator)
sb
- StringBuilderitems
- Object[]separator
- Stringpublic static int lengthOfShortestIn(String[] strings)
strings
- String[]public static int maxCommonLeadingWhitespaceForAll(String[] strings)
strings
- String[]public static String[] trimStartOn(String[] strings, int trimDepth)
strings
- trimDepth
- public static String lpad(String s, int length)
s
- The String to padlength
- The desired minimum length of the resulting padded Stringpublic static boolean isSame(String s1, 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.Copyright © 2002-2016 InfoEther. All Rights Reserved.