numericValue for (unicode) characters

bearophile bearophileHUGS at lycos.com
Wed Jan 2 07:24:32 PST 2013


monarch_dodra:

> The rationale for this:
> std.ascii: I think returning -1 as a magic number should help 
> keep the code faster and with less clutter than with exceptions.

For the ASCII version I have two use cases:
- Where I want to go fast&unsafe I just use "c - '0'".
- When I want more safety I'd like to use something as to!(), 
that raises exceptions in case of errors.

A function that works on ASCII and returns -1 doesn't give me 
much more than "c - '0'". So maybe exceptions are good in the 
ASCII case too.

There is also std.typecons.nullable, it's a possibility for 
std.uni.numericValue. Generally Phobos should eat more of its dog 
food :-)

Bye,
bearophile


More information about the Digitalmars-d mailing list