For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
*/
+#include <stdio.h>
#include "hb.h"
#include "hb_dict.h"
return type;
}
-hb_value_t * hb_value_dup(hb_value_t *value)
+hb_value_t * hb_value_dup(const hb_value_t *value)
{
if (value == NULL) return NULL;
return json_deep_copy(value);
return json_dumps(value, JSON_INDENT(4) | JSON_SORT_KEYS);
}
+int hb_value_write_file_json(hb_value_t *value, FILE *file)
+{
+ return json_dumpf(value, file, JSON_INDENT(4) | JSON_SORT_KEYS);
+}
+
int hb_value_write_json(hb_value_t *value, const char *path)
{
return json_dump_file(value, path, JSON_INDENT(4) | JSON_SORT_KEYS);
return json_object_del(dict, key) == 0;
}
-hb_value_t * hb_dict_get(hb_dict_t * dict, const char * key)
+hb_value_t * hb_dict_get(const hb_dict_t * dict, const char * key)
{
return json_object_get(dict, key);
}
return json_object_iter_value(iter);
}
+int
+hb_dict_iter_next_ex(hb_dict_t *dict, hb_dict_iter_t *iter,
+ const char **key, hb_value_t **val)
+{
+ if (*iter == NULL)
+ return 0;
+ if (key != NULL)
+ *key = json_object_iter_key(*iter);
+ if (val != NULL)
+ *val = json_object_iter_value(*iter);
+ *iter = json_object_iter_next(dict, *iter);
+ return 1;
+}
+
hb_value_array_t*
hb_value_array_init()
{
/* remove value from dictionary. releases reference to value */
int hb_dict_remove(hb_dict_t * dict, const char * key);
/* get value from dictionary. value has borrowed reference */
-hb_value_t * hb_dict_get(hb_dict_t * dict, const char * key);
+hb_value_t * hb_dict_get(const hb_dict_t * dict, const char * key);
/* dict iterator
* hb_dict_iter_init(dict) returns an iter to the first key/value in the dict
*/
hb_dict_iter_t hb_dict_iter_init(const hb_dict_t *dict);
hb_dict_iter_t hb_dict_iter_next(const hb_dict_t *dict, hb_dict_iter_t iter);
+int hb_dict_iter_next_ex(hb_dict_t *dict, hb_dict_iter_t *iter,
+ const char **key, hb_value_t **val);
/* get key from iter */
const char * hb_dict_iter_key(const hb_dict_iter_t iter);
/* get value from iter. value has borrowed reference */
/* hb_value_t */
int hb_value_type(const hb_value_t *value);
-hb_value_t * hb_value_dup(hb_value_t *value);
+hb_value_t * hb_value_dup(const hb_value_t *value);
void hb_value_incref(hb_value_t *value);
void hb_value_decref(hb_value_t *value);
void hb_value_free(hb_value_t **value);
/* converts value to json string */
char * hb_value_get_json(hb_value_t *value);
/* write json representation to a file */
+int hb_value_write_file_json(hb_value_t *value, FILE *file);
int hb_value_write_json(hb_value_t *value, const char *path);
/* specialized dict functions */