[Issue 8729] parse!bool does not work correctly
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 27 13:40:18 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8729
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
--- Comment #4 from monarchdodra at gmail.com 2012-09-27 13:40:52 PDT ---
(In reply to comment #0)
> This code
>
> import std.conv;
> import std.stdio;
>
> void main()
> {
> auto str = "123 456.7 false";
>
> auto i = parse!int(str);
> auto d = parse!double(str);
> auto b = parse!bool(str);
>
> assert(i == 123);
> assert(d == 456.7);
> assert(b == false);
> }
>
> results in this exception when you run it
>
> std.conv.ConvException at std/conv.d(2654): Can't parse string: bool should be
> case-insensive 'true' or 'false'
> ----------------
> ./q(bool std.conv.parse!(bool, immutable(char)[]).parse(ref
> immutable(char)[])+0x183) [0x43867b]
> ./q(_Dmain+0x42) [0x430ec2]
> ./q(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x1c) [0x43b240]
> ./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
> delegate())+0x2a) [0x43abba]
> ./q(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x3b) [0x43b287]
> ./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
> delegate())+0x2a) [0x43abba]
> ./q(main+0xd1) [0x43ab45]
> /usr/lib/libc.so.6(__libc_start_main+0xf5) [0x7fd238fc1725]
> ----------------
>
> If you change it to
>
> import std.conv;
> import std.stdio;
>
> void main()
> {
> auto str = "false 123 456.7";
>
> auto b = parse!bool(str);
> auto i = parse!int(str);
> auto d = parse!double(str);
>
> assert(i == 123);
> assert(d == 456.7);
> assert(b == false);
> }
>
> you get
>
> std.conv.ConvException at std/conv.d(1771): Unexpected ' ' when converting from
> type string to type int
> ----------------
> ./q(int std.conv.parse!(int, immutable(char)[]).parse(ref
> immutable(char)[])+0x1b8) [0x431984]
> ./q(_Dmain+0x33) [0x430eb3]
> ./q(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x1c) [0x43b240]
> ./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
> delegate())+0x2a) [0x43abba]
> ./q(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x3b) [0x43b287]
> ./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
> delegate())+0x2a) [0x43abba]
> ./q(main+0xd1) [0x43ab45]
> /usr/lib/libc.so.6(__libc_start_main+0xf5) [0x7f1286cc0725]
> ----------------
>
> Just parsing out bool when it's first and then parsing _nothing_ else works,
> but it seems like parsing it under any other circumstances fails (from what I
> can tell anyway).
https://github.com/D-Programming-Language/phobos/pull/817
--
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