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

Method normalize

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

Computes the strings preferred quotes and normalizes its content.

(&self, string: StringLikePart)

Source from the content-addressed store, hash-verified

235
236 /// Computes the strings preferred quotes and normalizes its content.
237 pub(crate) fn normalize(&self, string: StringLikePart) -> NormalizedString<'src> {
238 let raw_content = &self.context.source()[string.content_range()];
239 let quote_selection = self.choose_quotes(string);
240
241 let normalized = if let Some(first_quote_or_escape_offset) =
242 quote_selection.first_quote_or_normalized_char_offset
243 {
244 normalize_string(
245 raw_content,
246 first_quote_or_escape_offset,
247 quote_selection.flags,
248 false,
249 )
250 } else {
251 Cow::Borrowed(raw_content)
252 };
253
254 NormalizedString {
255 flags: quote_selection.flags,
256 content_range: string.content_range(),
257 text: normalized,
258 }
259 }
260}
261
262#[derive(Debug)]

Callers 5

fFunction · 0.45
normalize_stringFunction · 0.45
fmt_fieldsMethod · 0.45
fmt_fieldsMethod · 0.45

Calls 11

normalize_stringFunction · 0.85
choose_quotesMethod · 0.80
len_utf8Method · 0.80
sourceMethod · 0.45
content_rangeMethod · 0.45
lenMethod · 0.45
takeMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45
push_strMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected