From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, akong@redhat.com, berto@igalia.com,
armbru@redhat.com, mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v3 07/14] qapi: Move camel_to_upper(), c_enum_const() to closely related code
Date: Tue, 5 May 2015 06:30:48 -0600 [thread overview]
Message-ID: <1430829055-4739-8-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1430829055-4739-1-git-send-email-eblake@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi.py | 50 +++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 967dadb..b9822c6 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -742,6 +742,31 @@ def camel_case(name):
new_name += ch.lower()
return new_name
+# ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1
+# ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAME2
+# ENUM24_Name -> ENUM24_NAME
+def camel_to_upper(value):
+ c_fun_str = c_name(value, False)
+ if value.isupper():
+ return c_fun_str
+
+ new_name = ''
+ l = len(c_fun_str)
+ for i in range(l):
+ c = c_fun_str[i]
+ # When c is upper and no "_" appears before, do more checks
+ if c.isupper() and (i > 0) and c_fun_str[i - 1] != "_":
+ # Case 1: next string is lower
+ # Case 2: previous string is digit
+ if (i < (l - 1) and c_fun_str[i + 1].islower()) or \
+ c_fun_str[i - 1].isdigit():
+ new_name += '_'
+ new_name += c
+ return new_name.lstrip('_').upper()
+
+def c_enum_const(type_name, const_name):
+ return camel_to_upper(type_name + '_' + const_name)
+
c_name_trans = string.maketrans('.-', '__')
def c_name(name, protect=True):
@@ -926,28 +951,3 @@ def guardend(name):
''',
name=guardname(name))
-
-# ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1
-# ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAME2
-# ENUM24_Name -> ENUM24_NAME
-def camel_to_upper(value):
- c_fun_str = c_name(value, False)
- if value.isupper():
- return c_fun_str
-
- new_name = ''
- l = len(c_fun_str)
- for i in range(l):
- c = c_fun_str[i]
- # When c is upper and no "_" appears before, do more checks
- if c.isupper() and (i > 0) and c_fun_str[i - 1] != "_":
- # Case 1: next string is lower
- # Case 2: previous string is digit
- if (i < (l - 1) and c_fun_str[i + 1].islower()) or \
- c_fun_str[i - 1].isdigit():
- new_name += '_'
- new_name += c
- return new_name.lstrip('_').upper()
-
-def c_enum_const(type_name, const_name):
- return camel_to_upper(type_name + '_' + const_name)
--
2.1.0
next prev parent reply other threads:[~2015-05-05 12:31 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-05 12:30 [Qemu-devel] [PATCH v3 00/14] Fix qapi mangling of downstream names Eric Blake
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 01/14] qapi: Fix C identifiers generated for names containing '.' Eric Blake
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 02/14] qapi: Rename identical c_fun()/c_var() into c_name() Eric Blake
2015-05-07 7:39 ` Markus Armbruster
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 03/14] qapi: Rename _generate_enum_string() to camel_to_upper() Eric Blake
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 04/14] qapi: Rename generate_enum_full_value() to c_enum_const() Eric Blake
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 05/14] qapi: Simplify c_enum_const() Eric Blake
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 06/14] qapi: Use c_enum_const() in generate_alternate_qtypes() Eric Blake
2015-05-05 12:30 ` Eric Blake [this message]
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 08/14] qapi: Make c_type() consistently convert qapi names Eric Blake
2015-05-07 7:39 ` Markus Armbruster
2015-05-14 3:38 ` Eric Blake
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 09/14] qapi: Support downstream enums Eric Blake
2015-05-07 7:47 ` Markus Armbruster
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 10/14] qapi: Support downstream structs Eric Blake
2015-05-07 7:48 ` Markus Armbruster
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 11/14] qapi: Support downstream simple unions Eric Blake
2015-05-07 7:49 ` Markus Armbruster
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 12/14] qapi: Support downstream flat unions Eric Blake
2015-05-07 7:49 ` Markus Armbruster
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 13/14] qapi: Support downstream alternates Eric Blake
2015-05-07 7:50 ` Markus Armbruster
2015-05-05 12:30 ` [Qemu-devel] [PATCH v3 14/14] qapi: Support downstream events and commands Eric Blake
2015-05-07 7:53 ` Markus Armbruster
2015-05-12 15:37 ` [Qemu-devel] [PATCH v3 00/14] Fix qapi mangling of downstream names Markus Armbruster
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=1430829055-4739-8-git-send-email-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=akong@redhat.com \
--cc=armbru@redhat.com \
--cc=berto@igalia.com \
--cc=kwolf@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--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).