MT#55283 add is_dict method

Change-Id: I53068670f20bfae642577c078f7f73b97cf7eea7
pull/1848/head
Richard Fuchs 2 years ago
parent c18904d8db
commit c437c0a706

@ -101,6 +101,9 @@ static bool bencode_dict_iter(ng_parser_ctx_t *ctx, bencode_item_t *input,
return true; return true;
} }
static bool bencode_is_dict(bencode_item_t *arg) {
return arg->type == BENCODE_DICTIONARY;
}
static bool bencode_is_list(bencode_item_t *arg) { static bool bencode_is_list(bencode_item_t *arg) {
return arg->type == BENCODE_LIST; return arg->type == BENCODE_LIST;
} }
@ -143,6 +146,7 @@ const ng_parser_t ng_parser_native = {
.get_int_str = bencode_get_integer_str, .get_int_str = bencode_get_integer_str,
.is_int = bencode_is_int, .is_int = bencode_is_int,
.get_int = bencode_get_int, .get_int = bencode_get_int,
.is_dict = bencode_is_dict,
.dict = __bencode_dict, .dict = __bencode_dict,
.dict_get_str = bencode_dictionary_get_str, .dict_get_str = bencode_dictionary_get_str,
.dict_add = bencode_dictionary_add, .dict_add = bencode_dictionary_add,
@ -166,6 +170,7 @@ const ng_parser_t ng_parser_json = {
.get_int_str = bencode_get_integer_str, .get_int_str = bencode_get_integer_str,
.is_int = bencode_is_int, .is_int = bencode_is_int,
.get_int = bencode_get_int, .get_int = bencode_get_int,
.is_dict = bencode_is_dict,
.dict = __bencode_dict, .dict = __bencode_dict,
.dict_get_str = bencode_dictionary_get_str, .dict_get_str = bencode_dictionary_get_str,
.dict_add = bencode_dictionary_add, .dict_add = bencode_dictionary_add,

@ -1003,7 +1003,7 @@ const char *statistics_ng(ng_parser_ctx_t *ctx) {
assert(sub != NULL); assert(sub != NULL);
// is this a dictionary? // is this a dictionary?
if (dict->type == BENCODE_DICTIONARY) { if (ctx->parser->is_dict(dict)) {
assert(sub_label != NULL); assert(sub_label != NULL);
ctx->parser->dict_add(dict, bencode_strdup(buf, sub_label), sub); ctx->parser->dict_add(dict, bencode_strdup(buf, sub_label), sub);
} }

@ -125,6 +125,7 @@ struct ng_parser {
long long (*get_int_str)(bencode_item_t *, long long def); long long (*get_int_str)(bencode_item_t *, long long def);
bool (*is_int)(bencode_item_t *); bool (*is_int)(bencode_item_t *);
long long (*get_int)(bencode_item_t *); long long (*get_int)(bencode_item_t *);
bool (*is_dict)(bencode_item_t *);
bencode_item_t *(*dict)(ng_parser_ctx_t *); bencode_item_t *(*dict)(ng_parser_ctx_t *);
char *(*dict_get_str)(bencode_item_t *, const char *, str *); char *(*dict_get_str)(bencode_item_t *, const char *, str *);
bencode_item_t *(*dict_add)(bencode_item_t *, const char *, bencode_item_t *); bencode_item_t *(*dict_add)(bencode_item_t *, const char *, bencode_item_t *);

Loading…
Cancel
Save