[Issue 9797] to!int() cannot convert hexadecimal numbers

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 15 19:25:50 PDT 2013


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



--- Comment #2 from Sarath Kumar Kodali <kodlists-dlang at yahoo.com> 2013-04-15 19:25:49 PDT ---
(In reply to comment #1)
> This might end up being rejected like Issue 7692. See comment
> https://github.com/D-Programming-Language/phobos/pull/835#discussion_r1764414.

The reason given to close issue 7692 is wrong. In D a hexadecimal number is
prefixed with 0x. Not being able to recognize a valid D hexadecimal number is a
bug in to!int().

Below is what C's strtol() does and parse!int() should behave same.

value = strtol("0xyz", &leftover, 0);   // value == 0, leftover == "xyz"
value = strtol("0xyz", &leftover, 16);   // value == 0, leftover == "xyz"
value = strtol("0x0x", &leftover, 0);   // value == 0, leftover == "x"
value = strtol("0x0x", &leftover, 16);   // value == 0, leftover == "x"
value = strtol("0x0x", &leftover, 10);   // value == 0, leftover == "x0x"
value = strtol("abcd", &leftover, 0);   // value == 0, leftover == "abcd"
value = strtol("abcd", &leftover, 16);   // value == 0xabcd, leftover == ""

-- 
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