pub struct CharDrip {
chars : Vec<char>,
position : usize,
}
impl CharDrip {
pub fn new (chars: Vec<char>) -> CharDrip {
CharDrip {chars: chars, position: 0}
}
pub fn read (&mut self) -> Option<char> {
if self.position >= self.chars.len () {
return None;
} else {
self.position += 1;
return Some(self.chars[self.position-1]);
}
}
pub fn unread (&mut self) {
debug_assert! (self.position > 0);
if self.position > 0 {
self.position -= 1;
}
}
}
pub fn skip_blanks (dripper : &mut CharDrip) -> String {
let mut blanks = String::from("");
loop {
match dripper.read () {
Some(c) => {
if c.is_ascii_whitespace () {
blanks.push (c);
} else {
dripper.unread ();
return blanks;
}
},
None => {
return blanks;
},
}
}
}
pub fn skip_non_alphabetic (dripper : &mut CharDrip) -> String {
let mut ignored = String::from("");
loop {
match dripper.read () {
Some(c) => {
if c.is_alphabetic () {
dripper.unread ();
return ignored;
} else {
ignored.push (c);
}
},
None => {
return ignored;
},
}
}
}