A GString can be used with libraries that operate on normal strings, however, they are treated like normal strings, and these libraries should be used with caution.
Finds the grapheme-index of the given search string.
Enables the use of foreach (Grapheme; ...) statements.
Enables the use of foreach (size_t, Grapheme; ...) statements.
A binary operator to allow appending with a Grapheme.
A binary operator to allow appending with arbitrary strings.
A binary operator supporting appending a single character.
A binary operator to allow appending with a Grapheme.
A binary operator to allow appending with arbitrary strings.
A binary operator supporting appending a single character.
Returns the i'th displayable character (Grapheme) within the GString.
Returns a range of Graphemes representing the original string.
Replaces a single grapheme in the GString.
Allows appending to an existing GString using the ~= operator.
Allows appending to an existing GString using the ~= operator.
Creates a data structure to represent the 0'th index during array slicing, e.g. gstring[i..j].
The underlying stored string using UTF encoding according to CharT.
Controls the type of encoding to use. char => UTF-8, wchar => UTF-16, and dchar => UTF-32.
auto t1 = CGString("Test R̆ȧm͆b̪õ"); assert(t1.indexOf("ȧ") == 6); assert(t1.indexOf("m̪") == -1); t1[9] = "í"; assert(t1.toString() == "Test R̆ȧm͆b̪í");
A GString, or grapheme-string, is a unicode-aware string supporting simple array-index operations that operate on graphemes (displayable characters).
For example, consider the string "R̆um". At what array index is the character 'u'? Because this is a UTF-8 encoded string, it is actually at index 3, not 1. "R̆" is composed of 2 unicode code-points, "R" and " ̆ " (combining breve). The "R" code-point is encoded in a single byte, but the combining breve requires two bytes. These two code-points are combined into a single visible character (grapheme), "R̆".
This type permits simple array-index operations based on graphemes, that is, the visible position of characters. It uses a string as its undrelying storage without an additional memory footprint. However, array-like operations tend to have O(n) complexity, because the type must compute the offset of each grapheme. Thus, GString is best used with smaller strings, especially those that need to perform operations by character position, such as in user interfaces.
If memory is not an issue, and array-like operations by Grapheme are needed for very large strings, it is better to use dchar[] or Grapheme[].