dmd foreach loops throw exceptions on invalid UTF sequences, use replacementDchar instead
ag0aep6g
anonymous at example.com
Fri Nov 5 17:26:14 UTC 2021
On 05.11.21 15:22, jfondren wrote:
> Looping over the dchar of a char[] requires one of
>
> 1. throwing an error on invalid UTF (current behavior)
> 2. doing something else in that case (proposed: replacementDchar; also
> possible: silently doing something invalid like iterating over three
> dchars between "hello" and "there")
> 3. a compile-time error (also proposed in the thread)
4. Don't decode. Just do an implicit conversion from char to dchar. Just
like `char c; dchar d = c;`. It's horrible, but D usually allows it. So
let foreach do it too.
But I'd rather get an error (i.e. #3). And disallow the implicit
conversion as well while you're at it.
More information about the Digitalmars-d
mailing list