Skip to content

Should atod fail when different from inf or infinity #102

@captain-yoshi

Description

@captain-yoshi

A string that begins with inf, regardless of what comes after (except "" and "inity"), will silently succeed :

double d;
char str[] = "Informed"

if (atod(str, &d)) {
    std::cout << "This should fail !" << std::endl;
    std::cout << d << std::endl;
}

// This should fail !
// inf

Does atod do whole string matching ? Is this the intended behavior.


My use case is for decoding primitives not known in advance in a specific order :

    {  // bool
        bool value;
        if (from_chars(substr, &value))
            return XmlRpc::XmlRpcValue(value);
    }

    {  // int
        int value;
        if (from_chars(substr, &value))
            return XmlRpc::XmlRpcValue(value);
    }

    {  // double
        double value;
        if (from_chars(substr, &value))
            return XmlRpc::XmlRpcValue(value);
    }

    {  // string
        std::string value;
        if (from_chars(substr, &value))
            return XmlRpc::XmlRpcValue(value);
    }

Ultimately, is it up to me to check for a inf character is valid ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions