Class StringUtils
java.lang.Object
org.greenrobot.essentials.StringUtils
Utilities for working with strings like splitting, joining, url-encoding, hex, and digests.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringURL-Decodes a given string using UTF-8.static StringdecodeUrlIso(String stringToDecode) URL-Decodes a given string using ISO-8859-1.static StringGenerates a digest (hex string) for the given stringstatic StringCuts the string at the end if it's longer than maxLength and appends "..." to it.static StringCuts the string at the end if it's longer than maxLength and appends the given end string to it.static StringURL-Encodes a given string using UTF-8 (some web pages have problems with UTF-8 and umlauts, considerencodeUrlIso(String)also).static StringencodeUrlIso(String stringToEncode) URL-encodes a given string using ISO-8859-1, which may work better with web pages and umlauts compared to UTF-8.findLinesContaining(String text, String searchText) static Stringhex(byte[] bytes) static StringJoins the given ints using the given separator into a single string.static StringJoins the given iterable objects using the given separator into a single string.static StringJoins the given Strings using the given separator into a single string.static StringGenerates the MD5 digest (32 hex characters) for a given String based on UTF-8.static byte[]static intparseHexDigit(char c) static StringresolveEntity(String entity) Simple HTML/XML entity resolving: Only supports unicode entities and a very limited number text represented entities (apos, quot, gt, lt, and amp).static StringGenerates the SHA-1 digest (40 hex characters) for a given String based on UTF-8.static StringGenerates the SHA-256 digest (64 hex characters) for a given String based on UTF-8.static String[]Splits a String based on a single character, which is usually faster than regex-based String.split().static String[]splitLines(String text, boolean skipEmptyLines)
-
Field Details
-
HEX_CHARS
private static final char[] HEX_CHARS
-
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
split
-
encodeUrl
URL-Encodes a given string using UTF-8 (some web pages have problems with UTF-8 and umlauts, considerencodeUrlIso(String)also). No UnsupportedEncodingException to handle as it is dealt with in this method. -
encodeUrlIso
-
decodeUrl
-
decodeUrlIso
-
md5
-
sha1
-
sha256
-
digest
-
hex
-
parseHex
- Throws:
IllegalArgumentException- if the given string is invalid hex
-
parseHexDigit
public static int parseHexDigit(char c) - Throws:
IllegalArgumentException- if the given char is invalid hex
-
resolveEntity
Simple HTML/XML entity resolving: Only supports unicode entities and a very limited number text represented entities (apos, quot, gt, lt, and amp). There are many more: http://www.w3.org/TR/REC-html40/sgml/dtd.html- Parameters:
entity- The entity name without invalid input: '&' and ; (null throws NPE)- Returns:
- Resolved entity or the entity itself if it could not be resolved.
-
ellipsize
Cuts the string at the end if it's longer than maxLength and appends "..." to it. The length of the resulting string including "..." is always less or equal to the given maxLength. It's valid to pass a null text; in this case null is returned. -
ellipsize
Cuts the string at the end if it's longer than maxLength and appends the given end string to it. The length of the resulting string is always less or equal to the given maxLength. It's valid to pass a null text; in this case null is returned. -
splitLines
-
findLinesContaining
-
join
-
join
-
join
-