forked from bblanchon/ArduinoJson
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
7ae43bc4f8 | |||
056682327b | |||
8b66a25f66 | |||
96245dd3b4 | |||
9cc49da68a |
15
.travis.yml
15
.travis.yml
@ -1,17 +1,20 @@
|
|||||||
|
sudo: false
|
||||||
language: c++
|
language: c++
|
||||||
compiler:
|
compiler:
|
||||||
- gcc
|
- gcc
|
||||||
- clang
|
- clang
|
||||||
before_install:
|
before_install:
|
||||||
|
- pip install --user cpp-coveralls
|
||||||
|
- mkdir -p /tmp/cmake
|
||||||
|
- curl https://cmake.org/files/v3.4/cmake-3.4.0-Linux-x86_64.tar.gz | tar xz -C /tmp/cmake --strip 1
|
||||||
|
- export PATH=/tmp/cmake/bin:$PATH
|
||||||
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
|
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
|
||||||
- sleep 3
|
- sleep 3
|
||||||
- export DISPLAY=:1.0
|
- export DISPLAY=:1.0
|
||||||
- wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
|
- mkdir -p /tmp/arduino
|
||||||
- tar xf arduino-1.6.5-linux64.tar.xz
|
- curl http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz | tar xJ -C /tmp/arduino --strip 1
|
||||||
- sudo mv arduino-1.6.5 /usr/local/share/arduino
|
- export PATH=$PATH:/tmp/arduino/
|
||||||
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
|
- ln -s $PWD /tmp/arduino/libraries/ArduinoJson
|
||||||
- sudo ln -s $PWD /usr/local/share/arduino/libraries/ArduinoJson
|
|
||||||
- sudo pip install cpp-coveralls
|
|
||||||
script:
|
script:
|
||||||
- cmake -DCOVERAGE=true . && make && make test
|
- cmake -DCOVERAGE=true . && make && make test
|
||||||
- arduino --verify --board arduino:avr:uno $PWD/examples/JsonParserExample/JsonParserExample.ino
|
- arduino --verify --board arduino:avr:uno $PWD/examples/JsonParserExample/JsonParserExample.ino
|
||||||
|
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,6 +1,16 @@
|
|||||||
ArduinoJson: change log
|
ArduinoJson: change log
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
v5.0.7
|
||||||
|
------
|
||||||
|
|
||||||
|
* 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
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.4)
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
project(ArduinoJson)
|
project(ArduinoJson)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
@ -7,10 +7,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
|
|||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||||
|
|
||||||
if(MSVC)
|
|
||||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS -W4)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(${COVERAGE})
|
if(${COVERAGE})
|
||||||
set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
|
set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
|
||||||
endif()
|
endif()
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ class BlockJsonBuffer : public JsonBuffer {
|
|||||||
|
|
||||||
void* allocInNewBlock(size_t bytes) {
|
void* allocInNewBlock(size_t bytes) {
|
||||||
size_t capacity = _nextBlockSize;
|
size_t capacity = _nextBlockSize;
|
||||||
if (_head != NULL) capacity = _head->capacity * 2;
|
|
||||||
if (bytes > capacity) capacity = bytes;
|
if (bytes > capacity) capacity = bytes;
|
||||||
if (!addNewBlock(capacity)) return NULL;
|
if (!addNewBlock(capacity)) return NULL;
|
||||||
_nextBlockSize *= 2;
|
_nextBlockSize *= 2;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=ArduinoJson
|
name=ArduinoJson
|
||||||
version=5.0.6
|
version=5.0.7
|
||||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||||
sentence=An efficient and elegant JSON library for Arduino.
|
sentence=An efficient and elegant JSON library for Arduino.
|
||||||
|
@ -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
|
|
@ -48,4 +48,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
add_definitions(
|
||||||
|
-D_CRT_SECURE_NO_WARNINGS
|
||||||
|
-W4)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(ArduinoJson ${CPP_FILES} ${HPP_FILES} ${IPP_FILES})
|
add_library(ArduinoJson ${CPP_FILES} ${HPP_FILES} ${IPP_FILES})
|
||||||
|
|
||||||
|
target_include_directories(ArduinoJson INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../include)
|
||||||
|
@ -76,20 +76,12 @@ 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)
|
printTo(s);
|
||||||
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);
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
set(GTEST_DIR ../third-party/gtest-1.7.0)
|
set(GTEST_DIR ../third-party/gtest-1.7.0)
|
||||||
|
|
||||||
file(GLOB_RECURSE INC_FILES ../include/*.h)
|
|
||||||
file(GLOB TESTS_FILES *.hpp *.cpp)
|
file(GLOB TESTS_FILES *.hpp *.cpp)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
../include
|
|
||||||
${GTEST_DIR}
|
${GTEST_DIR}
|
||||||
${GTEST_DIR}/include)
|
${GTEST_DIR}/include)
|
||||||
|
|
||||||
@ -17,7 +15,6 @@ endif()
|
|||||||
|
|
||||||
add_executable(ArduinoJsonTests
|
add_executable(ArduinoJsonTests
|
||||||
${TESTS_FILES}
|
${TESTS_FILES}
|
||||||
${INC_FILES}
|
|
||||||
${GTEST_DIR}/src/gtest-all.cc
|
${GTEST_DIR}/src/gtest-all.cc
|
||||||
${GTEST_DIR}/src/gtest_main.cc)
|
${GTEST_DIR}/src/gtest_main.cc)
|
||||||
|
|
||||||
|
@ -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