1pub fn calculate_ratio(matches: usize, length: usize) -> f32 {
2 if length != 0 {
3 return 2.0 * matches as f32 / length as f32;
4 }
5 1.0
6}
7
8pub fn str_with_similar_chars(c: char, length: usize) -> String {
9 let mut s = String::new();
10 for _ in 0..length {
11 s.push_str(&c.to_string());
12 }
13 s
14}
15
16pub fn count_leading(line: &str, c: char) -> usize {
17 let (mut i, n) = (0, line.len());
18 let line: Vec<char> = line.chars().collect();
19 while (i < n) && line[i] == c {
20 i += 1;
21 }
22 i
23}
24
25pub fn format_range_unified(start: usize, end: usize) -> String {
26 let mut beginning = start + 1;
27 let length = end - start;
28 if length == 1 {
29 return beginning.to_string();
30 }
31 if length == 0 {
32 beginning -= 1;
33 }
34 format!("{},{}", beginning, length)
35}
36
37pub fn format_range_context(start: usize, end: usize) -> String {
38 let mut beginning = start + 1;
39 let length = end - start;
40 if length == 0 {
41 beginning -= 1
42 }
43 if length <= 1 {
44 return beginning.to_string();
45 }
46 format!("{},{}", beginning, beginning + length - 1)
47}
48