From 4ece4de43b29da747e18447d0de0480ff36545bf Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Thu, 4 Jun 2015 20:48:10 +0200 Subject: Refactor and optimize _strip_quotes(). Use the fact that startswith() can check multiple prefixes. --- kconfiglib.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index abc42ca..c9613de 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -3668,12 +3668,10 @@ def tri_greater_eq(v1, v2): # def _strip_quotes(s, line, filename, linenr): - """Removes any quotes surrounding 's' if it has them; otherwise returns 's' - unmodified.""" + """Strips leading and trailing whitespace from 's' and then strips any + surrounding quotes.""" s = s.strip() - if not s: - return "" - if s[0] == '"' or s[0] == "'": + if s.startswith(('"', "'")): if len(s) < 2 or s[-1] != s[0]: _parse_error(line, "malformed string literal", -- cgit v1.2.3