Skip to content

Commit e9672c3

Browse files
committed
Documentation enhancements for yajl_tree
1 parent aaf8992 commit e9672c3

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

src/api/yajl_tree.h

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
extern "C" {
3838
#endif
3939

40-
/** possible data types that a yajl_val_s can hold */
40+
/** Possible data types that a yajl_val_s can hold */
4141
typedef enum {
4242
yajl_t_string = 1,
4343
yajl_t_number = 2,
@@ -99,33 +99,33 @@ struct yajl_val_s
9999
/**
100100
* Parse a string.
101101
*
102-
* Parses an null-terminated string containing JSON data and returns a pointer
102+
* Parses a zero-terminated string containing JSON5 data and returns a pointer
103103
* to the top-level value (root of the parse tree).
104104
*
105105
* \param input Pointer to a null-terminated utf8 string containing
106-
* JSON data.
106+
* JSON or JSON5 data.
107107
* \param error_buffer Pointer to a buffer in which an error message will
108-
* be stored if \em yajl_tree_parse fails, or
108+
* be stored if yajl_tree_parse() fails, or
109109
* \c NULL. The buffer will be initialized before
110110
* parsing, so its content will be destroyed even if
111-
* \em yajl_tree_parse succeeds.
111+
* yajl_tree_parse() succeeds.
112112
* \param error_buffer_size Size of the memory area pointed to by
113-
* \em error_buffer_size. If \em error_buffer_size is
114-
* \c NULL, this argument is ignored.
113+
* \p error_buffer. If \p error_buffer
114+
* is \c NULL, this argument is ignored.
115115
*
116116
* \returns Pointer to the top-level value or \c NULL on error. The memory
117-
* pointed to must be freed using \em yajl_tree_free. In case of an error, a
118-
* null terminated message describing the error in more detail is stored in
119-
* \em error_buffer if it is not \c NULL.
117+
* pointed to must be freed using yajl_tree_free(). In case of an error, a
118+
* zero-terminated message describing the error in more detail is stored in
119+
* \p error_buffer if it is not \c NULL.
120120
*/
121121
YAJL_API yajl_val yajl_tree_parse (const char *input,
122122
char *error_buffer, size_t error_buffer_size);
123123

124124

125125
/**
126-
* Free a parse tree returned by "yajl_tree_parse".
126+
* Free a parse tree returned by yajl_tree_parse().
127127
*
128-
* \param v Pointer to a JSON value returned by "yajl_tree_parse". Passing NULL
128+
* \param v Pointer to a JSON value returned by yajl_tree_parse(). Passing \c NULL
129129
* is valid and results in a no-op.
130130
*/
131131
YAJL_API void yajl_tree_free (yajl_val v);
@@ -134,10 +134,10 @@ YAJL_API void yajl_tree_free (yajl_val v);
134134
* Access a nested value inside a tree.
135135
*
136136
* \param parent the node under which you'd like to extract values.
137-
* \param path A null terminated array of strings, each the name of an object key
138-
* \param type the yajl_type of the object you seek, or yajl_t_any if any will do.
137+
* \param path A null terminated array of strings, each the name of an object key.
138+
* \param type the \ref yajl_type of the object you seek, or \ref yajl_t_any if any will do.
139139
*
140-
* \returns a pointer to the found value, or NULL if we came up empty.
140+
* \returns a pointer to the found value, or \c NULL if we came up empty.
141141
*
142142
* Future Ideas: it'd be nice to move path to a string and implement support for
143143
* a teeny tiny micro language here, so you can extract array elements, do things
@@ -146,7 +146,11 @@ YAJL_API void yajl_tree_free (yajl_val v);
146146
*/
147147
YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type type);
148148

149-
/* Various convenience macros to check the type of a `yajl_val` */
149+
/** @name Type Check Macros
150+
*
151+
* Convenience macros to check the type of a \ref yajl_val.
152+
*/
153+
/**@{*/
150154
#define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string))
151155
#define YAJL_IS_NUMBER(v) (((v) != NULL) && ((v)->type == yajl_t_number))
152156
#define YAJL_IS_INTEGER(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_INT_VALID))
@@ -156,29 +160,38 @@ YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type t
156160
#define YAJL_IS_TRUE(v) (((v) != NULL) && ((v)->type == yajl_t_true ))
157161
#define YAJL_IS_FALSE(v) (((v) != NULL) && ((v)->type == yajl_t_false ))
158162
#define YAJL_IS_NULL(v) (((v) != NULL) && ((v)->type == yajl_t_null ))
163+
/**@}*/
164+
165+
/** @name Value Get Macros
166+
*
167+
* Macros to fetch values from a \ref yajl_val.
168+
*/
169+
/**@{*/
159170

160-
/** Given a yajl_val_string return a ptr to the bare string it contains,
161-
* or NULL if the value is not a string. */
171+
/** Given a \ref yajl_t_string return a ptr to the bare string it contains,
172+
* or \c NULL if the value is not a string. */
162173
#define YAJL_GET_STRING(v) (YAJL_IS_STRING(v) ? (v)->u.string : NULL)
163174

164175
/** Get the string representation of a number. You should check type first,
165-
* perhaps using YAJL_IS_NUMBER */
176+
* perhaps using \ref YAJL_IS_NUMBER */
166177
#define YAJL_GET_NUMBER(v) ((v)->u.number.r)
167178

168179
/** Get the double representation of a number. You should check type first,
169-
* perhaps using YAJL_IS_DOUBLE */
180+
* perhaps using \ref YAJL_IS_DOUBLE */
170181
#define YAJL_GET_DOUBLE(v) ((v)->u.number.d)
171182

172183
/** Get the 64bit (long long) integer representation of a number. You should
173-
* check type first, perhaps using YAJL_IS_INTEGER */
184+
* check type first, perhaps using \ref YAJL_IS_INTEGER */
174185
#define YAJL_GET_INTEGER(v) ((v)->u.number.i)
175186

176-
/** Get a pointer to a yajl_val_object or NULL if the value is not an object. */
187+
/** Get a pointer to a \ref yajl_t_object or \c NULL if the value is not an object. */
177188
#define YAJL_GET_OBJECT(v) (YAJL_IS_OBJECT(v) ? &(v)->u.object : NULL)
178189

179-
/** Get a pointer to a yajl_val_array or NULL if the value is not an object. */
190+
/** Get a pointer to a \ref yajl_t_array or \c NULL if the value is not an object. */
180191
#define YAJL_GET_ARRAY(v) (YAJL_IS_ARRAY(v) ? &(v)->u.array : NULL)
181192

193+
/**@}*/
194+
182195
#ifdef __cplusplus
183196
}
184197
#endif

0 commit comments

Comments
 (0)