[Issue 5543] to!int to see a char as a single-char string

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 21 08:08:23 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5543



--- Comment #13 from monarchdodra at gmail.com 2012-12-21 08:08:20 PST ---
(In reply to comment #12)
> (In reply to comment #9)
> > int numericValue(dchar c) @safe pure nothrow
> 
> What about int->dchar?
> 
> We could call it toNumericChar or something, but it would probably have to
> throw on invalid input? Or can we also return -1? E.g.
> 
> char toNumericChar(int i) @safe pure nothrow
> {
>     return cast(char)((0 <= i && i <= 9) ? (i + '0') : -1);
> }

-1 is char.init, so seems good to me. Although I'd go and write it as
"char.init" explicitly in the code actually, so as to limit any possible
confusion.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list