5 * Hu Tao <hutao@cn.fujitsu.com>
6 * Peter Lieven <pl@kamp.de>
8 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
9 * See the COPYING.LIB file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "qemu/ctype.h"
17 const char *qapi_enum_lookup(const QEnumLookup
*lookup
, int val
)
19 assert(val
>= 0 && val
< lookup
->size
);
21 return lookup
->array
[val
];
24 int qapi_enum_parse(const QEnumLookup
*lookup
, const char *buf
,
25 int def
, Error
**errp
)
33 for (i
= 0; i
< lookup
->size
; i
++) {
34 if (!strcmp(buf
, lookup
->array
[i
])) {
39 error_setg(errp
, "invalid parameter value: %s", buf
);
44 * Parse a valid QAPI name from @str.
45 * A valid name consists of letters, digits, hyphen and underscore.
46 * It may be prefixed by __RFQDN_ (downstream extension), where RFQDN
47 * may contain only letters, digits, hyphen and period.
48 * The special exception for enumeration names is not implemented.
49 * See docs/devel/qapi-code-gen.txt for more on QAPI naming rules.
50 * Keep this consistent with scripts/qapi.py!
51 * If @complete, the parse fails unless it consumes @str completely.
52 * Return its length on success, -1 on failure.
54 int parse_qapi_name(const char *str
, bool complete
)
58 if (*p
== '_') { /* Downstream __RFQDN_ */
64 if (!qemu_isalnum(*p
) && *p
!= '-' && *p
!= '.') {
75 if (!qemu_isalpha(*p
)) {
79 if (!qemu_isalnum(*p
) && *p
!= '-' && *p
!= '_') {