MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / _strip_strings_and_comments

Function _strip_strings_and_comments

scripts/code-verify.py:163–214  ·  view source on GitHub ↗

Return `line` with string literals and `//` comments blanked out, so bracket-counting on the result ignores brackets that live inside strings or end-of-line comments.

(line: str)

Source from the content-addressed store, hash-verified

161
162
163def _strip_strings_and_comments(line: str) -> str:
164 """Return `line` with string literals and `//` comments blanked out, so
165 bracket-counting on the result ignores brackets that live inside strings
166 or end-of-line comments."""
167 result: list[str] = []
168 i = 0
169 n = len(line)
170 while i < n:
171 ch = line[i]
172
173 # Line comment — drop everything to end-of-line
174 if ch == "/" and i + 1 < n and line[i + 1] == "/":
175 break
176
177 # Double-quoted string
178 if ch == '"':
179 result.append(" ")
180 i += 1
181 while i < n:
182 if line[i] == "\\" and i + 1 < n:
183 i += 2
184 result.append(" ")
185 continue
186 if line[i] == '"':
187 result.append(" ")
188 i += 1
189 break
190 result.append(" ")
191 i += 1
192 continue
193
194 # Single-quoted string (JS string literal)
195 if ch == "'":
196 result.append(" ")
197 i += 1
198 while i < n:
199 if line[i] == "\\" and i + 1 < n:
200 i += 2
201 result.append(" ")
202 continue
203 if line[i] == "'":
204 result.append(" ")
205 i += 1
206 break
207 result.append(" ")
208 i += 1
209 continue
210
211 result.append(ch)
212 i += 1
213
214 return "".join(result)
215
216
217def _bracket_delta(line: str) -> int:

Callers 6

_bracket_deltaFunction · 0.85
_brace_delta_rawFunction · 0.85
_has_trailing_operatorFunction · 0.85
opens_js_bodyFunction · 0.85
is_run_safeFunction · 0.85
_strip_eol_commentFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected