Merge remote-tracking branch 'ianloic/fuchsia' into fuchsia
* ianloic/fuchsia:
Ignore comments in JSON. Not spec compliant but useful.
Add BUILD.gn for Fuchsia
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 66420e9..2b41608 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -6,6 +6,10 @@
To make it as easy as possible for you to contribute and for me to keep an overview, here are a few guidelines which should help us avoid all kinds of unnecessary work or disappointment. And of course, this document is subject to discussion, so please [create an issue](https://github.com/nlohmann/json/issues/new) or a pull request if you find a way to improve it!
+## Private reports
+
+Usually, all issues are tracked publicly on [Github](https://github.com/nlohmann/json/issues). If you want to make a private report (e.g., for a vulnerability or to attach an example that is not meant to be publisheed), please send an email to <mail@nlohmann.me>.
+
## Prerequisites
Please [create an issue](https://github.com/nlohmann/json/issues/new), assuming one does not already exist, and describe your concern. Note you need a [GitHub account](https://github.com/signup/free) for this.
@@ -57,6 +61,7 @@
## Note
- If you open a pull request, the code will be automatically tested with [Valgrind](http://valgrind.org)'s Memcheck tool to detect memory leaks. Please be aware that the execution with Valgrind _may_ in rare cases yield different behavior than running the code directly. This can result in failing unit tests which run successfully without Valgrind.
+- There is a Makefile target `make pretty` which runs [Artistic Style](http://astyle.sourceforge.net) to fix indentation. If possible, run it before opening the pull request. Otherwise, we shall run it afterward.
## Please don't
diff --git a/.travis.yml b/.travis.yml
index ad1d12d..bd806cb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -41,6 +41,20 @@
after_success:
- valgrind --error-exitcode=1 --leak-check=full test/json_unit
+ # cppcheck
+
+ - os: linux
+ compiler: gcc
+ env:
+ - COMPILER=g++-4.9
+ - SPECIAL=cppcheck
+ addons:
+ apt:
+ sources: ['ubuntu-toolchain-r-test']
+ packages: [g++-4.9, cppcheck]
+ after_success:
+ - make cppcheck
+
# Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/)
- os: linux
diff --git a/Makefile b/Makefile
index f08d5cf..b53d8d3 100644
--- a/Makefile
+++ b/Makefile
@@ -64,8 +64,7 @@
# call cppcheck on the main header file
cppcheck:
- cppcheck --enable=all --inconclusive --std=c++11 src/json.hpp
-
+ cppcheck --enable=warning --inconclusive --force --std=c++11 src/json.hpp --error-exitcode=1
##########################################################################
# maintainer targets
diff --git a/README.md b/README.md
index de70912..3015e86 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
[![Github Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases)
[![Github Issues](https://img.shields.io/github/issues/nlohmann/json.svg)](http://github.com/nlohmann/json/issues)
+[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/289/badge)](https://bestpractices.coreinfrastructure.org/projects/289)
## Design goals
@@ -18,7 +19,7 @@
- **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/src/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings.
-- **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/src/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks.
+- **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/src/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks. To maintain high quality, the project is following the [Core Infrastructure Initiative (CII) best practices](https://bestpractices.coreinfrastructure.org/projects/289).
Other aspects were not so important to us:
diff --git a/src/json.hpp b/src/json.hpp
index 1703328..bd9ffed 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -8541,7 +8541,8 @@
{
case lexer::token_type::begin_object:
{
- if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result))))
+ if (keep and (not callback
+ or ((keep = callback(depth++, parse_event_t::object_start, result)) != 0)))
{
// explicitly set result to object to cope with {}
result.m_type = value_t::object;
@@ -8619,7 +8620,8 @@
case lexer::token_type::begin_array:
{
- if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result))))
+ if (keep and (not callback
+ or ((keep = callback(depth++, parse_event_t::array_start, result)) != 0)))
{
// explicitly set result to object to cope with []
result.m_type = value_t::array;
@@ -9133,7 +9135,7 @@
}
/// split the string input to reference tokens
- static std::vector<std::string> split(std::string reference_string)
+ static std::vector<std::string> split(const std::string& reference_string)
{
std::vector<std::string> result;
@@ -9861,7 +9863,7 @@
*/
static basic_json diff(const basic_json& source,
const basic_json& target,
- std::string path = "")
+ const std::string& path = "")
{
// the patch
basic_json result(value_t::array);
diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c
index ba7ef0f..f5347d6 100644
--- a/src/json.hpp.re2c
+++ b/src/json.hpp.re2c
@@ -8193,7 +8193,8 @@
{
case lexer::token_type::begin_object:
{
- if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result))))
+ if (keep and (not callback
+ or ((keep = callback(depth++, parse_event_t::object_start, result)) != 0)))
{
// explicitly set result to object to cope with {}
result.m_type = value_t::object;
@@ -8271,7 +8272,8 @@
case lexer::token_type::begin_array:
{
- if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result))))
+ if (keep and (not callback
+ or ((keep = callback(depth++, parse_event_t::array_start, result)) != 0)))
{
// explicitly set result to object to cope with []
result.m_type = value_t::array;
@@ -8785,7 +8787,7 @@
}
/// split the string input to reference tokens
- static std::vector<std::string> split(std::string reference_string)
+ static std::vector<std::string> split(const std::string& reference_string)
{
std::vector<std::string> result;
@@ -9513,7 +9515,7 @@
*/
static basic_json diff(const basic_json& source,
const basic_json& target,
- std::string path = "")
+ const std::string& path = "")
{
// the patch
basic_json result(value_t::array);