Unicode arithmetic at run-time
Charles McAnany via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 20 20:00:32 PDT 2014
Friends,
I note that there are playing cards in unicode:
http://en.wikipedia.org/wiki/Playing_cards_in_Unicode
They follow a nice pattern, so I can quickly convert from a rank
and suit to the appropriate escape sequence in D. I'd like to
automate this, but I can't seem to do arithmetic on unicode
characters as I could in ascii.
writefln("%c", '/U0001F0A1'); //works fine, ace of spades.
Backslash replaced with / for displayability.
//So logically, this would be the two of spades:
writefln("%c", '/U0001F0A1'+1); //
std.format.FormatException at format.d(1325): integral
Would this be solvable with a mixin (return "//U00001F0A" ~
rank;), or are escape sequences impossible to generate after the
source has been lexed by dmd?
I looked in std.uni and std.utf, but they don't seem to want to
generate a unicode character from an int, they're more concerned
about switching between encodings.
Cheers,
Charles.
More information about the Digitalmars-d-learn
mailing list