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

Function choose_quote

crates/literal/src/escape.rs:73–90  ·  view source on GitHub ↗

Returns the outer quotes to use and the number of quotes that need to be escaped.

(
    single_count: usize,
    double_count: usize,
    preferred_quote: Quote,
)

Source from the content-addressed store, hash-verified

71/// Returns the outer quotes to use and the number of quotes that need to be
72/// escaped.
73pub(crate) const fn choose_quote(
74 single_count: usize,
75 double_count: usize,
76 preferred_quote: Quote,
77) -> (Quote, usize) {
78 let (primary_count, secondary_count) = match preferred_quote {
79 Quote::Single => (single_count, double_count),
80 Quote::Double => (double_count, single_count),
81 };
82
83 // always use primary unless we have primary but no secondary
84 let use_secondary = primary_count > 0 && secondary_count == 0;
85 if use_secondary {
86 (preferred_quote.swap(), secondary_count)
87 } else {
88 (preferred_quote, primary_count)
89 }
90}
91
92pub struct UnicodeEscape<'a> {
93 source: &'a Wtf8,

Callers 2

stopMethod · 0.85

Calls 1

swapMethod · 0.45

Tested by

no test coverage detected