- java.lang.Object
-
- io.netty5.util.AsciiString
-
- All Implemented Interfaces:
CharSequence
,Comparable<CharSequence>
public final class AsciiString extends Object implements CharSequence, Comparable<CharSequence>
A string which has been encoded into a character encoding whose character always takes a single byte, similarly to ASCII. It internally keeps its content in a byte array unlikeString
, which uses a character array, for reduced memory footprint and faster data transfer from/to byte-based data structures such as a byte array andByteBuffer
. It is often used in conjunction withHeaders
that require aCharSequence
.This class was designed to provide an immutable array of bytes, and caches some internal state based upon the value of this array. However underlying access to this byte array is provided via not copying the array on construction or
array()
. If any changes are made to the underlying byte array it is the user's responsibility to callarrayChanged()
so the state of this class can be reset.
-
-
Field Summary
Fields Modifier and Type Field Description static HashingStrategy<CharSequence>
CASE_INSENSITIVE_HASHER
static HashingStrategy<CharSequence>
CASE_SENSITIVE_HASHER
static AsciiString
EMPTY_STRING
static int
INDEX_NOT_FOUND
-
Constructor Summary
Constructors Constructor Description AsciiString(byte[] value)
Initialize this byte string based upon a byte array.AsciiString(byte[] value, boolean copy)
Initialize this byte string based upon a byte array.AsciiString(byte[] value, int start, int length, boolean copy)
Construct a new instance from abyte[]
array.AsciiString(char[] value)
Create a copy ofvalue
into this instance assuming ASCII encoding.AsciiString(char[] value, int start, int length)
Create a copy ofvalue
into this instance assuming ASCII encoding.AsciiString(char[] value, Charset charset)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.AsciiString(char[] value, Charset charset, int start, int length)
Create a copy ofvalue
into a this instance using the encoding type ofcharset
.AsciiString(CharSequence value)
Create a copy ofvalue
into this instance assuming ASCII encoding.AsciiString(CharSequence value, int start, int length)
Create a copy ofvalue
into this instance assuming ASCII encoding.AsciiString(CharSequence value, Charset charset)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.AsciiString(CharSequence value, Charset charset, int start, int length)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.AsciiString(ByteBuffer value)
Create a copy of the underlying storage fromvalue
.AsciiString(ByteBuffer value, boolean copy)
Initialize an instance based upon the underlying storage fromvalue
.AsciiString(ByteBuffer value, int start, int length, boolean copy)
Initialize anAsciiString
based upon the underlying storage fromvalue
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
array()
This gives direct access to the underlying storage array.void
arrayChanged()
During normal use cases theAsciiString
should be immutable, but if the underlying array is shared, and changes then this needs to be called.int
arrayOffset()
The offset intoarray()
for which data for this ByteString begins.static char
b2c(byte b)
byte
byteAt(int index)
static byte
c2b(char c)
static AsciiString
cached(String string)
Returns anAsciiString
containing the given string and retains/caches the input string for later use intoString()
.char
charAt(int index)
int
compareTo(CharSequence string)
Compares the specified string to this string using the ASCII values of the characters.AsciiString
concat(CharSequence string)
Concatenates this string and the specified string.boolean
contains(CharSequence cs)
Determines if thisString
contains the sequence of characters in theCharSequence
passed.static boolean
contains(CharSequence a, CharSequence b)
Determine ifa
containsb
in a case sensitive manner.static boolean
containsAllContentEqualsIgnoreCase(Collection<CharSequence> a, Collection<CharSequence> b)
Determine ifa
contains all of the values inb
usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.static boolean
containsContentEqualsIgnoreCase(Collection<CharSequence> collection, CharSequence value)
Determine ifcollection
containsvalue
and usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.static boolean
containsIgnoreCase(CharSequence a, CharSequence b)
Determine ifa
containsb
in a case insensitive manner.boolean
contentEquals(CharSequence a)
Compares aCharSequence
to thisString
to determine if their contents are equal.static boolean
contentEquals(CharSequence a, CharSequence b)
Returnstrue
if the content of bothCharSequence
's are equals.boolean
contentEqualsIgnoreCase(CharSequence string)
Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.static boolean
contentEqualsIgnoreCase(CharSequence a, CharSequence b)
Returnstrue
if bothCharSequence
's are equals when ignore the case.void
copy(int srcIdx, byte[] dst, int dstIdx, int length)
Copies the content of this string to a byte array.void
copy(int srcIdx, char[] dst, int dstIdx, int length)
Copied the content of this string to a character array.boolean
endsWith(CharSequence suffix)
Compares the specified string to this string to determine if the specified string is a suffix.boolean
equals(Object obj)
int
forEachByte(int index, int length, ByteProcessor visitor)
Iterates over the specified area of this buffer with the specifiedprocessor
in ascending order.int
forEachByte(ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specifiedprocessor
in ascending order.int
forEachByteDesc(int index, int length, ByteProcessor visitor)
Iterates over the specified area of this buffer with the specifiedprocessor
in descending order.int
forEachByteDesc(ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specifiedprocessor
in descending order.int
hashCode()
static int
hashCode(CharSequence value)
Returns the case-insensitive hash code of the specified string.int
indexOf(char ch, int start)
Searches in this string for the index of the specified charch
.int
indexOf(CharSequence string)
Searches in this string for the first index of the specified string.static int
indexOf(CharSequence cs, char searchChar, int start)
Finds the first index in theCharSequence
that matches the specified character.int
indexOf(CharSequence subString, int start)
Searches in this string for the index of the specified string.static int
indexOfIgnoreCase(CharSequence str, CharSequence searchStr, int startPos)
Case in-sensitive find of the first index within a CharSequence from the specified position.static int
indexOfIgnoreCaseAscii(CharSequence str, CharSequence searchStr, int startPos)
Case in-sensitive find of the first index within a CharSequence from the specified position.boolean
isEmpty()
Determine if this instance has 0 length.boolean
isEntireArrayUsed()
Determine if the storage represented byarray()
is entirely used.static boolean
isUpperCase(byte value)
static boolean
isUpperCase(char value)
int
lastIndexOf(CharSequence string)
Searches in this string for the last index of the specified string.int
lastIndexOf(CharSequence subString, int start)
Searches in this string for the index of the specified string.int
length()
The length in bytes of this instance.boolean
matches(String expr)
Determines whether this string matches a given regular expression.static AsciiString
of(CharSequence string)
Returns anAsciiString
containing the given character sequence.boolean
parseBoolean()
char
parseChar()
char
parseChar(int start)
double
parseDouble()
double
parseDouble(int start, int end)
float
parseFloat()
float
parseFloat(int start, int end)
int
parseInt()
int
parseInt(int radix)
int
parseInt(int start, int end)
int
parseInt(int start, int end, int radix)
long
parseLong()
long
parseLong(int radix)
long
parseLong(int start, int end)
long
parseLong(int start, int end, int radix)
short
parseShort()
short
parseShort(int radix)
short
parseShort(int start, int end)
short
parseShort(int start, int end, int radix)
boolean
regionMatches(boolean ignoreCase, int thisStart, CharSequence string, int start, int length)
Compares the specified string to this string and compares the specified range of characters to determine if they are the same.boolean
regionMatches(int thisStart, CharSequence string, int start, int length)
Compares the specified string to this string and compares the specified range of characters to determine if they are the same.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 stringsstatic boolean
regionMatchesAscii(CharSequence cs, boolean ignoreCase, int csStart, CharSequence string, int start, int length)
This is optimized version of regionMatches for string with ASCII chars onlyAsciiString
replace(char oldChar, char newChar)
Copies this string replacing occurrences of the specified character with another character.AsciiString[]
split(char delim)
Splits the specifiedString
with the specified delimiter.AsciiString[]
split(String expr, int max)
Splits this string using the supplied regular expressionexpr
.boolean
startsWith(CharSequence prefix)
Compares the specified string to this string to determine if the specified string is a prefix.boolean
startsWith(CharSequence prefix, int start)
Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix.AsciiString
subSequence(int start)
Copies a range of characters into a new string.AsciiString
subSequence(int start, int end)
Copies a range of characters into a new string.AsciiString
subSequence(int start, int end, boolean copy)
Either copy or share a subset of underlying sub-sequence of bytes.byte[]
toByteArray()
Converts this string to a byte array.byte[]
toByteArray(int start, int end)
Converts a subset of this string to a byte array.char[]
toCharArray()
Copies the characters in this string to a character array.char[]
toCharArray(int start, int end)
Copies the characters in this string to a character array.AsciiString
toLowerCase()
Converts the characters in this string to lowercase, using the default Locale.static char
toLowerCase(char c)
If the character is uppercase - converts the character to lowercase, otherwise returns the character as it is.String
toString()
Translates the entire byte string to aString
.String
toString(int start)
Translates the entire byte string to aString
using thecharset
encoding.String
toString(int start, int end)
AsciiString
toUpperCase()
Converts the characters in this string to uppercase, using the default Locale.AsciiString
trim()
Duplicates this string removing white space characters from the beginning and end of the string, without copying.static CharSequence
trim(CharSequence c)
Copies this string removing white space characters from the beginning and end of the string, and tries not to copy if possible.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
-
-
-
Field Detail
-
EMPTY_STRING
public static final AsciiString EMPTY_STRING
-
INDEX_NOT_FOUND
public static final int INDEX_NOT_FOUND
- See Also:
- Constant Field Values
-
CASE_INSENSITIVE_HASHER
public static final HashingStrategy<CharSequence> CASE_INSENSITIVE_HASHER
-
CASE_SENSITIVE_HASHER
public static final HashingStrategy<CharSequence> CASE_SENSITIVE_HASHER
-
-
Constructor Detail
-
AsciiString
public AsciiString(byte[] value)
Initialize this byte string based upon a byte array. A copy will be made.
-
AsciiString
public AsciiString(byte[] value, boolean copy)
Initialize this byte string based upon a byte array.copy
determines if a copy is made or the array is shared.
-
AsciiString
public AsciiString(byte[] value, int start, int length, boolean copy)
Construct a new instance from abyte[]
array.- Parameters:
copy
-true
then a copy of the memory will be made.false
the underlying memory will be shared.
-
AsciiString
public AsciiString(ByteBuffer value)
Create a copy of the underlying storage fromvalue
. The copy will start atBuffer.position()
and copyBuffer.remaining()
bytes.
-
AsciiString
public AsciiString(ByteBuffer value, boolean copy)
Initialize an instance based upon the underlying storage fromvalue
. There is a potential to share the underlying array storage ifByteBuffer.hasArray()
istrue
. ifcopy
istrue
a copy will be made of the memory. ifcopy
isfalse
the underlying storage will be shared, if possible.
-
AsciiString
public AsciiString(ByteBuffer value, int start, int length, boolean copy)
Initialize anAsciiString
based upon the underlying storage fromvalue
. There is a potential to share the underlying array storage ifByteBuffer.hasArray()
istrue
. ifcopy
istrue
a copy will be made of the memory. ifcopy
isfalse
the underlying storage will be shared, if possible.
-
AsciiString
public AsciiString(char[] value)
Create a copy ofvalue
into this instance assuming ASCII encoding.
-
AsciiString
public AsciiString(char[] value, int start, int length)
Create a copy ofvalue
into this instance assuming ASCII encoding. The copy will start at indexstart
and copylength
bytes.
-
AsciiString
public AsciiString(char[] value, Charset charset)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.
-
AsciiString
public AsciiString(char[] value, Charset charset, int start, int length)
Create a copy ofvalue
into a this instance using the encoding type ofcharset
. The copy will start at indexstart
and copylength
bytes.
-
AsciiString
public AsciiString(CharSequence value)
Create a copy ofvalue
into this instance assuming ASCII encoding.
-
AsciiString
public AsciiString(CharSequence value, int start, int length)
Create a copy ofvalue
into this instance assuming ASCII encoding. The copy will start at indexstart
and copylength
bytes.
-
AsciiString
public AsciiString(CharSequence value, Charset charset)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.
-
AsciiString
public AsciiString(CharSequence value, Charset charset, int start, int length)
Create a copy ofvalue
into this instance using the encoding type ofcharset
. The copy will start at indexstart
and copylength
bytes.
-
-
Method Detail
-
forEachByte
public int forEachByte(ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specifiedprocessor
in ascending order.- Returns:
-1
if the processor iterated to or beyond the end of the readable bytes. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
forEachByte
public int forEachByte(int index, int length, ByteProcessor visitor)
Iterates over the specified area of this buffer with the specifiedprocessor
in ascending order. (i.e.index
,(index + 1)
, ..(index + length - 1)
).- Returns:
-1
if the processor iterated to or beyond the end of the specified area. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
forEachByteDesc
public int forEachByteDesc(ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specifiedprocessor
in descending order.- Returns:
-1
if the processor iterated to or beyond the beginning of the readable bytes. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
forEachByteDesc
public int forEachByteDesc(int index, int length, ByteProcessor visitor)
Iterates over the specified area of this buffer with the specifiedprocessor
in descending order. (i.e.(index + length - 1)
,(index + length - 2)
, ...index
).- Returns:
-1
if the processor iterated to or beyond the beginning of the specified area. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
byteAt
public byte byteAt(int index)
-
isEmpty
public boolean isEmpty()
Determine if this instance has 0 length.
-
length
public int length()
The length in bytes of this instance.- Specified by:
length
in interfaceCharSequence
-
arrayChanged
public void arrayChanged()
During normal use cases theAsciiString
should be immutable, but if the underlying array is shared, and changes then this needs to be called.
-
array
public byte[] array()
This gives direct access to the underlying storage array. ThetoByteArray()
should be preferred over this method. If the return value is changed thenarrayChanged()
must be called.- See Also:
arrayOffset()
,isEntireArrayUsed()
-
arrayOffset
public int arrayOffset()
The offset intoarray()
for which data for this ByteString begins.- See Also:
array()
,isEntireArrayUsed()
-
isEntireArrayUsed
public boolean isEntireArrayUsed()
Determine if the storage represented byarray()
is entirely used.- See Also:
array()
-
toByteArray
public byte[] toByteArray()
Converts this string to a byte array.
-
toByteArray
public byte[] toByteArray(int start, int end)
Converts a subset of this string to a byte array. The subset is defined by the range [start
,end
).
-
copy
public void copy(int srcIdx, byte[] dst, int dstIdx, int length)
Copies the content of this string to a byte array.- Parameters:
srcIdx
- the starting offset of characters to copy.dst
- the destination byte array.dstIdx
- the starting offset in the destination byte array.length
- the number of characters to copy.
-
charAt
public char charAt(int index)
- Specified by:
charAt
in interfaceCharSequence
-
contains
public boolean contains(CharSequence cs)
Determines if thisString
contains the sequence of characters in theCharSequence
passed.- Parameters:
cs
- the character sequence to search for.- Returns:
true
if the sequence of characters are contained in this string, otherwisefalse
.
-
compareTo
public int compareTo(CharSequence string)
Compares the specified string to this string using the ASCII values of the characters. Returns 0 if the strings contain the same characters in the same order. Returns a negative integer if the first non-equal character in this string has an ASCII value which is less than the ASCII value of the character at the same position in the specified string, or if this string is a prefix of the specified string. Returns a positive integer if the first non-equal character in this string has a ASCII value which is greater than the ASCII value of the character at the same position in the specified string, or if the specified string is a prefix of this string.- Specified by:
compareTo
in interfaceComparable<CharSequence>
- Parameters:
string
- the string to compare.- Returns:
- 0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
- Throws:
NullPointerException
- ifstring
isnull
.
-
concat
public AsciiString concat(CharSequence string)
Concatenates this string and the specified string.- Parameters:
string
- the string to concatenate- Returns:
- a new string which is the concatenation of this string and the specified string.
-
endsWith
public boolean endsWith(CharSequence suffix)
Compares the specified string to this string to determine if the specified string is a suffix.- Parameters:
suffix
- the suffix to look for.- Returns:
true
if the specified string is a suffix of this string,false
otherwise.- Throws:
NullPointerException
- ifsuffix
isnull
.
-
contentEqualsIgnoreCase
public boolean contentEqualsIgnoreCase(CharSequence string)
Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.- Parameters:
string
- the string to compare.- Returns:
true
if the specified string is equal to this string,false
otherwise.
-
toCharArray
public char[] toCharArray()
Copies the characters in this string to a character array.- Returns:
- a character array containing the characters of this string.
-
toCharArray
public char[] toCharArray(int start, int end)
Copies the characters in this string to a character array.- Returns:
- a character array containing the characters of this string.
-
copy
public void copy(int srcIdx, char[] dst, int dstIdx, int length)
Copied the content of this string to a character array.- Parameters:
srcIdx
- the starting offset of characters to copy.dst
- the destination character array.dstIdx
- the starting offset in the destination byte array.length
- the number of characters to copy.
-
subSequence
public AsciiString subSequence(int start)
Copies a range of characters into a new string.- Parameters:
start
- the offset of the first character (inclusive).- Returns:
- a new string containing the characters from start to the end of the string.
- Throws:
IndexOutOfBoundsException
- ifstart < 0
orstart > length()
.
-
subSequence
public AsciiString subSequence(int start, int end)
Copies a range of characters into a new string.- Specified by:
subSequence
in interfaceCharSequence
- Parameters:
start
- the offset of the first character (inclusive).end
- The index to stop at (exclusive).- Returns:
- a new string containing the characters from start to the end of the string.
- Throws:
IndexOutOfBoundsException
- ifstart < 0
orstart > length()
.
-
subSequence
public AsciiString subSequence(int start, int end, boolean copy)
Either copy or share a subset of underlying sub-sequence of bytes.- Parameters:
start
- the offset of the first character (inclusive).end
- The index to stop at (exclusive).copy
- Iftrue
then a copy of the underlying storage will be made. Iffalse
then the underlying storage will be shared.- Returns:
- a new string containing the characters from start to the end of the string.
- Throws:
IndexOutOfBoundsException
- ifstart < 0
orstart > length()
.
-
indexOf
public int indexOf(CharSequence string)
Searches in this string for the first index of the specified string. The search for the string starts at the beginning and moves towards the end of this string.- Parameters:
string
- the string to find.- Returns:
- the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
- Throws:
NullPointerException
- ifstring
isnull
.
-
indexOf
public int indexOf(CharSequence subString, int start)
Searches in this string for the index of the specified string. The search for the string starts at the specified offset and moves towards the end of this string.- Parameters:
subString
- the string to find.start
- the starting offset.- Returns:
- the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
- Throws:
NullPointerException
- ifsubString
isnull
.
-
indexOf
public int indexOf(char ch, int start)
Searches in this string for the index of the specified charch
. The search for the char starts at the specified offsetstart
and moves towards the end of this string.- Parameters:
ch
- the char to find.start
- the starting offset.- Returns:
- the index of the first occurrence of the specified char
ch
in this string, -1 if found no occurrence.
-
lastIndexOf
public int lastIndexOf(CharSequence string)
Searches in this string for the last index of the specified string. The search for the string starts at the end and moves towards the beginning of this string.- Parameters:
string
- the string to find.- Returns:
- the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
- Throws:
NullPointerException
- ifstring
isnull
.
-
lastIndexOf
public int lastIndexOf(CharSequence subString, int start)
Searches in this string for the index of the specified string. The search for the string starts at the specified offset and moves towards the beginning of this string.- Parameters:
subString
- the string to find.start
- the starting offset.- Returns:
- the index of the first character of the specified string in this string , -1 if the specified string is not a substring.
- Throws:
NullPointerException
- ifsubString
isnull
.
-
regionMatches
public boolean regionMatches(int thisStart, CharSequence string, int start, int length)
Compares the specified string to this string and compares the specified range of characters to determine if they are the same.- Parameters:
thisStart
- the starting offset in this string.string
- the string to compare.start
- the starting offset in the specified string.length
- the number of characters to compare.- Returns:
true
if the ranges of characters are equal,false
otherwise- Throws:
NullPointerException
- ifstring
isnull
.
-
regionMatches
public boolean regionMatches(boolean ignoreCase, int thisStart, CharSequence string, int start, int length)
Compares the specified string to this string and compares the specified range of characters to determine if they are the same. When ignoreCase is true, the case of the characters is ignored during the comparison.- Parameters:
ignoreCase
- specifies if case should be ignored.thisStart
- the starting offset in this string.string
- the string to compare.start
- the starting offset in the specified string.length
- the number of characters to compare.- Returns:
true
if the ranges of characters are equal,false
otherwise.- Throws:
NullPointerException
- ifstring
isnull
.
-
replace
public AsciiString replace(char oldChar, char newChar)
Copies this string replacing occurrences of the specified character with another character.- Parameters:
oldChar
- the character to replace.newChar
- the replacement character.- Returns:
- a new string with occurrences of oldChar replaced by newChar.
-
startsWith
public boolean startsWith(CharSequence prefix)
Compares the specified string to this string to determine if the specified string is a prefix.- Parameters:
prefix
- the string to look for.- Returns:
true
if the specified string is a prefix of this string,false
otherwise- Throws:
NullPointerException
- ifprefix
isnull
.
-
startsWith
public boolean startsWith(CharSequence prefix, int start)
Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix.- Parameters:
prefix
- the string to look for.start
- the starting offset.- Returns:
true
if the specified string occurs in this string at the specified offset,false
otherwise.- Throws:
NullPointerException
- ifprefix
isnull
.
-
toLowerCase
public AsciiString toLowerCase()
Converts the characters in this string to lowercase, using the default Locale.- Returns:
- a new string containing the lowercase characters equivalent to the characters in this string.
-
toUpperCase
public AsciiString toUpperCase()
Converts the characters in this string to uppercase, using the default Locale.- Returns:
- a new string containing the uppercase characters equivalent to the characters in this string.
-
trim
public static CharSequence trim(CharSequence c)
Copies this string removing white space characters from the beginning and end of the string, and tries not to copy if possible.- Parameters:
c
- TheCharSequence
to trim.- Returns:
- a new string with characters
<= \\u0020
removed from the beginning and the end.
-
trim
public AsciiString trim()
Duplicates this string removing white space characters from the beginning and end of the string, without copying.- Returns:
- a new string with characters
<= \\u0020
removed from the beginning and the end.
-
contentEquals
public boolean contentEquals(CharSequence a)
Compares aCharSequence
to thisString
to determine if their contents are equal.- Parameters:
a
- the character sequence to compare to.- Returns:
true
if equal, otherwisefalse
-
matches
public boolean matches(String expr)
Determines whether this string matches a given regular expression.- Parameters:
expr
- the regular expression to be matched.- Returns:
true
if the expression matches, otherwisefalse
.- Throws:
PatternSyntaxException
- if the syntax of the supplied regular expression is not valid.NullPointerException
- ifexpr
isnull
.
-
split
public AsciiString[] split(String expr, int max)
Splits this string using the supplied regular expressionexpr
. The parametermax
controls the behavior how many times the pattern is applied to the string.- Parameters:
expr
- the regular expression used to divide the string.max
- the number of entries in the resulting array.- Returns:
- an array of Strings created by separating the string along matches of the regular expression.
- Throws:
NullPointerException
- ifexpr
isnull
.PatternSyntaxException
- if the syntax of the supplied regular expression is not valid.- See Also:
Pattern.split(CharSequence, int)
-
split
public AsciiString[] split(char delim)
Splits the specifiedString
with the specified delimiter.
-
hashCode
public int hashCode()
Provides a case-insensitive hash code for Ascii like byte strings.
-
toString
public String toString()
Translates the entire byte string to aString
.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
- See Also:
toString(int)
-
toString
public String toString(int start)
Translates the entire byte string to aString
using thecharset
encoding.- See Also:
toString(int, int)
-
toString
public String toString(int start, int end)
-
parseBoolean
public boolean parseBoolean()
-
parseChar
public char parseChar()
-
parseChar
public char parseChar(int start)
-
parseShort
public short parseShort()
-
parseShort
public short parseShort(int radix)
-
parseShort
public short parseShort(int start, int end)
-
parseShort
public short parseShort(int start, int end, int radix)
-
parseInt
public int parseInt()
-
parseInt
public int parseInt(int radix)
-
parseInt
public int parseInt(int start, int end)
-
parseInt
public int parseInt(int start, int end, int radix)
-
parseLong
public long parseLong()
-
parseLong
public long parseLong(int radix)
-
parseLong
public long parseLong(int start, int end)
-
parseLong
public long parseLong(int start, int end, int radix)
-
parseFloat
public float parseFloat()
-
parseFloat
public float parseFloat(int start, int end)
-
parseDouble
public double parseDouble()
-
parseDouble
public double parseDouble(int start, int end)
-
of
public static AsciiString of(CharSequence string)
Returns anAsciiString
containing the given character sequence. If the given string is already aAsciiString
, just returns the same instance.
-
cached
public static AsciiString cached(String string)
Returns anAsciiString
containing the given string and retains/caches the input string for later use intoString()
. Used for the constants (which already stored in the JVM's string table) and in cases where the guaranteed use of thetoString()
method.
-
hashCode
public static int hashCode(CharSequence value)
Returns the case-insensitive hash code of the specified string. Note that this method uses the same hashing algorithm withhashCode()
so that you can put bothAsciiString
s and arbitraryCharSequence
s into the same headers.
-
contains
public static boolean contains(CharSequence a, CharSequence b)
Determine ifa
containsb
in a case sensitive manner.
-
containsIgnoreCase
public static boolean containsIgnoreCase(CharSequence a, CharSequence b)
Determine ifa
containsb
in a case insensitive manner.
-
contentEqualsIgnoreCase
public static boolean contentEqualsIgnoreCase(CharSequence a, CharSequence b)
Returnstrue
if bothCharSequence
's are equals when ignore the case. This only supports 8-bit ASCII.
-
containsContentEqualsIgnoreCase
public static boolean containsContentEqualsIgnoreCase(Collection<CharSequence> collection, CharSequence value)
Determine ifcollection
containsvalue
and usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.- Parameters:
collection
- The collection to look for and equivalent element asvalue
.value
- The value to look for incollection
.- Returns:
true
ifcollection
containsvalue
according tocontentEqualsIgnoreCase(CharSequence, CharSequence)
.false
otherwise.- See Also:
contentEqualsIgnoreCase(CharSequence, CharSequence)
-
containsAllContentEqualsIgnoreCase
public static boolean containsAllContentEqualsIgnoreCase(Collection<CharSequence> a, Collection<CharSequence> b)
Determine ifa
contains all of the values inb
usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.- Parameters:
a
- The collection under test.b
- The values to test for.- Returns:
true
ifa
contains all of the values inb
usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.false
otherwise.- See Also:
contentEqualsIgnoreCase(CharSequence, CharSequence)
-
contentEquals
public static boolean contentEquals(CharSequence a, CharSequence b)
Returnstrue
if the content of bothCharSequence
's are equals. This only supports 8-bit ASCII.
-
regionMatches
public 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- Parameters:
cs
- theCharSequence
to be processedignoreCase
- specifies if case should be ignored.csStart
- the starting offset in thecs
CharSequencestring
- theCharSequence
to compare.start
- the starting offset in the specifiedstring
.length
- the number of characters to compare.- Returns:
true
if the ranges of characters are equal,false
otherwise.
-
regionMatchesAscii
public static boolean regionMatchesAscii(CharSequence cs, boolean ignoreCase, int csStart, CharSequence string, int start, int length)
This is optimized version of regionMatches for string with ASCII chars only- Parameters:
cs
- theCharSequence
to be processedignoreCase
- specifies if case should be ignored.csStart
- the starting offset in thecs
CharSequencestring
- theCharSequence
to compare.start
- the starting offset in the specifiedstring
.length
- the number of characters to compare.- Returns:
true
if the ranges of characters are equal,false
otherwise.
-
indexOfIgnoreCase
public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr, int startPos)
Case in-sensitive find of the first index within a CharSequence from the specified position.
A
null
CharSequence will return-1
. A negative start position is treated as zero. An empty ("") search CharSequence always matches. A start position greater than the string length only matches an empty search CharSequence.AsciiString.indexOfIgnoreCase(null, *, *) = -1 AsciiString.indexOfIgnoreCase(*, null, *) = -1 AsciiString.indexOfIgnoreCase("", "", 0) = 0 AsciiString.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 AsciiString.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 AsciiString.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 AsciiString.indexOfIgnoreCase("aabaabaa", "", 2) = 2 AsciiString.indexOfIgnoreCase("abc", "", 9) = -1
- Parameters:
str
- the CharSequence to check, may be nullsearchStr
- the CharSequence to find, may be nullstartPos
- the start position, negative treated as zero- Returns:
- the first index of the search CharSequence (always ≥ startPos),
-1 if no match or
null
string input
-
indexOfIgnoreCaseAscii
public static int indexOfIgnoreCaseAscii(CharSequence str, CharSequence searchStr, int startPos)
Case in-sensitive find of the first index within a CharSequence from the specified position. This method optimized and works correctly for ASCII CharSequences only
A
null
CharSequence will return-1
. A negative start position is treated as zero. An empty ("") search CharSequence always matches. A start position greater than the string length only matches an empty search CharSequence.AsciiString.indexOfIgnoreCase(null, *, *) = -1 AsciiString.indexOfIgnoreCase(*, null, *) = -1 AsciiString.indexOfIgnoreCase("", "", 0) = 0 AsciiString.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 AsciiString.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 AsciiString.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 AsciiString.indexOfIgnoreCase("aabaabaa", "", 2) = 2 AsciiString.indexOfIgnoreCase("abc", "", 9) = -1
- Parameters:
str
- the CharSequence to check, may be nullsearchStr
- the CharSequence to find, may be nullstartPos
- the start position, negative treated as zero- Returns:
- the first index of the search CharSequence (always ≥ startPos),
-1 if no match or
null
string input
-
indexOf
public static int indexOf(CharSequence cs, char searchChar, int start)
Finds the first index in the
CharSequence
that matches the specified character.- Parameters:
cs
- theCharSequence
to be processed, not nullsearchChar
- the char to be searched forstart
- the start index, negative starts at the string start- Returns:
- the index where the search char was found,
-1 if char
searchChar
is not found orcs == null
-
toLowerCase
public static char toLowerCase(char c)
If the character is uppercase - converts the character to lowercase, otherwise returns the character as it is. Only for ASCII characters.- Returns:
- lowercase ASCII character equivalent
-
isUpperCase
public static boolean isUpperCase(byte value)
-
isUpperCase
public static boolean isUpperCase(char value)
-
c2b
public static byte c2b(char c)
-
b2c
public static char b2c(byte b)
-
-