D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6255 - Add support for different base conversions in std.conv
Summary: Add support for different base conversions in std.conv
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: patch
: 6992 (view as issue list)
Depends on:
Blocks:
 
Reported: 2011-07-05 14:58 UTC by Andrej Mitrovic
Modified: 2012-01-26 00:04 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2011-07-05 14:58:40 UTC
This doesn't work currently:
to!int("0xFF");

Python's int() function solves this by taking an optional base argument:
http://docs.python.org/library/functions.html#int

So it can be called like:
clr = int("0000FF", 16)

I've seen this used in some functions which convert web colors to an integer.

So std.conv could take an optional base argument or maybe try to parse the string and figure out if it's hexadecimal (since this is probably the most commonly used base after base-10).
Comment 1 Andrej Mitrovic 2011-07-05 14:59:31 UTC
I should have mentioned in the title that I'm looking for *string* to int conversions.
Comment 2 yebblies 2011-07-05 19:01:42 UTC
Looking at the docs, it seems there's parse!int(string, radix) and to!string(int, radix).  It's probably worth adding to!int(string, radix) as well (unless it's already there and not showing up in the docs)
Comment 3 yebblies 2011-12-13 18:25:18 UTC
*** Issue 6992 has been marked as a duplicate of this issue. ***
Comment 5 github-bugzilla 2012-01-25 23:55:44 UTC
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/42083000a43b569e1d368261678ebd140586ee73
Merge pull request #372 from 9rnsr/fix6255

Issue 6255 - Add support for different base conversions in std.conv