class String

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.

Constructors

this

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};

Brief

Creates a new string based on input characters.

Parameters

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

FromIndex

this FromIndex{chars: String, start: PtrSize};
this FromIndex{chars: String, start: PtrSize, end: PtrSize};

Brief

Creates a string based on substring defined by a `start` and optional `end` position.

Parameters

chars string
start start position
end end position

TakeOwnership

this TakeOwnership{chars: Ptr, len: PtrSize};

Brief

Takes ownership of an existing memory block of a given size.

Parameters

chars the memory block
len the size of the memory block

Methods

@attr

def @attr(obj: String);
def @attr(move obj: String);

Brief

Standard assignment/move operator.

Parameters

obj string to copy/move from

Clear

def Clear();

Brief

Sets the string to empty.


@eq

func @eq(second: String): Bool;

Brief

Compares two strings foe equality. Case sensitive.

Parameters

second string to compare against.

Returns

`true` if string are equal

@neq

func @neq(second: String): Bool;

Brief

Compares two strings foe inequality. Case sensitive.

Parameters

second string to compare against.

Returns

`true` if string are not equal

@shl

def @shl(ch: Char): ref String;
def @shl(str: String): ref String;

Brief

Appends a character or a string to the end of the instance.

Parameters

ch character to append
str string to append

Returns

`this` for chaining

Insert

def Insert(pos: PtrSize, string: String);

Brief

Inserts a `string` at a position `pos` into the current instance.

Parameters

pos position to insert at
string string to insert

Inserted

func Inserted(pos: PtrSize, string: String): String;

Brief

Returns a new string with a `string` inserted at position `pos`.

Parameters

pos position to insert at
string string to insert

Returns

the new string

Find

func Find(b: Byte): PtrSize;
func Find(b: Byte, start: PtrSize): PtrSize;

Brief

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.

Parameters

b item to search for
start start position for the search

Returns

index of the item

FindFirst

func FindFirst(b: CArray): PtrSize;

Brief

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.

Parameters

b an array of inputs

Returns

index of the first found item

RFind

func RFind(b: Byte): PtrSize;
func RFind(b: Byte, start: PtrSize): PtrSize;

Brief

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.

Parameters

b item to search for
start start position for the search

Returns

index of the item

RFindFirst

func RFindFirst(b: CArray): PtrSize;

Brief

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.

Parameters

b an array of inputs

Returns

index of the first found item

Split

func Split(b: Byte): Vector;

Brief

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.

Parameters

b character to search for

Returns

a vector of substrings

Trim

def Trim();

Brief

Removes any leading or trailing whitespace.


TrimLeft

def TrimLeft();

Brief

Removes any leading whitespace.


TrimRight

def TrimRight();

Brief

Removes any trailing whitespace.


Sub

def Sub(start: PtrSize, end: PtrSize);

Brief

REtruns a substring contained between the `start` and `end` positions.

Parameters

start start position
end end position

Trimmed

func Trimmed(): String;

Brief

Returns a string with any leading or trailing whitespace.

Returns

trimmed string

TrimmedLeft

func TrimmedLeft(): String;

Brief

Returns a string with any leading whitespace.

Returns

trimmed string

TrimmedRight

func TrimmedRight(): String;

Brief

Returns a string with any trailing whitespace.

Returns

trimmed string

@write

func @write(ref stream: Stream);
func @write(ref stream: Stream, format: OutputFormat);

Brief

Writes the string to an Utf8 text stream.

Can use an optional output format specifier.

Parameters

stream the output stream
format formatting information

@put

func @put(ref stream: Stream);

Brief

Writes the string to a binary stream by first writing the length then the actual data.

Parameters

stream the output stream

@get

def @get(ref stream: Stream);

Brief

Reads the string from binary stream.

Parameters

stream the input stream

Parse

Parse(): T;

Brief

Parses a numeric of type `T` from the string, skipping whitespace.


ParseSaturated

ParseSaturated(): T;

Brief

Parses and saturates a numeric of type `T` from the string, skipping whitespace.

Properties

Length

property Length: PtrSize

Brief

The length of the string.


Capacity

property Capacity: PtrSize

Brief

THe amount of available storage capacity allocated for the string.


@index

property @index: ref Byte; get;

Brief

Standard index operator.


IsEmpty

property IsEmpty: Bool; get;

Brief

Returns true if the string has an Length of zero.


SysDataPointer

property SysDataPointer: Ptr; get;

Brief

Returns a pointer to the the raw data.

Variables

GrowthSpacing

val GrowthSpacing;

Brief

A variable used to control the growth rate of the string.