mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
Backport from xs.
This commit is contained in:
parent
3dbeee863e
commit
45278afdf1
2 changed files with 14 additions and 6 deletions
18
xs.h
18
xs.h
|
@ -60,6 +60,7 @@ xstype xs_type(const xs_val *data);
|
||||||
int xs_size(const xs_val *data);
|
int xs_size(const xs_val *data);
|
||||||
int xs_is_null(const xs_val *data);
|
int xs_is_null(const xs_val *data);
|
||||||
int xs_cmp(const xs_val *v1, const xs_val *v2);
|
int xs_cmp(const xs_val *v1, const xs_val *v2);
|
||||||
|
const xs_val *xs_or(const xs_val *v1, const xs_val *v2);
|
||||||
xs_val *xs_dup(const xs_val *data);
|
xs_val *xs_dup(const xs_val *data);
|
||||||
xs_val *xs_expand(xs_val *data, int offset, int size);
|
xs_val *xs_expand(xs_val *data, int offset, int size);
|
||||||
xs_val *xs_collapse(xs_val *data, int offset, int size);
|
xs_val *xs_collapse(xs_val *data, int offset, int size);
|
||||||
|
@ -119,8 +120,8 @@ xs_dict *xs_dict_new(void);
|
||||||
xs_dict *xs_dict_append(xs_dict *dict, const xs_str *key, const 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);
|
xs_dict *xs_dict_prepend(xs_dict *dict, const xs_str *key, const xs_val *value);
|
||||||
int xs_dict_next(const xs_dict *dict, const xs_str **key, const xs_val **value, int *ctxt);
|
int xs_dict_next(const xs_dict *dict, const xs_str **key, const xs_val **value, int *ctxt);
|
||||||
const xs_val *xs_dict_get_def(const xs_dict *dict, const xs_str *key, const xs_val *def);
|
const xs_val *xs_dict_get(const xs_dict *dict, const xs_str *key);
|
||||||
#define xs_dict_get(dict, key) xs_dict_get_def(dict, key, NULL)
|
#define xs_dict_get_def(dict, key, def) xs_or(xs_dict_get(dict, key), def)
|
||||||
xs_dict *xs_dict_del(xs_dict *dict, const xs_str *key);
|
xs_dict *xs_dict_del(xs_dict *dict, const xs_str *key);
|
||||||
xs_dict *xs_dict_set(xs_dict *dict, const xs_str *key, const xs_val *data);
|
xs_dict *xs_dict_set(xs_dict *dict, const xs_str *key, const xs_val *data);
|
||||||
xs_dict *xs_dict_gc(const xs_dict *dict);
|
xs_dict *xs_dict_gc(const xs_dict *dict);
|
||||||
|
@ -360,6 +361,13 @@ int xs_cmp(const xs_val *v1, const xs_val *v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const xs_val *xs_or(const xs_val *v1, const xs_val *v2)
|
||||||
|
/* returns v1 if it's not NULL, else v2 */
|
||||||
|
{
|
||||||
|
return v1 == NULL ? v2 : v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
xs_val *xs_dup(const xs_val *data)
|
xs_val *xs_dup(const xs_val *data)
|
||||||
/* creates a duplicate of data */
|
/* creates a duplicate of data */
|
||||||
{
|
{
|
||||||
|
@ -1211,8 +1219,8 @@ xs_dict *xs_dict_del(xs_dict *dict, const xs_str *key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const xs_val *xs_dict_get_def(const xs_dict *dict, const xs_str *key, const xs_str *def)
|
const xs_val *xs_dict_get(const xs_dict *dict, const xs_str *key)
|
||||||
/* gets a value by key, or returns def */
|
/* gets a value by key, or NULL */
|
||||||
{
|
{
|
||||||
if (xs_type(dict) == XSTYPE_DICT) {
|
if (xs_type(dict) == XSTYPE_DICT) {
|
||||||
int *o = _xs_dict_locate(dict, key);
|
int *o = _xs_dict_locate(dict, key);
|
||||||
|
@ -1226,7 +1234,7 @@ const xs_val *xs_dict_get_def(const xs_dict *dict, const xs_str *key, const xs_s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return def;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
/* 3536c4e2ab0849eccf81c50741028453e9ad7f3a 2024-08-05T18:37:46+02:00 */
|
/* 7c7c38b6d14c07cb85698223bcff4d3193245437 2024-08-11T21:48:09+02:00 */
|
||||||
|
|
Loading…
Reference in a new issue