On Saturday, 6 November 2021 at 06:17:55 UTC, Alexey wrote:
>struct graphstring
{
grapheme[] grapheme_elements;
}
struct grapheme
{
dchar[] codepoints;
}
std.uni.Grapheme is more complex than a dchar[] (it tries to avoid allocating and it owns the dchars) but it has .length and opIndex that work like dchar[] (but read the warning on opSlice)
A Grapheme[] you can get with just s1.byGrapheme.array
.
Round-trip example from std.uni:
@safe unittest {
import std.array : array;
import std.conv : text;
import std.range : retro;
import std.uni : byGrapheme, byCodePoint;
string s = "noe\u0308l"; // noël
// reverse it and convert the result to a string
string reverse = s.byGrapheme
.array
.retro
.byCodePoint
.text;
assert(reverse == "le\u0308on"); // lëon
}