On Wednesday, 5 September 2018 at 07:48:34 UTC, Chris wrote:
On Tuesday, 4 September 2018 at 21:36:16 UTC, Walter Bright
wrote:
Autodecode - I've suffered under that, too. The solution was
fairly simple. Append .byCodeUnit to strings that would
otherwise autodecode. Annoying, but hardly a showstopper.
import std.array : array;
import std.stdio : writefln;
import std.uni : byCodePoint, byGrapheme;
import std.utf : byCodeUnit;
void main() {
string first = "á";
writefln("%d", first.length); // prints 2
auto firstCU = "á".byCodeUnit; // type is `ByCodeUnitImpl` (!)
writefln("%d", firstCU.length); // prints 2
auto firstGr = "á".byGrapheme.array; // type is `Grapheme[]`
writefln("%d", firstGr.length); // prints 1
auto firstCP = "á".byCodePoint.array; // type is `dchar[]`
writefln("%d", firstCP.length); // prints 1
dstring second = "á";
writefln("%d", second.length); // prints 1 (That was easy!)
// DMD64 D Compiler v2.081.2
}
Welcome to my world!
[snip]
The dstring is only ok because the 2 code units fit in a dchar
right? But all the other ones are as expected right?
Seriously... why is it not graphemes by default for correctness
whyyyyyyy!