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

           Summary: std.conv.to!int doesn't ignore whitespace
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2010-05-09 05:20:45 PDT ---
Too much flexibility in a language and its libs causes several problems, but
the opposite too makes the language and its use fussy. So there is a right
intermediate point of balance to be found.

The conversion from string to numbers performed by std.conv.to is excessively
rigid.

In Python this conversion works:

>>> int(" 0123\n")
123


In D v.2.043 the same produces an error:

import std.conv: to;
void main() {
    int x = to!int(" 0123\n");
}

std.conv.ConvError: Can't convert value ` 0123
' of type const(char)[] to type int


Can std.conv.to be modified to ignore whitespace?
In particular the ending newline is very common, for example every time I want
to convert a line from a text file to a number I have to use something like
this:

to!int(readln().chomp());

Instead of a simpler:

to!int(readln());

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to