[Issue 14519] [Enh] foreach on strings should return replacementDchar rather than throwing

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Apr 29 04:36:37 PDT 2015


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

--- Comment #17 from Vladimir Panteleev <thecybershadow at gmail.com> ---
Let's see if I understand the situation correctly... let's say we have a chain:

str.a.b.c

So, str is a UTF-8 string, and a, b and c are range algorithms (they use
.front/.popFront and provide .front/.popFront themselves).

If a/b/c don't throw anything themselves, the nothrow attribute will be
inferred from the .front/.popFront of the range in front of them (the range
they consume), right?

That means that if str.front can throw, c can't be nothrow. But if str.front is
nothrow, then c CAN be nothrow.

But what if we do this:

str.forceDecode.a.b.c

forceDecode doesn't use str.front - it reads the str directly, code unit by
code unit, and inserts replacement characters where it sees error. This allows
a, b and c to be nothrow.

Unless I'm wrong, I think this idea could work for opt-in replacement character
substitution. Following the 90/10 law, it should be easy to insert
"forceDecode" in the few relevant places as indicated by a profiler.

Does this proposal make sense?

--


More information about the Digitalmars-d-bugs mailing list