forked from bblanchon/ArduinoJson
@ -5,6 +5,11 @@ HEAD
|
|||||||
----
|
----
|
||||||
|
|
||||||
* Made library easier to use from a CMake project: simply add_subdirectory(ArduinoJson/src)
|
* Made library easier to use from a CMake project: simply add_subdirectory(ArduinoJson/src)
|
||||||
|
* Changed `String` to be a `typedef` of `std::string` (issues #142 and #161)
|
||||||
|
|
||||||
|
**BREAKING CHANGES**:
|
||||||
|
- `JsonVariant(true).as<String>()` now returns `"true"` instead of `"1"`
|
||||||
|
- `JsonVariant(false).as<String>()` now returns `"false"` instead of `"0"`
|
||||||
|
|
||||||
v5.0.6
|
v5.0.6
|
||||||
------
|
------
|
||||||
|
@ -9,16 +9,7 @@
|
|||||||
#ifndef ARDUINO
|
#ifndef ARDUINO
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
typedef std::string String;
|
||||||
// This class reproduces Arduino's String class
|
|
||||||
class String : public std::string {
|
|
||||||
public:
|
|
||||||
String(const char *cstr = "") : std::string(cstr) {}
|
|
||||||
String(const String &str) : std::string(str) {}
|
|
||||||
explicit String(long);
|
|
||||||
explicit String(int);
|
|
||||||
explicit String(double, unsigned char decimalPlaces = 2);
|
|
||||||
};
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
// Copyright Benoit Blanchon 2014-2015
|
|
||||||
// MIT License
|
|
||||||
//
|
|
||||||
// Arduino JSON library
|
|
||||||
// https://github.com/bblanchon/ArduinoJson
|
|
||||||
|
|
||||||
#ifndef ARDUINO
|
|
||||||
|
|
||||||
#include "../../include/ArduinoJson/Arduino/String.hpp"
|
|
||||||
|
|
||||||
#include <stdio.h> // for sprintf()
|
|
||||||
|
|
||||||
String::String(double value, unsigned char digits) {
|
|
||||||
char tmp[32];
|
|
||||||
sprintf(tmp, "%.*f", digits, value);
|
|
||||||
*this = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String::String(long value) {
|
|
||||||
char tmp[32];
|
|
||||||
sprintf(tmp, "%ld", value);
|
|
||||||
*this = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String::String(int value) {
|
|
||||||
char tmp[32];
|
|
||||||
sprintf(tmp, "%d", value);
|
|
||||||
*this = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -76,19 +76,11 @@ JsonInteger JsonVariant::asInteger() const {
|
|||||||
|
|
||||||
template <>
|
template <>
|
||||||
String JsonVariant::as<String>() const {
|
String JsonVariant::as<String>() const {
|
||||||
|
String s;
|
||||||
if ((_type == JSON_STRING || _type == JSON_UNPARSED) &&
|
if ((_type == JSON_STRING || _type == JSON_UNPARSED) &&
|
||||||
_content.asString != NULL)
|
_content.asString != NULL)
|
||||||
return String(_content.asString);
|
s = _content.asString;
|
||||||
|
else
|
||||||
if (_type == JSON_INTEGER || _type == JSON_BOOLEAN)
|
|
||||||
return String(_content.asInteger);
|
|
||||||
|
|
||||||
if (_type >= JSON_FLOAT_0_DECIMALS) {
|
|
||||||
uint8_t decimals = static_cast<uint8_t>(_type - JSON_FLOAT_0_DECIMALS);
|
|
||||||
return String(_content.asFloat, decimals);
|
|
||||||
}
|
|
||||||
|
|
||||||
String s;
|
|
||||||
printTo(s);
|
printTo(s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ TEST(JsonVariant_As_Tests, FalseAsLong) {
|
|||||||
|
|
||||||
TEST(JsonVariant_As_Tests, FalseAsString) {
|
TEST(JsonVariant_As_Tests, FalseAsString) {
|
||||||
JsonVariant variant = false;
|
JsonVariant variant = false;
|
||||||
ASSERT_EQ(String("0"), variant.as<String>());
|
ASSERT_EQ(String("false"), variant.as<String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(JsonVariant_As_Tests, TrueAsBool) {
|
TEST(JsonVariant_As_Tests, TrueAsBool) {
|
||||||
@ -77,7 +77,7 @@ TEST(JsonVariant_As_Tests, TrueAsLong) {
|
|||||||
|
|
||||||
TEST(JsonVariant_As_Tests, TrueAsString) {
|
TEST(JsonVariant_As_Tests, TrueAsString) {
|
||||||
JsonVariant variant = true;
|
JsonVariant variant = true;
|
||||||
ASSERT_EQ(String("1"), variant.as<String>());
|
ASSERT_EQ(String("true"), variant.as<String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(JsonVariant_As_Tests, LongAsBool) {
|
TEST(JsonVariant_As_Tests, LongAsBool) {
|
||||||
|
Reference in New Issue
Block a user