28
28
namespace Json {
29
29
30
30
/* * \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
31
- *Value.
31
+ * Value.
32
32
*
33
33
* \deprecated Use CharReader and CharReaderBuilder.
34
34
*/
@@ -41,60 +41,55 @@ class JSON_API Reader {
41
41
*
42
42
* The offsets give the [start, limit) range of bytes within the text. Note
43
43
* that this is bytes, not codepoints.
44
- *
45
44
*/
46
45
struct StructuredError {
47
46
ptrdiff_t offset_start;
48
47
ptrdiff_t offset_limit;
49
48
String message;
50
49
};
51
50
52
- /* * \brief Constructs a Reader allowing all features
53
- * for parsing.
51
+ /* * \brief Constructs a Reader allowing all features for parsing.
54
52
*/
55
53
JSONCPP_DEPRECATED (" Use CharReader and CharReaderBuilder instead" )
56
54
Reader ();
57
55
58
- /* * \brief Constructs a Reader allowing the specified feature set
59
- * for parsing.
56
+ /* * \brief Constructs a Reader allowing the specified feature set for parsing.
60
57
*/
61
58
JSONCPP_DEPRECATED (" Use CharReader and CharReaderBuilder instead" )
62
59
Reader (const Features& features);
63
60
64
61
/* * \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
65
62
* document.
66
- * \param document UTF-8 encoded string containing the document to read.
67
- * \param root [out] Contains the root value of the document if it was
68
- * successfully parsed .
69
- * \param collectComments \c true to collect comment and allow writing them
70
- * back during
71
- * serialization, \c false to discard comments.
72
- * This parameter is ignored if
73
- * Features::allowComments_
74
- * is \c false.
63
+ *
64
+ * \param document UTF-8 encoded string containing the document
65
+ * to read .
66
+ * \param[out] root Contains the root value of the document if it
67
+ * was successfully parsed.
68
+ * \param collectComments \c true to collect comment and allow writing
69
+ * them back during serialization, \c false to
70
+ * discard comments. This parameter is ignored
71
+ * if Features::allowComments_ is \c false.
75
72
* \return \c true if the document was successfully parsed, \c false if an
76
73
* error occurred.
77
74
*/
78
75
bool
79
76
parse (const std::string& document, Value& root, bool collectComments = true );
80
77
81
78
/* * \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
82
- document.
83
- * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the
84
- document to read.
85
- * \param endDoc Pointer on the end of the UTF-8 encoded string of the
86
- document to read.
87
- * Must be >= beginDoc.
88
- * \param root [out] Contains the root value of the document if it was
89
- * successfully parsed.
90
- * \param collectComments \c true to collect comment and allow writing them
91
- back during
92
- * serialization, \c false to discard comments.
93
- * This parameter is ignored if
94
- Features::allowComments_
95
- * is \c false.
79
+ * document.
80
+ *
81
+ * \param beginDoc Pointer on the beginning of the UTF-8 encoded
82
+ * string of the document to read.
83
+ * \param endDoc Pointer on the end of the UTF-8 encoded string
84
+ * of the document to read. Must be >= beginDoc.
85
+ * \param[out] root Contains the root value of the document if it
86
+ * was successfully parsed.
87
+ * \param collectComments \c true to collect comment and allow writing
88
+ * them back during serialization, \c false to
89
+ * discard comments. This parameter is ignored
90
+ * if Features::allowComments_ is \c false.
96
91
* \return \c true if the document was successfully parsed, \c false if an
97
- error occurred.
92
+ * error occurred.
98
93
*/
99
94
bool parse (const char * beginDoc,
100
95
const char * endDoc,
@@ -107,55 +102,56 @@ class JSON_API Reader {
107
102
108
103
/* * \brief Returns a user friendly string that list errors in the parsed
109
104
* document.
110
- * \return Formatted error message with the list of errors with their location
111
- * in
112
- * the parsed document. An empty string is returned if no error
113
- * occurred
114
- * during parsing.
105
+ *
106
+ * \return Formatted error message with the list of errors with their
107
+ * location in the parsed document. An empty string is returned if no error
108
+ * occurred during parsing.
115
109
* \deprecated Use getFormattedErrorMessages() instead (typo fix).
116
110
*/
117
111
JSONCPP_DEPRECATED (" Use getFormattedErrorMessages() instead." )
118
112
String getFormatedErrorMessages () const ;
119
113
120
114
/* * \brief Returns a user friendly string that list errors in the parsed
121
115
* document.
122
- * \return Formatted error message with the list of errors with their location
123
- * in
124
- * the parsed document. An empty string is returned if no error
125
- * occurred
126
- * during parsing.
116
+ *
117
+ * \return Formatted error message with the list of errors with their
118
+ * location in the parsed document. An empty string is returned if no error
119
+ * occurred during parsing.
127
120
*/
128
121
String getFormattedErrorMessages () const ;
129
122
130
123
/* * \brief Returns a vector of structured erros encounted while parsing.
124
+ *
131
125
* \return A (possibly empty) vector of StructuredError objects. Currently
132
- * only one error can be returned, but the caller should tolerate
133
- * multiple
134
- * errors. This can occur if the parser recovers from a non-fatal
135
- * parse error and then encounters additional errors.
126
+ * only one error can be returned, but the caller should tolerate multiple
127
+ * errors. This can occur if the parser recovers from a non-fatal parse
128
+ * error and then encounters additional errors.
136
129
*/
137
130
std::vector<StructuredError> getStructuredErrors () const ;
138
131
139
132
/* * \brief Add a semantic error message.
140
- * \param value JSON Value location associated with the error
133
+ *
134
+ * \param value JSON Value location associated with the error
141
135
* \param message The error message.
142
- * \return \c true if the error was successfully added, \c false if the
143
- * Value offset exceeds the document size.
136
+ * \return \c true if the error was successfully added, \c false if the Value
137
+ * offset exceeds the document size.
144
138
*/
145
139
bool pushError (const Value& value, const String& message);
146
140
147
141
/* * \brief Add a semantic error message with extra context.
148
- * \param value JSON Value location associated with the error
142
+ *
143
+ * \param value JSON Value location associated with the error
149
144
* \param message The error message.
150
- * \param extra Additional JSON Value location to contextualize the error
145
+ * \param extra Additional JSON Value location to contextualize the error
151
146
* \return \c true if the error was successfully added, \c false if either
152
147
* Value offset exceeds the document size.
153
148
*/
154
149
bool pushError (const Value& value, const String& message, const Value& extra);
155
150
156
151
/* * \brief Return whether there are any errors.
157
- * \return \c true if there are no errors to report \c false if
158
- * errors have occurred.
152
+ *
153
+ * \return \c true if there are no errors to report \c false if errors have
154
+ * occurred.
159
155
*/
160
156
bool good () const ;
161
157
@@ -255,22 +251,20 @@ class JSON_API CharReader {
255
251
public:
256
252
virtual ~CharReader () = default ;
257
253
/* * \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
258
- document.
259
- * The document must be a UTF-8 encoded string containing the document to
260
- read.
254
+ * document. The document must be a UTF-8 encoded string containing the
255
+ * document to read.
261
256
*
262
- * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the
263
- document to read.
264
- * \param endDoc Pointer on the end of the UTF-8 encoded string of the
265
- document to read.
266
- * Must be >= beginDoc.
267
- * \param root [out] Contains the root value of the document if it was
268
- * successfully parsed.
269
- * \param errs [out] Formatted error messages (if not NULL)
270
- * a user friendly string that lists errors in the parsed
271
- * document.
257
+ * \param beginDoc Pointer on the beginning of the UTF-8 encoded string
258
+ * of the document to read.
259
+ * \param endDoc Pointer on the end of the UTF-8 encoded string of the
260
+ * document to read. Must be >= beginDoc.
261
+ * \param[out] root Contains the root value of the document if it was
262
+ * successfully parsed.
263
+ * \param[out] errs Formatted error messages (if not NULL) a user
264
+ * friendly string that lists errors in the parsed
265
+ * document.
272
266
* \return \c true if the document was successfully parsed, \c false if an
273
- error occurred.
267
+ * error occurred.
274
268
*/
275
269
virtual bool parse (char const * beginDoc,
276
270
char const * endDoc,
@@ -288,59 +282,58 @@ class JSON_API CharReader {
288
282
}; // CharReader
289
283
290
284
/* * \brief Build a CharReader implementation.
291
-
292
- Usage:
293
- \code
294
- using namespace Json;
295
- CharReaderBuilder builder;
296
- builder["collectComments"] = false;
297
- Value value;
298
- String errs;
299
- bool ok = parseFromStream(builder, std::cin, &value, &errs);
300
- \endcode
301
- */
285
+ *
286
+ * Usage:
287
+ * \code
288
+ * using namespace Json;
289
+ * CharReaderBuilder builder;
290
+ * builder["collectComments"] = false;
291
+ * Value value;
292
+ * String errs;
293
+ * bool ok = parseFromStream(builder, std::cin, &value, &errs);
294
+ * \endcode
295
+ */
302
296
class JSON_API CharReaderBuilder : public CharReader::Factory {
303
297
public:
304
298
// Note: We use a Json::Value so that we can add data-members to this class
305
299
// without a major version bump.
306
300
/* * Configuration of this builder.
307
- These are case-sensitive.
308
- Available settings (case-sensitive):
309
- - `"collectComments": false or true`
310
- - true to collect comment and allow writing them
311
- back during serialization, false to discard comments.
312
- This parameter is ignored if allowComments is false.
313
- - `"allowComments": false or true`
314
- - true if comments are allowed.
315
- - `"strictRoot": false or true`
316
- - true if root must be either an array or an object value
317
- - `"allowDroppedNullPlaceholders": false or true`
318
- - true if dropped null placeholders are allowed. (See
319
- StreamWriterBuilder.)
320
- - `"allowNumericKeys": false or true`
321
- - true if numeric object keys are allowed.
322
- - `"allowSingleQuotes": false or true`
323
- - true if '' are allowed for strings (both keys and values)
324
- - `"stackLimit": integer`
325
- - Exceeding stackLimit (recursive depth of `readValue()`) will
326
- cause an exception.
327
- - This is a security issue (seg-faults caused by deeply nested JSON),
328
- so the default is low.
329
- - `"failIfExtra": false or true`
330
- - If true, `parse()` returns false when extra non-whitespace trails
331
- the JSON value in the input string.
332
- - `"rejectDupKeys": false or true`
333
- - If true, `parse()` returns false when a key is duplicated within an
334
- object.
335
- - `"allowSpecialFloats": false or true`
336
- - If true, special float values (NaNs and infinities) are allowed
337
- and their values are lossfree restorable.
338
-
339
- You can examine 'settings_` yourself
340
- to see the defaults. You can also write and read them just like any
341
- JSON Value.
342
- \sa setDefaults()
343
- */
301
+ * These are case-sensitive.
302
+ * Available settings (case-sensitive):
303
+ * - `"collectComments": false or true`
304
+ * - true to collect comment and allow writing them back during
305
+ * serialization, false to discard comments. This parameter is ignored
306
+ * if allowComments is false.
307
+ * - `"allowComments": false or true`
308
+ * - true if comments are allowed.
309
+ * - `"strictRoot": false or true`
310
+ * - true if root must be either an array or an object value
311
+ * - `"allowDroppedNullPlaceholders": false or true`
312
+ * - true if dropped null placeholders are allowed. (See
313
+ * StreamWriterBuilder.)
314
+ * - `"allowNumericKeys": false or true`
315
+ * - true if numeric object keys are allowed.
316
+ * - `"allowSingleQuotes": false or true`
317
+ * - true if '' are allowed for strings (both keys and values)
318
+ * - `"stackLimit": integer`
319
+ * - Exceeding stackLimit (recursive depth of `readValue()`) will cause an
320
+ * exception.
321
+ * - This is a security issue (seg-faults caused by deeply nested JSON), so
322
+ * the default is low.
323
+ * - `"failIfExtra": false or true`
324
+ * - If true, `parse()` returns false when extra non-whitespace trails the
325
+ * JSON value in the input string.
326
+ * - `"rejectDupKeys": false or true`
327
+ * - If true, `parse()` returns false when a key is duplicated within an
328
+ * object.
329
+ * - `"allowSpecialFloats": false or true`
330
+ * - If true, special float values (NaNs and infinities) are allowed and
331
+ * their values are lossfree restorable.
332
+ *
333
+ * You can examine 'settings_` yourself to see the defaults. You can also
334
+ * write and read them just like any JSON Value.
335
+ * \sa setDefaults()
336
+ */
344
337
Json::Value settings_;
345
338
346
339
CharReaderBuilder ();
@@ -381,29 +374,29 @@ bool JSON_API parseFromStream(CharReader::Factory const&,
381
374
String* errs);
382
375
383
376
/* * \brief Read from 'sin' into 'root'.
384
-
385
- Always keep comments from the input JSON.
386
-
387
- This can be used to read a file into a particular sub-object.
388
- For example:
389
- \code
390
- Json::Value root;
391
- cin >> root["dir"]["file"];
392
- cout << root;
393
- \endcode
394
- Result:
395
- \verbatim
396
- {
397
- "dir": {
398
- "file": {
399
- // The input stream JSON would be nested here.
400
- }
401
- }
402
- }
403
- \endverbatim
404
- \throw std::exception on parse error.
405
- \see Json::operator<<()
406
- */
377
+ *
378
+ * Always keep comments from the input JSON.
379
+ *
380
+ * This can be used to read a file into a particular sub-object.
381
+ * For example:
382
+ * \code
383
+ * Json::Value root;
384
+ * cin >> root["dir"]["file"];
385
+ * cout << root;
386
+ * \endcode
387
+ * Result:
388
+ * \verbatim
389
+ * {
390
+ * "dir": {
391
+ * "file": {
392
+ * // The input stream JSON would be nested here.
393
+ * }
394
+ * }
395
+ * }
396
+ * \endverbatim
397
+ * \throw std::exception on parse error.
398
+ * \see Json::operator<<()
399
+ */
407
400
JSON_API IStream& operator >>(IStream&, Value&);
408
401
409
402
} // namespace Json
0 commit comments