View source code Display the source code in std/uni.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Struct std.uni.Grapheme

A structure designed to effectively pack of a .

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.

Properties

Name Type Description
length [get] ulong Grapheme cluster length in .
valid [get] bool True if this object contains valid extended grapheme cluster. Decoding primitives of this module always return a valid Grapheme.

Methods

Name Description
opIndex Gets a at the given index in this cluster.
opIndexAssign Writes a ch at given index in this cluster.
opOpAssign Append ch to this grapheme.
opOpAssign Append all from the input range inp to this Grapheme.
opSlice Random-access range over Grapheme's .

Example

import std.algorithm;
string bold = "ku\u0308hn";

// note that decodeGrapheme takes parameter by ref
// slicing a grapheme yields a range of dchar
assert(decodeGrapheme(bold)[].equal("k"));

// the next grapheme is 2 characters long
auto wideOne = decodeGrapheme(bold);
assert(wideOne.length == 2);
assert(wideOne[].equal("u\u0308"));

// the usual range manipulation is possible
assert(wideOne[].filter!isMark.equal("\u0308"));

See Also

decodeGrapheme, graphemeStride

Authors

Dmitry Olshansky

License

Boost License 1.0.

Comments