Dicebot on leaving D: It is anarchy driven development in all its glory.

Chris wendlec at tcd.ie
Wed Sep 5 07:48:34 UTC 2018


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]


More information about the Digitalmars-d mailing list