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

kdevel kdevel at vogtner.de
Fri Nov 12 10:42:15 UTC 2021


On Thursday, 11 November 2021 at 07:58:54 UTC, Ola Fosheim 
Grøstad wrote:
> On Thursday, 11 November 2021 at 01:31:46 UTC, Elronnd wrote:
>> I agree this should be required.  If you want something which 
>> is not valid UTF-8, _do not put it into a string_.  Use 
>> ubyte[].
>
> Exactly.

[...]

> The compiler could do such checks in an extra-solid-debug-mode.

This requires lots of changes or additions

```
import std.stdio;
import std.file;

void main ()
{
    ubyte [] filename = [ 'a', 0x80, 'b', '\0' ]; // valid 
filename in some OS
    auto s = readText (filename);
}
```

This does not yet compile:

    [...]
           R = ubyte[]`
      must satisfy one of the following constraints:
    `       isSomeChar!(ElementType!R)
           is(StringTypeOf!R)`


More information about the Digitalmars-d mailing list