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

Class Description


This class is used for defining a region (sub-string) on an existing character array which is provided. This class will not manipulate the underlying data. In particular, there is no terminating zero written into the data.

The represented region is defined by the two fields Start and End. The fields are public accessible. In general, while working with a Substring, the size of it should shrink, e.g. by trimming but should not grow. However, if the code using this class is "sure" that enlarging the region does violate the bounds of the buffer, fields Start and End might be modified from outside.

If created or set using a reference of class AString, the buffer of AString is not copied. This allows efficient operations on sub-strings of class AString. However, the source string must not be changed (or only in a controlled way) during the use the Substring instance.

Objects of this class can be reused by freshly initializing them using one of the overloaded Set methods.

Note
To generate Substrings which are separated by a delimiter character within a character array, use class Tokenizer.
Note
In the Java and C# versions of ALib, due to the language design, fields Start and End have to be used to define the substring on a field Buf, the character buffer. This forces a reimplementation of a bigger portion of the interface of class AString. In the C++ version of ALib, there is a richer family of string classes that fully integrates with zero terminated C strings, standard C++ strings and 3rd party string libraries. Neither the fields start and end are necessary, nor the aforementioned reimplementation. Consequently, when directly accessing public fields Buf, Start and End, the code gets incompatible to C++ code.

Public Fields

char[] Buf
 
int End
 
int Start
 

Public Methods

Constructors

 Substring ()
 
 Substring (String src, int start=0, int length=-1)
 
 Substring (Substring src, int start=0, int length=-1)
 
 Substring (AString src, int start=0, int length=-1)
 
 Substring (char[] cstring, int start=0, int length=-1)
 
Set Data

Substring Set (Substring src, int regionStart=0, int regionLength=-1)
 
Substring Set (String src, int start=0, int length=-1)
 
Substring Set (AString src, int start, int length)
 
Substring Set (AString src, int start)
 
Substring Set (AString src)
 
Substring Set (char[] src, int start=0, int length=-1)
 
State and Character Access

int Length ()
 
void SetNull ()
 
void Clear ()
 
bool IsNull ()
 
bool IsNotNull ()
 
bool IsEmpty ()
 
bool IsNotEmpty ()
 
char CharAtStart ()
 
char CharAt (int n)
 
char CharAtEnd ()
 
char CharAtEnd (int n)
 
Consume

char ConsumeChar ()
 
char ConsumeCharFromEnd ()
 
bool ConsumeChar (char consumable, Case sensitivity=Case.Sensitive, Whitespaces trimBeforeConsume=Whitespaces.Keep)
 
bool ConsumeCharFromEnd (char consumable, Case sensitivity=Case.Sensitive, Whitespaces trimBeforeConsume=Whitespaces.Keep)
 
int ConsumeChars (int regionLength, Substring target=null)
 
int ConsumeCharsFromEnd (int regionLength, Substring target=null)
 
int ConsumeToken (Substring target, char separator=',')
 
bool ConsumeString (String consumable, Case sensitivity=Case.Sensitive, Whitespaces trimBeforeConsume=Whitespaces.Keep)
 
bool ConsumeString (AString consumable, Case sensitivity=Case.Sensitive, Whitespaces trimBeforeConsume=Whitespaces.Keep)
 
bool ConsumeString (Substring consumable, Case sensitivity=Case.Sensitive, Whitespaces trimBeforeConsume=Whitespaces.Keep)
 
bool ConsumeStringFromEnd (String consumable, Case sensitivity=Case.Sensitive, Whitespaces trimBeforeConsume=Whitespaces.Keep)
 
bool ConsumeStringFromEnd (AString consumable, Case sensitivity=Case.Sensitive, Whitespaces trimBeforeConsume=Whitespaces.Keep)
 
bool ConsumeStringFromEnd (Substring consumable, Case sensitivity=Case.Sensitive, Whitespaces trimBeforeConsume=Whitespaces.Keep)
 
int ConsumePartOf (String consumable, int minChars=1, lang.Case sensitivity=lang.Case.Ignore, lang.Whitespaces trimBeforeConsume=lang.Whitespaces.Keep)
 
Substring ConsumeField (char startChar, char endChar, Substring target, lang.Whitespaces trimBeforeConsume=lang.Whitespaces.Keep)
 
bool ConsumeDecDigits (out ulong result)
 
bool ConsumeDecDigits (out int result)
 
bool ConsumeInt (out long result, NumberFormat numberFormat=null)
 
bool ConsumeInt (out int result, NumberFormat numberFormat=null)
 
bool ConsumeDec (out ulong result, NumberFormat numberFormat=null)
 
bool ConsumeDec (out uint result, NumberFormat numberFormat=null)
 
bool ConsumeBin (out ulong result, NumberFormat numberFormat=null)
 
bool ConsumeBin (out uint result, NumberFormat numberFormat=null)
 
bool ConsumeHex (out ulong result, NumberFormat numberFormat=null)
 
bool ConsumeHex (out uint result, NumberFormat numberFormat=null)
 
bool ConsumeOct (out ulong result, NumberFormat numberFormat=null)
 
bool ConsumeOct (out uint result, NumberFormat numberFormat=null)
 
bool ConsumeFloat (out double result, NumberFormat numberFormat=null)
 
Substring Split (int position, Substring target, int separatorWidth=0)
 
Search

int IndexOf (char needle, int startIdx=0)
 
