Package nl.siegmann.epublib.util
Class StringUtil
java.lang.Object
nl.siegmann.epublib.util.StringUtil
Various String utility functions.
Most of the functions herein are re-implementations of the ones in apache
commons StringUtils. The reason for re-implementing this is that the
functions are fairly simple and using my own implementation saves the
inclusion of a 200Kb jar file.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcollapsePathDots(String path) Changes a path containing '..', '.' and empty dirs into a path that doesn't.static StringdefaultIfNull(String text) If the given text is null return "", the original text otherwise.static StringdefaultIfNull(String text, String defaultValue) If the given text is null return "", the given defaultValue otherwise.static booleanendsWithIgnoreCase(String source, String suffix) Whether the given source string ends with the given suffix, ignoring case.static booleanNull-safe string comparatorstatic intstatic booleanWhether the String is null, zero-length and does contain only whitespace.static booleanWhether the given string is null or zero-length.static booleanisNotBlank(String text) Whether the String is not null, not zero-length and does not contain of only whitespace.static StringsubstringAfter(String text, char c) Gives the substring of the given text after the given separator.static StringsubstringAfterLast(String text, char separator) Gives the substring of the given text after the last occurrence of the given separator.static StringsubstringBefore(String text, char separator) Gives the substring of the given text before the given separator.static StringsubstringBeforeLast(String text, char separator) Gives the substring of the given text before the last occurrence of the given separator.static StringPretty toString printer.
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
collapsePathDots
Changes a path containing '..', '.' and empty dirs into a path that doesn't. X/foo/../Y is changed into 'X/Y', etc. Does not handle invalid paths like "../".- Parameters:
path-- Returns:
- the normalized path
-
isNotBlank
Whether the String is not null, not zero-length and does not contain of only whitespace.- Parameters:
text-- Returns:
- Whether the String is not null, not zero-length and does not contain of
-
isBlank
Whether the String is null, zero-length and does contain only whitespace.- Returns:
- Whether the String is null, zero-length and does contain only whitespace.
-
isEmpty
Whether the given string is null or zero-length.- Parameters:
text- the input for this method- Returns:
- Whether the given string is null or zero-length.
-
endsWithIgnoreCase
Whether the given source string ends with the given suffix, ignoring case.- Parameters:
source-suffix-- Returns:
- Whether the given source string ends with the given suffix, ignoring case.
-
defaultIfNull
If the given text is null return "", the original text otherwise.- Parameters:
text-- Returns:
- If the given text is null "", the original text otherwise.
-
defaultIfNull
If the given text is null return "", the given defaultValue otherwise.- Parameters:
text-defaultValue-- Returns:
- If the given text is null "", the given defaultValue otherwise.
-
equals
Null-safe string comparator- Parameters:
text1-text2-- Returns:
- whether the two strings are equal
-
toString
Pretty toString printer.- Parameters:
keyValues-- Returns:
- a string representation of the input values
-
hashCode
-
substringBefore
Gives the substring of the given text before the given separator. If the text does not contain the given separator then the given text is returned.- Parameters:
text-separator-- Returns:
- the substring of the given text before the given separator.
-
substringBeforeLast
Gives the substring of the given text before the last occurrence of the given separator. If the text does not contain the given separator then the given text is returned.- Parameters:
text-separator-- Returns:
- the substring of the given text before the last occurrence of the given separator.
-
substringAfterLast
Gives the substring of the given text after the last occurrence of the given separator. If the text does not contain the given separator then "" is returned.- Parameters:
text-separator-- Returns:
- the substring of the given text after the last occurrence of the given separator.
-
substringAfter
Gives the substring of the given text after the given separator. If the text does not contain the given separator then "" is returned.- Parameters:
text- the input textc- the separator char- Returns:
- the substring of the given text after the given separator.
-