Conversation
| // since later there's a non-nothrow call to `toUpper` | ||
| import std.utf : validate, UTFException; | ||
| try validate(partial); | ||
| catch (UTFException) partial = ""; |
There was a problem hiding this comment.
I think that phobos misses a nothrow UTF validator. Using try catch for this is really horrible.
There was a problem hiding this comment.
Agreed. I also miss a way to process strings in nothrow e.g. by replacing with the invalid UTF char - though there was a DIP once: https://wiki.dlang.org/DIP76
There was a problem hiding this comment.
FYI: I recently hacked a toValidUTF method for run.dlang.io, because of similar problems.
Though it's really ugly (performance-wise), but Phobos is really lacking in this regard :/
There was a problem hiding this comment.
Though it's really ugly (performance-wise),
Thinking about it - maybe we should use this approach in the catch(UTFException) case? silently setting partial to an empty string if there's just one invalid UTF symbol looks a bit like patching over the actual problem.
There was a problem hiding this comment.
The actual problem comes from the IDE in first place and in dcd we just avoid a crash.
wilzbach
left a comment
There was a problem hiding this comment.
Thanks! I'm going to merge this as DCD clearly shouldn't crash on invalid UTF sequences. The exact behavior can also be redefined later.
No description provided.