public class StringHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char |
CARRIAGE_RETURN
The Carriage Return character (CR).
|
static char |
LINE_FEED
The Line Feed character (LF).
|
static char |
SPACE
The white-space character (
'\u0020' ). |
static char |
TAB
The tabulation character (
'\u0009' ). |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkRegex(java.lang.String src,
java.util.regex.Pattern pattern)
Check a regular expression.
|
static java.lang.String |
convertUnicodeEscapesToUTF8(java.lang.String unicodeString)
Convert Unicode escapes to UTF-8 characters.
|
static java.lang.String |
convertUTF8ToUnicodeEscapes(java.lang.String utf8String)
Convert UTF-8 characters to Unicode escapes.
|
static java.lang.String |
decomposeCollection(java.util.Collection<java.lang.String> collection,
java.lang.String separatorBetween)
Return a concatenation of all values of a
Collection , with a specified separator between all of them. |
static java.lang.String |
decomposeCollection(java.util.Collection<java.lang.String> collection,
java.lang.String separatorBetween,
int expectedResSize)
Return a concatenation of all values of a
Collection , with a specified separator between all of them. |
static java.lang.String |
generateStrConcat(java.lang.String model,
int occurences)
Return N concatenations of string.
|
static java.util.List<java.lang.String> |
getGroupsFromRegex(java.lang.String src,
java.util.regex.Pattern pattern,
int expectedNbMatchs)
Return the capturing groups from the regular expression in the string.
|
static java.lang.String |
mostLeft(java.lang.String str,
java.lang.String[] prefixes)
Find the "prefix" string the most at the left in the source string.
Example: with "my name is" as the source string, and {"name", "is"} as the prefix strings, "name" is returned. |
static java.lang.String |
mostRight(java.lang.String str,
java.lang.String[] suffixes)
Find the "suffix" string the most at the right in the source string.
Example: with "my name is" as the source string, and {"name", "is"} as the suffix strings array, "is" is returned. |
static java.lang.String |
replaceFirst(java.lang.String src,
java.util.regex.Pattern pattern,
java.lang.String replacement)
Replace the first substring of this string that matches the given compiled pattern with the literalized given replacement.
|
static boolean |
strAreEmpty(java.lang.String... strs)
Indicate if all the strings are null or length equals to zero or are entirely packed with spaces and/or tabulations.
|
static boolean |
strEndsWith(java.lang.String str,
java.lang.String... suffixes)
Indicate if the string ends with one of the specified prefixes.
|
static boolean |
strIsEmpty(java.lang.String str)
Indicate if the string is null or length equals to zero or is entirely packed with spaces and/or tabulations.
|
static boolean |
strIsNotEmpty(java.lang.String str)
Indicate if the string is not null and length greater than zero and is not entirely packed with spaces and/or tabulations.
|
static boolean |
strStartsWith(java.lang.String str,
java.lang.String... prefixes)
Indicate if the string starts with one of the specified prefixes.
|
static java.lang.String[] |
tSplit(java.lang.String str,
java.lang.String regex)
Splits this string around matches of the given regular expression.
|
static java.lang.String |
tTrim(java.lang.String str)
|
static java.lang.String |
tTrim(java.lang.String str,
boolean removeCRLF)
|
static java.lang.String |
tTrimLead(java.lang.String str)
|
static java.lang.String |
tTrimLead(java.lang.String str,
boolean removeCRLF)
Return a copy of the string, with leading (on the left side)
SPACE , TAB omitted, and optionally
CARRIAGE_RETURN and LINE_FEED too. |
static java.lang.String |
tTrimTrail(java.lang.String str)
|
static java.lang.String |
tTrimTrail(java.lang.String str,
boolean removeCRLF)
Return a copy of the string, with trailing (on the right side)
SPACE , TAB omitted, and optionally
CARRIAGE_RETURN and LINE_FEED too. |
public static final char SPACE
'\u0020'
).public static final char TAB
'\u0009'
).public static final char CARRIAGE_RETURN
public static final char LINE_FEED
public static boolean checkRegex(java.lang.String src, java.util.regex.Pattern pattern)
src
- the text to examine.pattern
- the compiled regular expression, targeted area are enclosed with parenthesis.true
if the regular expression is checked, otherwise false
.public static java.lang.String generateStrConcat(java.lang.String model, int occurences)
Example: StringHelper.generateStr("AB", 4)
will return "ABABABAB".
model
- the string to concatenate.occurences
- the number of concatenations. If zero of negative, the method will return an empty string.public static java.util.List<java.lang.String> getGroupsFromRegex(java.lang.String src, java.util.regex.Pattern pattern, int expectedNbMatchs)
src
- the string to search in.pattern
- the compiled pattern.expectedNbMatchs
- the expected tokens matched, for performance purpose.public static java.lang.String mostLeft(java.lang.String str, java.lang.String[] prefixes)
str
- the source string.prefixes
- the prefix strings array.null
is returned.public static java.lang.String mostRight(java.lang.String str, java.lang.String[] suffixes)
str
- the source string.suffixes
- the suffix strings array.null
is returned.public static java.lang.String replaceFirst(java.lang.String src, java.util.regex.Pattern pattern, java.lang.String replacement)
src
- the character sequence to be matched.pattern
- the compiled regular expression to which this string is to be matched.replacement
- the replacement string (internally literalized).public static java.lang.String[] tSplit(java.lang.String str, java.lang.String regex)
'\u0020'
) and tabulations ('\u0009'
) removed.str
- the string to split.regex
- the delimiting regular expression.public static boolean strAreEmpty(java.lang.String... strs)
strs
- the strings to check.true
if all the strings are empty, otherwise false
.public static boolean strIsEmpty(java.lang.String str)
str
- the string to check.true
if the string is empty, otherwise false
.public static boolean strIsNotEmpty(java.lang.String str)
str
- the string to check.true
if the string is not empty, otherwise false
.public static boolean strStartsWith(java.lang.String str, java.lang.String... prefixes)
str
- the source string.prefixes
- the list of prefixes.true
if the source string starts with one of these prefixes, otherwise false
.public static boolean strEndsWith(java.lang.String str, java.lang.String... suffixes)
str
- the source string.suffixes
- the list of prefixes.true
if the source string ends with one of these prefixes, otherwise false
.public static java.lang.String tTrim(java.lang.String str)
str
- the string.public static java.lang.String tTrim(java.lang.String str, boolean removeCRLF)
str
- the string.removeCRLF
- remove leading and trailing (CARRIAGE_RETURN
and LINE_FEED
).public static java.lang.String tTrimLead(java.lang.String str)
str
- the string.public static java.lang.String tTrimLead(java.lang.String str, boolean removeCRLF)
SPACE
, TAB
omitted, and optionally
CARRIAGE_RETURN
and LINE_FEED
too.str
- the string.removeCRLF
- remove leading (CARRIAGE_RETURN
and LINE_FEED
).public static java.lang.String tTrimTrail(java.lang.String str)
str
- the string.public static java.lang.String tTrimTrail(java.lang.String str, boolean removeCRLF)
SPACE
, TAB
omitted, and optionally
CARRIAGE_RETURN
and LINE_FEED
too.str
- the string.removeCRLF
- remove trailing New Lines (CARRIAGE_RETURN
and LINE_FEED
).public static java.lang.String decomposeCollection(java.util.Collection<java.lang.String> collection, java.lang.String separatorBetween)
Collection
, with a specified separator between all of them.
Example: with Collection of three elements "AB", "C" and "D", and a "--" separator, this method will return "AB--C--D". With an empty separator, the result would be "ABCD".
collection
- the Collection
to decompose.separatorBetween
- the separator. It can be an empty string.Collection
decomposition.public static java.lang.String decomposeCollection(java.util.Collection<java.lang.String> collection, java.lang.String separatorBetween, int expectedResSize)
Collection
, with a specified separator between all of them.
Example: with Collection of three elements "AB", "C" and "D", and a "--" separator, this method will return "AB--C--D". With an empty separator, the result would be "ABCD".
collection
- the Collection
to decompose.separatorBetween
- the separator. It can be an empty string.expectedResSize
- the expected size of decomposition. For performance purpose only.Collection
decomposition.public static java.lang.String convertUnicodeEscapesToUTF8(java.lang.String unicodeString) throws java.io.CharConversionException
unicodeString
- the string to convert Unicode escapes.java.io.CharConversionException
- if an invalid Unicode escape is detected.public static java.lang.String convertUTF8ToUnicodeEscapes(java.lang.String utf8String)
utf8String
- the string to convert UTF-8 characters.