Package uk.blankaspect.common.string
Class StringUtils
java.lang.Object
uk.blankaspect.common.string.StringUtils
This class contains utility methods that relate to strings and character
sequences.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
This is an enumeration of the ways in which an input string may be split by thesplit*(…)
methods. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char
The prefix that is recognised by theescape(CharSequence, String)
method. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
applyPrefix
(String str, String prefix) static boolean
containsIgnoreCase
(String target, Iterable<String> strs) static String
escape
(CharSequence seq, String metachars) extractLines
(CharSequence text) Splits the specified text at line separators and returns the resulting list of lines.static String
static String
static String
static String
static int
getMaxLength
(Iterable<? extends CharSequence> seqs) static int
getMaxLength
(String... strs) static String
getPrefixFirst
(String str, char ch) static String
getPrefixLast
(String str, char ch) static String
getSuffixAfterFirst
(String str, char ch) static String
getSuffixAfterLast
(String str, char ch) static String
getSuffixFirst
(String str, char ch) static String
getSuffixLast
(String str, char ch) static int
indexOfIgnoreCase
(String target, List<String> strs) static boolean
isNullOrBlank
(String str) static boolean
isNullOrEmpty
(String str) Returnstrue
if the specified string isnull
or empty.static String
join
(char separator, boolean trailingSeparator, Iterable<? extends CharSequence> seqs) static String
static String
join
(char separator, Iterable<? extends CharSequence> seqs) static String
static String
join
(CharSequence separator, boolean trailingSeparator, Iterable<? extends CharSequence> seqs) static String
join
(CharSequence separator, boolean trailingSeparator, String... strs) static String
join
(CharSequence separator, Iterable<? extends CharSequence> seqs) static String
join
(CharSequence separator, String... strs) static String
padAfter
(CharSequence seq, int length) static String
padAfter
(CharSequence seq, int length, char ch) static String
padBefore
(CharSequence seq, int length) static String
padBefore
(CharSequence seq, int length, char ch) static String
removePrefix
(String str, String prefix) static String
removeSuffix
(String str, String suffix) static String[]
splitAt
(String str, int index, StringUtils.SplitMode splitMode) static String[]
splitAtFirst
(String str, char ch) static String[]
splitAtFirst
(String str, char ch, StringUtils.SplitMode splitMode) static String[]
splitAtLast
(String str, char ch) static String[]
splitAtLast
(String str, char ch, StringUtils.SplitMode splitMode) static String
stripAfter
(CharSequence seq) static String
stripBefore
(CharSequence seq) static String
toCamelCase
(CharSequence text) Converts the specified text to camel case and returns the resulting string.static String
wrap
(CharSequence seq, int maxLineLength) wrapLines
(CharSequence seq, int maxLineLength)
-
Field Details
-
ESCAPE_PREFIX_CHAR
public static final char ESCAPE_PREFIX_CHARThe prefix that is recognised by theescape(CharSequence, String)
method.- See Also:
-
-
Method Details
-
isNullOrEmpty
Returnstrue
if the specified string isnull
or empty.- Parameters:
str
- the string that will be tested.- Returns:
true
ifstr
isnull
or empty.
-
isNullOrBlank
- Parameters:
str
- the string that will be tested.- Returns:
true
ifstr
isnull
or empty or it contains only whitespace characters.
-
getMaxLength
-
getMaxLength
-
stripBefore
-
stripAfter
-
padBefore
-
padBefore
-
padAfter
-
padAfter
-
split
-
split
-
splitAt
-
splitAtFirst
-
splitAtFirst
-
splitAtLast
-
splitAtLast
-
getPrefixFirst
-
getPrefixLast
-
getSuffixFirst
-
getSuffixAfterFirst
-
getSuffixLast
-
getSuffixAfterLast
-
removePrefix
-
removeSuffix
-
join
-
join
-
join
-
join
-
join
-
join
public static String join(char separator, boolean trailingSeparator, Iterable<? extends CharSequence> seqs) -
join
-
join
public static String join(CharSequence separator, boolean trailingSeparator, Iterable<? extends CharSequence> seqs) -
extractLines
Splits the specified text at line separators and returns the resulting list of lines. The line separators that are recognised are CR+LF (U+000D, U+000A) and LF (U+000A). The line separators are not included in the output list.- Parameters:
text
- the text that will be split into lines at line separators.- Returns:
- a list of the strings that result from splitting
text
at line separators.
-
wrap
-
wrapLines
-
firstCharToLowerCase
-
firstCharsToLowerCase
-
firstCharToUpperCase
-
firstCharsToUpperCase
-
toCamelCase
Converts the specified text to camel case and returns the resulting string.The conversion is described below. In the description,
- a digit is a character for which
Character.isDigit(char)
returnstrue
, - a letter is a character for which
Character.isLetter(char)
returnstrue
, - a non-alphanumeric character is a character that is neither a digit nor a letter.
- Each letter that immediately follows a digit or a non-alphanumeric character is converted to upper case except for a letter that follows a sequence of a latter and an apostrophe (U+0027).
- All other letters are converted to lower case.
- All non-alphanumeric characters are removed.
- Parameters:
text
- the text that will be converted.- Returns:
- the camel-case string that results from the conversion of
text
.
- a digit is a character for which
-
applyPrefix
-
escape
-
containsIgnoreCase
-
indexOfIgnoreCase
-