[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v11 02/24] qapi: More idiomatic string operations
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v11 02/24] qapi: More idiomatic string operations |
Date: |
Mon, 26 Oct 2015 16:34:41 -0600 |
Rather than slicing the end of a string, we can use python's
endswith(). And rather than creating a set of characters,
we can search for a character within a string.
Signed-off-by: Eric Blake <address@hidden>
---
v11: no change
v10: new patch
---
scripts/qapi.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 9d53255..3af4c2c 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -172,7 +172,7 @@ class QAPISchemaParser(object):
if self.tok == '#':
self.cursor = self.src.find('\n', self.cursor)
- elif self.tok in ['{', '}', ':', ',', '[', ']']:
+ elif self.tok in "{}:,[]":
return
elif self.tok == "'":
string = ''
@@ -390,7 +390,7 @@ def add_name(name, info, meta, implicit=False):
raise QAPIExprError(info,
"%s '%s' is already defined"
% (all_names[name], name))
- if not implicit and name[-4:] == 'Kind':
+ if not implicit and name.endswith('Kind'):
raise QAPIExprError(info,
"%s '%s' should not end in 'Kind'"
% (meta, name))
@@ -910,7 +910,7 @@ class QAPISchemaEnumType(QAPISchemaType):
def is_implicit(self):
# See QAPISchema._make_implicit_enum_type()
- return self.name[-4:] == 'Kind'
+ return self.name.endswith('Kind')
def c_type(self, is_param=False):
return c_name(self.name)
--
2.4.3
- [Qemu-devel] [PATCH v11 24/24] qapi: Simplify gen_struct_field(), (continued)
- [Qemu-devel] [PATCH v11 24/24] qapi: Simplify gen_struct_field(), Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 21/24] tpm: Convert to new qapi union layout, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 22/24] qapi: Finish converting to new qapi union layout, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 15/24] block: Convert to new qapi union layout, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 03/24] qapi: More robust conditions for when labels are needed, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 23/24] qapi: Reserve 'u' member name, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 16/24] sockets: Convert to new qapi union layout, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 17/24] net: Convert to new qapi union layout, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 18/24] char: Convert to new qapi union layout, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 02/24] qapi: More idiomatic string operations,
Eric Blake <=
- [Qemu-devel] [PATCH v11 19/24] input: Convert to new qapi union layout, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 06/24] vnc: Hoist allocation of VncBasicInfo to callers, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 20/24] memory: Convert to new qapi union layout, Eric Blake, 2015/10/26
- Re: [Qemu-devel] [PATCH v11 00/24] qapi collision reduction (post-introspection subset B'), Markus Armbruster, 2015/10/27