forked from bblanchon/ArduinoJson
Added comments
This commit is contained in:
@ -154,10 +154,10 @@ ERROR_MISSING_COMMA:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void JsonParser::parseBooleanTo(JsonVariant &destination) {
|
void JsonParser::parseBooleanTo(JsonVariant &destination) {
|
||||||
bool value = *_ptr == 't';
|
if (skip("true"))
|
||||||
|
destination = true;
|
||||||
if (skip(value ? "true" : "false"))
|
else if (skip("false"))
|
||||||
destination = value;
|
destination = false;
|
||||||
else
|
else
|
||||||
destination = JsonVariant::invalid();
|
destination = JsonVariant::invalid();
|
||||||
}
|
}
|
||||||
@ -166,20 +166,25 @@ void JsonParser::parseNumberTo(JsonVariant &destination) {
|
|||||||
char *endOfLong;
|
char *endOfLong;
|
||||||
long longValue = strtol(_ptr, &endOfLong, 10);
|
long longValue = strtol(_ptr, &endOfLong, 10);
|
||||||
|
|
||||||
|
// Could it be a floating point value?
|
||||||
if (*endOfLong == '.') {
|
if (*endOfLong == '.') {
|
||||||
// stopped on a decimal separator
|
// Yes => parse it as a double
|
||||||
double doubleValue = strtod(_ptr, &_ptr);
|
double doubleValue = strtod(_ptr, &_ptr);
|
||||||
|
// Count the decimal digits
|
||||||
uint8_t decimals = static_cast<uint8_t>(_ptr - endOfLong - 1);
|
uint8_t decimals = static_cast<uint8_t>(_ptr - endOfLong - 1);
|
||||||
|
// Set the variant as a double
|
||||||
destination.set(doubleValue, decimals);
|
destination.set(doubleValue, decimals);
|
||||||
} else {
|
} else {
|
||||||
|
// No => set the variant as a long
|
||||||
_ptr = endOfLong;
|
_ptr = endOfLong;
|
||||||
destination = longValue;
|
destination = longValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonParser::parseNullTo(JsonVariant &destination) {
|
void JsonParser::parseNullTo(JsonVariant &destination) {
|
||||||
|
const char *NULL_STRING = NULL;
|
||||||
if (skip("null"))
|
if (skip("null"))
|
||||||
destination = static_cast<const char *>(NULL);
|
destination = NULL_STRING;
|
||||||
else
|
else
|
||||||
destination = JsonVariant::invalid();
|
destination = JsonVariant::invalid();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user