int IndexOfOrLength (char needle)
 
int IndexOfOrLength (char needle, int startIdx)
 
int IndexOf (String needle, int startIdx=0, Case sensitivity=Case.Sensitive)
 
int IndexOf (AString needle, int startIdx=0, Case sensitivity=Case.Sensitive)
 
int IndexOf (Substring needle, int startIdx=0, Case sensitivity=Case.Sensitive)
 
int IndexOfFirstDifference (String needle, Case sensitivity=Case.Sensitive, int startIdx=0)
 
int IndexOfAny (char[] needles, Inclusion inclusion, int startIdx=0)
 
int LastIndexOfAny (char[] needles, Inclusion inclusion, int startIdx=int.MaxValue)
 
Comparison

int CompareTo (String needle, Case sensitivity=Case.Sensitive, int needleRegionStart=0, int needleRegionLength=int.MaxValue, int regionStart=0, int regionLength=int.MaxValue)
 
int CompareTo (AString needle, Case sensitivity=Case.Sensitive, int needleRegionStart=0, int needleRegionLength=int.MaxValue, int regionStart=0, int regionLength=int.MaxValue)
 
int CompareTo (char[] needle, Case sensitivity=Case.Sensitive, int needleRegionStart=0, int needleRegionLength=int.MaxValue, int regionStart=0, int regionLength=int.MaxValue)
 
int CompareTo (Substring needle, Case sensitivity=Case.Sensitive, int regionStart=0, int regionLength=int.MaxValue)
 
bool ContainsAt (String needle, int pos, Case sensitivity=Case.Sensitive)
 
bool ContainsAt (char[] needle, int needleStart, int needleLength, int pos, Case sensitivity=Case.Sensitive)
 
bool ContainsAt (AString needle, int pos, Case sensitivity=Case.Sensitive)
 
bool ContainsAt (Substring needle, int pos, Case sensitivity=Case.Sensitive)
 
override bool Equals (Object o)
 
bool Equals (AString compareString, Case sensitivity=Case.Sensitive)
 
bool Equals (String compareString, Case sensitivity=Case.Sensitive)
 
bool Equals (Substring compareString, Case sensitivity=Case.Sensitive)
 
bool Equals (Object compareString, Case sensitivity=Case.Sensitive)
 
bool StartsWith (String needle, Case sensitivity=Case.Sensitive)
 
bool StartsWith (AString needle, Case sensitivity=Case.Sensitive)
 
bool StartsWith (Substring needle, Case sensitivity=Case.Sensitive)
 
bool EndsWith (String needle, Case sensitivity=Case.Sensitive)
 
bool EndsWith (AString needle, Case sensitivity=Case.Sensitive)
 
bool EndsWith (Substring needle, Case sensitivity=Case.Sensitive)
 
Trim

Substring TrimStart (char[] whiteSpaces)
 
Substring TrimStart ()
 
Substring TrimEnd (char[] whiteSpaces)
 
Substring TrimEnd ()
 
Substring Trim (char[] whiteSpaces)
 
Substring Trim ()
 
Conversion

void CopyTo (AString target, bool append=false)
 
override String ToString ()
 
String ToString (int regionStart, int regionLength=int.MaxValue)
 
C# std library interface implementation

override int GetHashCode ()
 

Protected Fields

int hash =0
 

Constructor & Destructor Documentation

◆ Substring() [1/5]

Substring ( )
inline

Empty Constructor. Sets this sub-string to 'null'

◆ Substring() [2/5]

Substring ( String  src,
int  start = 0,
int  length = -1 
)
inline

Constructs the Substring on the given String. The String's data is copied. To avoid memory allocations (for copy operation) it is preferred to use an AString as input wherever appropriate.

Parameters
srcThe string we work with.
startThe start index of the substring within the given String.
lengthThe number of characters to include from the given String. If negative, length of the provided src is used. Defaults to -1.

◆ Substring() [3/5]

Substring ( Substring  src,
int  start = 0,
int  length = -1 
)
inline

Copy constructor.

Parameters
srcThe substring to copy.
startThe start index of the substring within the given Substring.
lengthThe number of characters to include from the given Substring. If negative, length of the provided src is used. Defaults to -1.

◆ Substring() [4/5]

Substring ( AString  src,
int  start = 0,
int  length = -1 
)
inline

Constructs the Substring on the given AString. Start and end markers will be cover all of AString. start and the end of the given AString.

Parameters
srcThe string we work with.
startThe start index of the substring within the given AString.
lengthThe number of characters to include from the given AString. If negative, length of the provided src is used. Defaults to -1.

◆ Substring() [5/5]

Substring ( char[]  cstring,
int  start = 0,
int  length = -1 
)
inline

Constructs the sub-string to work on the provided character array.

Parameters
cstringThe character array to work on.
startThe start index of the substring within the given character array. If negative, the character array is
lengthThe number of characters to include from the given character array. If negative, the character array is assumed to be zero terminated and its length is evaluated using the strlen() function from the standard C library.
Defaults to -1.

Member Function Documentation

◆ CharAt()

char CharAt ( int  n)
inline

Retrieve the n-th character in the substring.

Parameters
nThe offset of the requested character.
Returns
The n-th character start of the represented region. If this Substring empty or nulled, or if n is out of bounds, '\0' is returned.

◆ CharAtEnd() [1/2]

char CharAtEnd ( )
inline

Retrieve the last character in the substring.

