Skip to content

Instantly share code, notes, and snippets.

@gdamore
Created September 17, 2022 16:44
Show Gist options
  • Save gdamore/13cc3b50aa3dbffca291f76b87849645 to your computer and use it in GitHub Desktop.
Save gdamore/13cc3b50aa3dbffca291f76b87849645 to your computer and use it in GitHub Desktop.
unicode grapheme test
import std;
import std.utf;
import std.uni;
import std.range.primitives : walkLength;
import std.range : take, drop;
void main()
{
auto s2 = "\U0001f9db\u200d\u2640"; // this is a female vampire (vampire + ZWJ + female)
auto wr = byGrapheme(s2);
writefln("s2 is %s\n", s2);
writefln("graphemes %d (expect 1)\n", wr.walkLength); // this should be "1"
s2 = "\U0001f1fa\U0001f1f8"; // flag modified with USA, displays as US flag
wr = byGrapheme(s2);
writefln("s2 is %s\n", s2);
writefln("graphemes %d (expect 1)\n", wr.walkLength); // this should be "1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment