www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9797] New: to!int() cannot convert hexadecimal numbers

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9797

           Summary: to!int() cannot convert hexadecimal numbers
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: kodlists-dlang yahoo.com


--- Comment #0 from Sarath Kumar Kodali <kodlists-dlang yahoo.com> 2013-03-23
10:14:23 PDT ---
$ cat conv_bug.d
import std.conv;

void main()
{
        auto var = to!int("0x123");
}
$ rdmd conv_bug.d
std.conv.ConvException /usr/include/dmd/phobos/std/conv.d(1612): Unexpected 'x'
when converting from type string to type int

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 23 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9797


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-23
10:39:40 PDT ---
This might end up being rejected like Issue 7692. See comment
https://github.com/D-Programming-Language/phobos/pull/835#discussion_r1764414.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 23 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9797



--- Comment #2 from Sarath Kumar Kodali <kodlists-dlang 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: -------
Apr 15 2013