Ctor
A destructor is present on this object, but not explicitly documented in the source.
A postblit is present on this object, but not explicitly documented in the source.
Gets a $(CODEPOINT) at the given index in this cluster.
Writes a $(CODEPOINT) ch at given index in this cluster.
Append $(CHARACTER) ch to this grapheme. Warning: Use of this facility may invalidate grapheme cluster, see also valid.
Append all $(CHARACTERS) from the input range inp to this Grapheme.
Random-access range over Grapheme's $(CHARACTERS).
Grapheme cluster length in $(CODEPOINTS).
True if this object contains valid extended grapheme cluster. Decoding primitives of this module always return a valid Grapheme.
1 import std.algorithm.comparison : equal; 2 import std.algorithm.iteration : filter; 3 import std.range : isRandomAccessRange; 4 5 string bold = "ku\u0308hn"; 6 7 // note that decodeGrapheme takes parameter by ref 8 auto first = decodeGrapheme(bold); 9 10 assert(first.length == 1); 11 assert(first[0] == 'k'); 12 13 // the next grapheme is 2 characters long 14 auto wideOne = decodeGrapheme(bold); 15 // slicing a grapheme yields a random-access range of dchar 16 assert(wideOne[].equal("u\u0308")); 17 assert(wideOne.length == 2); 18 static assert(isRandomAccessRange!(typeof(wideOne[]))); 19 20 // all of the usual range manipulation is possible 21 assert(wideOne[].filter!isMark().equal("\u0308")); 22 23 auto g = Grapheme("A"); 24 assert(g.valid); 25 g ~= '\u0301'; 26 assert(g[].equal("A\u0301")); 27 assert(g.valid); 28 g ~= "B"; 29 // not a valid grapheme cluster anymore 30 assert(!g.valid); 31 // still could be useful though 32 assert(g[].equal("A\u0301B"));
A structure designed to effectively pack $(CHARACTERS) of a $(CLUSTER).
Grapheme has value semantics so 2 copies of a Grapheme always refer to distinct objects. In most actual scenarios a Grapheme fits on the stack and avoids memory allocation overhead for all but quite long clusters.