// Two Union Jacks of the Great Britain in each string s = "\U0001F1EC\U0001F1E7\U0001F1EC\U0001F1E7"; wstring ws = "\U0001F1EC\U0001F1E7\U0001F1EC\U0001F1E7"; dstring ds = "\U0001F1EC\U0001F1E7\U0001F1EC\U0001F1E7"; // String pop length in code units, not points. assert(s.popGrapheme() == 8); assert(ws.popGrapheme() == 4); assert(ds.popGrapheme() == 2); assert(s == "\U0001F1EC\U0001F1E7"); assert(ws == "\U0001F1EC\U0001F1E7"); assert(ds == "\U0001F1EC\U0001F1E7"); import std.algorithm.comparison : equal; import std.algorithm.iteration : filter; // Also works for non-random access ranges as long as the // character type is 32-bit. auto testPiece = "\r\nhello!"d.filter!(x => !x.isAlpha); // Windows-style line ending is two code points in a single grapheme. assert(testPiece.popGrapheme() == 2); assert(testPiece.equal("!"d));
Reads one full grapheme cluster from an input range of dchar inp, but doesn't return it. Instead returns the number of code units read. This differs from number of code points read only if input is an autodecodable string.
Note: This function modifies inp and thus inp must be an L-value.