On Friday, 5 November 2021 at 14:10:35 UTC, deadalnix wrote:
>On Friday, 5 November 2021 at 13:26:00 UTC, Andrei Alexandrescu wrote:
>"On demand" is not "auto".
From the bug repport:
>A simple foreach loop:
void test(char[] a)
{
foreach (char c; a) { }
}
will throw a UtfException if a
is not a valid UTF string. Instead, it should replace the invalid sequence with replacementDchar.
This shouldn't do anything related to unicode at all.
It doesn't. This does:
unittest {
enum invalid = "hello\247\205\257there";
foreach (dchar c; invalid) { }
}
Looping over the dchar of a char[] requires one of
- throwing an error on invalid UTF (current behavior)
- doing something else in that case (proposed: replacementDchar; also possible: silently doing something invalid like iterating over three dchars between "hello" and "there")
- a compile-time error (also proposed in the thread)