use std::borrow::Cow;
use crate::po::format::language::Language;
pub mod iter;
pub mod lang_c;
pub mod lang_null;
pub mod lang_python;
pub mod language;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MatchFmtPos<'a> {
pub s: &'a str,
pub start: usize,
pub end: usize,
}
pub trait FormatParser {
fn next_char(&self, _s: &str, _pos: usize) -> Option<(char, usize, bool)>;
fn find_end_format(&self, _s: &str, _pos: usize, len: usize) -> usize;
}
pub fn strip_formats<'a>(s: &'a str, language: &Language) -> Cow<'a, str> {
if language == &Language::Null {
Cow::Borrowed(s)
} else {
let len_s = s.len();
let mut result = String::with_capacity(len_s);
let mut pos = 0;
let fmt = language.format_parser();
while let Some((c, new_pos, is_format)) = fmt.next_char(s, pos) {
if is_format {
pos = fmt.find_end_format(s, new_pos, len_s);
} else {
result.push(c);
pos = new_pos;
}
}
Cow::Owned(result)
}
}