MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / pad_with

Function pad_with

compiler/src/modules/vm/handlers/format.rs:363–393  ·  view source on GitHub ↗
(body: &str, pad: usize, align: u8, fill: char, sign_prefix_len: usize)

Source from the content-addressed store, hash-verified

361}
362
363fn pad_with(body: &str, pad: usize, align: u8, fill: char, sign_prefix_len: usize) -> String {
364 let mut out = String::new();
365 match align {
366 b'<' => {
367 out.push_str(body);
368 for _ in 0..pad { out.push(fill); }
369 }
370 b'>' => {
371 for _ in 0..pad { out.push(fill); }
372 out.push_str(body);
373 }
374 b'^' => {
375 let l = pad / 2;
376 let r = pad - l;
377 for _ in 0..l { out.push(fill); }
378 out.push_str(body);
379 for _ in 0..r { out.push(fill); }
380 }
381 b'=' => {
382 /* Sign-aware: insert padding between the sign/prefix and the digits. */
383 let mut chars = body.chars();
384 for _ in 0..sign_prefix_len {
385 if let Some(c) = chars.next() { out.push(c); }
386 }
387 for _ in 0..pad { out.push(fill); }
388 out.push_str(chars.as_str());
389 }
390 _ => unreachable!(),
391 }
392 out
393}
394
395fn fixed(mag: f64, prec: usize) -> String {
396 // Round-half-to-even to `prec` decimals; renders manually to avoid `alloc::format!`'s %f.

Callers 2

pad_stringFunction · 0.85
pad_alignedFunction · 0.85

Calls 3

pushMethod · 0.80
nextMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected