[Issue 17861] UTF Decode fails with exception

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 3 22:02:23 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=17861

--- Comment #10 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
If you don't want foreach to throw when decoding, then don't use foreach to
decode. Call std.utf.decode yourself rather than having foreach automatically
call the druntime version for you. We can't change foreach right now for
exactly the same reasons that we can't change front and popFront for strings.
If it were decided that the breakage that would result from changing front and
popFront to use the replacement character was low enough that we were willing
to just change them and let things break, then we'd change foreach. But as long
as it's considered too risk to change front and popFront to not throw, it's too
risky to change foreach. There is nothing special about foreach that makes it
any different from front and popFront for strings in terms of whether we can
risk breaking code.

I'm sorry that you find the current behavior surprising, but string handling in
D in general requires understanding a number of quirks that we'd like to change
but can't due to how much existing code would break if we did make the desired
changes.

--


More information about the Digitalmars-d-bugs mailing list