Returns
The character at the start of the represented region. If this Substring empty or nulled, '\0' is returned.

◆ CharAtEnd() [2/2]

char CharAtEnd ( int  n)
inline

Retrieve the n-th character in the substring, counted from the back.

Parameters
nThe offset of the requested character. Attention: n is subtracted from the end. In other words, positive values peek towards the start of the region.
Returns
The n-th character counted from the end of the represented region backwards. If this Substring empty or nulled, or if n is out of bounds, '\0' is returned.

◆ CharAtStart()

char CharAtStart ( )
inline

Retrieve the first character in the substring.

Returns
The character at the start of the represented region. If this Substring empty or nulled, '\0' is returned.

◆ Clear()

void Clear ( )
inline

Sets the represented region to zero length by setting end to start -1.

◆ CompareTo() [1/4]

int CompareTo ( AString  needle,
Case  sensitivity = Case.Sensitive,
int  needleRegionStart = 0,
int  needleRegionLength = int.MaxValue,
int  regionStart = 0,
int  regionLength = int.MaxValue 
)
inline

Compares a given region of a given string with a region of this instance. Regions that are out of bounds get adjusted and then compared.

Parameters
needleAn object of type AString that is compared to this.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
needleRegionStartThe start of the substring within the given string that is to be compared to this. Defaults to 0.
needleRegionLengthThe length of the substring within the given string that is to be compared to this. Defaults to Integer.MAX_VALUE.
regionStartThe start of the substring within this string that is to be compared. Defaults to 0.
regionLengthThe length of the substring within this string that is to be compared. Defaults to Integer.MAX_VALUE.
Returns
  • 0 if this and needle are nulled or if both have a length of 0 or if both share the same content
  • <0 if this is nulled and needle is not or if this is smaller than needle.
  • >0 if this is not nulled but needle is or if this is greater than needle.

◆ CompareTo() [2/4]

int CompareTo ( char[]  needle,
Case  sensitivity = Case.Sensitive,
int  needleRegionStart = 0,
int  needleRegionLength = int.MaxValue,
int  regionStart = 0,
int  regionLength = int.MaxValue 
)
inline

Compares a given region of a given string with a region of this instance. Regions that are out of bounds get adjusted and then compared.

Parameters
needleAn object of type char[] that is compared to this.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
needleRegionStartThe start of the substring within the given string that is to be compared to this. Defaults to 0.
needleRegionLengthThe length of the substring within the given string that is to be compared to this. Defaults to Integer.MAX_VALUE.
regionStartThe start of the substring within this string that is to be compared. Defaults to 0.
regionLengthThe length of the substring within this string that is to be compared. Defaults to Integer.MAX_VALUE.
Returns
  • 0 if this and needle are nulled or if both have a length of 0 or if both share the same content
  • <0 if this is nulled and needle is not or if this is smaller than needle.
  • >0 if this is not nulled but needle is or if this is greater than needle.

◆ CompareTo() [3/4]

int CompareTo ( String  needle,
Case  sensitivity = Case.Sensitive,
int  needleRegionStart = 0,
int  needleRegionLength = int.MaxValue,
int  regionStart = 0,
int  regionLength = int.MaxValue 
)
inline

Compares a given region of a given string with a region of this instance. Regions that are out of bounds get adjusted and then compared.

Parameters
needleAn object of type String that is compared to this.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
needleRegionStartThe start of the substring within the given string that is to be compared to this. Defaults to 0.
needleRegionLengthThe length of the substring within the given string that is to be compared to this. Defaults to Integer.MAX_VALUE.
regionStartThe start of the substring within this string that is to be compared. Defaults to 0.
regionLengthThe length of the substring within this string that is to be compared. Defaults to Integer.MAX_VALUE.
Returns
  • 0 if this and needle are nulled or if both have a length of 0 or if both share the same content
  • <0 if this is nulled and needle is not or if this is smaller than needle.
  • >0 if this is not nulled but needle is or if this is greater than needle.

◆ CompareTo() [4/4]

int CompareTo ( Substring  needle,
Case  sensitivity = Case.Sensitive,
int  regionStart = 0,
int  regionLength = int.MaxValue 
)
inline

Compares a Substring with a region of this instance. The region bounds get adjusted to fit to this AString. (If this is not wanted, external checks have to be made prior to calling this method.)

Parameters
needleAn object of type char[] that is compared to this.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
regionStartThe start of the substring within this string that is to be compared. Defaults to 0.
regionLengthThe length of the substring within this string that is to be compared. Defaults to Integer.MAX_VALUE.
Returns
  • 0 if this and needle are nulled or if both have a length of 0 or if both share the same content
  • <0 if this is nulled and needle is not or if this is smaller than needle.
  • >0 if this is not nulled but needle is or if this is greater than needle.

◆ ConsumeBin() [1/2]

bool ConsumeBin ( out uint  result,
NumberFormat  numberFormat = null 
)
inline

Overloaded version of ConsumeBin(out ulong,NumberFormat =) accepting an uint value.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeBin() [2/2]

bool ConsumeBin ( out ulong  result,
NumberFormat  numberFormat = null 
)
inline

Reads an unsigned 64-bit integer in binary format at the given position from this AString. This is done, by invoking NumberFormat.ParseBin on the given numberFormat instance.
Parameter numberFormat defaults to null. This denotes static singleton NumberFormat.Computational which is configured to not using - and therefore also not parsing - grouping characters.

