dmd foreach loops throw exceptions on invalid UTF sequences, use replacementDchar instead
FeepingCreature
feepingcreature at gmail.com
Mon Nov 15 07:17:03 UTC 2021
On Friday, 12 November 2021 at 10:42:15 UTC, kdevel wrote:
> 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)`
Yes, because `readText` is typed in a way that it excludes valid
filenames. But it's *already* wrong - this feature would only
expose the wrongness, as `filename` is already not a validly
typed string. File a bug?
More information about the Digitalmars-d
mailing list