qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, Fam Zheng <famz@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 1/5] qapi: Add qapi_enum_parse_full
Date: Wed,  9 May 2018 13:57:58 +0800	[thread overview]
Message-ID: <20180509055802.28423-2-famz@redhat.com> (raw)
In-Reply-To: <20180509055802.28423-1-famz@redhat.com>

This variant of qapi_enum_parse can do case insensitive compare.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 include/qapi/util.h |  2 ++
 qapi/qapi-util.c    | 20 ++++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/qapi/util.h b/include/qapi/util.h
index a7c3c64148..2cec231919 100644
--- a/include/qapi/util.h
+++ b/include/qapi/util.h
@@ -19,6 +19,8 @@ typedef struct QEnumLookup {
 const char *qapi_enum_lookup(const QEnumLookup *lookup, int val);
 int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
                     int def, Error **errp);
+int qapi_enum_parse_full(const QEnumLookup *lookup, const char *buf,
+                         int def, bool ignore_case, Error **errp);
 
 int parse_qapi_name(const char *name, bool complete);
 
diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c
index e9b266bb70..6180957edb 100644
--- a/qapi/qapi-util.c
+++ b/qapi/qapi-util.c
@@ -21,8 +21,8 @@ const char *qapi_enum_lookup(const QEnumLookup *lookup, int val)
     return lookup->array[val];
 }
 
-int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
-                    int def, Error **errp)
+int qapi_enum_parse_full(const QEnumLookup *lookup, const char *buf,
+                         int def, bool ignore_case, Error **errp)
 {
     int i;
 
@@ -31,8 +31,14 @@ int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
     }
 
     for (i = 0; i < lookup->size; i++) {
-        if (!strcmp(buf, lookup->array[i])) {
-            return i;
+        if (ignore_case) {
+            if (!strcasecmp(buf, lookup->array[i])) {
+                return i;
+            }
+        } else {
+            if (!strcmp(buf, lookup->array[i])) {
+                return i;
+            }
         }
     }
 
@@ -40,6 +46,12 @@ int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
     return def;
 }
 
+int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
+                    int def, Error **errp)
+{
+    return qapi_enum_parse_full(lookup, buf, def, false, errp);
+}
+
 /*
  * Parse a valid QAPI name from @str.
  * A valid name consists of letters, digits, hyphen and underscore.
-- 
2.14.3

  reply	other threads:[~2018-05-09  5:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09  5:57 [Qemu-devel] [PATCH 0/5] vmdk: Implement x-blockdev-create Fam Zheng
2018-05-09  5:57 ` Fam Zheng [this message]
2018-05-09 11:53   ` [Qemu-devel] [PATCH 1/5] qapi: Add qapi_enum_parse_full Markus Armbruster
2018-05-09  5:57 ` [Qemu-devel] [PATCH 2/5] vmdk: Refactor vmdk_create_extent Fam Zheng
2018-05-09  5:58 ` [Qemu-devel] [PATCH 3/5] vmdk: Implement .bdrv_co_create callback Fam Zheng
2018-05-09 12:41   ` Markus Armbruster
2018-05-09 14:19     ` Fam Zheng
2018-05-09 18:59       ` Markus Armbruster
2018-05-09  5:58 ` [Qemu-devel] [PATCH 4/5] iotests: Filter cid numbers in VMDK extent info Fam Zheng
2018-05-09  5:58 ` [Qemu-devel] [PATCH 5/5] iotests: Add VMDK tests for blockdev-create Fam Zheng
2018-05-09  6:08 ` [Qemu-devel] [PATCH 0/5] vmdk: Implement x-blockdev-create no-reply
2018-05-09  9:35   ` Fam Zheng
2018-05-09  6:10 ` no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180509055802.28423-2-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).