pub fn replicate(c: char, n: usize) -> String {
let mut string = String::new();
for _ in 0..n {
string.push(c);
}
string
}
pub fn is_new_line(content: &str, byte: usize) -> bool {
content.is_char_boundary(byte)
&& content.is_char_boundary(byte + 1)
&& &content[byte..byte + 1] == "\n"
}
pub fn compute_column(content: &str, start: usize, current: usize) -> usize {
let mut column = 0;
let mut pointer = start;
for c in content[start..].chars() {
if pointer == current {
break;
}
column += 1;
pointer += c.len_utf8();
}
column
}
pub fn previous_new_line(content: &str, byte: usize) -> usize {
let mut i = byte;
while i != 0 && !is_new_line(content, i) {
i -= 1;
}
if &content[i..i + 1] == "\n" {
i + 1
} else {
i
}
}
pub fn next_new_line(content: &str, byte: usize) -> usize {
let mut i = byte;
while i != content.len() && !is_new_line(content, i) {
i += 1;
}
i
}