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

Method fill_string

crates/common/src/cformat.rs:325–353  ·  view source on GitHub ↗
(
        &self,
        string: T,
        fill_char: T::Char,
        num_prefix_chars: Option<usize>,
    )

Source from the content-addressed store, hash-verified

323 }
324
325 fn fill_string<T: FormatBuf>(
326 &self,
327 string: T,
328 fill_char: T::Char,
329 num_prefix_chars: Option<usize>,
330 ) -> T {
331 let mut num_chars = string.chars().count();
332 if let Some(num_prefix_chars) = num_prefix_chars {
333 num_chars += num_prefix_chars;
334 }
335 let num_chars = num_chars;
336
337 let width = match &self.min_field_width {
338 Some(CFormatQuantity::Amount(width)) => cmp::max(width, &num_chars),
339 _ => &num_chars,
340 };
341 let fill_chars_needed = width.saturating_sub(num_chars);
342 let fill_string: T = Self::compute_fill_string(fill_char, fill_chars_needed);
343
344 if !fill_string.is_empty() {
345 if self.flags.contains(CConversionFlags::LEFT_ADJUST) {
346 string.concat(fill_string)
347 } else {
348 fill_string.concat(string)
349 }
350 } else {
351 string
352 }
353 }
354
355 fn fill_string_with_precision<T: FormatBuf>(&self, string: T, fill_char: T::Char) -> T {
356 let num_chars = string.chars().count();

Callers 3

format_numberMethod · 0.80
format_floatMethod · 0.80

Calls 6

maxFunction · 0.85
charsMethod · 0.80
countMethod · 0.45
is_emptyMethod · 0.45
containsMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected