[Issue 3610] New: isNumeric("3.14w") is false.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 11 16:29:52 PST 2009


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

           Summary: isNumeric("3.14w") is false.
           Product: D
           Version: future
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dsimcha at yahoo.com


--- Comment #0 from David Simcha <dsimcha at yahoo.com> 2009-12-11 16:29:51 PST ---
import std.stdio, std.string;

void main() {
    writeln(isNumeric("3.14"));   // true
    writeln(isNumeric("3.14"w));  // false
    writeln(isNumeric("3.14"d));  // false
}


The problem is that we have isNumeric(...), which takes an argument using
runtime variadics and figures out whether it's numeric.  The default (if it's
not one of the listed types) is to return false.  However, the type list has
wchar[] and dchar[], not immutable(wchar)[] and immutable(dchar)[]:

    else if (_arguments[0] == typeid(wchar[]))
        return isNumeric(std.utf.toUTF8(va_arg!(wchar[])(_argptr)));
    else if (_arguments[0] == typeid(dchar[]))
        return isNumeric(std.utf.toUTF8(va_arg!(dstring)(_argptr)));

This leads to the default return false statement being executed.  IMHO the
solution is to just deprecate isNumeric(...), since it seems pretty useless
anyhow, and template isNumeric(string) and make it:

    isNumeric(String)(String s) if(isSomeString!(String))

This would also solve bug 3609.

-- 
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