fn linewidth_max2(a: f64, b: f64) -> f64 { if a > b { return a; } b } fn linewidth_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn linewidth_counts(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value >= 0.0 && value <= 9007199254740991.0 && value % 1.0 == 0.0) { return false; } i += 1; } true } fn linewidth_compute(widths: vector, limit: f64) -> vector { let mut count = 0; let mut first = -1; let mut excess = 0.0; let mut i = 0; while i < len(widths) { let gap = at(widths, i) - limit; if gap > 0.0 { if first < 0 { first = i; } count += 1; excess = linewidth_max2(excess, gap); } i += 1; } [count, first, excess] } // Find overlong source lines from measured display columns. // Returns [overlong rows, first overlong row, largest excess]. The host selects a Unicode display-width convention and supplies widths including indentation. pub fn linewidth_audit(widths: vector, limit: f64) -> vector { if !linewidth_counts(widths) { return []; } if !(limit >= 1.0 && limit <= 9007199254740991.0 && limit % 1.0 == 0.0) { return []; } let result = linewidth_compute(widths, limit); if !linewidth_finite(result) { return []; } result }