Package io.servicetalk.buffer.api
Class CharSequences
- java.lang.Object
-
- io.servicetalk.buffer.api.CharSequences
-
public final class CharSequences extends java.lang.Object8-bit ASCII strings factory and basic utilities helper. This class can work with 8-bitCharSequenceinstances only, any other input will have undefined behavior.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intasciiStringIndexOf(java.lang.CharSequence sequence, char c, int fromIndex)Find the index ofcwithinsequencestarting at indexfromIndex.static intcaseInsensitiveHashCode(java.lang.CharSequence seq)Calculate a hash code of a byte array assuming ASCII character encoding.static booleancontentEquals(java.lang.CharSequence a, java.lang.CharSequence b)Returnstrueif the content of bothCharSequence's are equals.static booleancontentEqualsIgnoreCase(java.lang.CharSequence a, java.lang.CharSequence b)Perform a case-insensitive comparison of twoCharSequences.static java.lang.CharSequenceemptyAsciiString()Get a reference to an unmodifiable emptyCharSequencewith the same properties asnewAsciiString(Buffer).static booleanequalsIgnoreCaseLower(char a, char lowerCaseChar)Compare an unknown ascii characterawith a known lowercase characterlowerCaseCharin a case insensitive manner.static intforEachByte(java.lang.CharSequence sequence, ByteProcessor visitor)Iterates over the readable bytes of thisCharSequencewith the specifiedByteProcessorin ascending order.static intindexOf(java.lang.CharSequence sequence, char c, int fromIndex)Find the index ofcwithinsequencestarting at indexfromIndex.static booleanisAsciiString(java.lang.CharSequence sequence)Deprecated.Internal implementation detail that will be removed in follow-up releases.static java.lang.CharSequencenewAsciiString(Buffer input)Create a newCharSequencefrom the specifiedinput, supporting only 8-bit ASCII characters, and with a case-insensitivehashCode.static java.lang.CharSequencenewAsciiString(java.lang.CharSequence input)Create a newCharSequencefrom the specifiedinput, supporting only 8-bit ASCII characters, and with a case-insensitivehashCode.static longparseLong(java.lang.CharSequence cs)Parses theCharSequenceargument as a signed decimallong.static booleanregionMatches(java.lang.CharSequence cs, boolean ignoreCase, int csStart, java.lang.CharSequence string, int start, int length)This methods make regionMatches operation correctly for any chars in strings.static java.util.List<java.lang.CharSequence>split(java.lang.CharSequence input, char delimiter, boolean trim)Split a givenAsciiStringto separate ones on the givendelimiter.static BufferunwrapBuffer(java.lang.CharSequence cs)Attempt to unwrap aCharSequenceand obtain the underlyingBufferif possible.
-
-
-
Method Detail
-
newAsciiString
public static java.lang.CharSequence newAsciiString(java.lang.CharSequence input)
Create a newCharSequencefrom the specifiedinput, supporting only 8-bit ASCII characters, and with a case-insensitivehashCode.- Parameters:
input- a character sequence containing only 8-bit ASCII characters.- Returns:
- a
CharSequence
-
newAsciiString
public static java.lang.CharSequence newAsciiString(Buffer input)
Create a newCharSequencefrom the specifiedinput, supporting only 8-bit ASCII characters, and with a case-insensitivehashCode.- Parameters:
input- aBuffercontaining- Returns:
- a
CharSequence.
-
emptyAsciiString
public static java.lang.CharSequence emptyAsciiString()
Get a reference to an unmodifiable emptyCharSequencewith the same properties asnewAsciiString(Buffer).- Returns:
- a reference to an unmodifiable empty
CharSequencewith the same properties asnewAsciiString(Buffer).
-
isAsciiString
@Deprecated public static boolean isAsciiString(java.lang.CharSequence sequence)
Deprecated.Internal implementation detail that will be removed in follow-up releases. Please rely on API insideCharSequencesto manipulated ascii strings.Check if the providedCharSequenceis an AsciiString, result of a call tonewAsciiString(CharSequence).- Parameters:
sequence- TheCharSequenceto check.- Returns:
trueif the check passes.
-
unwrapBuffer
@Nullable public static Buffer unwrapBuffer(java.lang.CharSequence cs)
Attempt to unwrap aCharSequenceand obtain the underlyingBufferif possible.- Parameters:
cs- theCharSequenceto unwrap.- Returns:
- the underlying
Bufferornull.
-
forEachByte
public static int forEachByte(java.lang.CharSequence sequence, ByteProcessor visitor)Iterates over the readable bytes of thisCharSequencewith the specifiedByteProcessorin ascending order.- Parameters:
sequence- theCharSequenceto operate on.visitor- theByteProcessorvisitor of each element.- Returns:
-1if the processor iterated to or beyond the end of the readable bytes. The last-visited index If theByteProcessor.process(byte)returnedfalse.
-
contentEqualsIgnoreCase
public static boolean contentEqualsIgnoreCase(@Nullable java.lang.CharSequence a, @Nullable java.lang.CharSequence b)Perform a case-insensitive comparison of twoCharSequences.NOTE: This only supports 8-bit ASCII.
- Parameters:
a- firstCharSequenceto compare.b- secondCharSequenceto compare.- Returns:
trueif bothCharSequence's are equals when ignoring the case.
-
contentEquals
public static boolean contentEquals(@Nullable java.lang.CharSequence a, @Nullable java.lang.CharSequence b)Returnstrueif the content of bothCharSequence's are equals. This only supports 8-bit ASCII.- Parameters:
a- left hand side of comparison.b- right hand side of comparison.- Returns:
trueifa's content equalsb.
-
indexOf
public static int indexOf(java.lang.CharSequence sequence, char c, int fromIndex)Find the index ofcwithinsequencestarting at indexfromIndex.- Parameters:
sequence- TheCharSequenceto search in.c- The character to find.fromIndex- The index to start searching (inclusive).- Returns:
- The index of
cor-1otherwise.
-
asciiStringIndexOf
public static int asciiStringIndexOf(java.lang.CharSequence sequence, char c, int fromIndex)Find the index ofcwithinsequencestarting at indexfromIndex. This version avoids instance type check for special occasions that we can know the type before hand. The input is expected to be anAsciiStringvalue; if the input type is not known use the genericindexOf(CharSequence, char, int)instead.- Parameters:
sequence- TheCharSequenceto search in.c- The character to find.fromIndex- The index to start searching (inclusive).- Returns:
- The index of
cor-1otherwise.
-
caseInsensitiveHashCode
public static int caseInsensitiveHashCode(java.lang.CharSequence seq)
Calculate a hash code of a byte array assuming ASCII character encoding. The resulting hash code will be case insensitive.- Parameters:
seq- The ascii string to produce hashcode for.- Returns:
- a hashcode for the given input.
-
split
public static java.util.List<java.lang.CharSequence> split(java.lang.CharSequence input, char delimiter, boolean trim)Split a givenAsciiStringto separate ones on the givendelimiter. Trimming white-space before and after each token can be controlled by thetrimflag This method has no support for regex.- Parameters:
input- The initialCharSequenceto split, this experiences no side effects.delimiter- The delimiter character.trim- Flag to control whether the individual items must be trimmed.- Returns:
- a
ListofCharSequencesubsequences of the input with the separated values
-
equalsIgnoreCaseLower
public static boolean equalsIgnoreCaseLower(char a, char lowerCaseChar)Compare an unknown ascii characterawith a known lowercase characterlowerCaseCharin a case insensitive manner.- Parameters:
a- an unknown ascii character.lowerCaseChar- a known to be lowercase ascii character.- Returns:
trueifaandlowerCaseCharare case insensitive equal.
-
regionMatches
public static boolean regionMatches(java.lang.CharSequence cs, boolean ignoreCase, int csStart, java.lang.CharSequence string, int start, int length)This methods make regionMatches operation correctly for any chars in strings.- Parameters:
cs- theCharSequenceto be processedignoreCase- specifies if case should be ignored.csStart- the starting offset in thecsCharSequencestring- theCharSequenceto compare.start- the starting offset in the specifiedstring.length- the number of characters to compare.- Returns:
trueif the ranges of characters are equal,falseotherwise.
-
parseLong
public static long parseLong(java.lang.CharSequence cs) throws java.lang.NumberFormatExceptionParses theCharSequenceargument as a signed decimallong.This is the equivalent of
Long.parseLong(String)that does not require toCharSequence.toString()conversion.- Parameters:
cs- aCharSequencecontaining thelongvalue to be parsed- Returns:
- {code long} representation of the passed
CharSequence - Throws:
java.lang.NumberFormatException- if the passedCharSequencecannot be parsed intolong
-
-