(body: &str, pad: usize, align: u8, fill: char, sign_prefix_len: usize)
| 361 | } |
| 362 | |
| 363 | fn 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 | |
| 395 | fn fixed(mag: f64, prec: usize) -> String { |
| 396 | // Round-half-to-even to `prec` decimals; renders manually to avoid `alloc::format!`'s %f. |
no test coverage detected