MCPcopy Create free account
hub / github.com/astral-sh/ruff / p_str_repr

Method p_str_repr

crates/ruff_python_codegen/src/generator.rs:208–226  ·  view source on GitHub ↗
(&mut self, s: &str, flags: impl Into<AnyStringFlags>)

Source from the content-addressed store, hash-verified

206 }
207
208 fn p_str_repr(&mut self, s: &str, flags: impl Into<AnyStringFlags>) {
209 let flags = flags.into();
210 if flags.prefix().is_raw() {
211 write!(self.buffer, "{}", flags.display_contents(s))
212 .expect("Writing to a String buffer should never fail");
213 return;
214 }
215 self.p(flags.prefix().as_str());
216
217 let quote_style = self.mode.quote_style(flags);
218 let escape = UnicodeEscape::with_preferred_quote(s, quote_style);
219 if let Some(len) = escape.layout().len {
220 self.buffer.reserve(len);
221 }
222 escape
223 .str_repr(flags.triple_quotes())
224 .write(&mut self.buffer)
225 .expect("Writing to a String buffer should never fail");
226 }
227
228 fn p_if(&mut self, cond: bool, s: &str) {
229 if cond {

Callers 1

Calls 10

is_rawMethod · 0.80
expectMethod · 0.80
pMethod · 0.80
layoutMethod · 0.80
str_reprMethod · 0.80
prefixMethod · 0.45
as_strMethod · 0.45
quote_styleMethod · 0.45
writeMethod · 0.45
triple_quotesMethod · 0.45

Tested by

no test coverage detected