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:
Definition: c4d_string.h:41
String(const Char *str, Int count, const StringDecodingRef &stringDecoding=GetUtf8DefaultDecoder())
Definition: string.h:1250
PyObject * x
Definition: bytesobject.h:38
const maxon::Char * cstr(const maxon::Error &err)
Debug helper, writing "cstr(err)" in the watch window will display the error as readable test.
#define iferr_return
Definition: resultbase.h:1524
- Note
- For + or += you have to enclose the expression in brackets, otherwise iferr_return will check the wrong term.
-
Error detection does not work for concatenated operations, e.g. for x.Append(y).Append(z) you cannot detect an error, the same goes for x = x + y + z;
|
| 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) |
|