String¶
- class
High level string class.
The mono framework has it own string class, that either reside on the HEAP or inside the read-only data segment (
.rodata
).We use this string class to pass string data to async routines like the View ‘s scheduleRepaint method. Because views might be repainted at any point in time, we cannot have view data reside on the stack. This string class hold its data on the HEAP, but behaves as it would reside on the stack.
This string class takes care of all alloc and dealloc of memory. It is a referenced based string class. You should not pass pointers of C++ references to this class, but instead normal assignment or pass the full class to functions. The efficient copy / assignment operator methods on the class ensure only data references are passed, behind the scenes.
For example:
String str = String::Format("Hello World, number: %i", 1); String str2 = str; String str3 = str2;
In the code only 1 copy of the string data is present in memory. And only references are passed to the objects
str2
andstr3
. Only as the last object is deallocated is the data disposed from the HEAP.These features makes the class very lightweight and safe to pass around functions and objects.
Public Functions
-
String::
String
()¶ Construct an empty invalid string.
-
String::
String
(uint32_t preAllocBytes)¶ Construct an empty string with a pre-allocated size.
Use this constructor to created a buffer-like string object.
- Parameters
preAllocBytes
-The number of bytes to allocate in the string object
-
String::
String
(char *str, uint32_t length)¶ Construct a string from an existing C string, with a fixed length.
The string data is copied to the mono string, such that String has it own copy of the string data.
- Parameters
str
-Pointer to the original C string
length
-The length of the provided string, without NULL terminator
-
String::
String
(char *str)¶ Construct a mono String from an existing NULL terminated C string.
The length of the source string is determined by the Clib function
strlen
.- Parameters
str
-A pointer to the C style string
-
String::
String
(const char *str)¶ Construct a mono String from an existing NULL terminated C string.
The length of the source string is determined by the Clib function
strlen
.- Parameters
str
-A pointer to the C style string
-
String::
String
(const String &str)¶ Construct a mono String from an existing mono string.
The length of the source string is determined by the Clib function
strlen
.- Parameters
str
-A reference to the mono string
-
uint32_t
String::
Length
()¶
const Return the length of the string.
The length of the actual string is returned, not counting the NULL terminator.
This method uses
strlen
which does not support variable byte-length character encoding. (That means UTF8, 16 and alike.)
-
char
String::
operator[]
(uint32_t pos)¶
const Access each character (or byte) of the string in an array like fashion.
-
char *
String::
CString
()¶
const Get a pointer to the raw C style string.
Use this method if need to print a string using
printf
or alike.To obtain a pointer to the raw string data.
-