]> xenbits.xensource.com Git - libvirt.git/commitdiff
apibuild: Simplify parsing string tokens
authorRadostin Stoyanov <rstoyanov1@gmail.com>
Tue, 20 Mar 2018 06:49:06 +0000 (06:49 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 20 Mar 2018 12:13:36 +0000 (12:13 +0000)
Improve readability and reduce the complexity of the code that is
searching for string tokens (i.e. characters surrounded by a single
or double quote).

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
docs/apibuild.py

index 4c8fa574098eb1084f22a3a67ee394dba11492bb..94de13b566bba3730c43a391a61386b021a95927 100755 (executable)
@@ -483,28 +483,16 @@ class CLexer:
                 break
             l = len(line)
             if line[0] == '"' or line[0] == "'":
-                end = line[0]
-                line = line[1:]
-                found = 0
-                tok = ""
-                while found == 0:
-                    i = 0
-                    l = len(line)
-                    while i < l:
-                        if line[i] == end:
-                            self.line = line[i+1:]
-                            line = line[:i]
-                            l = i
-                            found = 1
-                            break
-                        if line[i] == '\\':
-                            i = i + 1
-                        i = i + 1
-                    tok = tok + line
-                    if found == 0:
-                        line = self.getline()
-                        if line is None:
-                            return None
+                quote = line[0]
+                i = 1
+                while quote not in line[i:]:
+                    i = len(line)
+                    nextline = self.getline()
+                    if nextline is None:
+                        return None
+                    line += nextline
+
+                tok, self.line = line[1:].split(quote, 1)
                 self.last = ('string', tok)
                 return self.last