#include <string.h>
Class to store unicode strings. String stores unicode characters. Any unicode characters are legal, including 0C (strings are not null-terminated). Strings are reference-counted objects. This means that as long as you copy and do not modify strings they are just referenced. The first modification breaks the link and it becomes a unique new object.
Error handling for String For convenience the String class has a relaxed out of memory handling, for example String("Example", 7) might fail, but since it's a constructor there's no Result returned. The same goes for String a += b; In most cases this is no problem at all: If for example you want to concatenate a file url and this fails then loading the file will fail anyway. Nonetheless there cases where you must ensure that a string operation has succeeded. To enable this for methods, operators or constructor which are not returning a Result but modify the String (are non-const) the internal reference will be set to a nullptr on allocation failure. And this can be checked using iferr, iferr_return (or even GetPointer() would work). For example:
Classes | |
class | StringIterator |
Public Types | |
using | CharType = StringInterface::CharType |
using | ValueType = Utf32Char |
using | ConstIterator = StringIterator |
using | Iterator = ConstIterator |
Public Member Functions | |
MAXON_DEFAULT_REFERENCE_CONSTRUCTORS (String, Reference) | |
String (const Char *str, Int count, const StringDecodingRef &stringDecoding=GetUtf8DefaultDecoder()) | |
String (const Char *str, const StringDecodingRef &stringDecoding=GetUtf8DefaultDecoder()) | |
String (const Block< const Char > &str, const StringDecodingRef &stringDecoding=GetUtf8DefaultDecoder()) | |
String (const CString &str, const StringDecodingRef &stringDecoding=GetUtf8DefaultDecoder()) | |
String (const Utf32Char *str, Int count) | |
String (const Block< const Utf32Char > &str) | |
String (const Utf16Char *str, Int count) | |
String (Int count, Utf32Char fillChar) | |
String (const Id &prefix, const void *ptr) | |
String (const String &prefix, const void *ptr, Bool prefix0x=true) | |
Utf32Char | operator[] (Int pos) const |
MAXON_ATTRIBUTE_FORCE_INLINE StringInterface::CharPtr | operator[] (Int position) |
ConstIterator | Begin () const |
ConstIterator | End () const |
Bool | IsEmpty () const |
Bool | IsPopulated () const |
String & | operator+= (const String &str) |
Static Public Member Functions | |
static const String & | GetLineEnd () |
Private Member Functions | |
void | operator-> () const |
using CharType = StringInterface::CharType |
using ConstIterator = StringIterator |
using Iterator = ConstIterator |
|
explicit |
Constructor from Char array. If you have static strings use "..."_s instead.
[in] | str | C string block. |
[in] | count | Number of characters, -1 to auto detect the length of the string (search for the first 0). |
[in] | stringDecoding | Encoding type. |
|
explicit |
Constructor from Char array. If you have static strings use "..."_s instead.
[in] | str | C string block. |
[in] | stringDecoding | Encoding type. |
|
explicit |
Constructor from a Char Block. If you have static strings use "..."_s instead.
[in] | str | Char block, for example a BaseArray<Char>. |
[in] | stringDecoding | Encoding type. |
|
explicit |
Constructor from UTF-32 Utf32Char array. If you have static character strings use "..."_s instead.
[in] | str | UTF-32 character block. |
[in] | count | Number of characters, -1 to auto detect the length of the string (search for the first 0). |
Constructor from UTF-32 Utf32Char Block.
[in] | str | UTF-32 character block. |
Constructor from UTF-16 Utf16Char array.
[in] | str | UTF-16 character block. |
[in] | count | Number of characters, -1 to auto detect the length of the string (search for the first 0). |
Constructor to create a string with a specific length and a default character.
[in] | count | Number of characters of the new string. |
[in] | fillChar | Character to fill the string with. |
Constructs a string consisting of #prefix followed by an @ sign and the hex-formatted ptr.
[in] | prefix | The prefix for the string. |
[in] | ptr | A pointer. |
Constructor to create a string from a prefix and pointer address as hexadecimal text.
[in] | prefix | The prefix string. |
[in] | ptr | The pointer that will be added as hexadecimal text. |
[in] | prefix0x | If true the pointer will start with '0x'. |
MAXON_DEFAULT_REFERENCE_CONSTRUCTORS | ( | String | , |
Reference | |||
) |
Index operator to access single characters of the string.
[in] | pos | Position within the string the first character starts with an index of 0. If the position is out of boundaries 0 will be returned. |
MAXON_ATTRIBUTE_FORCE_INLINE StringInterface::CharPtr operator[] | ( | Int | position | ) |
Index operator to access single characters of the string.
[in] | position | Position within the string the first character starts with an index of 0. if the position is out of boundaries no changes will be made. |
ConstIterator Begin | ( | ) | const |
Returns and iterator pointing to the first character of this string.
ConstIterator End | ( | ) | const |
Returns and iterator pointing to the end of this string (one behind last character).
Bool IsEmpty | ( | ) | const |
Returns if the string length is zero.
Bool IsPopulated | ( | ) | const |
Returns if the string contains any characters.
Appends str at the end of this string.
[in] | str | Another string to append. |
|
static |
Returns a string with the platform specific line ending.
|
private |