dmd foreach loops throw exceptions on invalid UTF sequences, use replacementDchar instead

Alexey invalid at email.address
Sat Nov 6 06:17:55 UTC 2021


On Saturday, 6 November 2021 at 05:36:07 UTC, H. S. Teoh wrote:
>
> Unfortunately, codepoint != grapheme. This was the fundamental 
> error with autodecoding that made it so bad. It costs us a 
> performance hit but doesn't even produce the right results in 
> return.
>
> And even more unfortunately, grapheme segmentation is an 
> extremely convoluted (i.e. slow) operation that normally you 
> would *not* want to do it unless your code absolutely has to.
>
>
> T

```D
struct graphstring
{
     grapheme[] grapheme_elements;
}

struct grapheme
{
     dchar[] codepoints;
}

```
Would this really be _that_ slow? also, there is no need to do 
error checks on every action which user may do with graphstrings: 
no need to check on concatenations or slicings, for instance. but 
do checks on conversions from other string/ubyte[] types and to 
those types.


More information about the Digitalmars-d mailing list