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

Guillaume Piolat first.last at gmail.com
Fri Nov 5 10:13:13 UTC 2021


On Friday, 5 November 2021 at 09:57:45 UTC, Ola Fosheim Grøstad 
wrote:
> On Friday, 5 November 2021 at 09:34:31 UTC, Guillaume Piolat 
> wrote:
>> How about just assert(false)? It is @nogc and foreach over 
>> invalid utf-8 is a logic error (as you didn't sanitize).
>
> It is even worse, it is a type error. If "utf-8" is to be a 
> meaningful type you should be allowed to assume that it follows 
> the spec.

Well you only know that it is meant to be utf8 in the context of 
the auto-decoding foreach (which must still exist). string in 
actual programs may contains binary files, strings in other 
codepages encodings.



More information about the Digitalmars-d mailing list