ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Public Static Fields | Public Static Methods | List of all members
CString Class Reference

Class Description


This inner class of AString provides static methods working with character arrays.

Public Static Fields

static final char[] DEFAULT_WHITESPACES = {' ','\r','\n','\t' }
 
static final String EMPTY = ""
 
static final String NEW_LINE_CHARS =System.getProperty("line.separator")
 
static final char[] nullBuffer =new char[0]
 

Public Static Methods

static boolean adjustRegion (int referenceLength, int regionStart, int regionLength, int[] target)
 
static int compareTo (CharSequence needle, int needleStart, int needleLength, char[] haystack, int haystackStart, int haystackLength, Case sensitivity)
 
static boolean containsAt (char[] needle, int needleStart, int needleLength, char[] haystack, int haystackPos, int haystackLimit, Case sensitivity)
 
static boolean containsAt (CharSequence needle, char[] haystack, int haystackPos, int haystackLimit, Case sensitivity)
 
static boolean endsWithIgnoreCase (CharSequence haystack, CharSequence needle)
 
static int indexOf (char needle, char[] haystack)
 
static int indexOf (char needle, char[] haystack, int regionStart)
 
static int indexOf (char needle, char[] haystack, int regionStart, int regionLength)
 
static int indexOfAnyInRegion (char[] haystack, int regionStart, int regionLength, char[] needles, Inclusion inclusion)
 
static int indexOfFirstDifference (char[] haystack, int haystackStart, int haystackLength, CharSequence needle, Case sensitivity)
 
static int indexOfIgnoreCase (CharSequence haystack, CharSequence needle)
 
static int indexOfIgnoreCase (CharSequence haystack, CharSequence needle, int startIdx)
 
static int indexOfString (CharSequence needle, char[] haystack, int haystackStart, int haystackLength, Case sensitivity)
 
static boolean isNullOrEmpty (CharSequence cs)
 
static int lastIndexOfAny (char[] haystack, int regionStart, int regionLength, char[] needles, Inclusion inclusion)
 
static boolean startsWithIgnoreCase (CharSequence haystack, CharSequence needle)
 

Member Function Documentation

◆ adjustRegion()

static boolean adjustRegion ( int  referenceLength,
int  regionStart,
int  regionLength,
int[]  target 
)
static

Adjusts a given region to fit into the range [0 .. referenceLength].

Parameters
referenceLengthLength of the string that the given region will be adjusted to.
regionStartThe start of the region to be adjusted.
regionLengthThe length of the region to be adjusted.
targetArray of size 2 that receives the target values.
Returns
True if adjusted range is empty.

◆ compareTo()

static int compareTo ( CharSequence  needle,
int  needleStart,
int  needleLength,
char[]  haystack,
int  haystackStart,
int  haystackLength,
Case  sensitivity 
)
static

Compares a given region of a CharSequence with a in a char[].
No parameter checks are performed. Null and empty checks and proper region bounds have to be provided (this is a helper method for other compareTo methods).

Parameters
needleAn object of type CharSequence that is compared to haystack.
needleStartThe start of the region in needle that is to be compared.
needleLengthThe length of the region in needle.
haystackThe character buffer that is compared.
haystackStartThe start of the substring within haystack.
haystackLengthThe length of the substring within haystack.
sensitivityCase sensitivity of the operation.
Returns
  • 0 if haystack and needle are null or if both have a length of 0 or if both share the same content.
  • <0 if haystack is nulled and needle is not or if haystack is smaller than needle.
  • >0 if haystack is not nulled but needle is or if haystack is greater than needle.

◆ containsAt() [1/2]

static boolean containsAt ( char[]  needle,
int  needleStart,
int  needleLength,
char[]  haystack,
int  haystackPos,
int  haystackLimit,
Case  sensitivity 
)
static

Checks if a region of a char[] is located at the given position of another char[].

