Jump to content

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::{Extendrepeat, repeatExtend};
 
enum AlignmentType { Left, Center, Right }
Left,
Center,
Right,
}
 
fn get_column_widths(text: &str) -> Vec<usize> {
let mut widths = Vec::new();
for line in text.lines().map(|s| s.trim_matches(' ').trim_right_matches('$')) {
else {.lines()
.map(|s| s.trim_matches(' ').trim_end_matches('$'))
{
let lens = line.split('$').map(|s| s.chars().count());
for (idx, len) in lens.enumerate() {
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_right_matches('$')) {
.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();
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.