For more information on number conversion, see class NumberFormat.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeChar() [1/2]

char ConsumeChar ( )
inline

Retrieve and remove the first character in the substring.

Returns
The character at the start of the represented region. If this Substring empty or nulled, '\0' is returned.

◆ ConsumeChar() [2/2]

bool ConsumeChar ( char  consumable,
Case  sensitivity = Case.Sensitive,
Whitespaces  trimBeforeConsume = Whitespaces.Keep 
)
inline

Checks if this object starts with the given character consumable. If it does, this character is cut from this object.

Parameters
consumableThe consumable character
sensitivityThe sensitivity of the comparison.
trimBeforeConsumeDetermines if the string should be (left-) trimmed before the consume operation. Defaults to Whitespaces.Keep.
Returns
true, if this object was starting with consumable and consequently the string was cut by one.

◆ ConsumeCharFromEnd() [1/2]

char ConsumeCharFromEnd ( )
inline

Retrieve and remove the last character in the substring.

Returns
The character at the start of the represented region. If this Substring empty or nulled, '\0' is returned.

◆ ConsumeCharFromEnd() [2/2]

bool ConsumeCharFromEnd ( char  consumable,
Case  sensitivity = Case.Sensitive,
Whitespaces  trimBeforeConsume = Whitespaces.Keep 
)
inline

Checks if this object ends with the given character consumable. If it does, this character is cut from the end of object.

Parameters
consumableThe consumable character
sensitivityThe sensitivity of the comparison.
trimBeforeConsumeDetermines if the string should be (right-) trimmed before the consume operation. Defaults to Whitespaces.Keep.
Returns
true, if this object was starting with consumable and consequently the string was cut by one.

◆ ConsumeChars()

int ConsumeChars ( int  regionLength,
Substring  target = null 
)
inline

Cuts the given number of characters from the beginning of the Substring and optionally places the portion that was cut in parameter target (if provided).
Parameter regionLength is checked to be between 0 and length. If negative, nothing is cut and target is set empty. If regionLength is greater than this objects' length, all contents is 'moved' to target.

Parameters
regionLengthThe length of the region at the start to delete.
targetAn optional target Substring that receives the portion that is cut from this object. Defaults to null.
Returns
The new length of the substring.

◆ ConsumeCharsFromEnd()

int ConsumeCharsFromEnd ( int  regionLength,
Substring  target = null 
)
inline

Cuts the given number of characters from the end of the Substring and optionally places the portion that was cut in parameter target (if provided).
Parameter regionLength is checked to be between 0 and length. If negative, nothing is cut and target is set empty. If regionLength is greater than this objects' length, all contents is 'moved' to target.

Parameters
regionLengthThe length of the region at the start to delete.
targetAn optional target Substring that receives the portion that is cut from this object. Defaults to null.
Returns
The new length of the substring.

◆ ConsumeDec() [1/2]

bool ConsumeDec ( out uint  result,
NumberFormat  numberFormat = null 
)
inline

Overloaded version of ConsumeDec(out ulong,NumberFormat =) accepting an uint value.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeDec() [2/2]

bool ConsumeDec ( out ulong  result,
NumberFormat  numberFormat = null 
)
inline

Reads an unsigned 64-bit integer in standard decimal format at the given position from this AString. This is done, by invoking NumberFormat.ParseDec on the given numberFormat instance.
Parameter numberFormat defaults to null. This denotes static singleton NumberFormat.Computational which is configured to not using - and therefore also not parsing - grouping characters.

Sign literals '-' or '+' are not accepted and parsing will fail. For reading signed integer values, see methods ConsumeInt, for floating point numbers ConsumeFloat.

For more information on number conversion, see class NumberFormat.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeDecDigits() [1/2]

bool ConsumeDecDigits ( out int  result)
inline

Overloaded version of ConsumeDecDigits(out ulong) accepting an int value.

Parameters
[out]resultA reference to the result value.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeDecDigits() [2/2]

bool ConsumeDecDigits ( out ulong  result)
inline

Consumes all characters '0' to '9' at the start of this object and stores the number value they represent in result.
Unlike with ConsumeInt or ConsumeDec, no sign, whitespaces or group characters are consumed.

Parameters
[out]resultA reference to the result value.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeField()

Substring ConsumeField ( char  startChar,
char  endChar,
Substring  target,
lang.Whitespaces  trimBeforeConsume = lang.Whitespaces.Keep 
)
inline

Consumes a field from the beginning of this substring, which is surrounded by given start end end character identifiers. If both are the same, e.g. '"', then the first occurrence of the end character is used. If they are not the same, e.g. '<' and '>', then repeated start characters are counted and consumption only ends when a corresponding amount of end characters has been found.

Parameters
startCharThe start character of the field to consume.
endCharThe end character of the field to consume.
targetThe target string to place the field in.
trimBeforeConsumeDetermines if the string should be (left-) trimmed before the consume operation. Defaults to Whitespaces.Keep.
Returns
The string consumed. NullString on error (start/end character not found)

◆ ConsumeFloat()

bool ConsumeFloat ( out double  result,
NumberFormat  numberFormat = null 
)
inline

Reads a floating point number at the given position from this AString. This is done, by invoking NumberFormat.ParseFloat on the given numberFormat instance.
Parameter numberFormat defaults to null. This denotes static singleton NumberFormat.Computational which is configured to 'international' settings (not using the locale) and therefore also not parsing grouping characters.

