Skip to content

Commit c305d55

Browse files
optimize: rename cjson.decoce_allow_comments to cjson.decocde_allow_comment.
reslove two warnings and update the doc.
1 parent fed8c83 commit c305d55

4 files changed

Lines changed: 15 additions & 14 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Table of Contents
1818
* [encode_skip_unsupported_value_types](#encode_skip_unsupported_value_types)
1919
* [encode_indent](#encode_indent)
2020
* [decode_array_with_array_mt](#decode_array_with_array_mt)
21+
* [decode_allow_comment](#decode_allow_comment)
2122

2223
Description
2324
===========
@@ -263,9 +264,9 @@ cjson.encode(t) -- {"my_array":[]} properly re-encoded as an array
263264

264265
[Back to TOC](#table-of-contents)
265266

266-
decode_allow_comments
267+
decode_allow_comment
267268
--------------------------
268-
**syntax:** `cjson.decode_allow_comments(enabled)`
269+
**syntax:** `cjson.decode_allow_comment(enabled)`
269270

270271
**default:** false
271272

lua_cjson.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ typedef struct {
179179
int decode_invalid_numbers;
180180
int decode_max_depth;
181181
int decode_array_with_array_mt;
182-
int decode_allow_comments;
182+
int decode_allow_comment;
183183
int encode_skip_unsupported_value_types;
184184
} json_config_t;
185185

@@ -386,11 +386,11 @@ static int json_cfg_decode_array_with_array_mt(lua_State *l)
386386
}
387387

388388
/* Configures whether decoder allows comments */
389-
static int json_cfg_decode_allow_comments(lua_State *l)
389+
static int json_cfg_decode_allow_comment(lua_State *l)
390390
{
391391
json_config_t *cfg = json_arg_init(l, 1);
392392

393-
json_enum_option(l, 1, &cfg->decode_allow_comments, NULL, 1);
393+
json_enum_option(l, 1, &cfg->decode_allow_comment, NULL, 1);
394394

395395
return 1;
396396
}
@@ -527,7 +527,7 @@ static void json_create_config(lua_State *l)
527527
cfg->encode_number_precision = DEFAULT_ENCODE_NUMBER_PRECISION;
528528
cfg->encode_empty_table_as_object = DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT;
529529
cfg->decode_array_with_array_mt = DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT;
530-
cfg->decode_allow_comments = DEFAULT_DECODE_ALLOW_COMMENTS;
530+
cfg->decode_allow_comment = DEFAULT_DECODE_ALLOW_COMMENTS;
531531
cfg->encode_escape_forward_slash = DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH;
532532
cfg->encode_skip_unsupported_value_types = DEFAULT_ENCODE_SKIP_UNSUPPORTED_VALUE_TYPES;
533533
cfg->encode_indent = DEFAULT_ENCODE_INDENT;
@@ -1302,7 +1302,7 @@ static void json_next_token(json_parse_t *json, json_token_t *token)
13021302
json->ptr++;
13031303
}
13041304

1305-
if (!json->cfg->decode_allow_comments)
1305+
if (!json->cfg->decode_allow_comment)
13061306
break;
13071307

13081308
/* Eat comments. */
@@ -1671,7 +1671,7 @@ static int lua_cjson_new(lua_State *l)
16711671
{ "decode", json_decode },
16721672
{ "encode_empty_table_as_object", json_cfg_encode_empty_table_as_object },
16731673
{ "decode_array_with_array_mt", json_cfg_decode_array_with_array_mt },
1674-
{ "decode_allow_comments", json_cfg_decode_allow_comments },
1674+
{ "decode_allow_comment", json_cfg_decode_allow_comment },
16751675
{ "encode_sparse_array", json_cfg_encode_sparse_array },
16761676
{ "encode_max_depth", json_cfg_encode_max_depth },
16771677
{ "decode_max_depth", json_cfg_decode_max_depth },

strbuf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static inline void debug_stats(strbuf_t *s)
8686
{
8787
if (s->debug) {
8888
fprintf(stderr, "strbuf(%p) reallocs: %d, length: %zd, size: %zd\n",
89-
s, s->reallocs, s->length, s->size);
89+
(void *) s, s->reallocs, s->length, s->size);
9090
}
9191
}
9292

@@ -165,7 +165,7 @@ void strbuf_resize(strbuf_t *s, size_t len)
165165

166166
if (s->debug > 1) {
167167
fprintf(stderr, "strbuf(%p) resize: %zd => %zd\n",
168-
s, s->size, newsize);
168+
(void *) s, s->size, newsize);
169169
}
170170

171171
s->size = newsize;

tests/test.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ local cjson_tests = {
334334
false, { "Expected value but found invalid unicode escape code at character 2" } },
335335

336336
-- Test comments
337-
{ 'Set decode_allow_comments(true)',
338-
json.decode_allow_comments, { true }, true, { true } },
337+
{ 'Set decode_allow_comment(true)',
338+
json.decode_allow_comment, { true }, true, { true } },
339339
{ "Decode single-line comment",
340340
json.decode, { '{//comment\n}' }, true, { {} } },
341341
{ "Decode single-line comment with windows newline",
@@ -356,8 +356,8 @@ local cjson_tests = {
356356
{ "Decode comment inside number [throw error]",
357357
json.decode, { '{"a":1/*x*/0}' },
358358
false, { "Expected comma or object end but found T_INTEGER at character 12" } },
359-
{ 'Set decode_allow_comments(false)',
360-
json.decode_allow_comments, { false }, true, { false } },
359+
{ 'Set decode_allow_comment(false)',
360+
json.decode_allow_comment, { false }, true, { false } },
361361

362362
-- Test indenting
363363
{ 'Set encode_indent(" ")',

0 commit comments

Comments
 (0)