Skip to content

Parsing of numbers #42

@Elmue

Description

@Elmue

May be it is not very probable but what if the server sends a number that starts with a '+' sign?

// Is it a number?
if (**data == L'-' || (**data >= L'0' && **data <= L'9'))
{
    ......

should also expect a '+'

Additionally I would like to distinguish double numbers from integer numbers.
You put them all into a double variable.

I would prefer a double variable for floating point numbers and an __int64 variable for integer numbers.

Then there should be the functions:

bool JSONValue::IsLong()
{
     return type == JSONType_Long;
}
bool JSONValue::IsDouble()
{
     return type == JSONType_Double;
}
bool JSONValue::IsNumber()
{
     return type == JSONType_Long || type == JSONType_Double;
}

and

__int64 JSONValue::AsLong()
{
    assert(type == JSONType_Long);
    return long_value;
}
double JSONValue::AsDouble()
{
    assert(type == JSONType_Double);
    return double_value;
}
double JSONValue::AsNumber()
{
    switch (type)
    {
        case JSONType_Double: return double_value;
        case JSONType_Long:   return (double)long_value;
        default: 
            assert(false);
            return 0;
     }
}

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