From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtBBI-00049y-Ey for qemu-devel@nongnu.org; Mon, 02 Nov 2015 04:13:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtBBF-0002Py-S1 for qemu-devel@nongnu.org; Mon, 02 Nov 2015 04:13:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtBBF-0002Pl-Mu for qemu-devel@nongnu.org; Mon, 02 Nov 2015 04:13:33 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 4D6F1D9F for ; Mon, 2 Nov 2015 09:13:33 +0000 (UTC) From: Markus Armbruster Date: Mon, 2 Nov 2015 10:13:08 +0100 Message-Id: <1446455610-15739-4-git-send-email-armbru@redhat.com> In-Reply-To: <1446455610-15739-1-git-send-email-armbru@redhat.com> References: <1446455610-15739-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PULL v2 03/25] qapi: More idiomatic string operations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Eric Blake 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 Message-Id: <1445898903-12082-3-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- 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