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

Method regular

crates/ruff_python_formatter/src/string/normalize.rs:552–574  ·  view source on GitHub ↗

For single quoted strings, the preferred quote style is used, unless the alternative quote style would require fewer escapes.

(text: &str)

Source from the content-addressed store, hash-verified

550 /// For single quoted strings, the preferred quote style is used, unless the alternative quote style
551 /// would require fewer escapes.
552 fn regular(text: &str) -> Self {
553 let mut single_quotes = 0u32;
554 let mut double_quotes = 0u32;
555
556 for c in text.chars() {
557 match c {
558 '\'' => {
559 single_quotes += 1;
560 }
561
562 '"' => {
563 double_quotes += 1;
564 }
565
566 _ => continue,
567 }
568 }
569
570 Self::Regular {
571 single_quotes,
572 double_quotes,
573 }
574 }
575
576 /// Computes if a raw string uses the preferred quote. If it does, then it's not possible
577 /// to change the quote style because it would require escaping which isn't possible in raw strings.

Callers

nothing calls this directly

Calls 1

charsMethod · 0.45

Tested by

no test coverage detected