For more information on parsing options for floating point numbers and number conversion in general, see class NumberFormat.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeHex() [1/2]

bool ConsumeHex ( out uint  result,
NumberFormat  numberFormat = null 
)
inline

Overloaded version of ConsumeHex(out ulong,NumberFormat =) accepting an uint value.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeHex() [2/2]

bool ConsumeHex ( out ulong  result,
NumberFormat  numberFormat = null 
)
inline

Reads an unsigned 64-bit integer in hexadecimal format at the given position from this AString. This is done, by invoking NumberFormat.ParseHex on the given numberFormat instance.
Parameter numberFormat defaults to null. This denotes static singleton NumberFormat.Computational which is configured to not using - and therefore also not parsing - grouping characters.

For more information on number conversion, see class NumberFormat.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeInt() [1/2]

bool ConsumeInt ( out int  result,
NumberFormat  numberFormat = null 
)
inline

Overloaded version of ConsumeInt(out long,NumberFormat =) accepting an int value.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeInt() [2/2]

bool ConsumeInt ( out long  result,
NumberFormat  numberFormat = null 
)
inline

Parses a long integer value in decimal, binary, hexadecimal or octal format from the string by invoking method NumberFormat.ParseInt on the given numberFormat instance.
Parameter numberFormat defaults to null. This denotes static singleton NumberFormat.Computational which is configured to not using - and therefore also not parsing - grouping characters.

For more information on number conversion, see class NumberFormat.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeOct() [1/2]

bool ConsumeOct ( out uint  result,
NumberFormat  numberFormat = null 
)
inline

Overloaded version of ConsumeOct(out ulong,NumberFormat =) accepting an uint value.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumeOct() [2/2]

bool ConsumeOct ( out ulong  result,
NumberFormat  numberFormat = null 
)
inline

Reads an unsigned 64-bit integer in octal format at the given position from this AString. This is done, by invoking NumberFormat.ParseOct on the given numberFormat instance.
Parameter numberFormat defaults to null. This denotes static singleton NumberFormat.Computational which is configured to not using - and therefore also not parsing - grouping characters.

For more information on number conversion, see class NumberFormat.

Parameters
[out]resultA reference to the result value.
numberFormatDefines the input format. Optional and defaults to null.
Returns
true if a number was consumed, false otherwise.

◆ ConsumePartOf()

int ConsumePartOf ( String  consumable,
int  minChars = 1,
lang.Case  sensitivity = lang.Case.Ignore,
lang.Whitespaces  trimBeforeConsume = lang.Whitespaces.Keep 
)
inline

Consumes a minimum of minChars of string consumable from the start of this substring. If the minimum characters could not be found, nothing is consumed, otherwise as much as possible.
This method is useful for example to read commands from a string that may be abbreviated.

Parameters
consumableThe consumable string.
minCharsThe minimum amount of characters to consume. If 0 or negative, the length of consumable is chosen. Optional and defaults to 1.
sensitivityThe sensitivity of the comparison. Defaults to Case.Ignore.
trimBeforeConsumeDetermines if the string should be (left-) trimmed before the first character consume operation. Defaults to Whitespaces.Keep.
Returns
The amount of characters consumed.

◆ ConsumeString() [1/3]

bool ConsumeString ( AString  consumable,
Case  sensitivity = Case.Sensitive,
Whitespaces  trimBeforeConsume = Whitespaces.Keep 
)
inline

Checks if this object starts with the given string consumable. If it does, this string is cut from this object.

Parameters
consumableThe consumable string
sensitivityThe sensitivity of the comparison.
trimBeforeConsumeDetermines if the string should be (left-) trimmed before the consume operation. Defaults to Whitespaces.Keep.
Returns
true, if this object was starting with consumable and consequently the string was cut.

◆ ConsumeString() [2/3]

bool ConsumeString ( String  consumable,
Case  sensitivity = Case.Sensitive,
Whitespaces  trimBeforeConsume = Whitespaces.Keep 
)
inline

Checks if this object starts with the given string consumable. If it does, this string is cut from this object.

Parameters
consumableThe consumable string
sensitivityThe sensitivity of the comparison.
trimBeforeConsumeDetermines if the string should be (left-) trimmed before the consume operation. Defaults to Whitespaces.Keep.
Returns
true, if this object was starting with consumable and consequently the string was cut.

◆ ConsumeString() [3/3]

bool ConsumeString ( Substring  consumable,
Case  sensitivity = Case.Sensitive,
Whitespaces  trimBeforeConsume = Whitespaces.Keep 
)
inline

Checks if this object starts with the given string consumable. If it does, this string is cut from this object.

Parameters
consumableThe consumable string
sensitivityThe sensitivity of the comparison.
trimBeforeConsumeDetermines if the string should be (left-) trimmed before the consume operation. Defaults to Whitespaces.Keep.
Returns
true, if this object was starting with consumable and consequently the string was cut.

◆ ConsumeStringFromEnd() [1/3]

bool ConsumeStringFromEnd ( AString  consumable,
Case  sensitivity = Case.Sensitive,
Whitespaces  trimBeforeConsume = Whitespaces.Keep 
)
inline

Checks if this object ends with the given string consumable. If it does, this string is cut from the end of object.

Parameters
consumableThe consumable string
sensitivityThe sensitivity of the comparison.
trimBeforeConsumeDetermines if the string should be (right-) trimmed before the consume operation. Defaults to Whitespaces.Keep.
Returns
true, if this object was starting with consumable and consequently the string was cut.

