Lines Matching +full:- +full:- +full:prefix
4 * Copyright (c) 2013-2018 Red Hat, Inc.
7 * See the COPYING.LIB file in the top-level directory.
16 #include "qapi/qobject-input-visitor.h"
53 const char *prefix);
55 static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix) in qdict_flatten_qlist() argument
64 /* This function is never called with prefix == NULL, i.e., it is always in qdict_flatten_qlist()
68 assert(prefix); in qdict_flatten_qlist()
76 new_key = g_strdup_printf("%s.%i", prefix, i); in qdict_flatten_qlist()
79 * Flatten non-empty QDict and QList recursively into @target, in qdict_flatten_qlist()
94 static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) in qdict_flatten_qdict() argument
110 if (prefix) { in qdict_flatten_qdict()
111 key = new_key = g_strdup_printf("%s.%s", prefix, entry->key); in qdict_flatten_qdict()
113 key = entry->key; in qdict_flatten_qdict()
118 * Flatten non-empty QDict and QList recursively into @target, in qdict_flatten_qdict()
132 qdict_del(qdict, entry->key); in qdict_flatten_qdict()
137 qdict_del(qdict, entry->key); in qdict_flatten_qdict()
149 * qdict_flatten(): For each nested non-empty QDict with key x, all
151 * to "x.y". For each nested non-empty QList with key x, the field at
176 if (strstart(entry->key, start, &p)) { in qdict_extract_subqdict()
178 qdict_put_obj(*dst, p, qobject_ref(entry->value)); in qdict_extract_subqdict()
180 qdict_del(src, entry->key); in qdict_extract_subqdict()
192 if (strstart(entry->key, start, NULL)) { in qdict_count_prefixed_entries()
194 return -ERANGE; in qdict_count_prefixed_entries()
204 * qdict_array_split(): This function moves array-like elements of a QDict into
208 * output QList with the key prefix removed, if that prefix is "%u.". If the
211 * QDict with a prefix directly (incrementally) following the last one; it also
228 char indexstr[32], prefix[32]; in qdict_array_split() local
236 snprintf_ret = snprintf(prefix, 32, "%u.", i); in qdict_array_split()
239 /* Overflow is the same as positive non-zero results */ in qdict_array_split()
240 is_subqdict = qdict_count_prefixed_entries(src, prefix); in qdict_array_split()
252 qdict_extract_subqdict(src, &subqdict, prefix); in qdict_array_split()
266 * @prefix: non-NULL pointer to hold extracted prefix
267 * @suffix: non-NULL pointer to remaining suffix
274 * 'foo.0.bar' -> prefix='foo' and suffix='0.bar'
275 * 'foo..0.bar' -> prefix='foo.0' and suffix='bar'
277 * The '..' sequence will be unescaped in the returned 'prefix'
282 * The caller is responsible for freeing the string returned in @prefix
285 static void qdict_split_flat_key(const char *key, char **prefix, in qdict_split_flat_key() argument
304 *prefix = g_strndup(key, separator - key); in qdict_split_flat_key()
307 *prefix = g_strdup(key); in qdict_split_flat_key()
312 for (i = 0, j = 0; (*prefix)[i] != '\0'; i++, j++) { in qdict_split_flat_key()
313 if ((*prefix)[i] == '.') { in qdict_split_flat_key()
314 assert((*prefix)[i + 1] == '.'); in qdict_split_flat_key()
317 (*prefix)[j] = (*prefix)[i]; in qdict_split_flat_key()
319 (*prefix)[j] = '\0'; in qdict_split_flat_key()
327 * If @maybe_list is non-zero in length and all the keys look like
329 * length or all keys are non-numeric then it will return 0 to indicate
330 * it is a normal qdict. If there is a mix of numeric and non-numeric
331 * keys, or the list indexes are non-contiguous, an error is reported.
333 * Returns: 1 if a valid list, 0 if a dict, -1 on error
339 ssize_t max = -1; in qdict_is_list()
340 int is_list = -1; in qdict_is_list()
345 int is_index = !qemu_strtoi64(ent->key, NULL, 10, &val); in qdict_is_list()
347 if (is_list == -1) { in qdict_is_list()
352 error_setg(errp, "Cannot mix list and non-list keys"); in qdict_is_list()
353 return -1; in qdict_is_list()
364 if (is_list == -1) { in qdict_is_list()
369 /* NB this isn't a perfect check - e.g. it won't catch in qdict_is_list()
371 * does not matter - we've still proved that the in qdict_is_list()
378 return -1; in qdict_is_list()
411 * - Any values in @src are non-scalar types
412 * - If keys in @src imply that a particular level is both a
414 * - If keys in @src imply that a particular level is a list,
415 * but the indices are non-contiguous. e.g. "foo.0.bar" and
417 * - If keys in @src represent list indexes, but are not in
431 char *prefix = NULL; in qdict_crumple() local
439 dict_val = qobject_to(QDict, ent->value); in qdict_crumple()
440 list_val = qobject_to(QList, ent->value); in qdict_crumple()
443 error_setg(errp, "Value %s is not flat", ent->key); in qdict_crumple()
447 qdict_split_flat_key(ent->key, &prefix, &suffix); in qdict_crumple()
448 child = qdict_get(two_level, prefix); in qdict_crumple()
453 * If @child_dict, then all previous keys with this prefix in qdict_crumple()
458 error_setg(errp, "Cannot mix scalar and non-scalar keys"); in qdict_crumple()
466 qdict_put(two_level, prefix, child_dict); in qdict_crumple()
468 qdict_put_obj(child_dict, suffix, qobject_ref(ent->value)); in qdict_crumple()
470 qdict_put_obj(two_level, prefix, qobject_ref(ent->value)); in qdict_crumple()
473 g_free(prefix); in qdict_crumple()
474 prefix = NULL; in qdict_crumple()
478 * into a multi-level dict */ in qdict_crumple()
482 dict_val = qobject_to(QDict, ent->value); in qdict_crumple()
489 qdict_put_obj(multi_level, ent->key, child); in qdict_crumple()
491 qdict_put_obj(multi_level, ent->key, qobject_ref(ent->value)); in qdict_crumple()
528 g_free(prefix); in qdict_crumple()
558 switch (qobject_type(ent->value)) { in qdict_crumple_for_keyval_qiv()
563 s = buf = qnum_to_string(qobject_to(QNum, ent->value)); in qdict_crumple_for_keyval_qiv()
570 s = qbool_get_bool(qobject_to(QBool, ent->value)) in qdict_crumple_for_keyval_qiv()
580 qdict_put_str(tmp, ent->key, s); in qdict_crumple_for_keyval_qiv()
591 * sub-QDict of src specified by the prefix in subqdict (or src itself for
592 * prefix == "") is valid as an array, i.e. the length of the created list if
593 * the sub-QDict would become empty after calling qdict_array_split() on it. If
594 * the array is not valid, -EINVAL is returned.
603 assert(!subqdict_len || subqdict[subqdict_len - 1] == '.'); in qdict_array_entries()
607 * entries will lead to -EINVAL. */ in qdict_array_entries()
611 char *prefix = g_strdup_printf("%s%u.", subqdict, i); in qdict_array_entries() local
613 subqdict_entries = qdict_count_prefixed_entries(src, prefix); in qdict_array_entries()
616 prefix[strlen(prefix) - 1] = 0; in qdict_array_entries()
617 subqobj = qdict_get(src, prefix); in qdict_array_entries()
619 g_free(prefix); in qdict_array_entries()
628 return -EINVAL; in qdict_array_entries()
636 /* Consider everything handled that isn't part of the given sub-QDict */ in qdict_array_entries()
643 /* Anything left in the sub-QDict that wasn't handled? */ in qdict_array_entries()
645 return -EINVAL; in qdict_array_entries()
673 if (overwrite || !qdict_haskey(dest, entry->key)) { in qdict_join()
674 qdict_put_obj(dest, entry->key, qobject_ref(entry->value)); in qdict_join()
675 qdict_del(src, entry->key); in qdict_join()
697 while (renames->from) { in qdict_rename_keys()
698 if (qdict_haskey(qdict, renames->from)) { in qdict_rename_keys()
699 if (qdict_haskey(qdict, renames->to)) { in qdict_rename_keys()
701 "same time", renames->to, renames->from); in qdict_rename_keys()
705 qobj = qdict_get(qdict, renames->from); in qdict_rename_keys()
706 qdict_put_obj(qdict, renames->to, qobject_ref(qobj)); in qdict_rename_keys()
707 qdict_del(qdict, renames->from); in qdict_rename_keys()