Skip to content

Commit 483eba8

Browse files
BillyDonahuebaylesj
authored andcommitted
Improve code comment formatting (Issue open-source-parsers#985)
1 parent b350794 commit 483eba8

File tree

3 files changed

+189
-206
lines changed

3 files changed

+189
-206
lines changed

include/json/reader.h

Lines changed: 129 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
namespace Json {
2929

3030
/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
31-
*Value.
31+
* Value.
3232
*
3333
* \deprecated Use CharReader and CharReaderBuilder.
3434
*/
@@ -41,60 +41,55 @@ class JSON_API Reader {
4141
*
4242
* The offsets give the [start, limit) range of bytes within the text. Note
4343
* that this is bytes, not codepoints.
44-
*
4544
*/
4645
struct StructuredError {
4746
ptrdiff_t offset_start;
4847
ptrdiff_t offset_limit;
4948
String message;
5049
};
5150

52-
/** \brief Constructs a Reader allowing all features
53-
* for parsing.
51+
/** \brief Constructs a Reader allowing all features for parsing.
5452
*/
5553
JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
5654
Reader();
5755

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.
6057
*/
6158
JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
6259
Reader(const Features& features);
6360

6461
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
6562
* 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.
7572
* \return \c true if the document was successfully parsed, \c false if an
7673
* error occurred.
7774
*/
7875
bool
7976
parse(const std::string& document, Value& root, bool collectComments = true);
8077

8178
/** \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.
9691
* \return \c true if the document was successfully parsed, \c false if an
97-
error occurred.
92+
* error occurred.
9893
*/
9994
bool parse(const char* beginDoc,
10095
const char* endDoc,
@@ -107,55 +102,56 @@ class JSON_API Reader {
107102

108103
/** \brief Returns a user friendly string that list errors in the parsed
109104
* 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.
115109
* \deprecated Use getFormattedErrorMessages() instead (typo fix).
116110
*/
117111
JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
118112
String getFormatedErrorMessages() const;
119113

120114
/** \brief Returns a user friendly string that list errors in the parsed
121115
* 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.
127120
*/
128121
String getFormattedErrorMessages() const;
129122

130123
/** \brief Returns a vector of structured erros encounted while parsing.
124+
*
131125
* \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.
136129
*/
137130
std::vector<StructuredError> getStructuredErrors() const;
138131

139132
/** \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
141135
* \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.
144138
*/
145139
bool pushError(const Value& value, const String& message);
146140

147141
/** \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
149144
* \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
151146
* \return \c true if the error was successfully added, \c false if either
152147
* Value offset exceeds the document size.
153148
*/
154149
bool pushError(const Value& value, const String& message, const Value& extra);
155150

156151
/** \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.
159155
*/
160156
bool good() const;
161157

@@ -255,22 +251,20 @@ class JSON_API CharReader {
255251
public:
256252
virtual ~CharReader() = default;
257253
/** \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.
261256
*
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.
272266
* \return \c true if the document was successfully parsed, \c false if an
273-
error occurred.
267+
* error occurred.
274268
*/
275269
virtual bool parse(char const* beginDoc,
276270
char const* endDoc,
@@ -288,59 +282,58 @@ class JSON_API CharReader {
288282
}; // CharReader
289283

290284
/** \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+
*/
302296
class JSON_API CharReaderBuilder : public CharReader::Factory {
303297
public:
304298
// Note: We use a Json::Value so that we can add data-members to this class
305299
// without a major version bump.
306300
/** 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+
*/
344337
Json::Value settings_;
345338

346339
CharReaderBuilder();
@@ -381,29 +374,29 @@ bool JSON_API parseFromStream(CharReader::Factory const&,
381374
String* errs);
382375

383376
/** \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+
*/
407400
JSON_API IStream& operator>>(IStream&, Value&);
408401

409402
} // namespace Json

0 commit comments

Comments
 (0)