Skip to content

Commit

Permalink
Merge pull request #2 from RobinJadoul/master
Browse files Browse the repository at this point in the history
Change usage of `.len()` to `.chars().count()`
  • Loading branch information
cyanpencil authored Dec 4, 2020
2 parents f64d86a + bd2008c commit a109610
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ctfwatch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,19 @@ fn format_duration(d: &Duration) -> String {
tmp.join(" ")
}

fn strip_ansi(s: &String) -> String {
String::from_utf8(strip_ansi_escapes::strip(s).unwrap()).unwrap()
}

fn extra_bytes (s1: &String) -> usize {
s1.len() - strip_ansi_escapes::strip(&s1).unwrap().len()
s1.chars().count() - strip_ansi(&s1).chars().count()
}

fn double_line (s1: &String, s2: &String) -> String {
let mut fin = format!("│ {}", s1);
let fin_len = strip_ansi_escapes::strip(&fin).unwrap().len();
let fin_len2 = strip_ansi_escapes::strip(&s2).unwrap().len();
fin.push_str(&format!(" {: >1$} │", format!(" {}", s2), LEN + 1 - fin_len + (s2.len() - fin_len2)));
let fin_len = strip_ansi(&fin).chars().count();
let fin_len2 = strip_ansi(&s2).chars().count();
fin.push_str(&format!(" {: >1$} │", format!(" {}", s2), LEN - 1 - fin_len + (s2.chars().count() - fin_len2)));
fin
}

Expand Down

0 comments on commit a109610

Please sign in to comment.