Added custom implementation of ftoa (issues #266, #267, #269 and #270)

This commit is contained in:
Benoit Blanchon
2016-04-28 18:54:14 +02:00
parent f9f002c8f7
commit a138791964
15 changed files with 396 additions and 139 deletions

View File

@ -55,7 +55,7 @@ inline Internals::JsonInteger JsonVariant::asInteger() const {
case JSON_BOOLEAN:
return _content.asInteger;
case JSON_NEGATIVE_INTEGER:
return -_content.asInteger;
return -static_cast<Internals::JsonInteger>(_content.asInteger);
case JSON_STRING:
case JSON_UNPARSED:
if (!_content.asString) return 0;
@ -66,6 +66,25 @@ inline Internals::JsonInteger JsonVariant::asInteger() const {
}
}
inline Internals::JsonUInt JsonVariant::asUnsignedInteger() const {
using namespace Internals;
switch (_type) {
case JSON_UNDEFINED:
return 0;
case JSON_POSITIVE_INTEGER:
case JSON_BOOLEAN:
case JSON_NEGATIVE_INTEGER:
return _content.asInteger;
case JSON_STRING:
case JSON_UNPARSED:
if (!_content.asString) return 0;
if (!strcmp("true", _content.asString)) return 1;
return parse<Internals::JsonUInt>(_content.asString);
default:
return static_cast<Internals::JsonUInt>(_content.asFloat);
}
}
#if ARDUINOJSON_ENABLE_STD_STREAM
inline std::ostream &operator<<(std::ostream &os, const JsonVariant &source) {
return source.printTo(os);