| java.lang.Object org.zkoss.lang.Strings
Strings | public class Strings (Code) | | String utilties and constants
author: tomyeh |
Inner Class :public static class Result | |
Method Summary | |
final public static int | anyOf(String src, String delimiters, int from) Returns the index that is one of delimiters, or the length if none
of delimiter is found. | final public static StringBuffer | appendEscape(StringBuffer sb, String s, String specials) Escapes (aka. | final public static StringBuffer | encode(StringBuffer sb, int val) Returns an encoded string buffer, faster and shorter than
Integer.toHexString. | final public static StringBuffer | encode(StringBuffer sb, long val) Returns an encoded string buffer, faster and shorter than
Long.toHexString. | final public static String | encode(int val) Returns an encoded string, faster and shorter than
Long.toHexString. | final public static String | encode(long val) Returns an encoded string, faster and shorter than
Long.toHexString. | final public static String | escape(String s, String specials) Escapes (aka, quote) the special characters with backslash.
It prefix a backslash to any characters specfied in the specials
argument.
Note: specials usually contains '\\'.
For example,
org.zkoss.util.Maps.parse will un-quote
backspace. | final public static boolean | isBlank(String s) Returns true if the string is null or empty or pure blank. | final public static boolean | isEmpty(String s) Returns true if the string is null or empty. | final public static int | lastAnyOf(String src, String delimiters, int from) The backward version of
Strings.anyOf . | public static int | nextSeparator(String src, int from, char[] separators, boolean escBackslash, boolean escQuot, boolean quotAsSeparator) Returns the next seperator index in the src string.
Parameters: escQuot - whether to escape characters inside quotations('\'' or '"'). | final public static Result | nextToken(String src, int from, char[] separators) Returns the next token with unescape.
- It trims whitespaces before and after the token.
- It handles both '\'' and '"'.
| final public static Result | nextToken(String src, int from, char[] separators, boolean escBackslash, boolean quotAsToken) Returns the next token with unescape option. | final public static int | nextWhitespace(CharSequence src, int from) Returns the next whitespace. | final public static int | skipWhitespaces(CharSequence src, int from) Returns the next index after skipping whitespaces. | final public static int | skipWhitespacesBackward(CharSequence src, int from) The backward version of
Strings.skipWhitespaces . | final public static Result | substring(String src, int from, char until) Returns the substring from the from index up to the
until character or end-of-string.
Unlike String.subsring, it converts \f, \n, \t and \r. | final public static Result | substring(String src, int from, char until, boolean escBackslash) Returns the substring from the from index up to the
until character or end-of-string.
Parameters: escBackslash - whether to treat '\\' specially (as escape char)It doesn't handle u and x yet. | final public static String | unescape(String s) Un-escape the quoted string. |
anyOf | final public static int anyOf(String src, String delimiters, int from)(Code) | | Returns the index that is one of delimiters, or the length if none
of delimiter is found.
Unlike String.indexOf(String, int), this method returns the first
occurrence of any character in the delimiters.
This method is optimized to use String.indexOf(char, int)
if it found the length of dilimiter is 1.
Parameters: src - the source string to search Parameters: from - the index to start the search from Parameters: delimiters - the set of characters to search for the index that is one of delimiters.If return >= src.length(), it means no such delimiters See Also: Strings.lastAnyOf |
appendEscape | final public static StringBuffer appendEscape(StringBuffer sb, String s, String specials)(Code) | | Escapes (aka. quote) the special characters with backslash
and appends it the specified string buffer.
|
encode | final public static StringBuffer encode(StringBuffer sb, int val)(Code) | | Returns an encoded string buffer, faster and shorter than
Integer.toHexString. It uses numbers and lower-case leters only.
Thus it is a valid variable name if prefix with an alphabet.
At least one character is generated.
It works even in system that is case-insensitive, such as IE.
It is useful to generate a string to represent a number.
|
encode | final public static StringBuffer encode(StringBuffer sb, long val)(Code) | | Returns an encoded string buffer, faster and shorter than
Long.toHexString. It uses numbers and lower-case letters only.
Thus it is a valid variable name if prefix with an alphabet.
At least one character is generated.
It works even in system that is case-insensitive, such as IE.
It is useful to generate a string to represent a number.
|
encode | final public static String encode(int val)(Code) | | Returns an encoded string, faster and shorter than
Long.toHexString.
|
encode | final public static String encode(long val)(Code) | | Returns an encoded string, faster and shorter than
Long.toHexString.
|
escape | final public static String escape(String s, String specials)(Code) | | Escapes (aka, quote) the special characters with backslash.
It prefix a backslash to any characters specfied in the specials
argument.
Note: specials usually contains '\\'.
For example,
org.zkoss.util.Maps.parse will un-quote
backspace. Thus, if you want to preserve backslash, you have
invoke escape(s, "\\") before calling Maps.parse().
Parameters: s - the string to process. If null, null is returned. Parameters: specials - a string of characters that shall be escaped/quoted See Also: Strings.unescape |
isBlank | final public static boolean isBlank(String s)(Code) | | Returns true if the string is null or empty or pure blank.
|
isEmpty | final public static boolean isEmpty(String s)(Code) | | Returns true if the string is null or empty.
|
lastAnyOf | final public static int lastAnyOf(String src, String delimiters, int from)(Code) | | The backward version of
Strings.anyOf .
This method is optimized to use String.indexOf(char, int)
if it found the length of dilimiter is 1.
the previous index that is one of delimiter.If it is negative, it means no delimiter in front offrom See Also: Strings.anyOf |
nextSeparator | public static int nextSeparator(String src, int from, char[] separators, boolean escBackslash, boolean escQuot, boolean quotAsSeparator)(Code) | | Returns the next seperator index in the src string.
Parameters: escQuot - whether to escape characters inside quotations('\'' or '"'). In other words, ignore separators inside quotations Parameters: quotAsSeparator - whether to consider quotations as one ofthe separators since: 2.4.0 |
nextToken | final public static Result nextToken(String src, int from, char[] separators) throws IllegalSyntaxException(Code) | | Returns the next token with unescape.
- It trims whitespaces before and after the token.
- It handles both '\'' and '"'. All characters between them are
considered as a token.
- If nothing found before end-of-string, null is returned
If a separator is found, it is returned in
Strings.Result.separator .
exception: IllegalSyntaxException - if the quoted string is unclosed. |
nextToken | final public static Result nextToken(String src, int from, char[] separators, boolean escBackslash, boolean quotAsToken) throws IllegalSyntaxException(Code) | | Returns the next token with unescape option.
- It trims whitespaces before and after the token.
- If quotAsToken is true, all characters between quotations
('\'' or '"') are considered as a token.
- Consider '\\' as the escape char if escBackslash is true.
- If nothing found before end-of-string, null is returned
If a separator is found, it is returned in
Strings.Result.separator .
Parameters: escBackslash - whether to treat '\\' specially (as escape char)It doesn't handle u and x yet. Parameters: quotAsToken - whether to treat characters inside '\'' or '"'as a token exception: IllegalSyntaxException - if the quoted string is unclosed. |
nextWhitespace | final public static int nextWhitespace(CharSequence src, int from)(Code) | | Returns the next whitespace.
|
skipWhitespaces | final public static int skipWhitespaces(CharSequence src, int from)(Code) | | Returns the next index after skipping whitespaces.
|
skipWhitespacesBackward | final public static int skipWhitespacesBackward(CharSequence src, int from)(Code) | | The backward version of
Strings.skipWhitespaces .
the next index that is not a whitespace.If it is negative, it means no whitespace in front of it. |
substring | final public static Result substring(String src, int from, char until)(Code) | | Returns the substring from the from index up to the
until character or end-of-string.
Unlike String.subsring, it converts \f, \n, \t and \r. It doesn't
handle u and x yet.
the result (never null). Result.next is the position ofthe until character if found, ora number larger than length() if no such character. |
substring | final public static Result substring(String src, int from, char until, boolean escBackslash)(Code) | | Returns the substring from the from index up to the
until character or end-of-string.
Parameters: escBackslash - whether to treat '\\' specially (as escape char)It doesn't handle u and x yet. the result (never null). Result.next is the position ofthe until character if found, ora number larger than length() if no such character.You can tell which case it is by examining Result.separator. |
|
|