use super::attr::AttrChar;
pub fn skip_quotes<I>(iter: I) -> impl Iterator<Item = AttrChar>
where
I: IntoIterator<Item = AttrChar>,
{
iter.into_iter().filter(|c| !c.is_quoting)
}
pub fn remove_quotes(chars: &mut Vec<AttrChar>) {
chars.retain(|c| !c.is_quoting)
}
#[cfg(test)]
mod tests {
use super::super::attr::Origin;
use super::*;
#[test]
fn test_skip_quotes() {
let a = AttrChar {
value: 'a',
origin: Origin::Literal,
is_quoted: false,
is_quoting: false,
};
let b = AttrChar {
value: 'b',
origin: Origin::Literal,
is_quoted: false,
is_quoting: true,
};
let c = AttrChar {
value: 'c',
origin: Origin::Literal,
is_quoted: true,
is_quoting: false,
};
let d = AttrChar {
value: 'd',
origin: Origin::Literal,
is_quoted: true,
is_quoting: true,
};
let input = [a, b, c, d];
let output = skip_quotes(input).collect::<Vec<_>>();
assert_eq!(output, [a, c]);
}
#[test]
fn test_remove_quotes() {
let a = AttrChar {
value: 'a',
origin: Origin::Literal,
is_quoted: false,
is_quoting: false,
};
let b = AttrChar {
value: 'b',
origin: Origin::Literal,
is_quoted: false,
is_quoting: true,
};
let c = AttrChar {
value: 'c',
origin: Origin::Literal,
is_quoted: true,
is_quoting: false,
};
let d = AttrChar {
value: 'd',
origin: Origin::Literal,
is_quoted: true,
is_quoting: true,
};
let mut chars = vec![a, b, c, d];
remove_quotes(&mut chars);
assert_eq!(chars, [a, c]);
}
}