Parameters
needleThe character array containing the needle.
needleStartThe index of the start of the needle within the character array.
needleLengthThe length of the needle within the character array.
haystackThe character array to look in for the needle.
haystackPosThe position to look at in haystack.
haystackLimitThe length of the haystack (may be equal or less than haystack.length().
sensitivityCase sensitivity of the comparison.
Returns
true if the needle is found at the given position. false otherwise.

◆ containsAt() [2/2]

static boolean containsAt ( CharSequence  needle,
char[]  haystack,
int  haystackPos,
int  haystackLimit,
Case  sensitivity 
)
static

Checks if a CharSequence is located in a char[] at the given position.

Parameters
needleThe string to search.
haystackThe character array to look in for the needle.
haystackPosThe position to look at in haystack.
haystackLimitThe length of the haystack (may be equal or less than haystack.length().
sensitivityCase sensitivity of the comparison.
Returns
true if the sequence is found at the given position. false otherwise.

◆ endsWithIgnoreCase()

static boolean endsWithIgnoreCase ( CharSequence  haystack,
CharSequence  needle 
)
static

Static utility function to check if a string ends with another string with case insensitive compare. Using this function avoids to create two converted (lowered) temporary strings.

Parameters
haystackThe CharSequence to search in.
needleThe CharSequence to search for.
Returns
true, if given string s ends with given string prefix, false otherwise.

◆ indexOf() [1/3]

static int indexOf ( char  needle,
char[]  haystack 
)
static

Static method that searches a character in a character array.

Parameters
needleThe character to be searched for.
haystackCharacter array that is searched in.
Returns
The index of the first matching character found. If nothing is found, -1 is returned.

◆ indexOf() [2/3]

static int indexOf ( char  needle,
char[]  haystack,
int  regionStart 
)
static

Static method that searches a character in a character array, starting at a given index to the end of the array.

Parameters
needleThe character to be searched for.
haystackCharacter array that is searched in.
regionStartThe start of the region within haystack. Defaults to 0.
Returns
The index of the first matching character found. If nothing is found, -1 is returned.

◆ indexOf() [3/3]

static int indexOf ( char  needle,
char[]  haystack,
int  regionStart,
int  regionLength 
)
static

Static method that searches a character in a region of a character array.

Parameters
needleThe character to be searched for.
haystackCharacter array that is searched in.
regionStartThe start of the region within haystack. Defaults to 0.
regionLengthThe length of the region within haystack. Defaults to Integer.MAX_VALUE.
Returns
The index of the first matching character found. If nothing is found, -1 is returned.

◆ indexOfAnyInRegion()

static int indexOfAnyInRegion ( char[]  haystack,
int  regionStart,
int  regionLength,
char[]  needles,
Inclusion  inclusion 
)
static

Static method that returns the index of the first character which is included (alternatively not included) in a given set of characters.

This method searches from left to right. For backward search, see lastIndexOfAny

Parameters
haystackThe string to be searched.
regionStartThe start of the region within haystack.
regionLengthThe length of the region within haystack.
needlesCharacters to be searched for.
inclusionDenotes whether the search returns the first index that holds a value that is included or that is not excluded in the set of needle characters.
Returns
The index (relative to the start of the region) of the first character found which is included, respectively not included, in the given set of characters. If nothing is found, -1 is returned.

◆ indexOfFirstDifference()

static int indexOfFirstDifference ( char[]  haystack,
int  haystackStart,
int  haystackLength,
CharSequence  needle,
Case  sensitivity 
)
static

Static method that returns the index of the first character which not equal within two strings. If haystack starts with needle, then the length of needle is returned.

Parameters
haystackCharacter array that is searched in.
haystackStartThe start of the region within haystack.
haystackLengthThe length of the region within haystack.
needleThe string to be searched for.
sensitivityThe sensitivity to the case of characters of the operation.
Returns
The index within needle with the first difference.

◆ indexOfIgnoreCase() [1/2]

static int indexOfIgnoreCase ( CharSequence  haystack,
CharSequence  needle 
)
static

Search the given String in the Buffer.

Parameters
haystackThe CharSequence to search in.
needleThe CharSequence to search for.
Returns
-1 if the String is not found. Otherwise the index of first occurrence.

◆ indexOfIgnoreCase() [2/2]

static int indexOfIgnoreCase ( CharSequence  haystack,
CharSequence  needle,
int  startIdx 
)
static

Search a string within another starting at a given position.

Parameters
haystackThe CharSequence to search in.
needleThe CharSequence to search for.
startIdxThe index to start the search at. Optional and defaults to 0.
Returns
-1 if the String is not found. Otherwise the index of first occurrence.

◆ indexOfString()

static int indexOfString ( CharSequence  needle,
char[]  haystack,
int  haystackStart,
int  haystackLength,
Case  sensitivity 
)
static

Searches a CharSequence in a region of a character array.

Parameters
needleThe CharSequence to search.
haystackCharacter array that is searched in.
haystackStartThe start of the region within haystack. Defaults to 0.
haystackLengthThe length of the region within haystack. Defaults to Integer.MAX_VALUE.
sensitivityCase sensitivity of the operation. Optional and defaults to Case.Sensitive.
Returns
-1 if the String is not found. Otherwise the index of first occurrence relative to haystackStart.

◆ isNullOrEmpty()

static boolean isNullOrEmpty ( CharSequence  cs)
static

Checks if a given CharSequence is empty or has a length of zero.

Note
Mimics corresponding method in C# class String.
Parameters
csThe CharSequence to check.
Returns
Returns true if given String is empty or 0.

◆ lastIndexOfAny()

static int lastIndexOfAny ( char[]  haystack,
int  regionStart,
int  regionLength,
char[]  needles,
Inclusion  inclusion 
)
static

Static method that returns the index of the first character which is included (alternatively not included) in a given set of characters. The search starts at the end of the region and continues towards its start.

Parameters
haystackThe string to be searched.
regionStartThe start of the region within haystack.
regionLengthThe length of the region within haystack.
needlesAn array that holds the characters to be searched for.
inclusionDenotes whether the search returns the first index that holds a value that is included or that is not excluded in the set of needle characters.
Returns
The index relative to the start of the region. If the search was not successful, then regionStart -1 is returned;

◆ startsWithIgnoreCase()

static boolean startsWithIgnoreCase ( CharSequence  haystack,
CharSequence  needle 
)
static

Static utility function to check if a string starts with another string with case insensitive compare. Using this function avoids to create two converted (lowered) temporary strings.

Parameters
haystackThe CharSequence to search in.
needleThe CharSequence to search for.
Returns
true, if given string s starts with given string prefix, false otherwise.

Member Data Documentation

◆ DEFAULT_WHITESPACES

final char [] DEFAULT_WHITESPACES = {' ','\r','\n','\t' }
static

Contains all characters that by default get trimmed by trim methods defined in this class.

◆ EMPTY

final String EMPTY = ""
static

An empty String singleton

◆ NEW_LINE_CHARS

final String NEW_LINE_CHARS =System.getProperty("line.separator")
static

The system depended new line character codes retrieved statically (once) using "System.getProperty("line.separator");"

◆ nullBuffer

final char [] nullBuffer =new char[0]
static

A singleton that references a zero-length character array. Used to avoid object allocation.


The documentation for this class was generated from the following file: