Align columns: Difference between revisions
m
→{{header|Rust}}: Applied rustfmt, updated trim_right_matches to trim_end_matches
(Added Wren) |
m (→{{header|Rust}}: Applied rustfmt, updated trim_right_matches to trim_end_matches) |
||
Line 6,798:
=={{header|Rust}}==
<lang rust>use std::iter::{
enum AlignmentType {
Left,
Center,
Right,
}
fn get_column_widths(text: &str) -> Vec<usize> {
let mut widths = Vec::new();
for line in text
.map(|s| s.trim_matches(' ').trim_end_matches('$'))
{
let lens = line.split('$').map(|s| s.chars().count());
for
if idx < widths.len() {
widths[idx] = std::cmp::max(widths[idx], len);
} else {
▲ else {
widths.push(len);
}
Line 6,821 ⟶ 6,827:
let widths = get_column_widths(text);
let mut result = String::new();
for line in text
.lines()
.map(|s| s.trim_matches(' ').trim_end_matches('$'))
{
for (s, w) in line.split('$').zip(widths.iter()) {
let blank_count = w - s.chars().count();
|