Bug 7692 – std.conv.parse should do lookahead for "0x" in strings with radix 16

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-11T19:50:00Z
Last change time
2012-10-04T12:43:24Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-03-11T19:50:29Z
import std.conv; void main() { string s1 = "ff"; string s2 = "0xff"; assert(parse!uint(s1, 16) == 0xff); // ok assert(parse!uint(s2, 16) == 0xff); // fail, it's 0 } parse should pop the first two characters if the string starts with 0x.
Comment #1 by andrej.mitrovich — 2012-03-11T19:53:45Z
A simple thing to do would probably be to add this at the start of Target parse(Target, Source)(ref Source s, uint radix): if (radix == 16 && s.startsWith("0x")) s.popFrontN(2);
Comment #2 by andrej.mitrovich — 2012-10-04T12:43:24Z