public final class CharSequences
extends Object
CharSequence instances only, any other input will have undefined behavior.| Modifier and Type | Method and Description |
|---|---|
static int |
asciiStringIndexOf(CharSequence sequence,
char c,
int fromIndex)
Find the index of
c within sequence starting at index fromIndex. |
static int |
caseInsensitiveHashCode(CharSequence seq)
Calculate a hash code of a byte array assuming ASCII character encoding.
|
static boolean |
contentEquals(CharSequence a,
CharSequence b)
Returns
true if the content of both CharSequence's are equals. |
static boolean |
contentEqualsIgnoreCase(CharSequence a,
CharSequence b)
Perform a case-insensitive comparison of two
CharSequences. |
static CharSequence |
emptyAsciiString()
Get a reference to an unmodifiable empty
CharSequence with the same properties as
newAsciiString(Buffer). |
static boolean |
equalsIgnoreCaseLower(char a,
char lowerCaseChar)
Compare an unknown ascii character
a with a known lowercase character lowerCaseChar in a case
insensitive manner. |
static int |
forEachByte(CharSequence sequence,
ByteProcessor visitor)
Iterates over the readable bytes of this
CharSequence with the specified
ByteProcessor in ascending order. |
static int |
indexOf(CharSequence sequence,
char c,
int fromIndex)
Find the index of
c within sequence starting at index fromIndex. |
static boolean |
isAsciiString(CharSequence sequence)
Check if the provided
CharSequence is an AsciiString,
result of a call to newAsciiString(String). |
static CharSequence |
newAsciiString(Buffer input)
Create a new
CharSequence from the specified input, supporting only 8-bit ASCII characters, and
with a case-insensitive hashCode. |
static CharSequence |
newAsciiString(String input)
Create a new
CharSequence from the specified input, supporting only 8-bit ASCII characters, and
with a case-insensitive hashCode. |
static boolean |
regionMatches(CharSequence cs,
boolean ignoreCase,
int csStart,
CharSequence string,
int start,
int length)
This methods make regionMatches operation correctly for any chars in strings.
|
static List<CharSequence> |
split(CharSequence input,
char delimiter,
boolean trim)
Split a given
AsciiString to separate ones on the given delimiter. |
static Buffer |
unwrapBuffer(CharSequence cs)
Attempt to unwrap a
CharSequence and obtain the underlying Buffer if possible. |
public static CharSequence newAsciiString(String input)
CharSequence from the specified input, supporting only 8-bit ASCII characters, and
with a case-insensitive hashCode.input - a string containing only 8-bit ASCII characters.CharSequencepublic static CharSequence newAsciiString(Buffer input)
CharSequence from the specified input, supporting only 8-bit ASCII characters, and
with a case-insensitive hashCode.input - a Buffer containingCharSequence.public static CharSequence emptyAsciiString()
CharSequence with the same properties as
newAsciiString(Buffer).CharSequence with the same properties as
newAsciiString(Buffer).public static boolean isAsciiString(CharSequence sequence)
CharSequence is an AsciiString,
result of a call to newAsciiString(String).sequence - The CharSequence to check.true if the check passes.@Nullable public static Buffer unwrapBuffer(CharSequence cs)
CharSequence and obtain the underlying Buffer if possible.cs - the CharSequence to unwrap.Buffer or null.public static int forEachByte(CharSequence sequence,
ByteProcessor visitor)
CharSequence with the specified
ByteProcessor in ascending order.sequence - the CharSequence to operate on.visitor - the ByteProcessor visitor of each element.-1 if the processor iterated to or beyond the end of the readable bytes.
The last-visited index If the ByteProcessor.process(byte) returned false.public static boolean contentEqualsIgnoreCase(@Nullable
CharSequence a,
@Nullable
CharSequence b)
CharSequences.
NOTE: This only supports 8-bit ASCII.
a - first CharSequence to compare.b - second CharSequence to compare.true if both CharSequence's are equals when ignoring the case.public static boolean contentEquals(@Nullable
CharSequence a,
@Nullable
CharSequence b)
true if the content of both CharSequence's are equals. This only supports 8-bit ASCII.a - left hand side of comparison.b - right hand side of comparison.true if a's content equals b.public static int indexOf(CharSequence sequence,
char c,
int fromIndex)
c within sequence starting at index fromIndex.sequence - The CharSequence to search in.c - The character to find.fromIndex - The index to start searching (inclusive).c or -1 otherwise.public static int asciiStringIndexOf(CharSequence sequence,
char c,
int fromIndex)
c within sequence starting at index fromIndex.
This version avoids instance type check for special occasions that we can know the type before hand.
The input is expected to be an AsciiString value; if the input type is not known
use the generic indexOf(CharSequence, char, int) instead.sequence - The CharSequence to search in.c - The character to find.fromIndex - The index to start searching (inclusive).c or -1 otherwise.public static int caseInsensitiveHashCode(CharSequence seq)
seq - The ascii string to produce hashcode for.public static List<CharSequence> split(CharSequence input,
char delimiter,
boolean trim)
AsciiString to separate ones on the given delimiter.
Trimming white-space before and after each token can be controlled by the trim flag
This method has no support for regex.input - The initial CharSequence to split, this experiences no side effects.delimiter - The delimiter character.trim - Flag to control whether the individual items must be trimmed.List of CharSequence subsequences of the input with the separated valuespublic static boolean equalsIgnoreCaseLower(char a,
char lowerCaseChar)
a with a known lowercase character lowerCaseChar in a case
insensitive manner.a - an unknown ascii character.lowerCaseChar - a known to be lowercase ascii character.true if a and lowerCaseChar are case insensitive equal.public static boolean regionMatches(CharSequence cs,
boolean ignoreCase,
int csStart,
CharSequence string,
int start,
int length)
cs - the CharSequence to be processedignoreCase - specifies if case should be ignored.csStart - the starting offset in the cs CharSequencestring - the CharSequence to compare.start - the starting offset in the specified string.length - the number of characters to compare.true if the ranges of characters are equal, false otherwise.