![]() |
nCine 2025.06.r503-ff15d8d
A cross-platform 2D game engine
|
A basic string class made of chars. More...
#include <String.h>
Public Types | |
using | Iterator = StringIterator< false > |
Iterator type. | |
using | ConstIterator = StringIterator< true > |
Constant iterator type. | |
using | ReverseIterator = nctl::ReverseIterator< Iterator > |
Reverse iterator type. | |
using | ConstReverseIterator = nctl::ReverseIterator< ConstIterator > |
Reverse constant iterator type. | |
Public Member Functions | |
String () | |
Default constructor. | |
String (unsigned int capacity) | |
Constructs an empty string with explicit size. | |
String (StringMode mode) | |
Constructs an empty string with the option for it to be fixed. | |
String (unsigned int capacity, StringMode mode) | |
Constructs an empty string with explicit size and the option for it to be fixed. | |
String (const char *cString) | |
Constructs a string object from a C string. | |
String (const char *cString, StringMode mode) | |
Constructs a string object from a C string with the option for it to be fixed. | |
String (const String &other) | |
Copy constructor. | |
String (String &&other) | |
Move constructor. | |
String & | operator= (const String &other) |
Assignment operator (it might extend or truncate the original text) | |
String & | operator= (String &&other) |
Move assignment operator. | |
String & | operator= (const char *cString) |
Assigns a constant C string to the string object. | |
void | swap (String &first, String &second) |
Swaps two strings without copying their data. | |
Iterator | begin () |
Returns an iterator to the first character. | |
ReverseIterator | rBegin () |
Returns a reverse iterator to the last character. | |
Iterator | end () |
Returns an iterator to the termination character. | |
ReverseIterator | rEnd () |
Returns a reverse iterator to the byte preceding the first character. | |
ConstIterator | begin () const |
Returns a constant iterator to the first character. | |
ConstReverseIterator | rBegin () const |
Returns a constant reverse iterator to the last character. | |
ConstIterator | end () const |
Returns a constant iterator to the termination character. | |
ConstReverseIterator | rEnd () const |
Returns a constant reverse iterator to the byte preceding the first character. | |
ConstIterator | cBegin () const |
Returns a constant iterator to the first character. | |
ConstReverseIterator | crBegin () const |
Returns a constant reverse iterator to the last character. | |
ConstIterator | cEnd () const |
Returns a constant iterator to the termination character. | |
ConstReverseIterator | crEnd () const |
Returns a constant reverse iterator to the byte preceding the first character. | |
bool | isEmpty () const |
Returns true if the string is empty. | |
unsigned int | length () const |
Returns the string length. | |
unsigned int | capacity () const |
Returns the string capacity. | |
unsigned int | setLength (unsigned int newLength) |
Sets the string length. | |
void | setCapacity (unsigned int newCapacity) |
Sets a new capacity for the string (can be bigger or smaller than the current one) | |
void | shrinkToFit () |
Decreases the capacity to match the current length of the string. | |
void | clear () |
Clears the string. | |
char * | data () |
Returns a pointer to the internal array. | |
const char * | data () const |
Returns a constant pointer to the internal array. | |
unsigned int | replace (const String &source, unsigned int srcChar, unsigned int numChar, unsigned int destChar) |
Replaces characters from somewhere in the other string to somewhere in this one (no truncation) | |
unsigned int | replace (const char *source, unsigned int numChar, unsigned int destChar) |
Replaces characters from a C string to somewhere in this one (no truncation) | |
unsigned int | assign (const String &source, unsigned int srcChar, unsigned int numChar) |
Copies characters from somewhere in the other string to the beginning of this one. | |
unsigned int | assign (const String &source) |
Copies all characters from the other string to the beginning of this one. | |
unsigned int | assign (const char *source, unsigned int numChar) |
Copies characters from a C string to the beginning of this one. | |
unsigned int | copy (char *dest, unsigned int srcChar, unsigned int numChar) const |
Copies characters from somewhere in this string to a C string. | |
unsigned int | copy (char *dest) const |
Copies all characters from this string to a C string. | |
unsigned int | append (const String &other) |
Appends all the characters from the other string to the end of this one. | |
unsigned int | append (const char *cString) |
Appends all the characters from the C string to the end of this one. | |
int | compare (const String &other) const |
Compares the string with another one in lexicographical order. | |
int | compare (const char *cString) const |
Compares the string with a constant C string in lexicographical order. | |
int | findFirstChar (char c) const |
Finds the first occurrence of a character. | |
int | findLastChar (char c) const |
Finds the last occurrence of a character. | |
int | findFirstCharAfterIndex (char c, unsigned int index) const |
Finds the first occurrence of a character after the character at the index. | |
int | find (const String &other) const |
Finds the first occurrence of the given string. | |
int | find (const char *cString) const |
Finds the first occurrence of the given constant C string. | |
String & | format (const char *fmt,...) |
Replaces the string with the formatted result. | |
String & | formatAppend (const char *fmt,...) |
Append the formatted result to the string. | |
String & | operator+= (const String &other) |
Appends another string to this one. | |
String & | operator+= (const char *cString) |
Appends a constant C string to the string object. | |
String | operator+ (const String &other) const |
Concatenate two strings together to create a third one. | |
String | operator+ (const char *cString) const |
Concatenates a string with a constant C string to create a third one. | |
bool | operator== (const String &other) const |
bool | operator!= (const String &other) const |
bool | operator> (const String &other) const |
bool | operator< (const String &other) const |
bool | operator>= (const String &other) const |
bool | operator<= (const String &other) const |
bool | operator== (const char *cString) const |
bool | operator!= (const char *cString) const |
bool | operator> (const char *cString) const |
bool | operator< (const char *cString) const |
bool | operator>= (const char *cString) const |
bool | operator<= (const char *cString) const |
const char & | at (unsigned int index) const |
Read-only access to the specified element (with bounds checking) | |
char & | at (unsigned int index) |
Access to the specified element (with bounds checking) | |
const char & | operator[] (unsigned int index) const |
Read-only subscript operator. | |
char & | operator[] (unsigned int index) |
Subscript operator. | |
int | utf8ToCodePoint (unsigned int position, unsigned int &codePoint, unsigned int *codeUnits) const |
Retrieves the Unicode code point and the UTF-8 code units from the UTF-8 substring starting at the specified position. | |
int | utf8ToCodePoint (unsigned int position, unsigned int &codePoint) const |
Retrieves the Unicode code point from the UTF-8 substring starting at the specified position. | |
Static Public Attributes | |
static const unsigned int | MaxCStringLength = 512 - 1 |
Maximum length when creating an object from C-style strings. | |
Friends | |
DLL_PUBLIC String | operator+ (const char *cString, const String &string) |
Friend operator to concatenate a constant C string with a string to create a third one. | |
bool | operator== (const char *cString, String string) |
bool | operator!= (const char *cString, String string) |
bool | operator> (const char *cString, String string) |
bool | operator< (const char *cString, String string) |
bool | operator>= (const char *cString, String string) |
bool | operator<= (const char *cString, String string) |
A basic string class made of chars.
void nctl::String::clear | ( | ) |
Clears the string.
Assignment operator (it might extend or truncate the original text)
unsigned int nctl::String::replace | ( | const String & | source, |
unsigned int | srcChar, | ||
unsigned int | numChar, | ||
unsigned int | destChar | ||
) |
Replaces characters from somewhere in the other string to somewhere in this one (no truncation)
The method returns the number of characters copied, to allow truncation.
Sets the string length.
The method is useful to update the string length after writing into it through the data()
pointer.
Retrieves the Unicode code point from the UTF-8 substring starting at the specified position.
int nctl::String::utf8ToCodePoint | ( | unsigned int | position, |
unsigned int & | codePoint, | ||
unsigned int * | codeUnits | ||
) | const |
Retrieves the Unicode code point and the UTF-8 code units from the UTF-8 substring starting at the specified position.