Always std.utf.validate, or rely on exceptions?

Kagamin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 2 09:03:01 PST 2017


On Thursday, 2 March 2017 at 16:20:30 UTC, SimonN wrote:
> Should I always validate text from files manually with 
> std.utf.validate?
>
> Or should I memorize which functions throw, then validate 
> manually whenever I call the non-throwing UTF functions? What 
> is the pattern behind what throws and what asserts false?

If you expect file with malformed utf that can cause you trouble 
and want to handle it gracefully, pass its content through 
validator and catch exception from validator. Functions working 
with strings usually assume valid utf and can behave incorrectly 
on malformed utf.


More information about the Digitalmars-d-learn mailing list