[libvirt] [PATCH 22/22] apibuild: Simplify parsing string tokens

Radostin Stoyanov posted 22 patches 7 years, 3 months ago
[libvirt] [PATCH 22/22] apibuild: Simplify parsing string tokens
Posted by Radostin Stoyanov 7 years, 3 months ago
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).

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
---
 docs/apibuild.py | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/docs/apibuild.py b/docs/apibuild.py
index 24e0eb505..f2971db5b 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -484,28 +484,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
 
-- 
2.14.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 22/22] apibuild: Simplify parsing string tokens
Posted by Daniel P. Berrangé 7 years, 3 months ago
On Sat, Mar 17, 2018 at 02:23:40PM +0000, Radostin Stoyanov wrote:
> 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).
> 
> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
> ---
>  docs/apibuild.py | 32 ++++++++++----------------------
>  1 file changed, 10 insertions(+), 22 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list