◆ ConsumeStringFromEnd() [2/3]

bool ConsumeStringFromEnd ( String  consumable,
Case  sensitivity = Case.Sensitive,
Whitespaces  trimBeforeConsume = Whitespaces.Keep 
)
inline

Checks if this object ends with the given string consumable. If it does, this string is cut from the end of object.

Parameters
consumableThe consumable string
sensitivityThe sensitivity of the comparison.
trimBeforeConsumeDetermines if the string should be (right-) trimmed before the consume operation. Defaults to Whitespaces.Keep.
Returns
true, if this object was starting with consumable and consequently the string was cut.

◆ ConsumeStringFromEnd() [3/3]

bool ConsumeStringFromEnd ( Substring  consumable,
Case  sensitivity = Case.Sensitive,
Whitespaces  trimBeforeConsume = Whitespaces.Keep 
)
inline

Checks if this object ends with the given string consumable. If it does, this string is cut from the end of object.

Parameters
consumableThe consumable string
sensitivityThe sensitivity of the comparison.
trimBeforeConsumeDetermines if the string should be (right-) trimmed before the consume operation. Defaults to Whitespaces.Keep.
Returns
true, if this object was starting with consumable and consequently the string was cut.

◆ ConsumeToken()

int ConsumeToken ( Substring  target,
char  separator = ',' 
)
inline

Searches separator and cuts the beginning of this string, including the separator. What was consumed is returned, excluding the separator.

If the separator is not found, all of this string is consumed and returned.

Parameters
targetThe target substring.
separatorThe separator to search. Defaults to ','.
Returns
The number of characters consumed.

◆ ContainsAt() [1/4]

bool ContainsAt ( AString  needle,
int  pos,
Case  sensitivity = Case.Sensitive 
)
inline

Checks if the given AString is located at the given position.

Parameters
needleThe AString to search.
posThe position to look at.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
True if the given AString is found at the given position. False otherwise.

◆ ContainsAt() [2/4]

bool ContainsAt ( char[]  needle,
int  needleStart,
int  needleLength,
int  pos,
Case  sensitivity = Case.Sensitive 
)
inline

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

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.
posThe position to look at.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
True if the given AString is found at the given position. False otherwise.

◆ ContainsAt() [3/4]

bool ContainsAt ( String  needle,
int  pos,
Case  sensitivity = Case.Sensitive 
)
inline

Checks if the given String is located at the given position.

Parameters
needleThe string to search.
posThe position to look at.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
True if the given sequence is found at the given position. False otherwise .

◆ ContainsAt() [4/4]

bool ContainsAt ( Substring  needle,
int  pos,
Case  sensitivity = Case.Sensitive 
)
inline

Checks if the given AString is located at the given position.

Parameters
needleThe AString to search.
posThe position to look at.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
True if the given AString is found at the given position. False otherwise.

◆ CopyTo()

void CopyTo ( AString  target,
bool  append = false 
)
inline

Copies the string region represented by this object into the given AString

Parameters
targetThe target AString to copy the region this object represents to.
appendIf true, the target AString is not cleared. Defaults to false.

◆ EndsWith() [1/3]

bool EndsWith ( AString  needle,
Case  sensitivity = Case.Sensitive 
)
inline

Checks if this AString ends with the given AString.

Parameters
needleThe AString to be compared with the start of this AString. If this is null or empty, true is returned.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true if this starts with the given AString, false if not.

◆ EndsWith() [2/3]

bool EndsWith ( String  needle,
Case  sensitivity = Case.Sensitive 
)
inline

Checks if this String ends with the given String.

Parameters
needleThe string to be compared with the start of this AString. If this is null or empty, true is returned.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true if this starts with the given String, false if not.

◆ EndsWith() [3/3]

bool EndsWith ( Substring  needle,
Case  sensitivity = Case.Sensitive 
)
inline

Checks if this AString ends with the given Substring.

Parameters
needleThe Substring to be compared with the start of this AString. If this is null or empty, true is returned.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true if this starts with the given Substring, false if not.

◆ Equals() [1/5]

bool Equals ( AString  compareString,
Case  sensitivity = Case.Sensitive 
)
inline

Tests and returns true, if the given AString equals to what this object represents. True is returned if both are zero length or null.

Parameters
compareStringThe AString that is compared to this AString.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true, if contents of this and the given AString are equal

◆ Equals() [2/5]

bool Equals ( Object  compareString,
Case  sensitivity = Case.Sensitive 
)
inline

Tests and returns true, if the given string-type object equals to what this object represents. True is returned if both are zero length or null. If compiled in debug mode, an assertion is thrown if the given object is not of type String, AString, Substring or char[].

Parameters
compareStringAn object of string-type that is compared to this AString.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true, if contents of this and the given Substring are equal

◆ Equals() [3/5]

override bool Equals ( Object  o)
inline

Compares this to the given object. Given object can be AString or String.

Parameters
oThe Object that this instance is compared with.
Returns
True if given object equals this.

◆ Equals() [4/5]

bool Equals ( String  compareString,
Case  sensitivity = Case.Sensitive 
)
inline

Tests and returns true, if the given String equals to what this object represents. True is returned if both are zero length or null.

Parameters
compareStringThe AString that is compared to this AString.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true, if contents of this and the given AString are equal

