public class Strings
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Strings.CharacterEntity |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
capitalizeFirstLetter(java.lang.String value)
Capitalizes the first letter of the given string.
|
static java.lang.String |
escape(java.lang.String value,
char quote,
boolean escapeUnicode)
Escapes special characters in the given string, including ".
|
static java.lang.String |
fillTemplate(java.lang.String template,
java.util.Map<java.lang.String,java.lang.String> values) |
static int |
getCommonPrefixLength(java.lang.String a,
java.lang.String b)
Determines the length of the common string prefix; that is, the longest
value of L for which a.substring(0, L) == b.substring(0, L).
|
static int |
getCommonSuffixLength(java.lang.String a,
java.lang.String b)
Determines the length of the common string suffix; that is, the longest
value of L for which a.substring(a.length - L, a.length) == b.substring(
b.length - L, b.length).
|
static java.util.Collection<Strings.CharacterEntity> |
getNamedCharacterEntities()
Retrieves all official named character entities.
|
static java.lang.String |
join(java.lang.String separator,
java.lang.Iterable<java.lang.String> values)
Joins the given strings with the given separator.
|
static java.lang.String |
join(java.lang.String separator,
java.lang.String... values)
Joins the given strings with the given separator.
|
static java.lang.String |
lpad(java.lang.String value,
int length,
char c)
Left pads (prefixes) a string with characters until it reaches the given string
length.
|
static Strings.CharacterEntity |
readCharacterEntity(java.lang.String str,
int offset)
Reads a single character entity (formatted as &characterEntity;) at the
given string offset.
|
static int |
readHexCharacter(char hex)
Reads a single hex digit and converts it to a value 0-15.
|
static java.lang.String |
rpad(java.lang.String value,
int length,
char c)
Right pads (suffixes) a string with characters until it reaches the given
string length.
|
static byte[] |
sha256Hash(java.lang.String value)
Creates a sha256 hash of the given string, using UTF-8 encoding.
|
static java.lang.String[] |
split(java.lang.String value,
char delimiter)
Splits a string in parts, given a specified delimiter.
|
static java.lang.String[] |
split(java.lang.String value,
char delimiter,
int max)
Splits a string in parts, given a specified delimiter.
|
static java.lang.String |
stripAccents(java.lang.String str)
Strips all accents (and alike) from the given string.
|
static StringTemplate |
template(java.lang.String template)
Starts a string template.
|
static java.lang.String |
times(char c,
int count)
Constructs a string with count times the given character.
|
static java.lang.String |
unescape(java.lang.String escapedString)
Unescapes a string escaped in one of following ways:
A string escaped with single quotes (
'Hello "my" world')
A string escaped with double quotes ("Hello 'my' world")
A near-literal string (@"C:\Program Files\") in which escape sequences
aren't processed but the " character cannot occur
The following escape sequences are recognized:
\\
\'
\"
\&namedCharacterEntity; (note that although redundant, \&#ddd; and \&#xXXXX; are also allowed)
\t
\n
\r
\b
\f
\&uXXXX for unicode character points
|
public static byte[] sha256Hash(java.lang.String value)
value - string valuepublic static java.lang.String stripAccents(java.lang.String str)
str - original stringpublic static java.lang.String join(java.lang.String separator,
java.lang.String... values)
separator - separatorvalues - string valuespublic static java.lang.String join(java.lang.String separator,
java.lang.Iterable<java.lang.String> values)
separator - separatorvalues - string valuespublic static java.lang.String[] split(java.lang.String value,
char delimiter)
value - string to be splitdelimiter - delimiterpublic static java.lang.String[] split(java.lang.String value,
char delimiter,
int max)
value - string to be splitdelimiter - delimitermax - maximum number of substringspublic static java.lang.String capitalizeFirstLetter(java.lang.String value)
value - original stringpublic static int getCommonPrefixLength(java.lang.String a,
java.lang.String b)
a - first stringb - second stringpublic static int getCommonSuffixLength(java.lang.String a,
java.lang.String b)
a - first stringb - second stringpublic static java.lang.String lpad(java.lang.String value,
int length,
char c)
value - value to be paddedlength - desired string lengthc - padding characterpublic static java.lang.String rpad(java.lang.String value,
int length,
char c)
value - value to be paddedlength - desired string lengthc - padding characterpublic static java.lang.String fillTemplate(java.lang.String template,
java.util.Map<java.lang.String,java.lang.String> values)
public static StringTemplate template(java.lang.String template)
template - template stringpublic static java.lang.String times(char c,
int count)
c - filling charactercount - character countpublic static java.lang.String unescape(java.lang.String escapedString)
'Hello "my" world')"Hello 'my' world")@"C:\Program Files\") in which escape sequences
aren't processed but the " character cannot occurescapedString - escaped stringpublic static java.lang.String escape(java.lang.String value,
char quote,
boolean escapeUnicode)
value - value to be escapedquote - character (' or ")escapeUnicode - true to escape any non-ascii value, false to leave them bepublic static int readHexCharacter(char hex)
hex - hex digitpublic static java.util.Collection<Strings.CharacterEntity> getNamedCharacterEntities()
public static Strings.CharacterEntity readCharacterEntity(java.lang.String str, int offset)
str - string value to search inoffset - offset to look atjava.lang.IllegalArgumentException - if the given string does not contain a
valid character entity at the given position