Podger2016 / rapidjson

Automatically exported from code.google.com/p/rapidjson
0 stars 0 forks source link

Patch - Renaming of unsigned int members. Fix return type for GetUInt64. Validation functions. #47

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I did the following changes:

1) Renamed the unsigned int naming for both uint32_t and uint64_t members, i.e:
a) Member functions
Renamed IsUint() to IsUInt() 
Renamed IsUint64() to IsUInt64()
etc.

b) Enums
Renamed kUintFlag to kUIntFlag
Renamed kNumberUint64Flag to kNumberUInt64Flag
etc.

2) Changed the return type of GetUint64() member function from int64_t to 
uint64_t because data_.n.u64 is of type uint64_t

3) Added 3 validation member functions: EmptyArray(), EmptyObject(), 
EmptyString() , besides the Empty() function that only checks for empty arrays.

This is because there is often the need to check that a certain JSON value 
(string, array, object) is empty. It may not be null but empty.

I have utility functions for this and I thought putting the empty part inside 
the parser is more appropriate, like the following:

bool IsValidString (const char* name, const Value& value)
{
    if (value.HasMember (name) && ! value[name].IsNull() 
&& !value[name].EmptyString())
    {
        return true;
    }

    return false;
}

bool IsValidArray (const char* name, const Value& value)
{
    if (value.HasMember (name) && ! value[name].IsNull() 
&& !value[name].EmptyArray())
    {
        return true;
    }

    return false;
}

bool IsValidObject (const char* name, const Value& value)
{
    if (value.HasMember (name) && !value[name].IsNull() 
&& !value[name].EmptyObject())
    {
        return true;
    }

    return false;
}

Original issue reported on code.google.com by alex.bu...@gmail.com on 14 Nov 2012 at 2:34

GoogleCodeExporter commented 8 years ago
Uploaded the wrong patch file.

Original comment by alex.bu...@gmail.com on 14 Nov 2012 at 2:35

Attachments:

GoogleCodeExporter commented 8 years ago
The incorrect return type defeat has created an independent issue 48.
Renaming is not accepted.
Other API addition is considered as enhancement.

Original comment by milo...@gmail.com on 15 Nov 2012 at 3:00

GoogleCodeExporter commented 8 years ago
I see two more potential issues:
1) The code for the GetUint64() member function still uses kInt64Flag instead 
of kUint64Flag

2) The code for SetInt() member function on the "else if (IsUint64())" 
statement uses data_.n.i64 instead of data_.n.u64

Original comment by alex.bu...@gmail.com on 15 Nov 2012 at 7:02

GoogleCodeExporter commented 8 years ago
Thank you. These two issues was also added to issue 48 and fixed by revision 
r89.

Original comment by milo...@gmail.com on 15 Nov 2012 at 7:17

GoogleCodeExporter commented 8 years ago

Original comment by milo...@gmail.com on 10 Dec 2012 at 3:33