namespace sys.core.lang
class String
A dynamic string class that uses Utf8 as an encoding scheme.
Using a subset of the API it can be used to represent simple 8 bit strings instead of Unicode strings.
this{data: Char};
this{chars: Slice};
this{chars: String, len: PtrSize};
this{chars: String, start: PtrSize, end: PtrSize};
this{chars: Ptr, len: PtrSize};
this{chars: Ptr, len: PtrSize, cap: PtrSize};
this{chars: CArray};
this{chars: CArray, len: PtrSize};
this{obj: String};
this{move obj: String};
Creates a new string based on input characters.
data | single input character |
---|---|
chars | input buffer |
len | length of the input buffer |
start | start position |
end | end position |
cap | capacity for the new buffer |
obj | string to copy/move from |
this FromIndex{chars: String, start: PtrSize};
this FromIndex{chars: String, start: PtrSize, end: PtrSize};
Creates a string based on substring defined by a `start` and optional `end` position.
chars | string |
---|---|
start | start position |
end | end position |
this TakeOwnership{chars: Ptr, len: PtrSize};
Takes ownership of an existing memory block of a given size.
chars | the memory block |
---|---|
len | the size of the memory block |
def @attr(obj: String);
def @attr(move obj: String);
Standard assignment/move operator.
obj | string to copy/move from |
---|
def Clear();
Sets the string to empty.
func @eq(second: String): Bool;
Compares two strings foe equality. Case sensitive.
second | string to compare against. |
---|
`true` if string are equal
func @neq(second: String): Bool;
Compares two strings foe inequality. Case sensitive.
second | string to compare against. |
---|
`true` if string are not equal
def @shl(ch: Char): ref String;
def @shl(str: String): ref String;
Appends a character or a string to the end of the instance.
ch | character to append |
---|---|
str | string to append |
`this` for chaining
def Insert(pos: PtrSize, string: String);
Inserts a `string` at a position `pos` into the current instance.
pos | position to insert at |
---|---|
string | string to insert |
func Inserted(pos: PtrSize, string: String): String;
Returns a new string with a `string` inserted at position `pos`.
pos | position to insert at |
---|---|
string | string to insert |
the new string
func Find(b: Byte): PtrSize;
func Find(b: Byte, start: PtrSize): PtrSize;
Searches for the first position a given Utf8 code-unit/8 byte character can be found at, starting at a given position.
Returns -1 if the item was not found.
b | item to search for |
---|---|
start | start position for the search |
index of the item
func FindFirst(b: CArray): PtrSize;
Searches for the first position a given Utf8 code-unit/8 byte character from an array of inputs can be found at, starting at a given position.
Returns -1 if the item was not found.
b | an array of inputs |
---|
index of the first found item
func RFind(b: Byte): PtrSize;
func RFind(b: Byte, start: PtrSize): PtrSize;
Searches in reverse order for the first position a given Utf8 code-unit/8 byte character can be found at, starting at a given position.
Returns -1 if the item was not found.
b | item to search for |
---|---|
start | start position for the search |
index of the item
func RFindFirst(b: CArray): PtrSize;
Searches for the first position a given Utf8 code-unit/8 byte character from an array of inputs can be found at, starting at a given position.
Returns -1 if the item was not found.
b | an array of inputs |
---|
index of the first found item
func Split(b: Byte): Vector;
Splits the string into a vector of substrings based delimited by the input Utf8 code-unit/8 byte character.
The searched for input is not included in the substrings.
b | character to search for |
---|
a vector of substrings
def Trim();
Removes any leading or trailing whitespace.
def TrimLeft();
Removes any leading whitespace.
def TrimRight();
Removes any trailing whitespace.
def Sub(start: PtrSize, end: PtrSize);
REtruns a substring contained between the `start` and `end` positions.
start | start position |
---|---|
end | end position |
func Trimmed(): String;
Returns a string with any leading or trailing whitespace.
trimmed string
func TrimmedLeft(): String;
Returns a string with any leading whitespace.
trimmed string
func TrimmedRight(): String;
Returns a string with any trailing whitespace.
trimmed string
func @write(ref stream: Stream);
func @write(ref stream: Stream, format: OutputFormat);
Writes the string to an Utf8 text stream.
Can use an optional output format specifier.
stream | the output stream |
---|---|
format | formatting information |
func @put(ref stream: Stream);
Writes the string to a binary stream by first writing the length then the actual data.
stream | the output stream |
---|
def @get(ref stream: Stream);
Reads the string from binary stream.
stream | the input stream |
---|
Parse(): T;
Parses a numeric of type `T` from the string, skipping whitespace.
ParseSaturated(): T;
Parses and saturates a numeric of type `T` from the string, skipping whitespace.
property Length: PtrSize
The length of the string.
property Capacity: PtrSize
THe amount of available storage capacity allocated for the string.
property @index: ref Byte; get;
Standard index operator.
property IsEmpty: Bool; get;
Returns true if the string has an Length of zero.
property SysDataPointer: Ptr; get;
Returns a pointer to the the raw data.
val GrowthSpacing;
A variable used to control the growth rate of the string.