Add json_document and json_view, a read-only, zero-copy index of a JSON text, as the first public slice of the zero-copy view (#5295). A parse produces a flat array of 16-byte nodes in document order, one per value and one per object key. Strings stay in the source text; escaped strings are decoded into an arena. Integers are converted while their digits are in the cache; floats keep only their digit layout and are converted on read. Containers store the size of their subtree, so a reader can step over one in constant time. A document makes a handful of allocations, however many values it has. The parser accepts exactly what json::parse accepts, with every combination of ignore_comments and ignore_trailing_commas, with and without a trailing NUL, and under JSON_STRICT_NUL_HANDLING. It is portable C++11 and does not depend on byte order. basic_json_document adds parse, parse_copy, accept, read (reuses a document's memory), root, is_discarded, source, owns_source, node_count, memory_usage, and shrink_to_fit. basic_json_view adds type, the is_* queries, operator bool, size, empty, materialize, and source_offset. A parse error throws the same exception basic_json::parse would throw for the same input, message and position included. detail::abi_config keeps JSON_STRICT_NUL_HANDLING and JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON readable after json.hpp undefines them, in the ABI namespace so they always match the basic_json in use. A NUL byte that ends a // comment is the end of the input, as in parse() since #5696. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
amalgamate.py - Amalgamate C source and header files
Origin: https://github.com/edlund/amalgamate (formerly hosted at
https://bitbucket.org/erikedlund/amalgamate, which no longer exists; see
CHANGES.md for the upstream commit this copy is based on)
amalgamate.py aims to make it easy to use SQLite-style C source and header
amalgamation in projects.
For more information, please refer to: http://sqlite.org/amalgamation.html
Here be dragons
amalgamate.py is quite dumb, it only knows the bare minimum about C code
required in order to be able to handle trivial include directives. It can
produce weird results for unexpected code.
Things to be aware of:
amalgamate.py will not handle complex include directives correctly:
#define HEADER_PATH "path/to/header.h"
#include HEADER_PATH
In the above example, path/to/header.h will not be included in the
amalgamation (HEADER_PATH is never expanded).
amalgamate.py makes the assumption that each source and header file which
is not empty will end in a new-line character, which is not immediately
preceded by a backslash character (see 5.1.1.2p1.2 of ISO C99).
amalgamate.py should be usable with C++ code, but raw string literals from
C++11 will definitely cause problems:
R"delimiter(Terrible raw \ data " #include <sneaky.hpp>)delimiter"
R"delimiter(Terrible raw \ data " escaping)delimiter"
In the examples above, amalgamate.py will stop parsing the raw string literal
when it encounters the first quotation mark, which will produce unexpected
results.
Installing amalgamate.py
Python 3 is required.
In this repository, amalgamate.py is not installed separately; it is run in
place through make amalgamate, which calls it once for json.hpp and once
for json_fwd.hpp (see the root Makefile).
Using amalgamate.py
amalgamate.py -c path/to/config.json -s path/to/source/dir \
[-p path/to/prologue.(c|h)] [--verbose=yes|no]
-
The
-c, --configoption should specify the path to a JSON config file which lists the source files, include paths and where to write the resulting amalgamation.config_json.jsonandconfig_json_fwd.jsonin this directory are the configs used forjson.hppandjson_fwd.hpp; each setstarget,sourcesandinclude_paths.The optional
externallist names include paths that are kept as#includedirectives instead of being inlined, e.g.["nlohmann/json.hpp"]for a header that includes another amalgamated header. Only the first directive for each of these paths is kept; the repeated ones are commented out. -
The
-s, --sourceoption should specify the path to the source directory. This is useful for supporting separate source and build directories. -
The
-p, --prologueoption should specify the path to a file which will be added to the beginning of the amalgamation. It is optional. -
The
-v, --verboseoption takesyesorno(for example--verbose=yes, as used by the Makefile). It is optional.