◆ Equals() [5/5]

bool Equals ( Substring  compareString,
Case  sensitivity = Case.Sensitive 
)
inline

Tests and returns true, if the given Substring equals to what this object represents. True is returned if both are zero length or null.

Parameters
compareStringThe Substring that is compared to this AString.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true, if contents of this and the given Substring are equal

◆ GetHashCode()

override int GetHashCode ( )
inline

Calculates the hash value using the same formula as java.lang.String.

Returns
A hash value for this object.

◆ IndexOf() [1/4]

int IndexOf ( AString  needle,
int  startIdx = 0,
Case  sensitivity = Case.Sensitive 
)
inline

Search the given AString in the this.

Parameters
needleThe String to search.
startIdxThe index to start the search at. Optional and defaults to 0.
sensitivityIf true, the compare is case insensitive. Optional and defaults to false.
Returns
-1 if the string is not found. Otherwise the index of first occurrence.

◆ IndexOf() [2/4]

int IndexOf ( char  needle,
int  startIdx = 0 
)
inline

Searches the given character.

Parameters
needleThe character to search.
startIdxThe index to start the search at. Optional and defaults to 0.
Returns
The index of the character within this substring, -1 if the character is not found.

◆ IndexOf() [3/4]

int IndexOf ( String  needle,
int  startIdx = 0,
Case  sensitivity = Case.Sensitive 
)
inline

Search the given String in this.

Parameters
needleThe String to search.
startIdxThe index to start the search at. Optional and defaults to 0.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
-1 if the String is not found. Otherwise the index of first occurrence.

◆ IndexOf() [4/4]

int IndexOf ( Substring  needle,
int  startIdx = 0,
Case  sensitivity = Case.Sensitive 
)
inline

Search the given Substring in the this.

Parameters
needleThe string to search.
startIdxThe index to start the search at. Optional and defaults to 0.
sensitivityIf true, the compare is case insensitive. Optional and defaults to false.
Returns
-1 if the string is not found. Otherwise the index of first occurrence.

◆ IndexOfAny()

int IndexOfAny ( char[]  needles,
Inclusion  inclusion,
int  startIdx = 0 
)
inline

Returns the index of the first character which is included, respectively not included in a given set of characters.

This method searches from left to right. For reverse search, see LastIndexOfAny.

Parameters
needlesAString with 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.
startIdxThe index to start the search at. If the given value is less than 0, it is set to 0. If it exceeds the length of the string, the length of the string is returned. Defaults to 0.
Returns
The index 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()

int IndexOfFirstDifference ( String  needle,
Case  sensitivity = Case.Sensitive,
int  startIdx = 0 
)
inline

Searches the first difference with given string. If this string starts with needle, then the length of needle is returned.

Parameters
needleThe String to search.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
startIdxThe index to start the search at. Optional and defaults to 0.
Returns
The index of the first difference found in needle or the neele's length.

◆ IndexOfOrLength() [1/2]

int IndexOfOrLength ( char  needle)
inline

Like IndexOf but in case the character is not found, this method returns the length of this string instead of -1. Depending on the invocation context, the choice for the right version of this method may lead to shorter and more efficient code.

Parameters
needleThe character to search for.
Returns
This strings Length if the character needle is not found. Otherwise the index of first occurrence.

◆ IndexOfOrLength() [2/2]

int IndexOfOrLength ( char  needle,
int  startIdx 
)
inline

Like IndexOf but in case the character is not found, this method returns the length of this string instead of -1. Depending on the invocation context, the choice for the right version of this method may lead to shorter and more efficient code.

Parameters
needleThe character to search for.
startIdxThe index in this to start searching the character.
Returns
This strings Length if the character needle is not found. Otherwise the index of first occurrence.

◆ IsEmpty()

bool IsEmpty ( )
inline

Checks if represented region has a length of zero.

Returns
true if the represented region is empty.

◆ IsNotEmpty()

bool IsNotEmpty ( )
inline

Checks if the represented region has a length of more than zero.

Returns
true if the length of the substring represented does not equal zero.

◆ IsNotNull()

bool IsNotNull ( )
inline

Returns
true if this represents a null string

◆ IsNull()

bool IsNull ( )
inline

Returns
true if this represents a null string

◆ LastIndexOfAny()

int LastIndexOfAny ( char[]  needles,
Inclusion  inclusion,
int  startIdx = int.MaxValue 
)
inline

Returns the index of the first character which is included, respectively not included in a given set of characters. The search starts at the given index and goes backward. For forward search, see IndexOfAny.

Parameters
needlesAString with 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.
startIdxThe index to start the search at. The value is cropped to be in the bounds of 0 and the length of this AString minus one. Defaults to maximum integer value.
Returns
The index of the first character found which is included, respectively not included, in the given set of characters. If nothing is found, -1 is returned.

◆ Length()

int Length ( )
inline

Returns
The length of the represented region.

◆ Set() [1/6]

Substring Set ( AString  src)
inline

Sets the substring to represent the given AString.

Parameters
srcThe AString to work on.
Returns
this to allow concatenated calls.

◆ Set() [2/6]

Substring Set ( AString  src,
int  start 
)
inline

Sets the substring to represent a region of the given AString.

Parameters
srcThe AString to work on.
startThe start index of the substring within the given AString. Defaults to 0.
Returns
this to allow concatenated calls.

◆ Set() [3/6]

Substring Set ( AString  src,
int  start,
int  length 
)
inline

