Read a possible string-literal opener at ``i``. Returns ``(prefix_end, quote_run, interpolated, verbatim)``. ``quote_run`` is 0 when no string starts here, and ``prefix_end`` is always where the run of ``$``/``@`` characters stopped — the caller needs that even on a miss, so it can
(source: bytes, i: int)
| 4250 | |
| 4251 | |
| 4252 | def _csharp_string_opener(source: bytes, i: int) -> "tuple[int, int, bool, bool]": |
| 4253 | """Read a possible string-literal opener at ``i``. |
| 4254 | |
| 4255 | Returns ``(prefix_end, quote_run, interpolated, verbatim)``. ``quote_run`` is |
| 4256 | 0 when no string starts here, and ``prefix_end`` is always where the run of |
| 4257 | ``$``/``@`` characters stopped — the caller needs that even on a miss, so it |
| 4258 | can resume past the run instead of re-walking it from the next byte (a long |
| 4259 | run in malformed source would otherwise cost O(n^2)). |
| 4260 | |
| 4261 | C# lets the ``$`` and ``@`` prefixes appear in either order and repeat, and |
| 4262 | a raw string literal opens with a run of three or more quotes, so the prefix |
| 4263 | is read as a set of flags rather than matched as fixed spellings. |
| 4264 | """ |
| 4265 | j = i |
| 4266 | interpolated = False |
| 4267 | verbatim = False |
| 4268 | while j < len(source): |
| 4269 | ch = source[j:j + 1] |
| 4270 | if ch == b"$": |
| 4271 | interpolated = True |
| 4272 | elif ch == b"@": |
| 4273 | verbatim = True |
| 4274 | else: |
| 4275 | break |
| 4276 | j += 1 |
| 4277 | if source[j:j + 1] != b'"': |
| 4278 | return j, 0, interpolated, verbatim |
| 4279 | run = 0 |
| 4280 | while source[j + run:j + run + 1] == b'"': |
| 4281 | run += 1 |
| 4282 | return j, run, interpolated, verbatim |
| 4283 | |
| 4284 | |
| 4285 | def _csharp_broken_escape_offsets(source: bytes) -> list[int]: |
no outgoing calls
no test coverage detected