@@ -213,7 +213,10 @@ def escape_ascii(s, encoding):
213213def  escape_nonascii (s , encoding ):
214214    return  '' .join (escapes [b ] for  b  in  s .encode (encoding ))
215215
216- space_splitter  =  re .compile (r'(\s+)' ).split 
216+ # Split a string according to whitespaces and keep 
217+ # the whitespaces in the resulting array thanks to 
218+ # the capturing group. 
219+ _space_splitter  =  re .compile (r'(\s+)' ).split 
217220
218221def  normalize (s , encoding , options ):
219222    # This converts the various Python string types into a format that is 
@@ -222,16 +225,17 @@ def normalize(s, encoding, options):
222225    lines  =  []
223226    for  line  in  s .splitlines (True ):
224227        if  len (escape (line , encoding )) >  options .width :
225-             words  =  space_splitter (line )
228+             words  =  _space_splitter (line )
226229            words .reverse ()
227230            buf  =  []
228231            size  =  0 
229232            while  words :
230233                word  =  words .pop ()
231234                escaped_word_len  =  len (escape (word , encoding ))
232-                 if  size  +  escaped_word_len  <=  options .width :
235+                 new_size  =  size  +  escaped_word_len 
236+                 if  new_size  <=  options .width :
233237                    buf .append (word )
234-                     size  +=   escaped_word_len 
238+                     size  =   new_size 
235239                else :
236240                    lines .append ('' .join (buf ))
237241                    buf  =  [word ]
@@ -241,7 +245,7 @@ def normalize(s, encoding, options):
241245            lines .append (line )
242246    if  len (lines ) <=  1 :
243247        return  f'"{ escape (s , encoding )}  
244-     return  '""\n '  +  '\n ' .join ([ f'"{ escape (line , encoding )}   for  line  in  lines ] )
248+     return  '""\n '  +  '\n ' .join (f'"{ escape (line , encoding )}   for  line  in  lines )
245249
246250
247251def  containsAny (str , set ):
0 commit comments