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.

Function std.uni.byGrapheme

Iterate a string by grapheme.

Useful for doing string manipulation that needs to be aware of graphemes.

Prototype

auto byGrapheme(Range)(
  Range range
)
if (isInputRange!Range && is(Unqual!(ElementType!Range) == dchar));

See Also

byCodePoint

Example

import std.conv;
import std.range;
import std.algorithm;
auto text = "noe\u0308l"; // noël using e + combining diaeresis
assert(text.walkLength == 5); // 5 code points

auto gText = text.byGrapheme;
assert(gText.walkLength == 4); // 4 graphemes

assert(gText.take(3).equal("noe\u0308".byGrapheme));
assert(gText.drop(3).equal("l".byGrapheme));

Authors

Dmitry Olshansky

License

Boost License 1.0.

Comments