public final class StringTools extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
StringTools.XmlPrintMode
Constants for printing XML rule matches.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
addSpace(String word,
Language language)
Adds spaces before words that are not punctuation.
|
static String |
asString(CharSequence s) |
static void |
assureSet(String s,
String varName)
Throw exception if the given string is null or empty or only whitespace.
|
static String |
escapeForXmlAttribute(String s) |
static String |
escapeForXmlContent(String s) |
static String |
escapeHTML(String s)
Escapes these characters: less than, greater than, quote, ampersand.
|
static String |
escapeXML(String s)
Calls
escapeHTML(String). |
static String |
filterXML(String str)
Simple XML filtering for XML tags.
|
static boolean |
isAllUppercase(String str)
Returns true if the given string is made up of all-uppercase characters
(ignoring characters for which no upper-/lowercase distinction exists).
|
static boolean |
isCapitalizedWord(String str) |
static boolean |
isEmpty(String str)
Helper method to replace calls to
"".equals(). |
static boolean |
isMixedCase(String str)
Returns true if the given string is mixed case, like
MixedCase or mixedCase
(but not Mixedcase). |
static boolean |
isNonBreakingWhitespace(String str)
Checks if a string is the non-breaking whitespace (
). |
static boolean |
isNotAllLowercase(String str)
Returns true if
str is made up of all-lowercase characters
(ignoring characters for which no upper-/lowercase distinction exists). |
static boolean |
isPositiveNumber(char ch) |
static boolean |
isWhitespace(String str)
Checks if a string contains only whitespace, including all Unicode
whitespace, but not the non-breaking space.
|
static String |
listToString(Collection<String> l,
String delimiter) |
static String |
lowercaseFirstChar(String str)
Return
str modified so that its first character is now an
lowercase character. |
static String |
readerToString(Reader reader) |
static String |
readStream(InputStream stream,
String encoding)
Read the text stream using the given encoding.
|
static boolean |
startsWithUppercase(String str)
Whether the first character of
str is an uppercase character. |
static String |
streamToString(InputStream is,
String charsetName) |
static String |
trimWhitespace(String s)
Filters any whitespace characters.
|
static String |
uppercaseFirstChar(String str)
Return
str modified so that its first character is now an
uppercase character. |
static String |
uppercaseFirstChar(String str,
Language language)
Like
uppercaseFirstChar(String), but handles a special case for Dutch (IJ in
e.g. |
public static void assureSet(String s, String varName)
public static String readStream(InputStream stream, String encoding) throws IOException
stream - InputStream the stream to be readencoding - the stream's character encoding, e.g. utf-8, or null to use the system encoding\n (note that \n will
be added to the last line even if it is not in the stream)IOExceptionpublic static boolean isAllUppercase(String str)
public static boolean isMixedCase(String str)
MixedCase or mixedCase
(but not Mixedcase).str - input strpublic static boolean isNotAllLowercase(String str)
str is made up of all-lowercase characters
(ignoring characters for which no upper-/lowercase distinction exists).public static boolean isCapitalizedWord(String str)
str - input stringpublic static boolean startsWithUppercase(String str)
str is an uppercase character.@Nullable public static String uppercaseFirstChar(String str)
str modified so that its first character is now an
uppercase character. If str starts with non-alphabetic
characters, such as quotes or parentheses, the first character is
determined as the first alphabetic character.@Nullable public static String uppercaseFirstChar(String str, Language language)
uppercaseFirstChar(String), but handles a special case for Dutch (IJ in
e.g. "ijsselmeer" -> "IJsselmeer").language - the language, will be ignored if it's null@Nullable public static String lowercaseFirstChar(String str)
str modified so that its first character is now an
lowercase character. If str starts with non-alphabetic
characters, such as quotes or parentheses, the first character is
determined as the first alphabetic character.public static String readerToString(Reader reader) throws IOException
IOExceptionpublic static String streamToString(InputStream is, String charsetName) throws IOException
IOExceptionpublic static String escapeXML(String s)
escapeHTML(String).public static String escapeHTML(String s)
public static String listToString(Collection<String> l, String delimiter)
public static String trimWhitespace(String s)
s - String to be filtered.public static String addSpace(String word, Language language)
word - Word to add the preceding space.language - Language of the word (to check typography conventions). Currently
French convention of not adding spaces only before '.' and ',' is
implemented; other languages assume that before ,.;:!? no spaces
should be added.public static boolean isWhitespace(String str)
str - String to checkpublic static boolean isNonBreakingWhitespace(String str)
).public static boolean isPositiveNumber(char ch)
ch - Character to checkpublic static boolean isEmpty(String str)
"".equals().str - String to checknullpublic static String filterXML(String str)
str - XML string to be filtered.@Nullable public static String asString(CharSequence s)