Builtin data types
In extension to the primitive data types, Spice offers builtin data types.
The String
data type¶
In opposite to the string primitive type, the String
builtin type is mutable and offers several ways to modify the contained value.
Tip
Use the string
primitive type over the String
builtin type as much as possible, due to its advantages in runtime performance. The usage of the String
builtin type is only recommended, when you need to modify the value of the string at runtime. string
variables are always immutable.
Constructors¶
The String
builtin type offers the following constructors:
void String()
: Initialize emptyvoid String(string)
: Initialize with a rawstring
as start valuevoid String(char)
: Initialize with a single charvoid String(String)
: Initialize by copying anotherString
(copy constructor)
Methods¶
The String
builtin type offers the following methods:
void append(string)
: Appends a raw stringvoid append(String)
: Appends a stringvoid append(char)
: Appends a single charchar* getRaw()
: Returns a char* to the heap allocated valuelong getLength()
: Returns the length of the string in charsbool isEmpty()
: Checks if the string has a length of 0long getCapacity()
: Returns the allocated space in bytesbool isFull()
: Checks if the length is equal with the capacityvoid clear()
: Clear the value of the stringlong find(string, int)
: Returns the index, where a substring was found, starting from a start indexlong find(string, long)
: Returns the index, where a substring was found, starting from a start indexlong find(string, short)
: Returns the index, where a substring was found, starting from a start indexbool contains(string)
: Checks if the string contains a substringvoid reverse()
: Reverses the value of the stringString substring(int, long)
: Returns the substring from start indexx
and lengthy
String substring(long, long)
: Returns the substring from start indexx
and lengthy
String substring(short, long)
: Returns the substring from start indexx
and lengthy
void reserve(int)
: Increase the capacity to the given numbervoid reserve(long)
: Increase the capacity to the given numbervoid reserve(short)
: Increase the capacity to the given number
Operators¶
The String
builtin type overrides the following operators:
String operator+(String, String)
: Concatenates two strings and returns the resultString operator+(String, string)
: Concatenates a string and a raw string and returns the resultString operator+(string, String)
: Concatenates a raw string and a string and returns the resultString operator+(string, string)
: Concatenates two raw strings and returns the resultvoid operator+=(String&, String)
: Appends a stringvoid operator+=(String&, string)
: Appends a raw stringvoid operator+=(String&, string)
: Appends a single charString operator*(String, int)
: Concatenates a string with itself n timesString operator*(String, long)
: Concatenates a string with itself n timesString operator*(String, short)
: Concatenates a string with itself n timesString operator*(int, String)
: Concatenates a string with itself n timesString operator*(long, String)
: Concatenates a string with itself n timesString operator*(short, String)
: Concatenates a string with itself n timesvoid operator*=(String&, int)
: Concatenates with itself n timesvoid operator*=(String&, long)
: Concatenates with itself n timesvoid operator*=(String&, short)
: Concatenates with itself n timesbool operator==(String, String)
: Checks if two strings are equal in valuebool operator!=(String, String)
: Checks if two strings are unequal in value