use std::str::Chars;
pub struct CommaIter<'a> {
chars: Chars<'a>,
}
impl<'a> CommaIter<'a> {
pub fn new(string: &'a str) -> Self {
Self {
chars: string.chars(),
}
}
}
impl<'a> Iterator for CommaIter<'a> {
type Item = &'a str;
fn next(&mut self) -> Option<Self::Item> {
let chars_clone = self.chars.clone();
let mut i = 0;
while let Some(char) = self.chars.next() {
match char {
'(' => {
for close_paren in self.chars.by_ref() {
i += 1;
if close_paren == ')' {
break;
}
}
}
',' => break,
_ => {}
}
i += 1;
}
match i {
0 => None,
_ => Some(&chars_clone.as_str()[..i]),
}
}
}