Strip Python comments from f-string debug text (leading/trailing around `=`). A comment starts with `#` and extends to the end of the line. The newline character itself is preserved.
(text: &str)
| 10561 | /// A comment starts with `#` and extends to the end of the line. |
| 10562 | /// The newline character itself is preserved. |
| 10563 | fn strip_fstring_debug_comments(text: &str) -> String { |
| 10564 | let mut result = String::with_capacity(text.len()); |
| 10565 | let mut in_comment = false; |
| 10566 | for ch in text.chars() { |
| 10567 | if in_comment { |
| 10568 | if ch == '\n' { |
| 10569 | in_comment = false; |
| 10570 | result.push(ch); |
| 10571 | } |
| 10572 | } else if ch == '#' { |
| 10573 | in_comment = true; |
| 10574 | } else { |
| 10575 | result.push(ch); |
| 10576 | } |
| 10577 | } |
| 10578 | result |
| 10579 | } |
| 10580 | |
| 10581 | #[cfg(test)] |
| 10582 | mod ruff_tests { |
no test coverage detected