features.md 4.5 KB
Newer Older
miloyip's avatar
miloyip committed
1
# Features
Milo Yip's avatar
Milo Yip committed
2 3 4 5

## General

* Cross-platform
Milo Yip's avatar
Milo Yip committed
6 7 8
 * Compilers: Visual Studio, gcc, clang, etc.
 * Architectures: x86, x64, ARM, etc.
 * Operating systems: Windows, Mac OS X, Linux, iOS, Android, etc.
Milo Yip's avatar
Milo Yip committed
9 10
* Easy installation
 * Header files only library. Just copy the headers to your project.
Milo Yip's avatar
Milo Yip committed
11
* Self-contained, minimal dependences
Milo Yip's avatar
Milo Yip committed
12
 * No STL, BOOST, etc.
Milo Yip's avatar
Milo Yip committed
13
 * Only included `<cstdio>`, `<cstdlib>`, `<cstring>`, `<inttypes.h>`, `<new>`, `<stdint.h>`. 
Milo Yip's avatar
Milo Yip committed
14
* Without C++ exception, RTTI
Milo Yip's avatar
Milo Yip committed
15 16
* High performance
 * Use template and inline functions to reduce function call overheads.
Milo Yip's avatar
Milo Yip committed
17
 * Internal optimized Grisu2 and floating point parsing implementations.
18
 * Optional SSE2/SSE4.2 support.
Milo Yip's avatar
Milo Yip committed
19 20 21 22

## Standard compliance

* RapidJSON should be fully RFC4627/ECMA-404 compliance.
23
* Support Unicode surrogate.
Milo Yip's avatar
Milo Yip committed
24
* Support null character (`"\u0000"`)
Milo Yip's avatar
Milo Yip committed
25
 * For example, `["Hello\u0000World"]` can be parsed and handled gracefully. There is API for getting/setting lengths of string.
26 27
* Support optional relaxed syntax.
 * Single line (`// ...`) and multiple line (`/* ... */`) comments.
Milo Yip's avatar
Milo Yip committed
28 29 30 31 32

## Unicode

* Support UTF-8, UTF-16, UTF-32 encodings, including little endian and big endian.
 * These encodings are used in input/output streams and in-memory representation.
Milo Yip's avatar
Milo Yip committed
33
* Support automatic detection of encodings in input stream.
Milo Yip's avatar
Milo Yip committed
34 35 36 37
* Support transcoding between encodings internally.
 * For example, you can read a UTF-8 file and let RapidJSON transcode the JSON strings into UTF-16 in the DOM.
* Support encoding validation internally.
 * For example, you can read a UTF-8 file, and let RapidJSON check whether all JSON strings are valid UTF-8 byte sequence.
Milo Yip's avatar
Milo Yip committed
38 39
* Support custom character types.
 * By default the character types are `char` for UTF8, `wchar_t` for UTF16, `uint32_t` for UTF32.
Milo Yip's avatar
Milo Yip committed
40 41
* Support custom encodings.

Milo Yip's avatar
Milo Yip committed
42 43 44
## API styles

* SAX (Simple API for XML) style API
45
 * Similar to [SAX](http://en.wikipedia.org/wiki/Simple_API_for_XML), RapidJSON provides a event sequential access parser API (`rapidjson::GenericReader`). It also provides a generator API (`rapidjson::Writer`) which consumes the same set of events.
Milo Yip's avatar
Milo Yip committed
46
* DOM (Document Object Model) style API
47 48
 * Similar to [DOM](http://en.wikipedia.org/wiki/Document_Object_Model) for HTML/XML, RapidJSON can parse JSON into a DOM representation (`rapidjson::GenericDocument`), for easy manipulation, and finally stringify back to JSON if needed.
 * The DOM style API (`rapidjson::GenericDocument`) is actually implemented with SAX style API (`rapidjson::GenericReader`). SAX is faster but sometimes DOM is easier. Users can pick their choices according to scenarios.
Milo Yip's avatar
Milo Yip committed
49

Milo Yip's avatar
Milo Yip committed
50
## Parsing
Milo Yip's avatar
Milo Yip committed
51

Milo Yip's avatar
Milo Yip committed
52 53 54
* Recursive (default) and iterative parser
 * Recursive parser is faster but prone to stack overflow in extreme cases.
 * Iterative parser use custom stack to keep parsing state.
55
* Support *in situ* parsing.
Milo Yip's avatar
Milo Yip committed
56 57 58
 * Parse JSON string values in-place at the source JSON, and then the DOM points to addresses of those strings.
 * Faster than convention parsing: no allocation for strings, no copy (if string does not contain escapes), cache-friendly.
* Support 32-bit/64-bit signed/unsigned integer and `double` for JSON number type.
Milo Yip's avatar
Milo Yip committed
59 60 61 62
* Support parsing multiple JSONs in input stream (`kParseStopWhenDoneFlag`).
* Error Handling
 * Support comprehensive error code if parsing failed.
 * Support error message localization.
Milo Yip's avatar
Milo Yip committed
63

Milo Yip's avatar
Milo Yip committed
64
## DOM (Document)
Milo Yip's avatar
Milo Yip committed
65

Milo Yip's avatar
Milo Yip committed
66 67 68 69 70 71 72
* RapidJSON checks range of numerical values for conversions.
* Optimization for string literal
 * Only store pointer instead of copying
* Optimization for "short" strings
 * Store short string in `Value` internally without additional allocation.
 * For UTF-8 string: maximum 11 characters in 32-bit, 15 characters in 64-bit.
* Optionally support `std::string` (define `RAPIDJSON_HAS_STDSTRING=1`)
Milo Yip's avatar
Milo Yip committed
73

Milo Yip's avatar
Milo Yip committed
74
## Generation
Milo Yip's avatar
Milo Yip committed
75

76
* Support `rapidjson::PrettyWriter` for adding newlines and indentations.
Milo Yip's avatar
Milo Yip committed
77

Milo Yip's avatar
Milo Yip committed
78 79
## Stream

80
* Support `rapidjson::GenericStringBuffer` for storing the output JSON as string.
81
* Support `rapidjson::FileReadStream` and `rapidjson::FileWriteStream` for input/output `FILE` object.
Milo Yip's avatar
Milo Yip committed
82 83 84 85 86 87 88 89 90
* Support custom streams.

## Memory

* Minimize memory overheads for DOM.
 * Each JSON value occupies exactly 16/20 bytes for most 32/64-bit machines (excluding text string).
* Support fast default allocator.
 * A stack-based allocator (allocate sequentially, prohibit to free individual allocations, suitable for parsing).
 * User can provide a pre-allocated buffer. (Possible to parse a number of JSONs without any CRT allocation)
Milo Yip's avatar
Milo Yip committed
91
* Support standard CRT(C-runtime) allocator.
Milo Yip's avatar
Milo Yip committed
92
* Support custom allocators.
Milo Yip's avatar
Milo Yip committed
93 94 95 96 97 98

## Miscellaneous

* Some C++11 support (optional)
 * Rvalue reference
 * `noexcept` specifier