mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
Backport from xs.
This commit is contained in:
parent
4817585733
commit
20bc826300
48
xs.h
48
xs.h
@ -110,11 +110,8 @@ xs_list *xs_split_n(const char *str, const char *sep, int times);
|
||||
xs_list *xs_list_cat(xs_list *l1, const xs_list *l2);
|
||||
|
||||
xs_dict *xs_dict_new(void);
|
||||
xs_dict *xs_dict_append_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz);
|
||||
#define xs_dict_append(dict, key, data) xs_dict_append_m(dict, key, data, xs_size(data))
|
||||
xs_dict *xs_dict_prepend_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz);
|
||||
#define xs_dict_prepend(dict, key, data) xs_dict_prepend_m(dict, key, data, xs_size(data))
|
||||
int xs_dict_iter(xs_dict **dict, xs_str **key, xs_val **value);
|
||||
xs_dict *xs_dict_append(xs_dict *dict, const xs_str *key, const xs_val *value);
|
||||
xs_dict *xs_dict_prepend(xs_dict *dict, const xs_str *key, const xs_val *value);
|
||||
int xs_dict_next(const xs_dict *dict, xs_str **key, xs_val **value, int *ctxt);
|
||||
xs_val *xs_dict_get_def(const xs_dict *dict, const xs_str *key, const xs_val *def);
|
||||
#define xs_dict_get(dict, key) xs_dict_get_def(dict, key, NULL)
|
||||
@ -1042,50 +1039,17 @@ xs_dict *_xs_dict_write_ditem(xs_dict *dict, int offset, const xs_str *key,
|
||||
}
|
||||
|
||||
|
||||
xs_dict *xs_dict_append_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz)
|
||||
xs_dict *xs_dict_append(xs_dict *dict, const xs_str *key, const xs_val *value)
|
||||
/* appends a memory block to the dict */
|
||||
{
|
||||
return _xs_dict_write_ditem(dict, xs_size(dict) - 1, key, mem, dsz);
|
||||
return _xs_dict_write_ditem(dict, xs_size(dict) - 1, key, value, xs_size(value));
|
||||
}
|
||||
|
||||
|
||||
xs_dict *xs_dict_prepend_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz)
|
||||
xs_dict *xs_dict_prepend(xs_dict *dict, const xs_str *key, const xs_val *value)
|
||||
/* prepends a memory block to the dict */
|
||||
{
|
||||
return _xs_dict_write_ditem(dict, 4, key, mem, dsz);
|
||||
}
|
||||
|
||||
|
||||
int xs_dict_iter(xs_dict **dict, xs_str **key, xs_val **value)
|
||||
/* iterates a dict value */
|
||||
{
|
||||
int goon = 1;
|
||||
|
||||
xs_val *p = *dict;
|
||||
|
||||
/* skip the start of the list */
|
||||
if (xs_type(p) == XSTYPE_DICT)
|
||||
p += 1 + _XS_TYPE_SIZE;
|
||||
|
||||
/* an element? */
|
||||
if (xs_type(p) == XSTYPE_DITEM) {
|
||||
p++;
|
||||
|
||||
*key = p;
|
||||
p += xs_size(*key);
|
||||
|
||||
*value = p;
|
||||
p += xs_size(*value);
|
||||
}
|
||||
else {
|
||||
/* end of list */
|
||||
goon = 0;
|
||||
}
|
||||
|
||||
/* store back the pointer */
|
||||
*dict = p;
|
||||
|
||||
return goon;
|
||||
return _xs_dict_write_ditem(dict, 4, key, value, xs_size(value));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
/* 0206a65508e86f66b6aa329418ddc8f6f8c1ecb2 2024-04-22T07:31:05+02:00 */
|
||||
/* f3818ad611f09313008a2102a5e543c232e1d824 2024-05-02T23:45:38+02:00 */
|
||||
|
Loading…
Reference in New Issue
Block a user