On Thursday, November 24, 2016 at 3:07:21 PM UTC+1, Edward K. Ream wrote: > > On Saturday, November 12, 2016 at 12:32:55 PM UTC-6, Terry Brown wrote: >> >> That tripped me up too, empty strings are OK if you're using 'not >> s.isspace()'. >> > > ...
> The bug in i.check was serious. In essence, it caused i.check to ignored > all blank lines! And it masked a similar bug in the xml importer. > > While making i.check line-oriented (more about this in another post) I > came across this code: > > def strip_lws(self, lines): > '''Strip leading whitespace from all lines of s.''' > return ''.join([z.lstrip() for z in g.splitLines(s)]) > > Because of our conversation here, I realized that this was wrong, wrong, > wrong. Thank you, Terry and Reinhard, for burning this issue into my > consciousness! > > Eventually, the code got replaced with: > > def strip_lws(self, lines): > '''Strip leading whitespace from all lines of s.''' > return [self.lstrip_line(z) for z in lines] > > All this goes to show that the i.check's helpers should be covered by unit > tests! > > Why use two functions, when one suffices? def strip_lws(s): return '\n'.join([z.lstrip() for z in s.splitlines(False)]) Just remove the lineends when splitting the string and add it in when rejoining them. -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at https://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.