[libvirt] [PATCH 17/22] apibuild: Simplify strip_lead_star()

Radostin Stoyanov posted 22 patches 7 years, 3 months ago
[libvirt] [PATCH 17/22] apibuild: Simplify strip_lead_star()
Posted by Radostin Stoyanov 7 years, 3 months ago
The method strip_lead_star() removes a single leading asterisk
character from a string by ignoring leading whitespace, otherwise it
returns the original string.

This could be achieved with a single if-statement followed by replace.

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

diff --git a/docs/apibuild.py b/docs/apibuild.py
index 9e73b4d27..b914b1dce 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -722,15 +722,8 @@ class CParser:
         self.index.info = res
 
     def strip_lead_star(self, line):
-        l = len(line)
-        i = 0
-        while i < l:
-            if line[i] == ' ' or line[i] == '\t':
-                i += 1
-            elif line[i] == '*':
-                return line[:i] + line[i + 1:]
-            else:
-                return line
+        if line.lstrip().startswith('*'):
+            line = line.replace('*', '', 1)
         return line
 
     def cleanupComment(self):
-- 
2.14.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 17/22] apibuild: Simplify strip_lead_star()
Posted by Daniel P. Berrangé 7 years, 3 months ago
On Sat, Mar 17, 2018 at 02:23:35PM +0000, Radostin Stoyanov wrote:
> The method strip_lead_star() removes a single leading asterisk
> character from a string by ignoring leading whitespace, otherwise it
> returns the original string.
> 
> This could be achieved with a single if-statement followed by replace.
> 
> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
> ---
>  docs/apibuild.py | 11 ++---------
>  1 file changed, 2 insertions(+), 9 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