@@ -121,14 +121,24 @@ def _strip_line(single_line):
121121 return single_line
122122
123123 within_quotes = False
124- parts = []
125- for part in re .split ('"' , single_line ):
126- if within_quotes :
127- parts .append (part )
124+ quote_char = None
125+ result = []
126+ for char in single_line :
127+ if char in ['"' , "'" ]:
128+ if within_quotes :
129+ if char == quote_char :
130+ within_quotes = False
131+ quote_char = None
132+ else :
133+ within_quotes = True
134+ quote_char = char
135+ result .append (char )
136+ elif not within_quotes and re .match (r'\s' , char ):
137+ if result [- 1 ] != ' ' :
138+ result .append (' ' )
128139 else :
129- parts .append (re .sub (r'[\s]+' , ' ' , part ))
130- within_quotes = not within_quotes
131- return '"' .join (parts )
140+ result .append (char )
141+ return '' .join (result )
132142
133143 @staticmethod
134144 def _count_multi_semicolon (single_line ):
@@ -138,14 +148,21 @@ def _count_multi_semicolon(single_line):
138148 return 0 , 0
139149
140150 within_quotes = False
151+ quote_char = None
141152 q = 0
142153 c = 0
143- for part in re .split ('"' , single_line ):
144- if within_quotes :
145- q = 1
146- else :
147- c += part .count (';' )
148- within_quotes = not within_quotes
154+ for char in single_line :
155+ if char in ['"' , "'" ]:
156+ if within_quotes :
157+ if char == quote_char :
158+ within_quotes = False
159+ quote_char = None
160+ else :
161+ within_quotes = True
162+ quote_char = char
163+ q = 1
164+ elif not within_quotes and char == ';' :
165+ c += 1
149166 return q , c
150167
151168 @staticmethod
@@ -156,14 +173,23 @@ def _multi_semicolon(single_line):
156173 return single_line
157174
158175 within_quotes = False
159- parts = []
160- for part in re .split ('"' , single_line ):
161- if within_quotes :
162- parts .append (part )
176+ quote_char = None
177+ result = []
178+ for char in single_line :
179+ if char in ['"' , "'" ]:
180+ if within_quotes :
181+ if char == quote_char :
182+ within_quotes = False
183+ quote_char = None
184+ else :
185+ within_quotes = True
186+ quote_char = char
187+ result .append (char )
188+ elif not within_quotes and char == ';' :
189+ result .append (";\n " )
163190 else :
164- parts .append (part .replace (";" , ";\n " ))
165- within_quotes = not within_quotes
166- return '"' .join (parts )
191+ result .append (char )
192+ return '' .join (result )
167193
168194 def _apply_variable_template_tags (self , line : str ) -> str :
169195 """Replaces variable indicators ${ and } with tags, so subsequent formatting is easier."""
0 commit comments