MT#55283 add str_dup_dup helper function

Change-Id: Ieacb147e3a98b5f31a8e45fb709df73636347cc0
(cherry picked from commit b1ac55c844)
(cherry picked from commit 624d97e014)
mr14.0.1
Richard Fuchs 1 week ago
parent c5876252eb
commit effc7fd01c

@ -480,6 +480,7 @@ const ng_parser_t ng_parser_native = {
.dict_add_string = bencode_dictionary_add_string,
.dict_add_str = bencode_dictionary_add_str,
.dict_add_str_dup = bencode_dictionary_add_str_dup,
.dict_add_str_dup_dup = bencode_dictionary_add_str_dup_dup,
.dict_add_int = bencode_dictionary_add_integer,
.dict_add_dict = __bencode_dictionary_add_dictionary,
.dict_add_dict_dup = __bencode_dictionary_add_dictionary_dup,
@ -516,6 +517,7 @@ const ng_parser_t ng_parser_json = {
.dict_add_string = json_dict_add_string,
.dict_add_str = json_dict_add_str,
.dict_add_str_dup = json_dict_add_str,
.dict_add_str_dup_dup = json_dict_add_str,
.dict_add_int = json_dict_add_int,
.dict_add_dict = json_dict_add_dict,
.dict_add_dict_dup = json_dict_add_dict,

@ -120,6 +120,7 @@ struct ng_parser {
void (*dict_add_string)(parser_arg, const char *, const char *);
void (*dict_add_str)(parser_arg, const char *, const str *);
void (*dict_add_str_dup)(parser_arg, const char *, const str *);
void (*dict_add_str_dup_dup)(parser_arg, const char *, const str *);
void (*dict_add_int)(parser_arg, const char *, long long);
parser_arg (*dict_add_dict)(parser_arg, const char *);
parser_arg (*dict_add_dict_dup)(parser_arg, const char *);

@ -116,6 +116,7 @@ INLINE void bencode_dictionary_add_string(bencode_item_t *dict, const char *key,
INLINE void bencode_dictionary_add_str(bencode_item_t *dict, const char *key, const str *val);
INLINE void bencode_dictionary_str_add_str(bencode_item_t *dict, const str *key, const str *val);
INLINE void bencode_dictionary_add_str_dup(bencode_item_t *dict, const char *key, const str *val);
INLINE void bencode_dictionary_add_str_dup_dup(bencode_item_t *dict, const char *key, const str *val);
/* Convenience functions to add the respective (newly created) objects to a dictionary */
INLINE void bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val);
@ -427,6 +428,12 @@ INLINE void bencode_dictionary_add_str_dup(bencode_item_t *dict, const char *key
bencode_dictionary_add(dict, key, bencode_str_dup(bencode_item_buffer(dict), val));
}
INLINE void bencode_dictionary_add_str_dup_dup(bencode_item_t *dict, const char *key, const str *val) {
if (val)
bencode_dictionary_add(dict, bencode_strdup(bencode_item_buffer(dict), key),
bencode_str_dup(bencode_item_buffer(dict), val));
}
INLINE void bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val) {
bencode_dictionary_add(dict, key, bencode_integer(bencode_item_buffer(dict), val));
}

Loading…
Cancel
Save