public final class StringUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char |
TRUNCATE_CHAR |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
capitalizeFirst(java.lang.String text,
java.util.Locale locale) |
static <T extends java.lang.Comparable<T>> |
compareToWithNulls(T v1,
T v2)
Compare two values, which could be null.
|
static java.lang.String |
compressSpaces(java.lang.String str)
Compresses spaces in case of non-preformatting paragraph.
|
static java.lang.String |
decodeBase64(java.lang.String b64data,
java.nio.charset.Charset charset)
Decode the Base64-encoded
charset bytes back to a String. |
static java.lang.String |
encodeBase64(char[] chars,
java.nio.charset.Charset charset)
Convert a char array's
charset bytes into a Base64-encoded String. |
static java.lang.String |
encodeBase64(java.lang.String string,
java.nio.charset.Charset charset)
Convert a string's
charset bytes into a Base64-encoded String. |
static boolean |
equal(java.lang.String one,
java.lang.String two)
Compares two strings for equality.
|
static java.lang.String |
escapeXMLChars(int cp)
Converts a single code point into valid XML.
|
static java.lang.String |
firstN(java.lang.String str,
int len)
Extracts first N codepoints from string.
|
static java.lang.String |
format(java.lang.String str,
java.lang.Object... arguments)
Formats UI strings.
|
static int |
getFirstLetterLowercase(java.lang.String s)
Returns first letter in lowercase.
|
static java.lang.String |
getTailSegments(java.lang.String str,
int separator,
int segments)
For a string delimited by some separator, retrieve the last
segments segments. |
static boolean |
isCJK(java.lang.String input) |
static boolean |
isEmpty(java.lang.String str)
Check if string is empty, i.e.
|
static boolean |
isLowerCase(java.lang.String input)
Returns true if the input has at least one letter and
all letters are lower case.
|
static boolean |
isMixedCase(java.lang.String input)
Returns true if the input has both upper case and lower case letters, but
is not title case.
|
static boolean |
isSubstringAfter(java.lang.String text,
int pos,
java.lang.String substring)
Checks if text contains substring after specified position.
|
static boolean |
isSubstringBefore(java.lang.String text,
int pos,
java.lang.String substring)
Checks if text contains substring before specified position.
|
static boolean |
isTitleCase(int codePoint) |
static boolean |
isTitleCase(java.lang.String input)
Returns true if the input is title case, meaning the first character is UpperCase or
TitleCase* and the rest of the string (if present) is LowerCase.
|
static boolean |
isUpperCase(java.lang.String input)
Returns true if the input is upper case.
|
static boolean |
isValidXMLChar(int codePoint) |
static boolean |
isWhiteSpace(int codePoint)
Returns true if the input is a whitespace character
(including non-breaking characters that are false according to
Character.isWhitespace(int) ). |
static boolean |
isWhiteSpace(java.lang.String input)
Returns true if the input consists only of whitespace characters
(including non-breaking characters that are false according to
Character.isWhitespace(int) ). |
static java.lang.String |
makeValidXML(java.lang.String plaintext)
Converts a stream of plaintext into valid XML.
|
static java.lang.String |
matchCapitalization(java.lang.String text,
java.lang.String matchTo,
java.util.Locale locale) |
static java.lang.String |
normalizeUnicode(java.lang.CharSequence text)
Apply Unicode NFC normalization to a string.
|
static java.lang.String |
normalizeWidth(java.lang.String text)
Normalize the
width of characters in the supplied text.
|
static <T> T |
nvl(T... values)
Returns first not null object from list, or null if all values is null.
|
static long |
nvlLong(long... values)
Returns first non-zero object from list, or zero if all values is null.
|
static java.lang.String |
removeXMLInvalidChars(java.lang.String str)
Replace invalid XML chars by spaces.
|
static java.lang.String |
replaceCase(java.lang.String txt,
java.util.Locale lang)
Interpret the case replacement language used in regular expressions:
backslash u = uppercase next letter
backslash l = lowercase next letter
backslash U = uppercase next letters until backslash E
backslash L = lowercase next letters until backslash E
backslash u + backslash L = uppercase next letter then lowercase all until backslash E
backslash l + backslash U = lowercase next letter then uppercase all until backslash E
Warning: this method works with the string you give to it; if you want to do other substitutions, such as
variable conversions, they must be done before the call to replaceCase, else this method will not apply to the
non-yet converted parts!
|
static java.lang.String |
rstrip(java.lang.String text)
Strip whitespace from the end of a string.
|
static java.lang.String |
stripFromEnd(java.lang.String string,
java.lang.String... toStrip) |
static java.lang.String |
toTitleCase(java.lang.String text,
java.util.Locale locale)
Convert text to title case according to the supplied locale.
|
static java.lang.String |
truncate(java.lang.String text,
int len)
Truncate the supplied text to a maximum of len codepoints.
|
static java.lang.String |
unescapeXMLEntities(java.lang.String text)
Converts XML entities to characters.
|
public static final char TRUNCATE_CHAR
public static boolean isEmpty(java.lang.String str)
public static boolean isLowerCase(java.lang.String input)
public static boolean isUpperCase(java.lang.String input)
public static boolean isMixedCase(java.lang.String input)
public static boolean isTitleCase(java.lang.String input)
*There are exotic characters that are neither UpperCase nor LowerCase, but are TitleCase:
e.g. LATIN CAPITAL LETTER L WITH SMALL LETTER J (U+01C8)
These are handled correctly.
public static boolean isTitleCase(int codePoint)
public static boolean isWhiteSpace(java.lang.String input)
Character.isWhitespace(int)
).public static boolean isWhiteSpace(int codePoint)
Character.isWhitespace(int)
).public static boolean isCJK(java.lang.String input)
public static java.lang.String capitalizeFirst(java.lang.String text, java.util.Locale locale)
public static java.lang.String replaceCase(java.lang.String txt, java.util.Locale lang)
public static java.lang.String matchCapitalization(java.lang.String text, java.lang.String matchTo, java.util.Locale locale)
public static java.lang.String toTitleCase(java.lang.String text, java.util.Locale locale)
@SafeVarargs public static <T> T nvl(T... values)
public static long nvlLong(long... values)
public static <T extends java.lang.Comparable<T>> int compareToWithNulls(T v1, T v2)
public static java.lang.String firstN(java.lang.String str, int len)
public static java.lang.String truncate(java.lang.String text, int len)
text
- The text to truncatelen
- The desired length (in codepoints) of the resultpublic static int getFirstLetterLowercase(java.lang.String s)
public static boolean isSubstringAfter(java.lang.String text, int pos, java.lang.String substring)
public static boolean isSubstringBefore(java.lang.String text, int pos, java.lang.String substring)
public static java.lang.String stripFromEnd(java.lang.String string, java.lang.String... toStrip)
public static java.lang.String normalizeUnicode(java.lang.CharSequence text)
public static java.lang.String removeXMLInvalidChars(java.lang.String str)
str
- input streampublic static boolean isValidXMLChar(int codePoint)
public static java.lang.String makeValidXML(java.lang.String plaintext)
public static java.lang.String compressSpaces(java.lang.String str)
public static java.lang.String escapeXMLChars(int cp)
public static java.lang.String unescapeXMLEntities(java.lang.String text)
public static boolean equal(java.lang.String one, java.lang.String two)
public static java.lang.String format(java.lang.String str, java.lang.Object... arguments)
str
- The string to formatarguments
- Arguments to use in formatting the stringpublic static java.lang.String normalizeWidth(java.lang.String text)
text
- public static java.lang.String rstrip(java.lang.String text)
Character.isWhitespace(int)
, so it does not strip the extra
non-breaking whitespace included in isWhiteSpace(int)
.text
- public static java.lang.String encodeBase64(java.lang.String string, java.nio.charset.Charset charset)
charset
bytes into a Base64-encoded String.string
- a stringcharset
- the charset with which to obtain the bytespublic static java.lang.String encodeBase64(char[] chars, java.nio.charset.Charset charset)
charset
bytes into a Base64-encoded String.
Useful for handling passwords. Intermediate buffers are cleared after use.chars
- a char arraycharset
- the charset with which to obtain the bytespublic static java.lang.String decodeBase64(java.lang.String b64data, java.nio.charset.Charset charset)
charset
bytes back to a String.b64data
- Base64-encoded Stringcharset
- charset of decoded bytespublic static java.lang.String getTailSegments(java.lang.String str, int separator, int segments)
segments
segments.str
- The stringseparator
- The separator delimiting the string's segmentssegments
- The number of segments to return, starting at the endsegments
is greater than the number of segments contained in
str
, then str
itself.