MCPcopy Index your code
hub / github.com/RustPython/RustPython / strip_fstring_debug_comments

Function strip_fstring_debug_comments

crates/codegen/src/compile.rs:10563–10579  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

10561/// A comment starts with `#` and extends to the end of the line.
10562/// The newline character itself is preserved.
10563fn 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)]
10582mod ruff_tests {

Callers 1

Calls 3

charsMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected