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

nkm1 t4nk074 at openmailbox.org
Thu Sep 6 08:44:15 UTC 2018


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
> }

And this has what to do with autodecoding?

>
> Welcome to my world!
>

TBH, it looks like you're just confused about how Unicode works. 
None of that is something particular to D. You should probably 
address your concerns to the Unicode Consortium. Not that they 
care.


More information about the Digitalmars-d mailing list