Class StringUtil
java.lang.Object
io.netty.util.internal.StringUtil
String utility class.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbyteToHexString(int value) Converts the specified byte value into a hexadecimal integer.static <T extends Appendable>
TbyteToHexString(T buf, int value) Converts the specified byte value into a hexadecimal integer and appends it to the specified buffer.static StringbyteToHexStringPadded(int value) Converts the specified byte value into a 2-digit hexadecimal integer.static <T extends Appendable>
TbyteToHexStringPadded(T buf, int value) Converts the specified byte value into a 2-digit hexadecimal integer and appends it to the specified buffer.static StringGenerates a class name from aClass.static booleancommonSuffixOfLength(String s, String p, int len) Checks if two strings have the same suffix of specified lengthstatic bytedecodeHexByte(CharSequence s, int pos) Decode a 2-digit hex byte from within a string.static byte[]decodeHexDump(CharSequence hexDump) Decodes a hex dumpstatic byte[]decodeHexDump(CharSequence hexDump, int fromIndex, int length) Decodes part of a string with hex dumpstatic intdecodeHexNibble(byte b) Helper to decode half of a hexadecimal number from a string.static intdecodeHexNibble(char c) Helper to decode half of a hexadecimal number from a string.static booleanendsWith(CharSequence s, char c) Determine if the stringsends with the charc.static CharSequenceescapeCsv(CharSequence value) Escapes the specified value, if necessary according to RFC-4180.static CharSequenceescapeCsv(CharSequence value, boolean trimWhiteSpace) Escapes the specified value, if necessary according to RFC-4180.static intindexOfNonWhiteSpace(CharSequence seq, int offset) Find the index of the first non-white space character insstarting atoffset.static intindexOfWhiteSpace(CharSequence seq, int offset) Find the index of the first white space character insstarting atoffset.static booleanstatic booleanisSurrogate(char c) Determine ifclies within the range of values defined for Surrogate Code Point.static CharSequencejoin(CharSequence separator, Iterable<? extends CharSequence> elements) Returns a char sequence that contains allelementsjoined by a given separator.static intGet the length of a string,nullinput is considered0length.static StringsimpleClassName(Class<?> clazz) Generates a simplified name from aClass.static StringThe shortcut tosimpleClassName(o.getClass()).static StringsubstringAfter(String value, char delim) Get the item after one char delim if the delim is found (else null).static StringsubstringBefore(String value, char delim) Get the item before one char delim if the delim is found (else null).static StringtoHexString(byte[] src) Converts the specified byte array into a hexadecimal value.static StringtoHexString(byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value.static <T extends Appendable>
TtoHexString(T dst, byte[] src) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.static <T extends Appendable>
TtoHexString(T dst, byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.static StringtoHexStringPadded(byte[] src) Converts the specified byte array into a hexadecimal value.static StringtoHexStringPadded(byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value.static <T extends Appendable>
TtoHexStringPadded(T dst, byte[] src) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.static <T extends Appendable>
TtoHexStringPadded(T dst, byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.static CharSequencetrimOws(CharSequence value) Trim optional white-space characters from the specified value, according to RFC-7230.static CharSequenceunescapeCsv(CharSequence value) Unescapes the specified escaped CSV field, if necessary according to RFC-4180.static List<CharSequence> unescapeCsvFields(CharSequence value) Unescapes the specified escaped CSV fields according to RFC-4180.
-
Field Details
-
EMPTY_STRING
- See Also:
-
NEWLINE
-
DOUBLE_QUOTE
public static final char DOUBLE_QUOTE- See Also:
-
COMMA
public static final char COMMA- See Also:
-
LINE_FEED
public static final char LINE_FEED- See Also:
-
CARRIAGE_RETURN
public static final char CARRIAGE_RETURN- See Also:
-
TAB
public static final char TAB- See Also:
-
SPACE
public static final char SPACE- See Also:
-
-
Method Details
-
substringAfter
Get the item after one char delim if the delim is found (else null). This operation is a simplified and optimized version ofString.split(String, int). -
substringBefore
Get the item before one char delim if the delim is found (else null). This operation is a simplified and optimized version ofString.split(String, int). -
commonSuffixOfLength
-
byteToHexStringPadded
Converts the specified byte value into a 2-digit hexadecimal integer. -
byteToHexStringPadded
Converts the specified byte value into a 2-digit hexadecimal integer and appends it to the specified buffer. -
toHexStringPadded
Converts the specified byte array into a hexadecimal value. -
toHexStringPadded
Converts the specified byte array into a hexadecimal value. -
toHexStringPadded
Converts the specified byte array into a hexadecimal value and appends it to the specified buffer. -
toHexStringPadded
Converts the specified byte array into a hexadecimal value and appends it to the specified buffer. -
byteToHexString
Converts the specified byte value into a hexadecimal integer. -
byteToHexString
Converts the specified byte value into a hexadecimal integer and appends it to the specified buffer. -
toHexString
Converts the specified byte array into a hexadecimal value. -
toHexString
Converts the specified byte array into a hexadecimal value. -
toHexString
Converts the specified byte array into a hexadecimal value and appends it to the specified buffer. -
toHexString
Converts the specified byte array into a hexadecimal value and appends it to the specified buffer. -
decodeHexNibble
public static int decodeHexNibble(char c) Helper to decode half of a hexadecimal number from a string.- Parameters:
c- The ASCII character of the hexadecimal number to decode. Must be in the range[0-9a-fA-F].- Returns:
- The hexadecimal value represented in the ASCII character
given, or
-1if the character is invalid.
-
decodeHexNibble
public static int decodeHexNibble(byte b) Helper to decode half of a hexadecimal number from a string.- Parameters:
b- The ASCII character of the hexadecimal number to decode. Must be in the range[0-9a-fA-F].- Returns:
- The hexadecimal value represented in the ASCII character
given, or
-1if the character is invalid.
-
decodeHexByte
Decode a 2-digit hex byte from within a string. -
decodeHexDump
Decodes part of a string with hex dump- Parameters:
hexDump- aCharSequencewhich contains the hex dumpfromIndex- start of hex dump inhexDumplength- hex string length
-
decodeHexDump
Decodes a hex dump -
className
Generates a class name from aClass. Similar toClass.getName(), but null-safe. -
simpleClassName
The shortcut tosimpleClassName(o.getClass()). -
simpleClassName
Generates a simplified name from aClass. Similar toClass.getSimpleName(), but it works fine with anonymous classes. -
escapeCsv
Escapes the specified value, if necessary according to RFC-4180.- Parameters:
value- The value which will be escaped according to RFC-4180- Returns:
CharSequencethe escaped value if necessary, or the value unchanged
-
escapeCsv
Escapes the specified value, if necessary according to RFC-4180.- Parameters:
value- The value which will be escaped according to RFC-4180trimWhiteSpace- The value will first be trimmed of its optional white-space characters, according to RFC-7230- Returns:
CharSequencethe escaped value if necessary, or the value unchanged
-
unescapeCsv
Unescapes the specified escaped CSV field, if necessary according to RFC-4180.- Parameters:
value- The escaped CSV field which will be unescaped according to RFC-4180- Returns:
CharSequencethe unescaped value if necessary, or the value unchanged
-
unescapeCsvFields
Unescapes the specified escaped CSV fields according to RFC-4180. -
length
Get the length of a string,nullinput is considered0length. -
isNullOrEmpty
-
indexOfNonWhiteSpace
Find the index of the first non-white space character insstarting atoffset.- Parameters:
seq- The string to search.offset- The offset to start searching at.- Returns:
- the index of the first non-white space character or <
-1if none was found.
-
indexOfWhiteSpace
Find the index of the first white space character insstarting atoffset.- Parameters:
seq- The string to search.offset- The offset to start searching at.- Returns:
- the index of the first white space character or <
-1if none was found.
-
isSurrogate
public static boolean isSurrogate(char c) Determine ifclies within the range of values defined for Surrogate Code Point.- Parameters:
c- the character to check.- Returns:
trueifclies within the range of values defined for Surrogate Code Point.falseotherwise.
-
endsWith
Determine if the stringsends with the charc.- Parameters:
s- the string to testc- the tested char- Returns:
- true if
sends with the charc
-
trimOws
Trim optional white-space characters from the specified value, according to RFC-7230.- Parameters:
value- the value to trim- Returns:
CharSequencethe trimmed value if necessary, or the value unchanged
-
join
Returns a char sequence that contains allelementsjoined by a given separator.- Parameters:
separator- for each elementelements- to join together- Returns:
- a char sequence joined by a given separator.
-