pub(super) fn get_indent(line: &str) -> usize {
line.len() - line.trim_start().len()
}
pub(super) fn is_comment_line(trimmed: &str, lang: &str) -> bool {
match lang {
"python" | "py" => trimmed.starts_with('#'),
_ => {
trimmed.starts_with("//")
|| trimmed.starts_with("/*")
|| trimmed.starts_with('*')
|| trimmed.starts_with("*/")
}
}
}
pub(super) fn count_keyword(line: &str, keyword: &str) -> usize {
let mut count = 0;
let mut pos = 0;
while let Some(idx) = line[pos..].find(keyword) {
let abs_pos = pos + idx;
let before_ok = abs_pos == 0
|| !line[..abs_pos]
.chars()
.last()
.map(|c| c.is_alphanumeric() || c == '_')
.unwrap_or(false);
if before_ok {
count += 1;
}
pos = abs_pos + keyword.len();
}
count
}