- 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 withHeadersthat 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_HASHERstatic HashingStrategy<CharSequence>CASE_SENSITIVE_HASHERstatic AsciiStringEMPTY_STRINGstatic intINDEX_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 ofvalueinto this instance assuming ASCII encoding.AsciiString(char[] value, int start, int length)Create a copy ofvalueinto this instance assuming ASCII encoding.AsciiString(char[] value, Charset charset)Create a copy ofvalueinto this instance using the encoding type ofcharset.AsciiString(char[] value, Charset charset, int start, int length)Create a copy ofvalueinto a this instance using the encoding type ofcharset.AsciiString(CharSequence value)Create a copy ofvalueinto this instance assuming ASCII encoding.AsciiString(CharSequence value, int start, int length)Create a copy ofvalueinto this instance assuming ASCII encoding.AsciiString(CharSequence value, Charset charset)Create a copy ofvalueinto this instance using the encoding type ofcharset.AsciiString(CharSequence value, Charset charset, int start, int length)Create a copy ofvalueinto 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 anAsciiStringbased 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.voidarrayChanged()During normal use cases theAsciiStringshould be immutable, but if the underlying array is shared, and changes then this needs to be called.intarrayOffset()The offset intoarray()for which data for this ByteString begins.static charb2c(byte b)bytebyteAt(int index)static bytec2b(char c)static AsciiStringcached(String string)Returns anAsciiStringcontaining the given string and retains/caches the input string for later use intoString().charcharAt(int index)intcompareTo(CharSequence string)Compares the specified string to this string using the ASCII values of the characters.AsciiStringconcat(CharSequence string)Concatenates this string and the specified string.booleancontains(CharSequence cs)Determines if thisStringcontains the sequence of characters in theCharSequencepassed.static booleancontains(CharSequence a, CharSequence b)Determine ifacontainsbin a case sensitive manner.static booleancontainsAllContentEqualsIgnoreCase(Collection<CharSequence> a, Collection<CharSequence> b)Determine ifacontains all of the values inbusingcontentEqualsIgnoreCase(CharSequence, CharSequence)to compare values.static booleancontainsContentEqualsIgnoreCase(Collection<CharSequence> collection, CharSequence value)Determine ifcollectioncontainsvalueand usingcontentEqualsIgnoreCase(CharSequence, CharSequence)to compare values.static booleancontainsIgnoreCase(CharSequence a, CharSequence b)Determine ifacontainsbin a case insensitive manner.booleancontentEquals(CharSequence a)Compares aCharSequenceto thisStringto determine if their contents are equal.static booleancontentEquals(CharSequence a, CharSequence b)Returnstrueif the content of bothCharSequence's are equals.booleancontentEqualsIgnoreCase(CharSequence string)Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.static booleancontentEqualsIgnoreCase(CharSequence a, CharSequence b)Returnstrueif bothCharSequence's are equals when ignore the case.voidcopy(int srcIdx, byte[] dst, int dstIdx, int length)Copies the content of this string to a byte array.voidcopy(int srcIdx, char[] dst, int dstIdx, int length)Copied the content of this string to a character array.booleanendsWith(CharSequence suffix)Compares the specified string to this string to determine if the specified string is a suffix.booleanequals(Object obj)intforEachByte(int index, int length, ByteProcessor visitor)Iterates over the specified area of this buffer with the specifiedprocessorin ascending order.intforEachByte(ByteProcessor visitor)Iterates over the readable bytes of this buffer with the specifiedprocessorin ascending order.intforEachByteDesc(int index, int length, ByteProcessor visitor)Iterates over the specified area of this buffer with the specifiedprocessorin descending order.intforEachByteDesc(ByteProcessor visitor)Iterates over the readable bytes of this buffer with the specifiedprocessorin descending order.inthashCode()static inthashCode(CharSequence value)Returns the case-insensitive hash code of the specified string.intindexOf(char ch, int start)Searches in this string for the index of the specified charch.intindexOf(CharSequence string)Searches in this string for the first index of the specified string.static intindexOf(CharSequence cs, char searchChar, int start)Finds the first index in theCharSequencethat matches the specified character.intindexOf(CharSequence subString, int start)Searches in this string for the index of the specified string.static intindexOfIgnoreCase(CharSequence str, CharSequence searchStr, int startPos)Case in-sensitive find of the first index within a CharSequence from the specified position.static intindexOfIgnoreCaseAscii(CharSequence str, CharSequence searchStr, int startPos)Case in-sensitive find of the first index within a CharSequence from the specified position.booleanisEmpty()Determine if this instance has 0 length.booleanisEntireArrayUsed()Determine if the storage represented byarray()is entirely used.static booleanisUpperCase(byte value)static booleanisUpperCase(char value)intlastIndexOf(CharSequence string)Searches in this string for the last index of the specified string.intlastIndexOf(CharSequence subString, int start)Searches in this string for the index of the specified string.intlength()The length in bytes of this instance.booleanmatches(String expr)Determines whether this string matches a given regular expression.static AsciiStringof(CharSequence string)Returns anAsciiStringcontaining the given character sequence.booleanparseBoolean()charparseChar()charparseChar(int start)doubleparseDouble()doubleparseDouble(int start, int end)floatparseFloat()floatparseFloat(int start, int end)intparseInt()intparseInt(int radix)intparseInt(int start, int end)intparseInt(int start, int end, int radix)longparseLong()longparseLong(int radix)longparseLong(int start, int end)longparseLong(int start, int end, int radix)shortparseShort()shortparseShort(int radix)shortparseShort(int start, int end)shortparseShort(int start, int end, int radix)booleanregionMatches(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.booleanregionMatches(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 booleanregionMatches(CharSequence cs, boolean ignoreCase, int csStart, CharSequence string, int start, int length)This methods make regionMatches operation correctly for any chars in stringsstatic booleanregionMatchesAscii(CharSequence cs, boolean ignoreCase, int csStart, CharSequence string, int start, int length)This is optimized version of regionMatches for string with ASCII chars onlyAsciiStringreplace(char oldChar, char newChar)Copies this string replacing occurrences of the specified character with another character.AsciiString[]split(char delim)Splits the specifiedStringwith the specified delimiter.AsciiString[]split(String expr, int max)Splits this string using the supplied regular expressionexpr.booleanstartsWith(CharSequence prefix)Compares the specified string to this string to determine if the specified string is a prefix.booleanstartsWith(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.AsciiStringsubSequence(int start)Copies a range of characters into a new string.AsciiStringsubSequence(int start, int end)Copies a range of characters into a new string.AsciiStringsubSequence(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.AsciiStringtoLowerCase()Converts the characters in this string to lowercase, using the default Locale.static chartoLowerCase(char c)If the character is uppercase - converts the character to lowercase, otherwise returns the character as it is.StringtoString()Translates the entire byte string to aString.StringtoString(int start)Translates the entire byte string to aStringusing thecharsetencoding.StringtoString(int start, int end)AsciiStringtoUpperCase()Converts the characters in this string to uppercase, using the default Locale.AsciiStringtrim()Duplicates this string removing white space characters from the beginning and end of the string, without copying.static CharSequencetrim(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.copydetermines 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-truethen a copy of the memory will be made.falsethe 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. ifcopyistruea copy will be made of the memory. ifcopyisfalsethe underlying storage will be shared, if possible.
-
AsciiString
public AsciiString(ByteBuffer value, int start, int length, boolean copy)
Initialize anAsciiStringbased upon the underlying storage fromvalue. There is a potential to share the underlying array storage ifByteBuffer.hasArray()istrue. ifcopyistruea copy will be made of the memory. ifcopyisfalsethe underlying storage will be shared, if possible.
-
AsciiString
public AsciiString(char[] value)
Create a copy ofvalueinto this instance assuming ASCII encoding.
-
AsciiString
public AsciiString(char[] value, int start, int length)Create a copy ofvalueinto this instance assuming ASCII encoding. The copy will start at indexstartand copylengthbytes.
-
AsciiString
public AsciiString(char[] value, Charset charset)Create a copy ofvalueinto this instance using the encoding type ofcharset.
-
AsciiString
public AsciiString(char[] value, Charset charset, int start, int length)Create a copy ofvalueinto a this instance using the encoding type ofcharset. The copy will start at indexstartand copylengthbytes.
-
AsciiString
public AsciiString(CharSequence value)
Create a copy ofvalueinto this instance assuming ASCII encoding.
-
AsciiString
public AsciiString(CharSequence value, int start, int length)
Create a copy ofvalueinto this instance assuming ASCII encoding. The copy will start at indexstartand copylengthbytes.
-
AsciiString
public AsciiString(CharSequence value, Charset charset)
Create a copy ofvalueinto this instance using the encoding type ofcharset.
-
AsciiString
public AsciiString(CharSequence value, Charset charset, int start, int length)
Create a copy ofvalueinto this instance using the encoding type ofcharset. The copy will start at indexstartand copylengthbytes.
-
-
Method Detail
-
forEachByte
public int forEachByte(ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specifiedprocessorin ascending order.- Returns:
-1if 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 specifiedprocessorin ascending order. (i.e.index,(index + 1), ..(index + length - 1)).- Returns:
-1if 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 specifiedprocessorin descending order.- Returns:
-1if 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 specifiedprocessorin descending order. (i.e.(index + length - 1),(index + length - 2), ...index).- Returns:
-1if 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:
lengthin interfaceCharSequence
-
arrayChanged
public void arrayChanged()
During normal use cases theAsciiStringshould 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:
charAtin interfaceCharSequence
-
contains
public boolean contains(CharSequence cs)
Determines if thisStringcontains the sequence of characters in theCharSequencepassed.- Parameters:
cs- the character sequence to search for.- Returns:
trueif 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:
compareToin 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- ifstringisnull.
-
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:
trueif the specified string is a suffix of this string,falseotherwise.- Throws:
NullPointerException- ifsuffixisnull.
-
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:
trueif the specified string is equal to this string,falseotherwise.
-
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 < 0orstart > length().
-
subSequence
public AsciiString subSequence(int start, int end)
Copies a range of characters into a new string.- Specified by:
subSequencein 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 < 0orstart > 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- Iftruethen a copy of the underlying storage will be made. Iffalsethen the underlying storage will be shared.- Returns:
- a new string containing the characters from start to the end of the string.
- Throws:
IndexOutOfBoundsException- ifstart < 0orstart > 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- ifstringisnull.
-
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- ifsubStringisnull.
-
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 offsetstartand 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
chin 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- ifstringisnull.
-
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- ifsubStringisnull.
-
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:
trueif the ranges of characters are equal,falseotherwise- Throws:
NullPointerException- ifstringisnull.
-
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:
trueif the ranges of characters are equal,falseotherwise.- Throws:
NullPointerException- ifstringisnull.
-
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:
trueif the specified string is a prefix of this string,falseotherwise- Throws:
NullPointerException- ifprefixisnull.
-
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:
trueif the specified string occurs in this string at the specified offset,falseotherwise.- Throws:
NullPointerException- ifprefixisnull.
-
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- TheCharSequenceto trim.- Returns:
- a new string with characters
<= \\u0020removed 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
<= \\u0020removed from the beginning and the end.
-
contentEquals
public boolean contentEquals(CharSequence a)
Compares aCharSequenceto thisStringto determine if their contents are equal.- Parameters:
a- the character sequence to compare to.- Returns:
trueif 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:
trueif the expression matches, otherwisefalse.- Throws:
PatternSyntaxException- if the syntax of the supplied regular expression is not valid.NullPointerException- ifexprisnull.
-
split
public AsciiString[] split(String expr, int max)
Splits this string using the supplied regular expressionexpr. The parametermaxcontrols 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- ifexprisnull.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 specifiedStringwith 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:
toStringin interfaceCharSequence- Overrides:
toStringin classObject- See Also:
toString(int)
-
toString
public String toString(int start)
Translates the entire byte string to aStringusing thecharsetencoding.- 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 anAsciiStringcontaining the given character sequence. If the given string is already aAsciiString, just returns the same instance.
-
cached
public static AsciiString cached(String string)
Returns anAsciiStringcontaining 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 bothAsciiStrings and arbitraryCharSequences into the same headers.
-
contains
public static boolean contains(CharSequence a, CharSequence b)
Determine ifacontainsbin a case sensitive manner.
-
containsIgnoreCase
public static boolean containsIgnoreCase(CharSequence a, CharSequence b)
Determine ifacontainsbin a case insensitive manner.
-
contentEqualsIgnoreCase
public static boolean contentEqualsIgnoreCase(CharSequence a, CharSequence b)
Returnstrueif 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 ifcollectioncontainsvalueand 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:
trueifcollectioncontainsvalueaccording tocontentEqualsIgnoreCase(CharSequence, CharSequence).falseotherwise.- See Also:
contentEqualsIgnoreCase(CharSequence, CharSequence)
-
containsAllContentEqualsIgnoreCase
public static boolean containsAllContentEqualsIgnoreCase(Collection<CharSequence> a, Collection<CharSequence> b)
Determine ifacontains all of the values inbusingcontentEqualsIgnoreCase(CharSequence, CharSequence)to compare values.- Parameters:
a- The collection under test.b- The values to test for.- Returns:
trueifacontains all of the values inbusingcontentEqualsIgnoreCase(CharSequence, CharSequence)to compare values.falseotherwise.- See Also:
contentEqualsIgnoreCase(CharSequence, CharSequence)
-
contentEquals
public static boolean contentEquals(CharSequence a, CharSequence b)
Returnstrueif 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- 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.
-
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- 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.
-
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
nullCharSequence 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
nullstring 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
nullCharSequence 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
nullstring input
-
indexOf
public static int indexOf(CharSequence cs, char searchChar, int start)
Finds the first index in the
CharSequencethat matches the specified character.- Parameters:
cs- theCharSequenceto 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
searchCharis 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)
-
-