Stringify NaN, Inf as null if needs
This commit is contained in:
parent
973dc9c06d
commit
a95e013b97
@ -67,6 +67,7 @@ enum WriteFlag {
|
|||||||
kWriteNoFlags = 0, //!< No flags are set.
|
kWriteNoFlags = 0, //!< No flags are set.
|
||||||
kWriteValidateEncodingFlag = 1, //!< Validate encoding of JSON strings.
|
kWriteValidateEncodingFlag = 1, //!< Validate encoding of JSON strings.
|
||||||
kWriteNanAndInfFlag = 2, //!< Allow writing of Infinity, -Infinity and NaN.
|
kWriteNanAndInfFlag = 2, //!< Allow writing of Infinity, -Infinity and NaN.
|
||||||
|
kWriteNanAndInfNullFlag = 4, //!< Allow writing of Infinity, -Infinity and NaN as null.
|
||||||
kWriteDefaultFlags = RAPIDJSON_WRITE_DEFAULT_FLAGS //!< Default write flags. Can be customized by defining RAPIDJSON_WRITE_DEFAULT_FLAGS
|
kWriteDefaultFlags = RAPIDJSON_WRITE_DEFAULT_FLAGS //!< Default write flags. Can be customized by defining RAPIDJSON_WRITE_DEFAULT_FLAGS
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -350,6 +351,11 @@ protected:
|
|||||||
if (internal::Double(d).IsNanOrInf()) {
|
if (internal::Double(d).IsNanOrInf()) {
|
||||||
if (!(writeFlags & kWriteNanAndInfFlag))
|
if (!(writeFlags & kWriteNanAndInfFlag))
|
||||||
return false;
|
return false;
|
||||||
|
if (writeFlags & kWriteNanAndInfNullFlag) {
|
||||||
|
PutReserve(*os_, 4);
|
||||||
|
PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (internal::Double(d).IsNan()) {
|
if (internal::Double(d).IsNan()) {
|
||||||
PutReserve(*os_, 3);
|
PutReserve(*os_, 3);
|
||||||
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
||||||
@ -548,6 +554,11 @@ inline bool Writer<StringBuffer>::WriteDouble(double d) {
|
|||||||
// Note: This code path can only be reached if (RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag).
|
// Note: This code path can only be reached if (RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag).
|
||||||
if (!(kWriteDefaultFlags & kWriteNanAndInfFlag))
|
if (!(kWriteDefaultFlags & kWriteNanAndInfFlag))
|
||||||
return false;
|
return false;
|
||||||
|
if (kWriteDefaultFlags & kWriteNanAndInfNullFlag) {
|
||||||
|
PutReserve(*os_, 4);
|
||||||
|
PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (internal::Double(d).IsNan()) {
|
if (internal::Double(d).IsNan()) {
|
||||||
PutReserve(*os_, 3);
|
PutReserve(*os_, 3);
|
||||||
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user