Sets the substring to represent a region of the given AString.

Parameters
srcThe AString to work on.
startThe start index of the substring within the given AString.
lengthThe number of characters to include from the given AString. If negative, length of the provided src is used.
Returns
this to allow concatenated calls.

◆ Set() [4/6]

Substring Set ( char[]  src,
int  start = 0,
int  length = -1 
)
inline

Resets the sub-string to work on the provided character array.

Parameters
srcThe character array to work on.
startThe start index of the substring within the given character array.
lengthThe number of characters to include from the given character array. If negative, length of the provided src is used. Defaults to -1.
Returns
this to allow concatenated calls.

◆ Set() [5/6]

Substring Set ( String  src,
int  start = 0,
int  length = -1 
)
inline

Sets the substring to represent a region of the given String.

Parameters
srcThe string we work with.
startThe start index of the substring within the given String.
lengthThe number of characters to include from the given String.. If negative, length of the provided src is used. Defaults to -1.
Returns
this to allow concatenated calls.

◆ Set() [6/6]

Substring Set ( Substring  src,
int  regionStart = 0,
int  regionLength = -1 
)
inline

Sets the substring to represent a region of the given Substring.

Parameters
srcThe substring to copy from.
regionStartThe start of the region within src. Defaults to 0.
regionLengthThe length of the region within src. If negative, length of the provided src is used. Defaults to -1.
Returns
this to allow concatenated calls.

◆ SetNull()

void SetNull ( )
inline

Sets this to null state and in addition to empty state.

◆ Split()

Substring Split ( int  position,
Substring  target,
int  separatorWidth = 0 
)
inline

Splits this substring into two parts. What remains in this object is the region from 0 to position. target receives the rest. If separatorWidth is given, this is subtracted from the front of target.

Parameters
positionThe index where this object is split.
targetThe target substring to receive the right part of the string.
separatorWidthThis does not change what remains in this object, but defines the number of characters that are cut from the front of the target. Defaults to 0.
Returns
this to allow concatenated calls.

◆ StartsWith() [1/3]

bool StartsWith ( AString  needle,
Case  sensitivity = Case.Sensitive 
)
inline

Checks if this AString starts with the given String.

Parameters
needleThe AString to search. If s is null or empty, false is returned.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true if this starts with the given AString, false if not.

◆ StartsWith() [2/3]

bool StartsWith ( String  needle,
Case  sensitivity = Case.Sensitive 
)
inline

Checks if this AString starts with the given String.

Parameters
needleThe String to search. If s is null or empty, false is returned.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true if this starts with the given sequence, false if not.

◆ StartsWith() [3/3]

bool StartsWith ( Substring  needle,
Case  sensitivity = Case.Sensitive 
)
inline

Checks if this AString starts with the given Substring.

Parameters
needleThe Substring to search. If s is null or empty, false is returned.
sensitivityCase sensitivity of the comparison. Optional and defaults to Case.Sensitive.
Returns
true if this starts with the given Substring, false if not.

◆ ToString() [1/2]

override String ToString ( )
inline

Overrides Object.ToString(). Copies the string region represented by this object into a new string.

Returns
A String with the contents of this sub-string.

◆ ToString() [2/2]

String ToString ( int  regionStart,
int  regionLength = int.MaxValue 
)
inline

Creates a String containing a copy of a region of the this Substring.

Parameters
regionStartThe start index of the region in this to create the string from.
regionLengthThe maximum length of the region to create the string from. Defaults to int.MaxValue.
Returns
A String that represents the specified sub region of this object.

◆ Trim() [1/2]

Substring Trim ( )
inline

Invokes Trim(char[] whiteSpaces) providing default parameter CString.DefaultWhitespaces.

Returns
this to allow concatenated calls.

◆ Trim() [2/2]

Substring Trim ( char[]  whiteSpaces)
inline

Invokes TrimStart and TrimEnd .

Parameters
whiteSpacesThe characters used for trimming. Defaults to CString.DefaultWhitespaces.
Returns
this to allow concatenated calls.

◆ TrimEnd() [1/2]

Substring TrimEnd ( )
inline

Invokes TrimEnd(char[] whiteSpaces) providing default parameter CString.DefaultWhitespaces.

Returns
this to allow concatenated calls.

◆ TrimEnd() [2/2]

Substring TrimEnd ( char[]  whiteSpaces)
inline

Moves the start marker to the first character not found in parameter whiteSpaces.

Parameters
whiteSpacesThe characters used for trimming. Defaults to CString.DefaultWhitespaces.
Returns
this to allow concatenated calls.

◆ TrimStart() [1/2]

Substring TrimStart ( )
inline

Invokes TrimStart(char[] whiteSpaces) providing default parameter CString.DefaultWhitespaces.

Returns
this to allow concatenated calls.

◆ TrimStart() [2/2]

Substring TrimStart ( char[]  whiteSpaces)
inline

Moves the start marker to the first character not found in parameter whiteSpaces.

Parameters
whiteSpacesThe characters used for trimming. Defaults to CString.DefaultWhitespaces.
Returns
this to allow concatenated calls.

Member Data Documentation

◆ Buf

char [] Buf

The character array we work on.

◆ End

int End

End marker within buf (points to the last character)

◆ hash

int hash =0
protected

The hash value. Has to be set dirty (0) whenever String is changed from outside!.

◆ Start

int Start

Start marker within buf


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