OSDN Git Service

qapi: More idiomatic string operations
authorEric Blake <eblake@redhat.com>
Mon, 26 Oct 2015 22:34:41 +0000 (16:34 -0600)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 2 Nov 2015 07:30:26 +0000 (08:30 +0100)
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 <eblake@redhat.com>
Message-Id: <1445898903-12082-3-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
scripts/qapi.py

index 9d53255..3af4c2c 100644 (file)
@@ -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)