String Rt¶
| Spice | |
|---|---|
String struct¶
Heap-allocated builtin String type to enable dynamic modification in contrast to the primitive string type.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a String from a raw string value
Parameters
| Name | Type | Description |
|---|---|---|
value |
const string |
Initial raw string value (default: "") |
ctor¶
| Spice | |
|---|---|
Construct a String holding a single character
Parameters
| Name | Type | Description |
|---|---|---|
value |
const char |
Initial character |
ctor¶
| Spice | |
|---|---|
Construct a String as a deep copy of another String
Parameters
| Name | Type | Description |
|---|---|---|
original |
const String& |
String to copy |
ctor¶
| Spice | |
|---|---|
Construct a String pre-allocating space for the given number of characters
Parameters
| Name | Type | Description |
|---|---|---|
initialSize |
IntLong |
Number of characters to pre-allocate space for |
dtor¶
| Spice | |
|---|---|
Destruct the String, freeing its heap-allocated character buffer
Methods¶
append¶
| Spice | |
|---|---|
Appends the given string to the current one
Parameters
| Name | Type | Description |
|---|---|---|
appendix |
const string |
String to be appended |
append¶
| Spice | |
|---|---|
Appends the given String to the current one
Parameters
| Name | Type | Description |
|---|---|---|
appendix |
const String& |
String to be appended |
append¶
| Spice | |
|---|---|
Appends the given char to the string and resize it if needed
Parameters
| Name | Type | Description |
|---|---|---|
c |
const char |
Char to append |
insert¶
| Spice | |
|---|---|
Insert a raw string into the string at the given position
Parameters
| Name | Type | Description |
|---|---|---|
position |
unsigned IntLong |
Position to insert at |
str |
string |
Raw string to insert |
insert¶
| Spice | |
|---|---|
Insert a String into the string at the given position
Parameters
| Name | Type | Description |
|---|---|---|
position |
unsigned IntLong |
Position to insert at |
str |
const String& |
String to insert |
insert¶
| Spice | |
|---|---|
Insert a single character into the string at the given position
Parameters
| Name | Type | Description |
|---|---|---|
position |
unsigned IntLong |
Position to insert at |
c |
char |
Character to insert |
getRaw¶
| Spice | |
|---|---|
Get the raw and immutable string from this container instance
Returns: string — Raw immutable string
getLength¶
| Spice | |
|---|---|
Retrieve the current length of the string
Returns: unsigned long — Current length of the string
getCapacity¶
| Spice | |
|---|---|
Retrieve the current capacity of the string
Returns: unsigned long — Current capacity of the string
isEmpty¶
| Spice | |
|---|---|
Check if the string is empty
Returns: bool
isFull¶
| Spice | |
|---|---|
Checks if the string exhausts its capacity
Returns: bool — Full or not full
clear¶
| Spice | |
|---|---|
Replaces the current contents of the string with an empty string
find¶
| Spice | |
|---|---|
Searches for a substring in a string. Returns -1 if the string was not found.
Parameters
| Name | Type | Description |
|---|---|---|
needle |
string |
|
startIndex |
unsigned long |
Index where to start the search (default: 0l) |
Returns: long — Index, where the substring was found / -1
find¶
| Spice | |
|---|---|
Searches for a substring in a string. Returns -1 if the string was not found.
Parameters
| Name | Type | Description |
|---|---|---|
needle |
string |
|
startIndex |
unsigned int |
Index where to start the search |
Returns: long — Index, where the substring was found / -1
find¶
| Spice | |
|---|---|
Searches for a char in a string. Returns -1 if the char was not found.
Parameters
| Name | Type | Description |
|---|---|---|
needle |
char |
|
startIndex |
unsigned long |
Index where to start the search (default: 0l) |
Returns: long — Index, where the char was found / -1
rfind¶
| Spice | |
|---|---|
Searches for a substring in a string from the back. Returns -1 if the string was not found.
Parameters
| Name | Type | Description |
|---|---|---|
needle |
string |
|
startIndex |
unsigned long |
Index where to start the search (default: 0l) |
Returns: long — Index, where the substring was found / -1
rfind¶
| Spice | |
|---|---|
Searches for a substring in a string from the back. Returns -1 if the string was not found.
Parameters
| Name | Type | Description |
|---|---|---|
needle |
string |
|
startIndex |
unsigned int |
Index where to start the search |
Returns: long — Index, where the substring was found / -1
rfind¶
| Spice | |
|---|---|
Searches for a char in a string from the back. Returns -1 if the char was not found.
Parameters
| Name | Type | Description |
|---|---|---|
needle |
char |
|
startIndex |
unsigned long |
Index where to start the search (default: 0l) |
Returns: long — Index, where the char was found / -1
contains¶
| Spice | |
|---|---|
Checks if the string contains a substring
Parameters
| Name | Type | Description |
|---|---|---|
needle |
string |
Substring to search for |
Returns: bool — Found or not
startsWith¶
| Spice | |
|---|---|
Checks if the string starts with a given prefix
Parameters
| Name | Type | Description |
|---|---|---|
prefix |
string |
Prefix to check for |
Returns: bool — Starts with prefix or not
endsWith¶
| Spice | |
|---|---|
Checks if the string ends with a given suffix
Parameters
| Name | Type | Description |
|---|---|---|
suffix |
string |
Returns: bool — Ends with suffix or not
reverse¶
| Spice | |
|---|---|
Reverse the string
replace¶
| Spice | |
|---|---|
Replace occurrence of substring with the replacement string
Parameters
| Name | Type | Description |
|---|---|---|
needle |
string |
Substring to replace |
replacement |
string |
Replacement for the substring |
startIdx |
unsigned long |
(default: 0l) |
Returns: bool
replaceAll¶
| Spice | |
|---|---|
Replace all occurrences of substring with the replacement string
Parameters
| Name | Type | Description |
|---|---|---|
needle |
string |
Substring to replace |
replacement |
string |
Replacement for the substring |
Returns: unsigned long
getSubstring¶
| Spice | |
|---|---|
Returns the substring of the current string, starting at position startIndex with the length of length.
Parameters
| Name | Type | Description |
|---|---|---|
startIdx |
unsigned IntLongShort |
|
length |
long |
Length of substring (default: -1l) |
Returns: String — Substring
trim¶
| Spice | |
|---|---|
Returns a new string without leading or trailing whitespaces.
Returns: String — Trimmed string
reserve¶
| Spice | |
|---|---|
Reserves charCount items
Parameters
| Name | Type | Description |
|---|---|---|
charCount |
unsigned IntLongShort |
Number of chars to reserve for the string |
Functions¶
getRawLength¶
| Spice | |
|---|---|
Returns the length of a string
Parameters
| Name | Type | Description |
|---|---|---|
input |
string |
Input string |
Returns: unsigned long — Length of the input string
isRawEqual¶
| Spice | |
|---|---|
Checks the equality of two raw strings
Parameters
| Name | Type | Description |
|---|---|---|
lhs |
string |
First input raw string |
rhs |
string |
Second input raw string |
Returns: bool — Equality of lhs and rhs
Operators¶
operator=¶
| Spice | |
|---|---|
Copy-assign the contents of another String into this one
Parameters
| Name | Type | Description |
|---|---|---|
newValue |
const String& |
String to copy from |
operator+¶
| Spice | |
|---|---|
Concatenates two strings and returns the result
Parameters
| Name | Type | Description |
|---|---|---|
a |
const StrTy& |
String a |
b |
const StrTyChar& |
String b |
Returns: String — Concatenated string
operator+=¶
| Spice | |
|---|---|
Concatenates b to the end of a
Parameters
| Name | Type | Description |
|---|---|---|
a |
String& |
String a |
b |
const StrTyChar& |
String/string/char b |
operator*¶
| Spice | |
|---|---|
Concatenates the given string with itself n times.
Parameters
| Name | Type | Description |
|---|---|---|
str |
const String& |
Input string |
n |
const IntLongShort |
Multiplication operand |
Returns: String — Result string
operator*¶
| Spice | |
|---|---|
Concatenates the given string with itself n times
Parameters
| Name | Type | Description |
|---|---|---|
n |
const IntLongShort |
Multiplication operand |
str |
const String& |
Input string |
Returns: String — Result string
operator*=¶
| Spice | |
|---|---|
Concatenates this string with itself n times
Parameters
| Name | Type | Description |
|---|---|---|
str |
String& |
Input string |
n |
const IntLongShort |
Multiplication operand |
operator==¶
| Spice | |
|---|---|
Checks if two strings have the same value
Parameters
| Name | Type | Description |
|---|---|---|
a |
const String& |
First input string |
b |
const String& |
Second input string |
Returns: bool — Equal or not
operator==¶
| Spice | |
|---|---|
Checks if a String and a raw string have the same value
Parameters
| Name | Type | Description |
|---|---|---|
a |
const String& |
First input string |
b |
string |
Second input string |
Returns: bool — Equal or not
operator==¶
| Spice | |
|---|---|
Checks if a raw string and a String have the same value
Parameters
| Name | Type | Description |
|---|---|---|
a |
string |
First input string |
b |
const String& |
Second input string |
Returns: bool — Equal or not
operator!=¶
| Spice | |
|---|---|
Checks if two strings have not the same value
Parameters
| Name | Type | Description |
|---|---|---|
a |
const String& |
First input string |
b |
const String& |
Second input string |
Returns: bool — Not equal or not
operator!=¶
| Spice | |
|---|---|
Checks if a String and a raw string do not have the same value
Parameters
| Name | Type | Description |
|---|---|---|
a |
const String& |
First input string |
b |
const string& |
Second input string |
Returns: bool — Not equal or not
operator!=¶
| Spice | |
|---|---|
Checks if a raw string and a String do not have the same value
Parameters
| Name | Type | Description |
|---|---|---|
a |
const string& |
First input string |
b |
const String& |
Second input string |
Returns: bool — Not equal or not
operator[]¶
| Spice | |
|---|---|
Extract the char at the given index and return it
Parameters
| Name | Type | Description |
|---|---|---|
str |
String& |
|
idx |
unsigned long |
Returns: char& — Character at the given index
operator[]¶
| Spice | |
|---|---|
Extract the char at the given index and return it
Parameters
| Name | Type | Description |
|---|---|---|
str |
String& |
Input string |
idx |
unsigned int |
Returns: char& — Character at the given index