A D vs. Rust example
Walter Bright
newshound2 at digitalmars.com
Sun Oct 30 02:29:36 UTC 2022
On 10/28/2022 2:07 AM, Dukc wrote:
> - No string handling function needs to throw anything. The could all be
> `nothrow`.
> - If two string handling functions that need to decode are chained to each
> other, they don't need to both reduntantly check for invalid UTF-8.
> - You don't accidently forget to check for invalid UTF-8, or recheck an
> already checked string.
I've discovered that:
1. throwing on invalid UTF-8 is the wrong solution. Phobos' autodecode does
that. It was a huge mistake, but is a problem with Phobos, not D itself.
2. very, very few string algorithms have any need to decode the UTF-8. String
copying, searching, hashing, etc., all have no need to decode. I've fixed a lot
of the algorithms in Phobos to not decode.
3. detecting bad UTF-8 encodings only happens when decoding is needed. It costs
nothing extra, as it falls out of the decoding logic. Then, one can decide to
safely ignore it, or use the Replacement Char.
It works fine. There just is no need to purify the strings.
More information about the Digitalmars-d
mailing list