55
edits
m (→String types) |
|||
| Line 15: | Line 15: | ||
Strings are immutable, but their contents may be different. String data can be 8, 16, or 32 bits wide; A string may contain a pointer to a string buffer, which may need to be deleted or not; or the string data may immediately follow the String instance in memory (by doing a raw allocate followed by an in-place constructor call); or it can hold two String references if is the result of a concat operation. The contents may change dynamically during a flatten operation. Therefore, a String instance contains a <tt>union</tt> with a tag. | Strings are immutable, but their contents may be different. String data can be 8, 16, or 32 bits wide; A string may contain a pointer to a string buffer, which may need to be deleted or not; or the string data may immediately follow the String instance in memory (by doing a raw allocate followed by an in-place constructor call); or it can hold two String references if is the result of a concat operation. The contents may change dynamically during a flatten operation. Therefore, a String instance contains a <tt>union</tt> with a tag. | ||
=== String creation === | |||
Strings may either be created with 8, 16, or 32 bit data. In addition, string may be created with UTF-8 data, which results in the smallest width that can hold the data. | |||
String are created using static creator function. This allows the implementation to use raw memory allocation and in-place constructor calls to avoid having to do two memory allocations, one for the instance, and the other for the data. Strings created that way contain the data right behind the instance data. | |||
The maximum string width determines the way strings are created. It is an optional argument to the string constructors. | |||
# 8 bits: If the source data contains 16 or 32 bit data, the return value is null. | |||
#16 bits: If the source data contains 32 bit values, surrogate pairs are created. If a source data value of > 0x10FFFF, null is returned. | |||
=== String concatenation and flattening === | === String concatenation and flattening === | ||
edits