object: dict: use b_strings as keys rather than plain c-strings.

now that strings can contain UTF-8 codepoints and null chars, the b_dict
api has been enhanced to accept keys as b_strings as well as regular c-strings.

keys are now stored as b_strings internally, to allow a wider range of
keys to be used.
This commit is contained in:
2025-09-22 10:50:07 +01:00
parent b7da91ac93
commit be47176524
3 changed files with 85 additions and 10 deletions

View File

@@ -8,6 +8,8 @@
#include <blue/object/object.h>
#include <blue/object/type.h>
struct b_string;
#define B_DICT(p) ((b_dict *)(p))
#define B_DICT_ITEM(k, v) \
@@ -28,7 +30,7 @@ typedef struct b_dict b_dict;
typedef struct b_dict_iterator {
b_iterator _base;
size_t i;
const char *key;
const struct b_string *key;
b_object *value;
b_dict *_d;
@@ -54,10 +56,15 @@ static inline void b_dict_release(b_dict *dict)
}
BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_object *value);
BLUE_API b_status b_dict_put_sk(
b_dict *dict, const struct b_string *key, b_object *value);
BLUE_API b_object *b_dict_at(const b_dict *dict, const char *key);
BLUE_API b_object *b_dict_at_sk(const b_dict *dict, const struct b_string *key);
BLUE_API b_object *b_dict_get(b_dict *dict, const char *key);
BLUE_API b_object *b_dict_get_sk(b_dict *dict, const struct b_string *key);
BLUE_API bool b_dict_has_key(const b_dict *dict, const char *key);
BLUE_API bool b_dict_has_skey(const b_dict *dict, const struct b_string *key);
BLUE_API size_t b_dict_get_size(const b_dict *dict);
BLUE_API bool b_dict_is_empty(const b_dict *dict);